I am trying to write a simple multitasking communication function. Not quite there.
My program starts. SetUpProcesses() to start new process. I can't talk to it. I never get past IExec->WaitPort(). (The process is started.)
I just want to PutMsg() a simple message with a int32 value to tell it what to do, 1 through 99. -1 to quit. Or even send a text message, "start", "stop", "quit". A reply back that it's done would be nice, success or fail.
I based this off Thomas Rapp's multi3.c example. Tried to update it to OS4.
Can someone straighten me out?
from Protos.h: extern struct MyMessage { struct Message Msg; // need this???? int32 ActionID; int32 ResultID; } *MyMsg; struct MyMessage *MyMsg; struct MsgPort *SetMenuStatePort=NULL; struct Process *SetMenuStateProcess=NULL; BOOL SetUpProcesses() { if (!(ReplyPort=(struct MsgPort *)IExec->AllocSysObject(ASOT_PORT,NULL))) return(FALSE); // Probably don't need this if ((MyMsg=IExec->AllocSysObjectTags(ASOT_MESSAGE, ASOMSG_Size, sizeof(struct MyMessage), ASOMSG_ReplyPort, ReplyPort, TAG_END))) { return(FALSE); } if (!(SetMenuStatePort=(struct MsgPort *)IExec->AllocSysObject(ASOT_PORT,NULL))) return(FALSE); else { SetMenuStateSig=PORTMASK(SetMenuStatePort); if ((SetMenuStateProcess=IDOS->CreateNewProcTags( NP_Entry, NP_SetMenuStateProcess, // NP_NotifyOnDeathSigTask, me, /* SIGB_CHILD signal */ // NP_FinalCode, finalfunc, /* executes this ending */ // NP_FinalData, fd, /* tracking data for above */ // NP_EntryCode, entryfunc, /* executes this starting */ // NP_EntryData, fd, /* tracking data for above */ NP_Child, TRUE, NP_ExitData, IDOS, /* share idos with children. */ TAG_DONE))) { IDOS->Printf("Started SetMenuStateProcess\n"); } else return(FALSE); } return(TRUE); } BOOL SendCommandToPort(struct MsgPort *replyport,struct MsgPort *cmdport,int32 ActionID) { struct MyMessage *MyMsg; if ((MyMsg=IExec->AllocSysObjectTags(ASOT_MESSAGE, ASOMSG_Size, sizeof(struct MyMessage), ASOMSG_ReplyPort, replyport, TAG_END))) { MyMsg->Msg.mn_ReplyPort=replyport; MyMsg->ActionID=ActionID; IExec->PutMsg(cmdport,(struct Message *)MyMsg); } // free the message??? return(TRUE); } int32 GetPortResponse(struct MsgPort *replyport) { struct MyMessage *MyMsg; int32 Result=-1; if ((MyMsg=(struct MyMessage *)IExec->GetMsg(replyport))) { Result=MyMsg->ResultID; IExec->FreeSysObject(ASOT_MESSAGE,MyMsg); // how does it know the pointer??? } return(Result); } VOID ShutDownProcesses() { if (SetMenuStateProcess) { if (SendCommandToPort(ReplyPort,SetMenuStatePort,-1)) { IExec->WaitPort(ReplyPort); GetPortResponse(ReplyPort); } } if (SetMenuStatePort) IExec->FreeSysObject(ASOT_PORT,SetMenuStatePort); if (MyMsg) IExec->FreeSysObject(ASOT_MESSAGE,MyMsg); if (ReplyPort) IExec->FreeSysObject(ASOT_PORT,ReplyPort); } ////////////////////////////// int32 NP_SetMenuStateProcess(STRPTR *args UNUSED,int32 arglen UNUSED,struct ExecBase *sysbase) { // struct ExecIFace *iexec=(APTR)sysbase->MainInterface; // struct Process *me=(APTR)iexec->FindTask(0); // struct DOSIFace *idos=(APTR)me->pr_ExitData; /* via parent */ uint32 Loc=AT_NOWHERE; int32 Action; BOOL done=FALSE; struct MyMessage *MyMsg; // if ((MyMsg=IExec->AllocSysObjectTags(ASOT_MESSAGE, // ASOMSG_Size, sizeof(struct MyMessage), // ASOMSG_ReplyPort, replyport, // TAG_END))) { while(!done) { IExec->WaitPort(SetMenuStatePort); while((MyMsg=(struct MyMessage *)IExec->GetMsg(SetMenuStatePort))) { Action=MyMsg->ActionID; IExec->ReplyMsg(&MyMsg->Msg); switch(Action) { case 1: if (Loc != SMSLocation) { IIntuition->DisplayBeep(NULL); // just visual to know worked Loc=SMSLocation; } break; case 2: // do something else break; case -1: done=TRUE; break; } } } // IExec->FreeSysObject(ASOT_MESSAGE,MyMsg); } return(RETURN_OK); }