static PyObject* osl_messageBox(PyObject *self, PyObject *args, PyObject *kwargs) { char *text, *title; int ret; int b1, a1; int b2 = 0, a2 = 0; int b3 = 0, a3 = 0; if (!PyArg_ParseTuple(args, "ssii|iiii:messageBox", &text, &title, &b1, &a1, &b2, &a2, &b3, &a3)) return NULL; text = strdup(text); title = strdup(title); Py_BEGIN_ALLOW_THREADS ret = oslMessageBox(text, title, oslMake3Buttons(b1, a1, b2, a2, b3, a3)); Py_END_ALLOW_THREADS free(text); free(title); return Py_BuildValue("i", ret); }
//Waits for a connection from a psp: void doServer() { int skip = 0; int quit = 0; char message[100] = ""; int dialog = OSL_DIALOG_NONE; int connected = 0; int init = oslAdhocInit("ULUS99999"); if (init) { snprintf(message, sizeof(message), "adhocInit error: %i", init); oslMessageBox(message, "Debug", oslMake3Buttons(OSL_KEY_CROSS, OSL_MB_OK , 0, 0, 0, 0)); return; } while(!osl_quit && !quit){ struct remotePsp *reqPsp = oslAdhocGetConnectionRequest(); if (!skip){ oslStartDrawing(); printInfo(); oslDrawString(10, 40, "Press O to abort"); if (reqPsp == NULL) { oslDrawString(10, 100, "Waiting for a connection request..."); } else { snprintf(message, sizeof(message), "Accept request from psp : %s", reqPsp->name); oslDrawString(10, 100, message); if (oslGetDialogType() == OSL_DIALOG_NONE) oslInitMessageDialog(message, 1); } dialog = oslGetDialogType(); if (dialog){ oslDrawDialog(); if (oslGetDialogStatus() == PSP_UTILITY_DIALOG_NONE){ if (dialog == OSL_DIALOG_MESSAGE){ int button = oslGetDialogButtonPressed(); if (button == PSP_UTILITY_MSGDIALOG_RESULT_YES) { oslAdhocAcceptConnection(reqPsp); connected = 1; } else if (button == PSP_UTILITY_MSGDIALOG_RESULT_NO) { oslAdhocRejectConnection(reqPsp); } } oslEndDialog(); } } oslEndDrawing(); } oslEndFrame(); skip = oslSyncFrame(); if (connected) serverConnected(reqPsp); oslReadKeys(); if (dialog == OSL_DIALOG_NONE) { if (osl_keys->released.circle) { quit = 1; } } } oslAdhocTerm(); }
//Connects to a psp: void doClient() { int skip = 0; int quit = 0; int i = 0; int current = 0; int init = oslAdhocInit("ULUS99999"); if (init) { char message[100] = ""; sprintf(message, "adhocInit error: %i", init); oslMessageBox(message, "Debug", oslMake3Buttons(OSL_KEY_CROSS, OSL_MB_OK , 0, 0, 0, 0)); return; } while(!osl_quit && !quit){ if (!skip){ oslStartDrawing(); printInfo(); if (oslAdhocGetRemotePspCount()) oslDrawString(10, 60, "Press X to request a connection"); oslDrawString(10, 70, "Press O to abort"); for (i=0; i < oslAdhocGetRemotePspCount(); i++) { if (i == current) oslIntraFontSetStyle(Roboto, 1.0, RGBA(100,100,100,255), RGBA(0,0,0,0), INTRAFONT_ALIGN_LEFT); else oslIntraFontSetStyle(Roboto, 1.0, RGBA(255,255,255,255), RGBA(0,0,0,0), INTRAFONT_ALIGN_LEFT); oslDrawString(10, 100 + 15 * i, oslAdhocGetPspByIndex(i)->name); } oslEndDrawing(); } oslEndFrame(); skip = oslSyncFrame(); oslReadKeys(); if (osl_keys->released.down) { if (++current >= oslAdhocGetRemotePspCount()) current = 0; } else if (osl_keys->released.up) { if (--current < 0) current = oslAdhocGetRemotePspCount() - 1; } else if (osl_keys->released.cross && oslAdhocGetRemotePspCount()) { //Request a connection: int ret = oslAdhocRequestConnection(oslAdhocGetPspByIndex(current), 30, NULL); if (ret == OSL_ADHOC_ACCEPTED || ret == OSL_ADHOC_ESTABLISHED) { clientConnected(oslAdhocGetPspByIndex(current)); } } else if (osl_keys->released.circle) { quit = 1; } } oslAdhocTerm(); }