]> Chaos Git - corbenik/ctrulib.git/commitdiff
APT : added ability to specify APPID to aptInit
authorsmea <smealum@gmail.com>
Sat, 1 Feb 2014 18:56:36 +0000 (19:56 +0100)
committersmea <smealum@gmail.com>
Sat, 1 Feb 2014 18:56:36 +0000 (19:56 +0100)
arm11u/source/main.c
libctru/include/ctr/APT.h
libctru/include/ctr/SOC.h
libctru/include/ctr/svc.h
libctru/source/APT.c
sdmc/source/main.c

index 3f49a562c6750a01a33367db90facd6cd125d257..1cfed164d2aca9f6b0a75ea556c7a596a7b65dfb 100644 (file)
@@ -104,7 +104,7 @@ int main()
 {
        initSrv();
        
-       aptInit();
+       aptInit(APPID_APPLICATION);
 
        gspGpuInit();
 
index 60e7d750ef7688e05c8bf0ae210302e357c903e9..505d7cda0970507353bfb3ed91bb0a05a833badd 100644 (file)
@@ -8,15 +8,21 @@ typedef enum{
        APPID_APPLICATION = 0x300, // Application
 }NS_APPID; // cf http://3dbrew.org/wiki/NS#AppIDs
 
+typedef enum{
+       APP_RUNNING,
+       APP_SUSPENDED,
+       APP_EXITING
+}APP_STATUS;
+
 extern Handle aptEvents[3];
 
-void aptInit();
+void aptInit(NS_APPID appID);
 void aptExit();
 void aptOpenSession();
 void aptCloseSession();
 void aptSetupEventHandler();
-u32 aptGetStatus();
-void aptSetStatus(u32 status);
+void aptSetStatus(APP_STATUS status);
+APP_STATUS aptGetStatus();
 
 Result APT_GetLockHandle(Handle* handle, u16 flags, Handle* lockHandle);
 Result APT_Initialize(Handle* handle, NS_APPID appId, Handle* eventHandle1, Handle* eventHandle2);
index 4008230ff68e273723beee6829cbb41f38cec843..2bb2e7c017df800bfe78e334c5c6ab15eff3ff8c 100644 (file)
@@ -6,4 +6,3 @@ Result SOC_Shutdown();
 int SOC_GetErrno();
 
 #endif
-
index e1566169e89a397b80f889b0326a9ca9a889046c..e66fe786c6abc649838ad453e01a266763f3287f 100644 (file)
@@ -3,13 +3,13 @@
 
        u32* getThreadCommandBuffer(void);
        
+       Result svc_controlMemory(u32* outaddr, u32 addr0, u32 addr1, u32 size, u32 operation, u32 permissions); //(outaddr is usually the same as the input addr0)
        void svc_exitProcess(void);
        Result svc_createThread(Handle* thread, ThreadFunc entrypoint, u32 arg, u32* stacktop, s32 threadpriority, s32 processorid);
        void svc_exitThread();
        void svc_sleepThread(s64 ns);
        Result svc_createMutex(Handle* mutex, bool initialLocked);
        Result svc_releaseMutex(Handle handle);
-       Result svc_controlMemory(u32* outaddr, u32 addr0, u32 addr1, u32 size, u32 operation, u32 permissions); //(outaddr is usually the same as the input addr0)
        Result svc_createEvent(Handle* event, u8 resettype);
        Result svc_clearEvent(Handle handle);
        Result svc_createMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 mypermission, u32 otherpermission);
index 78e097ea9b27d4a675aab5e4e3befafac3a8960c..e533fce50f8070ce01ba399ae8860bfc5d02441a 100644 (file)
@@ -9,6 +9,8 @@
 
 #define APT_HANDLER_STACKSIZE (0x10000)
 
+NS_APPID currentAppId;
+
 Handle aptLockHandle;
 Handle aptuHandle;
 Handle aptEvents[3];
@@ -37,7 +39,7 @@ void aptEventHandler(u32 arg)
                                        u8 signalType;
 
                                        aptOpenSession();
