int main(int argc, char *argv[]) { int server_pid; // PID serwera int server_chid; // CHID serwera int coid; // COID int value1; // wysylana liczba1 int value2 = 38; // wyslana liczba2 int status; // status z funkcji MsgSend() if(argc != 4) { printf("K: Program musi byc wywolany z 3 argumentami, np:\n\n"); printf("K: client 482834 1 abcdefghi \n\n"); printf("K: - pierwszy arg(482834): pid serwera\n"); printf("K: - drugi arg(1): chid serwera\n"); printf("K: - trzeci arg(5): int wysylany do serwera\n"); exit(EXIT_FAILURE); } server_pid = atoi(argv[1]); server_chid = atoi(argv[2]); printf("K: Probuje nawiazac polaczenie z serwerem pid: %d, chid %d\n", server_pid, server_chid); /* Tworzenie polaczenia */ coid = ConnectAttach(ND_LOCAL_NODE, server_pid, server_chid,_NTO_SIDE_CHANNEL,0); if (coid == -1) { printf("K: Nie moge utworzyc polaczenia: %s\n", strerror(errno)); exit(EXIT_FAILURE); } value1 = atoi(argv[3]); printf("K: Wysylam wiadomosc: %d\n", value1); // getprio(0) pobiera priorytet biezacego procesu. status = MsgSendPulse(coid, getprio(0),_PULSE_CODE_MINAVAIL,value1); if (status == -1) { printf("K: Nie moge wyslac impulsu 1: %s\n", strerror(errno)); exit(EXIT_FAILURE); } printf("K: Wysylam wiadomosc: %d\n", value2); status = MsgSendPulse(coid, getprio(0), _PULSE_CODE_MINAVAIL+5, value2); if (status == -1) { printf("K: Nie moge wyslac impulsu 2: %s\n", strerror(errno)); exit(EXIT_FAILURE); } return EXIT_SUCCESS; }
void B1S02_Seg1::timerSeg1Max() { PuckHandler::getInstance()->printQueueStatus(); if(controller->isFirstElementInSegment()) { puckHandler->removePuckFromSeg1(); puckHandler->removePuckFromBand(controller); if(puckHandler->isBandEmpty()){ actorHAL->engineStop(); } controller->resetController(); printf("Debug State <B1S02_Seg1>: ERROR<ERR_STATE_ERROR_MAX> called by puck%d\n", controller->getID()); int errorfsmChid = errfsm->getErrorFSMChid(); int errorfsmCoid; int rc; if ((errorfsmCoid = ConnectAttach(0, 0, errorfsmChid, _NTO_SIDE_CHANNEL, 0)) == -1) { printf("B1S02_Seg1: Error in ConnectAttach\n"); } //rc = MsgSendPulse(errorfsmCoid, SIGEV_PULSE_PRIO_INHERIT, PULSE_FROM_PUCK, ERR_STATE_CRITICAL_ERROR); rc = MsgSendPulse(errorfsmCoid, SIGEV_PULSE_PRIO_INHERIT, PULSE_FROM_PUCK, ERR_STATE_ERROR_MAX); if (rc < 0) { printf("B1S02_Seg1: Error in MsgSendPulse"); } if (ConnectDetach(errorfsmCoid) == -1) { printf("B1S02_Seg1: Error in ConnectDetach\n"); } } }
static void* client(void* arg) { int nodeId = 0; // 0 = local pid_t pid = 0; // 0 = same process int connectionId = 0; int number = 0; int res = 0; connectionId = ConnectAttach(nodeId, pid, channelId, 0, 0); if(connectionId == -1) { printf("msgSendReceivePulse: client: error attaching to channel!\n");fflush(stdout); exit(EXIT_FAILURE); } while(run) { sleep(WAIT_SHORT); number++; printf("Client: sending pulse message #%d\n", number);fflush(stdout); res = MsgSendPulse(connectionId, SIGEV_PULSE_PRIO_INHERIT, 1, 0); if(res == -1) { printf("msgSendReceivePulse: client: error sending pulse!\n");fflush(stdout); exit(EXIT_FAILURE); } } ConnectDetach(connectionId); if(res == -1) { printf("msgSendReceiveReply: client: error detaching from channel!\n");fflush(stdout); exit(EXIT_FAILURE); } pthread_exit(NULL); }
void B1S02_Seg1::sbHeightcontrolOpen() { if(controller->isFirstElementInSegment()) { if(this->controller->isSegTimerMinCalled()){ controller->resetSegTimers(); puckHandler->removePuckFromSeg1(); new (this) B1S03_Height(controller); } else { printf("Debug State <B1S02_Seg1>: ERROR<ERR_STATE_ERROR_MIN> called by puck%d\n", controller->getID()); int errorfsmChid = errfsm->getErrorFSMChid(); int errorfsmCoid; int rc; if ((errorfsmCoid = ConnectAttach(0, 0, errorfsmChid, _NTO_SIDE_CHANNEL, 0)) == -1) { printf("B1S02_Seg1: Error in ConnectAttach\n"); } rc = MsgSendPulse(errorfsmCoid, SIGEV_PULSE_PRIO_INHERIT, PULSE_FROM_PUCK, ERR_STATE_ERROR_MIN); if (rc < 0) { printf("B1S02_Seg1: Error in MsgSendPulse"); } if (ConnectDetach(errorfsmCoid) == -1) { printf("B1S02_Seg1: Error in ConnectDetach\n"); } } } else { new (this) B1S02_Seg1(controller); } }
int main(int argc, char* argv[]) { int ping_coid; int status; //status return value used for ConnectAttach and MsgSend struct _pulse *mypulse; struct _msg_info info; mss_t msg; name_attach_t *attach; setvbuf(stdout, NULL, _IOLBF, 0); if ((attach = name_attach(NULL, PONG, 0)) == NULL) { printf("server:failed to attach name, errno %d\n", errno ); exit(1); } if ((ping_coid = name_open(PING, 0)) == -1) { printf("failed to find ping, errno %d\n", errno ); exit(1); } status = MsgSendPulse(ping_coid, PULSE_PRIORITY, PULSE_CODE, 1); if (-1 == status) { perror("MsgSendPulse"); exit(EXIT_FAILURE); } while (1) { int rcvid = MsgReceive(attach->chid, &msg, sizeof(msg), &info); if (rcvid == -1) { perror("MsgReceive"); break; } else if (rcvid == 0) { mypulse = (struct _pulse *) &msg; printf("Pulse code: %d, pulse value %d\n", mypulse->code, mypulse->value.sival_int); sleep(1); status = MsgSendPulse(ping_coid, PULSE_PRIORITY, PULSE_CODE, mypulse->value.sival_int + 1); } else { printf("Unexpcted message"); } } return EXIT_SUCCESS; }
void SerielleSchnittstelle::sendePulsMessage(uint8_t iq, uint8_t state){ PulsNachricht nachricht; int *val = NULL; int code = FEHLER; nachricht.iq = iq; nachricht.state = state; val = (int*)(&nachricht); MsgSendPulse(dispatcherConnectionID, SIGEV_PULSE_PRIO_INHERIT, code, *val); }
/** * Send a message to Dispatcher */ int Demultiplexer::sendMsg2Dispatcher(int message){ if (-1 == MsgSendPulse(con_id_,SIGEV_PULSE_PRIO_INHERIT, DEMULTIPLEXER_CODE, message )) { if (isStopped()) { return -1; // channel destroyed, Thread ending } perror("Demultiplexer : MsgSendPulse"); exit(EXIT_FAILURE); } else { #ifdef DEBUG_ cout << "Demultiplexer: message sent to dispatcher: " << message << " code " << DEMULTIPLEXER_CODE << endl; #endif } return 0; }
void bootimage_init(void) { int code; if(imagefs_mount_mounter() == -1) { crash(); } code = pulse_attach(dpp, MSG_FLAG_ALLOC_PULSE, 0, bootimage_start, NULL); if(code == -1) { crash(); } MsgSendPulse(PROCMGR_COID, PROC_INIT_PRIORITY, code, 0); }
void B2S02_Seg1::timerSeg1Max() { puckHandler->removePuckFromBand(controller); actorHAL->engineStop(); printf("Debug State <B2S02_Seg1>: ERROR<ERR_STATE_ERROR_MAX> called by puck%d\n", controller->getID()); int replyChid = errfsm->getReplyChid(); int errorfsmChid = errfsm->getErrorFSMChid(); int errorfsmCoid; int rc; struct _pulse pulse; if ((errorfsmCoid = ConnectAttach(0, 0, errorfsmChid, _NTO_SIDE_CHANNEL, 0)) == -1) { printf("B2S02_Seg1: Error in ConnectAttach\n"); } //rc = MsgSendPulse(errorfsmCoid, SIGEV_PULSE_PRIO_INHERIT, PULSE_FROM_PUCK, ERR_STATE_CRITICAL_ERROR); rc = MsgSendPulse(errorfsmCoid, SIGEV_PULSE_PRIO_INHERIT, PULSE_FROM_PUCK, ERR_STATE_ERROR_MAX); if (rc < 0) { printf("B2S02_Seg1: Error in MsgSendPulse"); } rc = MsgReceivePulse(replyChid, &pulse, sizeof(pulse), NULL); if (rc < 0) { printf("B2S02_Seg1: Error in recv pulse\n"); } if (ConnectDetach(errorfsmCoid) == -1) { printf("B2S02_Seg1: Error in ConnectDetach\n"); } bool tmpBand1Waiting = controller->isBand1Waiting(); controller->resetController(); if(tmpBand1Waiting){ rs232_1->sendMsg(RS232_BAND2_READY); ActorHAL::getInstance()->engineRight(false); ActorHAL::getInstance()->engineUnstop(); controller->handOverTimer = timerHandler->createTimer(puckHandler->getDispChid(), TIME_VALUE_HAND_OVER_SEC, TIME_VALUE_HAND_OVER_MSEC, TIMER_HAND_OVER); timerHandler->startTimer(controller->handOverTimer); } }
void Sensorik::execute(void *arg) { struct _pulse pulse; while (!isStopped()) { if (-1 == MsgReceivePulse(isr_Chid, &pulse, sizeof(pulse), NULL)) { if (isStopped()) { break; // channel destroyed, Thread ending } perror("SensorCtrl: MsgReceivePulse"); exit(EXIT_FAILURE); } // printf("Sensorik:: BLAU: Coid %d\n", sensorik_Coid); // fflush(stdout); MsgSendPulse(sensorik_Coid, SIGEV_PULSE_PRIO_INHERIT, pulse.code, pulse.value.sival_int); } }
void _message_unblock(dispatch_context_t *ctp) { dispatch_t *dpp = ((message_context_t *) ctp)->dpp; struct sched_param param; int coid; if ((coid = ConnectAttach(0, 0, dpp->chid, _NTO_SIDE_CHANNEL, 0)) == -1) { return; //We should indicate an error, but we can't } memset(¶m, 0, sizeof(param)); if (SchedGet(0, 0, ¶m) == -1) { param.sched_priority = 1; } /* An unblock pulse with rcvid == 0 should be treated as a noop */ //MsgSendPulse(coid, param.sched_priority, _PULSE_CODE_UNBLOCK, getpid()); (void)MsgSendPulse(coid, param.sched_priority, _PULSE_CODE_UNBLOCK, 0); ConnectDetach(coid); }
B1S09_ERR_TurnOver::B1S09_ERR_TurnOver(Controller* controller) : BaseState(controller) { this->controller = controller; #ifdef DEBUG_STATE_PRINTF printf("DEBUG STATE: Puck%d -> B1S09_ERR_TurnOver \n", this->controller->getID()); #endif printf("Debug State <B1S09_ERR_TurnOver>: ERROR<ERR_STATE_TURNOVER> called by puck%d\n", controller->getID()); //int replyChid = errfsm->getReplyChid(); int errorfsmChid = errfsm->getErrorFSMChid(); int errorfsmCoid; int rc; //struct _pulse pulse; if ((errorfsmCoid = ConnectAttach(0, 0, errorfsmChid, _NTO_SIDE_CHANNEL, 0)) == -1) { printf("B1S09_ERR_TurnOver: Error in ConnectAttach\n"); } rc = MsgSendPulse(errorfsmCoid, SIGEV_PULSE_PRIO_INHERIT, PULSE_FROM_PUCK, ERR_STATE_TURNOVER); if (rc < 0) { printf("B1S09_ERR_TurnOver: Error in MsgSendPulse"); } /* rc = MsgReceivePulse(replyChid, &pulse, sizeof(pulse), NULL); if (rc < 0) { printf("B1S09_ERR_TurnOver: Error in recv pulse\n"); } */ //this->controller->puckType = PUCK_ACCEPTED; if (ConnectDetach(errorfsmCoid) == -1) { printf("B1S09_ERR_TurnOver: Error in ConnectDetach\n"); } //new (this) B1S08_End(this->controller); }
/* * Return -1 * This prp can never match the criteria * Return 0 * This prp does not currently match the criteria * Return WNOHANG * An error with wap, reply was done (i.e. a thread unblocked) * Return non-zero W????? * This prp matched and a reply was done (i.e. a thread unblocked) */ int procmgr_wait_check(PROCESS *prp, PROCESS *parent, struct wait_entry *wap, int match) { struct _msg_info info; /* * Check if this prp matched the requested group */ switch(wap->idtype) { case P_ALL: break; case P_PID: if(prp->pid != wap->id) { return -1; } break; case P_PGID: if(prp->pgrp != wap->id) { return -1; } break; default: MsgError(wap->rcvid, EINVAL); return WNOHANG; } if(match) { /* * Check for match, if parent is ignoring SIGCHLD, are we the last child? */ match &= wap->options; if(wap->idtype == P_ALL && (prp->sibling || parent->child != prp) && sigismember(&parent->sig_ignore, SIGCHLD)) { match &= ~WEXITED; } /* * Have we already responded with exit code? */ if(!(prp->flags & _NTO_PF_WAITINFO)) { match &= ~WEXITED; } } else { /* * Check if the requested prp currently matches any options */ if((wap->options & WTRAPPED) && (prp->flags & (_NTO_PF_DEBUG_STOPPED | _NTO_PF_PTRACED)) == (_NTO_PF_DEBUG_STOPPED | _NTO_PF_PTRACED)) { match = WTRAPPED; } else if((wap->options & WEXITED) && (prp->flags & _NTO_PF_WAITINFO)) { match = WEXITED; } else if((wap->options & WCONTINUED) && (prp->flags & _NTO_PF_CONTINUED)) { match = WCONTINUED; } else if((wap->options & WUNTRACED) && (prp->flags & _NTO_PF_STOPPED) && prp->siginfo.si_signo != 0) { match = WUNTRACED; } } /* * If no options matched, check if it could ever match options */ if(match == 0) { int options = wap->options; if(prp->flags & (_NTO_PF_ZOMBIE | _NTO_PF_TERMING)) { options &= ~(WUNTRACED|WTRAPPED|WCONTINUED); } if((prp->flags & (_NTO_PF_ZOMBIE | _NTO_PF_WAITINFO)) == _NTO_PF_ZOMBIE) { options &= ~WEXITED; } if((prp->flags & _NTO_PF_NOZOMBIE) || sigismember(&parent->sig_ignore, SIGCHLD)) { options &= ~WEXITED; } if(prp->flags & _NTO_PF_WAITDONE) { options &= ~WEXITED; } if(!(prp->flags & _NTO_PF_PTRACED)) { options &= ~WTRAPPED; } if((options & (WEXITED|WUNTRACED|WTRAPPED|WCONTINUED)) == 0) { return -1; } return 0; } /* * Unblock the waiting thread... */ if(MsgInfo(wap->rcvid, &info) != -1) { siginfo_t siginfo; // unbind and unblock if rcvid is still around if((!parent->wap) || ((parent->wap == wap) && (parent->wap->next == NULL))) { (void)_resmgr_unbind(&info); } siginfo = prp->siginfo; if(siginfo.si_signo != SIGCHLD) { if(prp->flags & _NTO_PF_COREDUMP) { siginfo.si_code = CLD_DUMPED; } else { siginfo.si_code = CLD_KILLED; } siginfo.si_status = siginfo.si_signo; siginfo.si_pid = prp->pid; siginfo.si_signo = SIGCHLD; } if(info.flags & _NTO_MI_ENDIAN_DIFF) { ENDIAN_SWAP32(&siginfo.si_signo); ENDIAN_SWAP32(&siginfo.si_code); ENDIAN_SWAP32(&siginfo.si_errno); ENDIAN_SWAP32(&siginfo.si_pid); ENDIAN_SWAP32(&siginfo.si_status); ENDIAN_SWAP32(&siginfo.si_utime); ENDIAN_SWAP32(&siginfo.si_stime); } MsgReply(wap->rcvid, 0, &siginfo, sizeof siginfo); } else { KerextSlogf( _SLOG_SETCODE( _SLOGC_PROC, 0 ), _SLOG_INFO, "proc_wait_check: MsgInfo() failed, errno=%d", errno); } /* * Clean up prp status if requested so it is not reported again */ if(wap->options & WNOWAIT) { return WNOWAIT; } switch(match) { case WEXITED: if(prp->flags & _NTO_PF_WAITINFO) { parent->kids_running_time += prp->running_time + prp->kids_running_time; parent->kids_system_time += prp->system_time + prp->kids_system_time; prp->flags &= ~_NTO_PF_WAITINFO; prp->flags |= _NTO_PF_WAITDONE; } if(prp->flags & _NTO_PF_ZOMBIE) { MsgSendPulse(PROCMGR_COID, prp->terming_priority, PROC_CODE_TERM, prp->pid); } else { match = WNOWAIT; } break; case WUNTRACED: // also WSTOPPED prp->siginfo.si_signo = 0; break; case WTRAPPED: break; case WCONTINUED: prp->flags &= ~_NTO_PF_CONTINUED; break; default: break; } return match; }
void clsThread::SendPulse(int priority, int code, int value) { MsgSendPulse(m_coidThread, priority, code, value); }