Setupcallbacks

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Setupcallbacks

Post by jojojoris »

Hello,

I'm a c/c++ beginner and i have a question about the SetupCallbacks();?

What does it exactly? A program without that code runs fine too.

Code: Select all

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
	sceKernelExitGame();
    return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
	int cbid;

    cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
    sceKernelRegisterExitCallback(cbid);

    sceKernelSleepThreadCB();

    return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
    int thid = 0;

    thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
    if(thid >= 0) {
		sceKernelStartThread(thid, 0, 0);
		}

    return thid;
} 
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Ever seen the screen that pops up when you press the HOME button from ingame? That's what makes that screen appear.
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

basically it is creating a thread whose function is only to register the exit callback....this means: its function is to make your app correctly react to the [home] button press. Just an advice: don't call sceKernelExitGame(); in exit callback: better setting a flag (e.g. "exitRequested=1") that other loops in your application should check against. Like

Code: Select all

int exitRequested;

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
   exitRequested = 1;
   return 0;
&#125; 

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
 
    exitRequested = 0;

    int cbid;

    cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
    sceKernelRegisterExitCallback&#40;cbid&#41;;

    sceKernelSleepThreadCB&#40;&#41;;

    return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;
    int thid = 0;

    thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
    if&#40;thid >= 0&#41; &#123;
      sceKernelStartThread&#40;thid, 0, 0&#41;;
      &#125;

    return thid;
&#125; 
.
.
.
// main loop
while &#40;!exitRequested&#41;
&#123;
...do your stuff here
&#125;
sceKernelExitGame&#40;&#41;; // finally exit here
Post Reply