Example #1
0
Result aptInit(void)
{
	Result ret=0;

	if (aptInitialised) return ret;

	aptStatusMutex = 0;

	// Initialize APT stuff, escape load screen.
	ret = __apt_initservicehandle();
	if(ret!=0)return ret;
	if((ret=APT_GetLockHandle(&aptuHandle, 0x0, &aptLockHandle)))return ret;
	svcCloseHandle(aptuHandle);

	currentAppId = __apt_appid;

	svcCreateEvent(&aptStatusEvent, 0);
	svcCreateEvent(&aptSleepSync, 0);

	if(!aptIsCrippled())
	{
		aptOpenSession();
		if((ret=APT_Initialize(NULL, currentAppId, &aptEvents[0], &aptEvents[1])))return ret;
		aptCloseSession();
		
		aptOpenSession();
		if((ret=APT_Enable(NULL, 0x0)))return ret;
		aptCloseSession();
		
		// create APT close event
		svcCreateEvent(&aptEvents[2], 0);

		// After a cycle of APT_Finalize+APT_Initialize APT thinks the
		// application is suspended, so we need to tell it to unsuspend us.
		if (aptIsReinit())
		{
			aptOpenSession();
			APT_PrepareToJumpToApplication(NULL, 0x0);
			aptCloseSession();

			aptOpenSession();
			APT_JumpToApplication(NULL, 0x0, 0x0, 0x0);
			aptCloseSession();
		}
		
		aptOpenSession();
		if((ret=APT_NotifyToWait(NULL, currentAppId)))return ret;
		aptCloseSession();

		// create APT event handler thread
		svcCreateThread(&aptEventHandlerThread, aptEventHandler, 0x0,
			(u32*)(&aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]), 0x31, 0xfffffffe);
	} else
		aptAppStarted();

	aptInitialised = true;

	return 0;
}
Example #2
0
Result aptInit(void)
{
	Result ret=0;

	if (AtomicPostIncrement(&aptRefCount)) return 0;

	// Initialize APT stuff, escape load screen.
	ret = __apt_initservicehandle();
	if(R_FAILED(ret)) goto _fail;
	if(R_FAILED(ret=APT_GetLockHandle(0x0, &aptLockHandle))) goto _fail;
	svcCloseHandle(aptuHandle);

	currentAppId = envGetAptAppId();

	svcCreateEvent(&aptStatusEvent, 0);
	svcCreateEvent(&aptSleepSync, 0);
	LightLock_Init(&aptStatusMutex);
	aptStatus=0;

	if(!aptIsCrippled())
	{
		aptOpenSession();
		if(R_FAILED(ret=APT_Initialize(currentAppId, &aptEvents[0], &aptEvents[1])))return ret;
		aptCloseSession();
		
		aptOpenSession();
		if(R_FAILED(ret=APT_Enable(0x0))) goto _fail;
		aptCloseSession();
		
		// create APT close event
		svcCreateEvent(&aptEvents[2], 0);

		// After a cycle of APT_Finalize+APT_Initialize APT thinks the
		// application is suspended, so we need to tell it to unsuspend us.
		if (aptIsReinit())
		{
			aptOpenSession();
			APT_PrepareToJumpToApplication(0x0);
			aptCloseSession();

			aptOpenSession();
			APT_JumpToApplication(0x0, 0x0, 0x0);
			aptCloseSession();
		}
		
		aptOpenSession();
		if(R_FAILED(ret=APT_NotifyToWait(currentAppId)))goto _fail;
		aptCloseSession();

		// create APT event handler thread
		aptEventHandlerThread = threadCreate(aptEventHandler, 0x0, APT_HANDLER_STACKSIZE, 0x31, -2, true);

		// Wait for the state to become APT_RUNNING
		aptWaitStatusEvent();
	} else
		aptAppStarted();

	return 0;

_fail:
	AtomicDecrement(&aptRefCount);
	return ret;
}