コード例 #1
0
ファイル: swkbd.c プロジェクト: Caboosium/ctrulib
static void swkbdMessageCallback(void* user, NS_APPID sender, void* msg, size_t msgsize)
{
	SwkbdExtra* extra = (SwkbdExtra*)user;
	SwkbdState* swkbd = (SwkbdState*)msg;

	if (sender != APPID_SOFTWARE_KEYBOARD || msgsize != sizeof(SwkbdState))
		return;

	u16* text16 = (u16*)(swkbdSharedMem + swkbd->text_offset);
	ssize_t units = utf16_to_utf8(NULL, text16, 0);
	if (units < 0) svcBreak(USERBREAK_PANIC); // Shouldn't happen.
	char* text8 = (char*)malloc(units+1);
	if (!text8) svcBreak(USERBREAK_PANIC); // Shouldn't happen.
	swkbdConvertToUTF8(text8, text16, units);

	const char* retmsg = NULL;
	swkbd->callback_result = extra->callback(extra->callback_user, &retmsg, text8, units);
	if (swkbd->callback_result > SWKBD_CALLBACK_OK)
		swkbdConvertToUTF16(swkbd->callback_msg, retmsg, SWKBD_MAX_CALLBACK_MSG_LEN);
	else
		swkbd->callback_msg[0] = 0;

	free(text8);
	APT_SendParameter(envGetAptAppId(), sender, APTCMD_MESSAGE, swkbd, sizeof(*swkbd), 0);
}
コード例 #2
0
ファイル: apt.c プロジェクト: botanyaki/ctrulib
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;
}