-                                       APT_InquireNotification(NULL, APPID_APPLICATION, &signalType); //check signal type
+                                       APT_InquireNotification(NULL, currentAppId, &signalType); //check signal type
                                        aptCloseSession();
        
                                        switch(signalType)
@@ -46,6 +48,8 @@ void aptEventHandler(u32 arg)
                                                        aptOpenSession();
                                                        APT_PrepareToJumpToHomeMenu(NULL); //prepare for return to menu
                                                        aptCloseSession();
+
+                                                       aptSetStatus(APP_SUSPENDED);
                        
                                                        GSPGPU_ReleaseRight(NULL); //disable GSP module access
                        
@@ -56,11 +60,11 @@ void aptEventHandler(u32 arg)
                                        }
                                }
                                break;
-                       case 0x1: //event 1 means app just started or we're returning to app
+                       case 0x1: //event 1 means app just started, we're returning to app, exiting app etc.
                                {
                                        u8 signalType;
                                        aptOpenSession();
-                                       APT_ReceiveParameter(NULL, APPID_APPLICATION, 0x1000, aptParameters, NULL, &signalType);
+                                       APT_ReceiveParameter(NULL, currentAppId, 0x1000, aptParameters, NULL, &signalType);
                                        aptCloseSession();
        
                                        switch(signalType)
@@ -69,14 +73,15 @@ void aptEventHandler(u32 arg)
                                                        break;
                                                case 0xB: //just returned from menu
                                                        GSPGPU_AcquireRight(NULL, 0x0);
+                                                       aptSetStatus(APP_RUNNING);
                                                        break;
                                                case 0xC: //exiting application
                                                        aptOpenSession();
-                                                       APT_ReplySleepQuery(NULL, APPID_APPLICATION, 0x0);
+                                                       APT_ReplySleepQuery(NULL, currentAppId, 0x0);
                                                        aptCloseSession();
 
                                                        runThread=false;
-                                                       aptSetStatus(1); //app exit signal
+                                                       aptSetStatus(APP_EXITING); //app exit signal
                                                        break;
                                        }
                                }
@@ -89,15 +94,17 @@ void aptEventHandler(u32 arg)
        svc_exitThread();
 }
 
-void aptInit()
+void aptInit(NS_APPID appID)
 {
        //initialize APT stuff, escape load screen
        srv_getServiceHandle(NULL, &aptuHandle, "APT:U");
        APT_GetLockHandle(&aptuHandle, 0x0, &aptLockHandle);
        svc_closeHandle(aptuHandle);
 
+       currentAppId=appID;
+
        aptOpenSession();
-       APT_Initialize(NULL, APPID_APPLICATION, &aptEvents[0], &aptEvents[1]);
+       APT_Initialize(NULL, currentAppId, &aptEvents[0], &aptEvents[1]);
        aptCloseSession();
        
        aptOpenSession();
@@ -105,7 +112,7 @@ void aptInit()
        aptCloseSession();
        
        aptOpenSession();
-       APT_NotifyToWait(NULL, APPID_APPLICATION);
+       APT_NotifyToWait(NULL, currentAppId);
        aptCloseSession();
 }
 
@@ -154,16 +161,16 @@ void aptSetupEventHandler()
        svc_createThread(&aptEventHandlerThread, aptEventHandler, 0x0, (u32*)(&aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]), 0x31, 0xfffffffe);
 }
 
-u32 aptGetStatus()
+APP_STATUS aptGetStatus()
 {
-       u32 ret;
+       APP_STATUS ret;
        svc_waitSynchronization1(aptStatusMutex, U64_MAX);
        ret=aptStatus;
        svc_releaseMutex(aptStatusMutex);
        return ret;
 }
 
-void aptSetStatus(u32 status)
+void aptSetStatus(APP_STATUS status)
 {
        svc_waitSynchronization1(aptStatusMutex, U64_MAX);
        aptStatus=status;
index 9039842c45e9e0204c6b4b2566c298d2662a23da..f8426339f4bb4df5950e70aaaf9182a5c58bc302 100644 (file)
@@ -106,7 +106,7 @@ int main()
 {
        initSrv();
                
-       aptInit();
+       aptInit(APPID_APPLICATION);
 
        gspGpuInit();