static t_stat ipc_set_node (UNIT UNUSED *uptr, int32 UNUSED val, char *cval, void UNUSED *desc) { if (cval == NULL || *cval == 0) { strcpy(fnpName, IPC_NODE); #ifdef VM_FNP set_prompt (0, "sim>"); // reset prompt to default #endif } else { stripquotes(cval); if (!startsWith(cval, "cpu")) sim_printf("WARNING: Node name <%s> does not begin with 'cpu'\n", cval); strcpy(fnpName, cval); #ifdef VM_FNP char temp[132]; sprintf(temp, "%s>", fnpName); set_prompt(0, temp); #endif } // if IPC is already running, resrart it with new node if (actor) { ipc(ipcStop, 0, 0, 0, 0); // ki;; IPC ipc(ipcStart, fnpName, 0, 0, 0); } return SCPE_OK; }
static t_stat ipc_restart (UNIT UNUSED *uptr, int32 UNUSED val, char UNUSED *cval, void UNUSED *desc) { if (actor) ipc(ipcStop, 0, 0, 0, 0); // kill IPC ipc(ipcStart, fnpName, 0, 0, 0); return SCPE_OK; }
static t_stat ipc_set_grp (UNIT UNUSED *uptr, int32 UNUSED val, char UNUSED *cval, void UNUSED *desc) { stripquotes(cval); strcpy(fnpGroup, cval); if (actor) { ipc(ipcStop, 0, 0, 0, 0); // kill IPC ipc(ipcStart, fnpName, 0, 0, 0); } return SCPE_OK; }
static t_stat Test (FILE UNUSED *st, UNIT UNUSED *uptr, int32 UNUSED val, void UNUSED *desc) { sim_printf("Test: IPC not enabled.\n"); return ipc(ipcTest, 0, 0, 0, 0); }
int semctl (int semid, int semnum, int cmd, ...) { union semun arg; va_list ap; va_start(ap, cmd); /* Get the argument only if required. */ arg.buf = NULL; switch (cmd) { case SETVAL: case GETALL: case SETALL: case IPC_STAT: case IPC_SET: case SEM_STAT: case IPC_INFO: case SEM_INFO: va_start(ap, cmd); arg = va_arg (ap, union semun); va_end(ap); break; } va_end(ap); return ipc(SEMCTL, semid, semnum, cmd, &arg, (long)NULL); }
void testShout(void) { //load configuration: configParser config(configFile); string dbPath = config.getset("musicDB", "path", "." ); //path to music files string dbFile = config.getset("musicDB", "dbFile", "SqueezeD.db" ); string dbIdx = config.getset("musicDB", "dbIdx", "SqueezeD.idx"); int shoutPort = config.getset("shout", "port", 9000 ); int shoutConn = config.getset("shout", "maxConnections", 10 ); int slimPort = config.getset("slim", "port", 3483); config.write(configFile); // Resolve home directory ('~'), if required. dbPath = path::normalize(dbPath); // Initialize music databse: musicDB db( dbPath.c_str() ); //db.scan( dbFile.c_str() ); //printf("scanning: found %llu items\n", (LLU)db.size() ); //db.index( dbIdx.c_str() ); db.init( dbFile.c_str(), dbIdx.c_str() ); // Initialize servers slimIPC ipc(&db, &config); TCPserverShout shoutServer( &ipc, shoutPort, shoutConn); TCPserverSlim slimServer( &ipc, slimPort); // Run only the shoutcast server shoutServer.runNonBlock(); }
int main() { std::cout << "1" << std::endl; std::string reply; std::cout << "2" << std::endl; ssodc::ipc::IProcessMQ ipc("tcp://192.168.1.2:6555"); std::cout << "3" << std::endl; ipc.Send("Hello world!"); std::cout << "4" << std::endl; return 0; }
EXPORT_C TInt RScsTestSession::Double(TInt& aValue) /** Calls a synchronous session function to ensure the function call is routed to the session subclass on the server side. @param aValue An arbitrary integer. On completion this should be double its entry value. @return Symbian OS error code where KErrNone indicates success and any other value indicates failure. */ { TPckg<TInt> valPckg(aValue); TIpcArgs ipc(&valPckg); return CallSessionFunction(ScsTestImpl::ESessDouble, ipc); }
EXPORT_C void RScsTestSession::Treble(TDes8& aValue, TRequestStatus& aStatus) /** Calls an asynchronous function to test the SCS can successfully manage asynchronous requests. @param aValue Describes an integer, e.g. TPckgBuf<TInt>. The descriptor must be supplied by the caller instead of being constructed in this function because it must persist until the request has been completed. @param aStatus The server will complete this status object when it has handled the function. @see CancelTreble */ { TIpcArgs ipc(&aValue); CallSessionFunction(ScsTestImpl::ESessTreble, ipc, aStatus); }
int main(int argc, const char *argv[]) { ProcessState* proc(ProcessState::self()); IPCThreadState* ipc(new IPCThreadState); int msg, reply; // int handle = binder_call(proc->get_driver(), (int*)"LedService", &reply, // BINDER_SERVICE_MANAGER, SVC_MGR_CHECK_SERVICE); int handle = ipc->transact(BINDER_SERVICE_MANAGER, SVC_MGR_CHECK_SERVICE, (int*)"LedService", &reply); while (1) { // getchar(); binder_call(proc->get_driver(), &msg, &reply, handle, 1); getchar(); ipc->transact(handle, 1, &msg, &reply); // getchar(); binder_call(proc->get_driver(), &msg, &reply, handle, 2); getchar(); ipc->transact(handle, 2, &msg, &reply); } return 0; }
int usbguard_list_devices(int argc, char *argv[]) { bool list_blocked = false; bool list_allowed = false; int opt = 0; while ((opt = getopt_long(argc, argv, options_short, options_long, nullptr)) != -1) { switch(opt) { case 'h': showHelp(std::cout); return EXIT_SUCCESS; case 'a': list_allowed = true; break; case 'b': list_blocked = true; break; case '?': showHelp(std::cerr); default: return EXIT_FAILURE; } } const bool list_everything = (list_blocked == list_allowed); std::string query = "match"; if (!list_everything) { if (list_allowed) { query = "allow"; } else { query = "block"; } } usbguard::IPCClient ipc(/*connected=*/true); for (auto device_rule : ipc.listDevices(query)) { std::cout << device_rule.getRuleID() << ": " << device_rule.toString() << std::endl; } return EXIT_SUCCESS; }
int main(int argc, char** argv) #endif { IPC ipc("videotest", true); SDL_Init(SDL_INIT_EVERYTHING); SDL_Surface* screen = SDL_SetVideoMode(800, 600, 0, SDL_SWSURFACE); bool done = false; int positionCounter = 0; CommandLine::Start(); SDL_Surface* surface = 0; std::shared_ptr<char> surfacePixels; while(!done){ SDL_Event event; while(SDL_PollEvent(&event)){ if(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE){ done = true; } } std::vector<std::string> arg; if((arg = CommandLine::GetCommand()).size() > 0){ if(arg[0] == "exit"){ done = true; ipc.WriteMessage("quit", ""); } CMD_REQ("volume", 1) ipc.WriteMessage("volume", arg[1]); else CMD_REQ("qvmute", 1) ipc.WriteMessage("qvmute", arg[1]); else CMD_REQ("mute", 1) ipc.WriteMessage("mute", arg[1]); else CMD_REQ("load", 1) ipc.WriteMessage("load", arg[1]);
int usbguard_block_device(int argc, char *argv[]) { uint32_t id = 0; bool append = false; int opt = 0; while ((opt = getopt_long(argc, argv, options_short, options_long, nullptr)) != -1) { switch(opt) { case 'h': showHelp(std::cout); return EXIT_SUCCESS; case 'p': append = true; break; case '?': showHelp(std::cerr); default: return EXIT_FAILURE; } } argc -= optind; argv += optind; if (argc != 1) { showHelp(std::cerr); return EXIT_FAILURE; } id = std::stoul(argv[0]); usbguard::IPCClient ipc(/*connected=*/true); ipc.blockDevice(id, append, 0); return EXIT_SUCCESS; }
int msgsnd ( int msqid, const struct msgbuf *msgp, size_t msgsz, int msgflg ) { return ipc( MSGSND, msqid, msgsz, msgflg, (void*)msgp ); }
int msgget ( key_t key, int msgflg ) { return ipc( MSGGET, key, msgflg, 0, 0 ); }
int semop(int semid, struct sembuf *sops, unsigned nsops) { return ipc(SEMOP, semid, nsops, 0, sops, 0); }
//one thread per port: void startThreads() { // Default settings: configParser::config_t defaults; defaults["config"]["path"] = configValue("."); //path to configuration data of sub-modules defaults["musicDB"]["path"] = configValue("." ); //path to music files defaults["musicDB"]["dbFile"] = configValue("SqueezeD.db"); defaults["musicDB"]["dbIdx"] = configValue("SqueezeD.idx"); // Load configuration data db_printf(6,"Loading confugaration data from %s\n", configFile); configParser config(configFile, defaults); int shoutPort = config.getset("shout", "port", 9000 ); int shoutConn = config.getset("shout", "maxConnections", 10 ); int slimPort = config.getset("slim", "port", 3483); string cfgPath= config.get("config", "path"); string dbPath = config.get("musicDB", "path"); string dbFile = config.get("musicDB", "dbFile"); string dbIdx = config.get("musicDB", "dbIdx"); // Write back the default values, in case some are missing: config.write(configFile); // Initialize the database db_printf(6,"checking path '%s'\n", dbPath.c_str() ); dbPath = path::normalize(dbPath); // Resolve home directory ('~'), if required. db_printf(6,"opening musicDB '%s'\n", dbPath.c_str() ); musicDB db( dbPath.c_str() ); //Load database, or scan if it's missing: db.init( dbFile.c_str() , dbIdx.c_str() ); db_printf(1,"found %llu files\n", (LLU)db.size() ); //Both shout- and slim-server need to share some info. // the IPC block will provide the mutexes for safe multi-threading // slim relies on shout to keep it's playlist, and get stream-audio-formats?? // shout needs playback control from slim, and also status info. // IPC keeps a playlist per group, and device status per device. // for now, slim IPC can have only one client and one server // since all initiative is from both servers, they both get an handle to the IPC slimIPC ipc(&db, &config); TCPserverShout shoutServer( &ipc, shoutPort, shoutConn); TCPserverSlim slimServer( &ipc, slimPort); //shoutcast server in one thread: pthread_t thread; pthread_create( &thread, NULL, shoutThread, &shoutServer); //slim server in the main trhead: int i = slimServer.runNonBlock(); printf("slimServer returned : %i\n", i); //stop the shoutcast server, when slim-server stops: shoutServer.stop = true; //wait for the thread to finish: pthread_join(thread, NULL); }
int semop (int semid, struct sembuf* sops, size_t nsops) { return ipc(SEMOP, semid, (int)nsops, 0, sops, (long)NULL); }
int semget (key_t key, int nsems, int semflg) { return ipc(SEMGET, key, nsems, semflg, (void*)NULL, (long)NULL); }
static void ipc_actor (zsock_t *pipe, void *args) { // Do some initialization char* name = (char*) args; node = zyre_new (name); assert(node); if (!node) // Could not create new node { sim_printf("Couldn't create IPC node ... %s\n", name); return; } ipc_printf("Starting IPC node %s ...", name); if (ipc_verbose) zyre_set_verbose (node); // uncomment to watch the events zyre_start (node); zyre_join (node, fnpGroup); zsock_signal (pipe, 0); // Signal "ready" to caller terminated = false; poller = zpoller_new (pipe, zyre_socket (node), NULL); assert(poller); ipc_printf(" done\n"); while (!terminated) { void *which = zpoller_wait (poller, -1); // no timeout if (!terminated && which == pipe) { zmsg_t *msg = zmsg_recv (which); if (!msg) break; // Interrupted char *command = zmsg_popstr (msg); if (streq (command, "$TERM")) { terminated = true; } else if (streq (command, "SHOUT")) { char *string = zmsg_popstr (msg); zyre_shouts (node, fnpGroup, "%s", string); } else if (streq (command, "WHISPER")) { char *string = zmsg_popstr (msg); zyre_whispers (node, lastPeer, "%s", string); } else { sim_debug (DBG_IPCVERBOSE, &ipc_dev,"ipc_actor(): E: invalid message to actor"); //assert (false); } free (command); zmsg_destroy (&msg); } else if (!terminated && which == zyre_socket (node)) { zmsg_t *msg = zmsg_recv (which); char *event = zmsg_popstr (msg); char *peer = zmsg_popstr (msg); char *name = zmsg_popstr (msg); char *group = zmsg_popstr (msg); char *message = zmsg_popstr (msg); // change to zmsg_popmsg (zmsg_t *self) later if (streq (event, "ENTER")) { ipc(ipcEnter, name, peer, message, 0); } else if (streq (event, "EXIT")) { ipc(ipcExit, name, peer, 0, 0); } if (streq (event, "SHOUT")) { ipc(ipcShoutRx, name, peer, message, 0); } if (streq (event, "WHISPER")) { ipc(ipcWhisperRx, name, peer, group, 0); } if (ipc_verbose) { ipc_printf("Message from node\n"); ipc_printf("event: %s peer: %s name: %s group: %s message: %s\n", event, peer, name, group, message); } free (event); free (peer); free (name); free (group); free (message); zmsg_destroy (&msg); } } }
t_stat ipc (ipc_funcs fn, char *arg1, char *arg2, char *arg3, int32 UNUSED arg4) { // if (!checkIPC()) // return SCPE_UDIS; switch (fn) { case ipcStart: if (actor) killIPC(); actor = zactor_new (ipc_actor, arg1); assert (actor); deletePeers(); // remove all peers break; case ipcStop: ipc_printf("Stopping IPC ... "); killIPC(); ipc_printf("deleted %d peers ... ", deletePeers()); ipc_printf("done\n"); break; case ipcRestart: ipc(ipcStop, 0, 0, 0, 0); // kill IPC deletePeers(); ipc(ipcStart, fnpName, 0, 0, 0); // start IPC break; case ipcEnter: //sim_debug (DBG_VERBOSE, &ipc_dev, "%s/%s has entered " STR(IPC_GROUP) "\n", arg1, arg2); if (ipc_verbose) ipc_printf("(ENTER) %s/%s has entered %s from %s\n", arg1, arg2, fnpGroup, arg3); savePeer(arg1, arg2); break; case ipcExit: //sim_debug (DBG_VERBOSE, &ipc_dev, "%s has left " STR(IPC_GROUP) "\n", arg1); if (ipc_verbose) ipc_printf("(EXIT) %s/%s has left %s\n", arg1, arg2, fnpGroup); removePeer(arg1); break; case ipcShoutTx: zstr_sendx (actor, "SHOUT", arg1, NULL); break; case ipcWhisperTx: #if 1 if (arg1) // WHISPER msg (use last whisper peer) { IPC_Peer *p1 = findPeer(stripquotes(trim(arg1))); // f**k for peer named 'name' if (p1) strcpy(lastPeer, p1->peerID); // save Peer id else { bool bGuid = isGUID(stripquotes(trim(arg1))); if (!bGuid) { sim_printf("Error: '%s' is not a GUID or a known peer\n", arg1); return SCPE_ARG; } strcpy(lastPeer, arg1); // Peer name not found, assume arg1 is a peerID then... } } #endif zstr_sendx (actor, "WHISPER", arg2, NULL); break; case ipcShoutRx: // when we receive a broadcast message //sim_debug (DBG_VERBOSE, &ipc_dev, "%s: %s\n", arg1, arg2); if (ipc_verbose) ipc_printf("(RX SHOUT) %s/%s:<%s>\n", arg1, arg2, arg3); break; case ipcWhisperRx: // when we receive a peer-to-peer (whisper) message //sim_debug (DBG_VERBOSE, &ipc_dev, "%s: %s\n", arg1, arg2); if (ipc_verbose) ipc_printf("(RX WHISPER) %s/%s:<%s>\n", arg1, arg2, arg3); if (strncmp (arg1, "fnp-", 4) == 0) diaCommand (arg1, arg2, arg3); else if (strncmp (arg1, "scp", 3) == 0) scpCommand (arg1, arg2, arg3); else ipc_printf ("dropping whisper from unknown source %s/%s:<%s>\n", arg1, arg2, arg3); break; case ipcTest: zyre_test(true); break; default: break; } return SCPE_OK; }
static t_stat ipc_start(UNIT UNUSED *uptr, int32 UNUSED val, char UNUSED *cval, void UNUSED *desc) { return ipc(ipcStart, fnpName, 0, 0, 0); }
static t_stat ipc_stop(UNIT UNUSED *uptr, int32 UNUSED val, char UNUSED *cval, void UNUSED *desc) { return ipc(ipcStop, 0, 0, 0, 0); }