/** Dispatch checks args and then trys to match against commands */ void cmd_dispatch(int argc, char **argv) { int i; if(argc < 1) { cmd_sendresponse(put_error(501,"Bad Request"), 404); cmd_done(); return; } for(i = 0; i < sizeof(commands) / sizeof(commands[0]); i++) { if(!strcmp(commands[i].name, argv[0])) { if(commands[i].fn(argc, argv)) cmd_done(); return; }else if(!strcmp("playlist", argv[0])) { /// @note: this is soon to be deprecated, a backwardcomp for prev version #ifdef USE_MYSQL _mysql_updateStats(g_conn, "init"); cmd_sendresponse(put_error(200,"Pong"), 200); cmd_done(); return; #endif } } cmd_sendresponse(put_error(501,"Not implemented"), 404); cmd_done(); }
/** * Get Header response callback * @param pucFrame - pointer to response frame * @param pusLength - response frame length * @return */ eMBException cmd_prepareflash_callback( UCHAR * pucFrame, USHORT * pusLength ) { cmdFrameHeader *pFrame = (cmdFrameHeader *)(pucFrame - 1); DEBUG_PUTSTRING("PREPARE_FLASH CALLBACK"); switch (pFrame->status) { case BOOT_OK: printf ("Selected Bank: "); switch(pFrame->subcmdId) { case 1: printf("A\n"); break; case 2: printf("B\n"); break; case 3: printf("F\n"); break; default: printf("Unknown\n"); break; } break; default: printf ("PrepareFlash: %s\n", cmd_errorString(pFrame->status)); break; } cmd_done(pFrame->status); return MB_EX_NONE; }
static void playlist_browse_try(void) { int i, tracks; metadata_updated_fn = playlist_browse_try; if(!sp_playlist_is_loaded(playlist_browse)) return; tracks = sp_playlist_num_tracks(playlist_browse); for(i = 0; i < tracks; i++) { sp_track *t = sp_playlist_track(playlist_browse, i); if (!sp_track_is_loaded(t)) return; } printf("\tPlaylist and metadata loaded\n"); for(i = 0; i < tracks; i++) { sp_track *t = sp_playlist_track(playlist_browse, i); printf(" %5d: ", i + 1); print_track(t); } sp_playlist_remove_callbacks(playlist_browse, &pl_callbacks, NULL); sp_playlist_release(playlist_browse); playlist_browse = NULL; metadata_updated_fn = NULL; cmd_done(); }
void cmd_dispatch(int argc, char **argv) { int i; if(argc < 1) { cmd_done(); return; } for(i = 0; i < sizeof(commands) / sizeof(commands[0]); i++) { if(!strcmp(commands[i].name, argv[0])) { if(commands[i].fn(argc, argv)) cmd_done(); return; } } printf("No such command\n"); cmd_done(); }
/** Cmd pong Used when you need to ping the service, and see if its up Responds with "pong" if available. */ int cmd_pong(int arc, char **argv){ #ifdef USE_MYSQL _mysql_updateStats(g_conn, "init"); #endif cmd_sendresponse(put_error(200,"Pong"), 200); cmd_done(); return 1; }
static void pl_state_change(sp_playlist *pl, void *userdata) { struct pl_update_work *puw = userdata; if(apply_changes(pl, puw)) return; sp_playlist_remove_callbacks(pl, &pl_update_callbacks, puw); sp_playlist_release(pl); cmd_done(); }
/** * Callback for libspotify * * @param browse The browse result object that is now done * @param userdata The opaque pointer given to sp_artistbrowse_create() */ static void browse_artist_callback(sp_artistbrowse *browse, void *userdata) { if (sp_artistbrowse_error(browse) == SP_ERROR_OK) print_artistbrowse(browse); else fprintf(stderr, "Failed to browse artist: %s\n", sp_error_message(sp_artistbrowse_error(browse))); sp_artistbrowse_release(browse); cmd_done(); }
/** * Callback for libspotify * * @param browse The browse result object that is now done * @param userdata The opaque pointer given to sp_artistbrowse_create() */ static void search_complete(sp_search *search, void *userdata) { if (sp_search_error(search) == SP_ERROR_OK) print_search(search); else fprintf(stderr, "Failed to search: %s\n", sp_error_message(sp_search_error(search))); sp_search_release(search); cmd_done(); }
static void search_complete(sp_search *search, void *userdata) { if (sp_search_error(search) == SP_ERROR_OK){ get_search(search); } else cmd_sendresponse(put_error(400, sp_error_message(sp_search_error(search))), 400); sp_search_release(search); cmd_done(); }
static void track_browse_try(void) { switch (sp_track_error(track_browse)) { case SP_ERROR_OK: print_track(track_browse); break; case SP_ERROR_IS_LOADING: return; // Still pending default: fprintf(stderr, "Unable to resolve track: %s\n", sp_error_message(sp_track_error(track_browse))); break; } metadata_updated_fn = NULL; cmd_done(); sp_track_release(track_browse); }
/** * Callback for libspotify * * @param result The toplist result object that is now done * @param userdata The opaque pointer given to sp_toplistbrowse_create() */ static void got_toplist(sp_toplistbrowse *result, void *userdata) { int i; // We print from all types. Only one of the loops will acually yield anything. for(i = 0; i < sp_toplistbrowse_num_artists(result); i++) print_artist(i + 1, sp_toplistbrowse_artist(result, i)); for(i = 0; i < sp_toplistbrowse_num_albums(result); i++) print_album(i + 1, sp_toplistbrowse_album(result, i)); for(i = 0; i < sp_toplistbrowse_num_tracks(result); i++) { printf("%3d: ", i + 1); print_track(sp_toplistbrowse_track(result, i)); } sp_toplistbrowse_release(result); cmd_done(); }
/** * Poll the modbus. * * @param pvParameter */ void * pvPollingThread( void *pvParameter ) { vSetPollingThreadState( RUNNING ); DEBUG_PUTSTRING("Thread started!"); if( eMBEnable( ) == MB_ENOERR ) { do { if( eMBPoll( ) != MB_ENOERR ) break; } while( eGetPollingThreadState( ) != SHUTDOWN ); } ( void )eMBDisable( ); vSetPollingThreadState( STOPPED ); DEBUG_PUTSTRING("Thread stopped!"); cmd_done(BOOT_EXIT); return 0; }
/** * Callback for libspotify * * @param result The toplist result object that is now done * @param userdata The opaque pointer given to sp_toplistbrowse_create() */ static void got_toplist(sp_toplistbrowse *result, void *userdata) { int i; json_t *json = json_object(); json_t *toplist = json_object(); json_object_set_new(json, "toplist", toplist); json_t *results = json_array(); json_object_set_new(toplist, "result", results); // We print from all types. Only one of the loops will acually yield anything. for(i = 0; i < sp_toplistbrowse_num_artists(result); i++) json_array_append_new(results, get_artist(sp_toplistbrowse_artist(result, i))); for(i = 0; i < sp_toplistbrowse_num_albums(result); i++) json_array_append_new(results, get_album(sp_toplistbrowse_album(result, i))); for(i = 0; i < sp_toplistbrowse_num_tracks(result); i++) json_array_append_new(results, get_track(sp_toplistbrowse_track(result, i))); cmd_sendresponse(json, 200); sp_toplistbrowse_release(result); cmd_done(); }
void start_prompt(void) { cmd_done(); }
static void mac53c94_interrupt(int irq, void *dev_id) { struct fsc_state *state = (struct fsc_state *) dev_id; struct mac53c94_regs __iomem *regs = state->regs; struct dbdma_regs __iomem *dma = state->dma; struct scsi_cmnd *cmd = state->current_req; int nb, stat, seq, intr; static int mac53c94_errors; /* * Apparently, reading the interrupt register unlatches * the status and sequence step registers. */ seq = readb(®s->seqstep); stat = readb(®s->status); intr = readb(®s->interrupt); #if 0 printk(KERN_DEBUG "mac53c94_intr, intr=%x stat=%x seq=%x phase=%d\n", intr, stat, seq, state->phase); #endif if (intr & INTR_RESET) { /* SCSI bus was reset */ printk(KERN_INFO "external SCSI bus reset detected\n"); writeb(CMD_NOP, ®s->command); writel(RUN << 16, &dma->control); /* stop dma */ cmd_done(state, DID_RESET << 16); return; } if (intr & INTR_ILL_CMD) { printk(KERN_ERR "53c94: invalid cmd, intr=%x stat=%x seq=%x phase=%d\n", intr, stat, seq, state->phase); cmd_done(state, DID_ERROR << 16); return; } if (stat & STAT_ERROR) { #if 0 /* XXX these seem to be harmless? */ printk("53c94: bad error, intr=%x stat=%x seq=%x phase=%d\n", intr, stat, seq, state->phase); #endif ++mac53c94_errors; writeb(CMD_NOP + CMD_DMA_MODE, ®s->command); } if (cmd == 0) { printk(KERN_DEBUG "53c94: interrupt with no command active?\n"); return; } if (stat & STAT_PARITY) { printk(KERN_ERR "mac53c94: parity error\n"); cmd_done(state, DID_PARITY << 16); return; } switch (state->phase) { case selecting: if (intr & INTR_DISCONNECT) { /* selection timed out */ cmd_done(state, DID_BAD_TARGET << 16); return; } if (intr != INTR_BUS_SERV + INTR_DONE) { printk(KERN_DEBUG "got intr %x during selection\n", intr); cmd_done(state, DID_ERROR << 16); return; } if ((seq & SS_MASK) != SS_DONE) { printk(KERN_DEBUG "seq step %x after command\n", seq); cmd_done(state, DID_ERROR << 16); return; } writeb(CMD_NOP, ®s->command); /* set DMA controller going if any data to transfer */ if ((stat & (STAT_MSG|STAT_CD)) == 0 && (scsi_sg_count(cmd) > 0 || scsi_bufflen(cmd))) { nb = cmd->SCp.this_residual; if (nb > 0xfff0) nb = 0xfff0; cmd->SCp.this_residual -= nb; writeb(nb, ®s->count_lo); writeb(nb >> 8, ®s->count_mid); writeb(CMD_DMA_MODE + CMD_NOP, ®s->command); writel(virt_to_phys(state->dma_cmds), &dma->cmdptr); writel((RUN << 16) | RUN, &dma->control); writeb(CMD_DMA_MODE + CMD_XFER_DATA, ®s->command); state->phase = dataing; break; } else if ((stat & STAT_PHASE) == STAT_CD + STAT_IO) {
/* Client command loop only considers console inputs + controller messages */ void run_client(char *infile_name) { if (!start_cmd(infile_name)) return; while (!cmd_done()) { /* Select among controller port, and connections to routers */ FD_ZERO(&cset); maxcfd = 0; add_cfd(controller_fd); cmd_select(maxcfd+1, &cset, NULL, NULL, NULL); if (cmd_done()) break; int fd; for (fd = 0; fd <= maxcfd; fd++) { if (!FD_ISSET(fd, &cset)) continue; bool eof; chunk_ptr msg = chunk_read(fd, &eof); if (eof) { /* Unexpected EOF */ if (fd == controller_fd) { err(true, "Unexpected EOF from controller (fatal)"); } else { err(false, "Unexpected EOF from unexpected source. fd %d (ignored)", fd); } close(fd); continue; } if (msg == NULL) { err(false, "Could not read chunk from fd %d (ignored)", fd); continue; } word_t h = chunk_get_word(msg, 0); unsigned code = msg_get_header_code(h); if (fd == controller_fd) { /* Message from controller */ switch(code) { case MSG_DO_FLUSH: chunk_free(msg); #if RPT >= 5 report(5, "Received flush message from controller"); #endif if (flush_helper) { flush_helper(); } break; case MSG_STAT: #if RPT >= 5 report(5, "Received summary statistics from controller"); #endif if (stat_helper) { /* Get a copy of the byte usage from mem. allocator */ stat_helper(msg); } chunk_free(msg); /* Client can proceed with next command */ unblock_console(); break; case MSG_KILL: chunk_free(msg); #if RPT >= 1 report(1, "Received kill message from controller"); #endif finish_cmd(); break; case MSG_GC_START: chunk_free(msg); gc_start(code); break; case MSG_GC_FINISH: chunk_free(msg); gc_finish(code); break; default: chunk_free(msg); err(false, "Unknown message code %u from controller (ignored)", code); } } else { err(false, "Received message from unknown source. fd %d (ignored)", fd); close(fd); continue; } } } }
/* Fire an operation and wait for returned operand */ chunk_ptr fire_and_wait_defer(chunk_ptr msg) { chunk_ptr rval = NULL; if (!send_op(msg)) { err(false, "Failed to send message"); return NULL; } bool local_done = false; while (!(local_done || cmd_done())) { /* Select among controller port, and connections to routers. Do not accept console input */ FD_ZERO(&rset); maxrfd = 0; add_rfd(controller_fd); unsigned ridx; for (ridx = 0; ridx < nrouters; ridx++) add_rfd(router_fd_array[ridx]); buf_select(maxrfd+1, &rset, NULL, NULL, NULL); int fd; for (fd = 0; fd <= maxrfd; fd++) { if (!FD_ISSET(fd, &rset)) continue; bool eof; chunk_ptr msg = chunk_read(fd, &eof); if (eof) { /* Unexpected EOF */ if (fd == controller_fd) { err(true, "Unexpected EOF from controller (fatal)"); } else { err(false, "Unexpected EOF from router with fd %d (shutting down)", fd); finish_cmd(); exit(0); } close(fd); continue; } if (msg == NULL) { err(false, "Could not read chunk from fd %d (ignored)", fd); continue; } word_t h = chunk_get_word(msg, 0); unsigned code = msg_get_header_code(h); if (fd == controller_fd) { /* Message from controller */ switch(code) { case MSG_KILL: chunk_free(msg); #if RPT >= 1 report(1, "Received kill message from controller"); #endif quit_agent(0, NULL); break; case MSG_DO_FLUSH: chunk_free(msg); #if RPT >= 2 report(2, "Received flush message from controller"); #endif if (flush_helper) { flush_helper(0, NULL); } break; case MSG_GC_START: /* Got notice that should initiate garbage collection. Defer until current operation done */ #if RPT >= 3 report(3, "Deferring GC start"); #endif chunk_free(msg); gc_state = GC_DEFER; break; case MSG_GC_FINISH: #if RPT >= 3 report(3, "Unexpected GC_FINISH message from controller when waiting for result (ignored)"); #endif chunk_free(msg); break; default: chunk_free(msg); err(false, "Unknown message code %u from controller (ignored)", code); } } else { dword_t dh; word_t id = 0; /* Must be message from router */ switch (code) { case MSG_OPERATION: chunk_free(msg); err(false, "Received unexpected operation. Ignored."); local_done = true; break; case MSG_OPERAND: #if RPT >= 5 dh = chunk_get_dword(msg, 0); id = msg_get_dheader_op_id(dh); report(5, "Received operand with id 0x%lx", id); #endif rval = msg; local_done = true; break; default: chunk_free(msg); err(false, "Received message with unknown code %u (ignored)", code); local_done = true; } } } } return rval; }
static void run_controller(char *infile_name) { if (!start_cmd(infile_name)) return; while (!cmd_done()) { FD_ZERO(&set); int fd; word_t w; unsigned ip; unsigned port; add_fd(listen_fd); keyvalue_iterstart(new_conn_map); /* Check for messages from newly connected clients, workers, and routers */ while (keyvalue_iternext(new_conn_map, &w, NULL)) { fd = w; add_fd(fd); } if (need_routers == 0) { /* Accept messages from workers */ set_iterstart(worker_fd_set); while (set_iternext(worker_fd_set, &w)) { fd = w; add_fd(fd); } /* Accept messages from clients */ set_iterstart(client_fd_set); while (set_iternext(client_fd_set, &w)) { fd = w; add_fd(fd); } } cmd_select(maxfd+1, &set, NULL, NULL, NULL); for (fd = 0; fd <= maxfd; fd++) { if (!FD_ISSET(fd, &set)) continue; if (fd == listen_fd) { unsigned ip; int connfd = accept_connection(fd, &ip); keyvalue_insert(new_conn_map, (word_t) connfd, (word_t) ip); #if RPT >= 4 report(4, "Accepted new connection. Connfd = %d, IP = 0x%x", connfd, ip); #endif continue; } bool eof; chunk_ptr msg = chunk_read(fd, &eof); if (eof) { /* Unexpected EOF */ if (keyvalue_remove(new_conn_map, (word_t) fd, NULL, NULL)) { err(false, "Unexpected EOF from new connection, fd %d", fd); } else if (set_member(worker_fd_set, (word_t) fd, true)) { err(false, "Unexpected EOF from connected worker, fd %d. Shutting down", fd); /* Shut down system */ finish_cmd(); } else if (set_member(client_fd_set, (word_t) fd, true)) { #if RPT >= 3 report(3, "Disconnection from client (fd %d)", fd); #endif if (need_client_fd_set && set_member(need_client_fd_set, (word_t) fd, false)) { #if RPT >= 3 report(3, "Removing client from GC activities"); #endif handle_gc_msg(MSG_GC_FINISH, 0, fd, true); } } else { err(false, "Unexpected EOF from unknown source, fd %d", fd); } close(fd); continue; } if (msg == NULL) { err(false, "Could not read chunk from fd %d (ignored)", fd); continue; } word_t h = chunk_get_word(msg, 0); unsigned code = msg_get_header_code(h); #if RPT >= 5 report(5, "Received message with code %d from fd %d", code, fd); #endif if (keyvalue_remove(new_conn_map, (word_t) fd, NULL, &w)) { ip = w; chunk_free(msg); /* Should be a registration message */ switch (code) { case MSG_REGISTER_ROUTER: if (need_routers == 0) { err(false, "Unexpected router registration. (Ignored)"); close(fd); break; } port = msg_get_header_port(h); word_t node_id = msg_build_node_id(port, ip); set_insert(router_addr_set, node_id); set_insert(router_fd_set, (word_t) fd); #if RPT >= 4 report(4, "Added router with fd %d. IP 0x%x. Port %u", fd, ip, port); #endif need_routers --; if (need_routers == 0) { #if RPT >= 2 report(2, "All routers connected"); #endif /* Have gotten all of the necessary routers. Notify any registered workers */ set_iterstart(worker_fd_set); int wfd; while (set_iternext(worker_fd_set, &w)) { wfd = w; add_agent(wfd, false); } } break; case MSG_REGISTER_WORKER: if (worker_fd_set->nelements >= worker_cnt) { err(false, "Unexpected worker registration. (Ignored)"); close(fd); break; } set_insert(worker_fd_set, (word_t) fd); #if RPT >= 4 report(4, "Added worker with fd %d", fd); #endif if (need_routers == 0) add_agent(fd, false); break; case MSG_REGISTER_CLIENT: if (gc_state == GC_READY) { set_insert(client_fd_set, (word_t) fd); #if RPT >= 4 report(4, "Added client with fd %d", fd); #endif if (need_workers == 0) add_agent(fd, true); } else { if (!defer_client_fd_set) { defer_client_fd_set = word_set_new(); } set_insert(defer_client_fd_set, (word_t) fd); #if RPT >= 3 report(3, "Deferring client with fd %d until GC completed", fd); #endif } break; default: err(false, "Unexpected message code %u from new connection", code); break; } } else if (set_member(worker_fd_set, (word_t) fd, false)) { /* Message from worker */ switch (code) { unsigned agent; unsigned gen; case MSG_READY_WORKER: chunk_free(msg); if (need_workers == 0) { err(false, "Unexpected worker ready. (Ignored)"); close(fd); break; } need_workers--; if (need_workers == 0) { #if RPT >= 2 report(2, "All workers connected"); #endif /* Notify any pending clients */ set_iterstart(client_fd_set); int cfd; while (set_iternext(client_fd_set, &w)) { cfd = w; add_agent(cfd, true); } } break; case MSG_STAT: /* Message gets stashed away. Don't free it */ add_stat_message(msg); break; case MSG_CLIOP_ACK: /* Worker acknowledging receipt of global operation info */ agent = msg_get_header_agent(h); int client_fd = receive_global_op_worker_ack(agent); if (client_fd >= 0) { /* Have received complete set of acknowledgements. */ /* Send ack to client */ if (chunk_write(client_fd, msg)) { #if RPT >= 6 report(6, "Sent ack to client for global operation with id %u", agent); #endif } else { err(false, "Failed to send ack to client for global operation with id %u. Fd %d", agent, client_fd); } } chunk_free(msg); break; case MSG_GC_START: case MSG_GC_FINISH: handle_gc_msg(code, 0, fd, false); chunk_free(msg); break; case MSG_GC_REQUEST: gen = msg_get_header_generation(h); chunk_free(msg); handle_gc_msg(code, gen, fd, false); break; default: chunk_free(msg); err(false, "Unexpected message code %u from worker", code); } } else if (set_member(client_fd_set, (word_t) fd, false)) { /* Message from client */ switch(code){ unsigned agent; word_t w; case MSG_KILL: /* Shutdown entire system */ chunk_free(msg); #if RPT >= 2 report(2, "Remote request to kill system"); #endif finish_cmd(); return; case MSG_DO_FLUSH: /* Initiate a flush operation */ chunk_free(msg); flush_requestor_fd = fd; do_controller_flush_cmd(0, NULL); break; case MSG_CLIOP_DATA: /* Request for global operation from client */ agent = msg_get_header_agent(h); add_global_op(agent, fd); /* Send message to all workers */ set_iterstart(worker_fd_set); while (set_iternext(worker_fd_set, &w)) { int worker_fd = (int) w; if (chunk_write(worker_fd, msg)) { #if RPT >= 6 report(6, "Sent global operation information with id %u to worker with fd %d", agent, worker_fd); #endif } else { err(false, "Failed to send global operation information with id %u to worker with fd %d", agent, worker_fd); } } chunk_free(msg); break; case MSG_CLIOP_ACK: /* Completion of global operation by client */ agent = msg_get_header_agent(h); /* Send message to all workers */ set_iterstart(worker_fd_set); while (set_iternext(worker_fd_set, &w)) { int worker_fd = (int) w; if (chunk_write(worker_fd, msg)) { #if RPT >= 6 report(6, "Sent global operation acknowledgement with id %u to worker with fd %d", agent, worker_fd); #endif } else { err(false, "Failed to send global operation acknowledgement with id %u to worker with fd %d", agent, worker_fd); } } chunk_free(msg); break; case MSG_GC_START: case MSG_GC_FINISH: handle_gc_msg(code, 0, fd, true); chunk_free(msg); break; default: err(false, "Unexpected message code %u from client", code); } } else { chunk_free(msg); err(false, "Unexpected message on fd %d (Ignored)", fd); } } } }