I'm trying to Wait for signals coming to my registered application, along withew Ctrl-C and ARexx messages. But I don't seem to get any signals, when waiting for the mp_SigBit from the MsgPort gotten with GetApplicationAttrs. I do however get messages on the MsgPort, when doing a WaitPort.
This is a compilable example, where I test what I want to achieve (so it's not pretty or anything). In my real applicaton, I use the same kind of code, and can successfully receive both Ctrl-C and ARexx signals.
// g++ apptest.cpp -ggdb -lauto -o apptest
//
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/dos.h>
#include <proto/application.h>
#define LOG_DEBUG IDOS->Printf
#define LOG_INFO IDOS->Printf
int main(int argc, char **argv) {
struct MsgPort * msgPort = NULL;
uint32 signal;
int loop = 10;
struct Message * msg = NULL;
msg = new struct Message();
uint32 appId = 0;
appId = IApplication->RegisterApplication(
"test",
REGAPP_URLIdentifier, "test.amigaos.se",
REGAPP_UniqueApplication, TRUE,
TAG_DONE
);
LOG_INFO("Got appId: %ld\n", appId);
if(appId == 0) {
LOG_INFO("Couldn't register application!\n");
return 20;
}
if(!IApplication->GetApplicationAttrs(appId, APPATTR_Port, &msgPort, TAG_DONE)) {
LOG_INFO("Couldn't get application attributes!\n");
return 20;
}
LOG_INFO("Got msgPort: %lx, sigbit: %ld\n", msgPort, msgPort->mp_SigBit);
// I believe this should be set to signal
// the mp_SigBit and not only the port?
// Works equally bad with or without.
msgPort->mp_Flags << PA_SIGNAL;
do {
// This code works:
/* Uncomment from here...
msg = IExec->WaitPort(msgPort);
while(msg != NULL) {
msg = IExec->GetMsg(msgPort);
LOG_DEBUG("Got message: %lx! (%ld)\n", msg, loop);
}
.... to here. */
loop = loop-1;
// This code doesn't work
// From here...
signal = IExec->Wait(SIGBREAKF_CTRL_C | msgPort->mp_SigBit );
if (signal & msgPort->mp_SigBit) {
LOG_DEBUG("Got App port!\n");
} else if (signal & SIGBREAKF_CTRL_C) {
LOG_DEBUG("Got Ctrl-C\n");
loop=0;
} else {
LOG_DEBUG("Something else\n");
}
// ...to here
} while(loop >0);
LOG_DEBUG("Aftermainloop.\n");
IApplication->UnregisterApplication(appId, NULL);
return 0;
}