static void vstat_init_ctx(struct agent_core_t *core, struct vstat_thread_ctx_t *t_ctx) { t_ctx->vd = VSM_New(); t_ctx->vsb = VSB_new_auto(); t_ctx->curl = ipc_register(core,"curl"); t_ctx->logger = ipc_register(core,"logger"); if (core->config->n_arg) VSC_Arg(t_ctx->vd, 'n', core->config->n_arg); }
void vping_init(struct agent_core_t *core) { struct agent_plugin_t *plug; struct vping_priv_t *priv = malloc(sizeof(struct vping_priv_t)); plug = plugin_find(core,"vping"); priv->vadmin_sock = ipc_register(core,"vadmin"); priv->logger = ipc_register(core,"logger"); plug->data = (void *)priv; plug->start = vping_start; }
void vban_init(struct agent_core_t *core) { struct agent_plugin_t *plug; struct vban_priv_t *priv; ALLOC_OBJ(priv); plug = plugin_find(core,"vban"); priv->logger = ipc_register(core,"logger"); priv->vadmin = ipc_register(core,"vadmin"); plug->data = (void *)priv; http_register_url(core, "/ban", M_GET | M_POST, vban_reply, core); http_register_url(core, "/help/ban", M_GET, help_reply, strdup(BAN_HELP_TEXT)); }
void vdirect_init(struct agent_core_t *core) { struct agent_plugin_t *plug; struct vdirect_priv_t *priv = malloc(sizeof(struct vdirect_priv_t)); plug = plugin_find(core,"vdirect"); priv->logger = ipc_register(core,"logger"); priv->vadmin = ipc_register(core,"vadmin"); plug->data = (void *)priv; plug->start = NULL; http_register_url(core, "/direct", M_POST, vdirect_reply, core); http_register_url(core, "/help/direct", M_GET, help_reply, strdup(DIRECT_HELP)); }
void main (int argc, char **argv) { pid_t pid; uint pte; #define SIZE (1024*1024) char buf[SIZE]; pid = fork(); //==================== SERVER ====================// if (pid == 0) { ipc_register(IPC_USER, dispatch); envid = sys_geteid(); sleep(5); return; } //==================== CLIENT ====================// envid = pid2envid(pid); yield(envid); // The "shared" memory used to communicate with the server shared_state = (arg_t *) malloc (sizeof(arg_t)); if (shared_state == NULL) { printf ("[CLIENT] Couldn't allocate shared_state memory\n"); exit(-1); } shared_state->nbytes = 12345; // touch the memory // Figure out the pte corresponding to the "shared" memory pte = sys_read_pte ((uint) shared_state, 0, sys_geteid()); if (pte == 0) { printf ("[CLIENT] Found null pte\n"); exit (-1); } // Now start the operations S_INIT(pte); { int i, t=0, rounds=atoi(argv[1]); for (i=0 ; i < rounds ; i++) { pctrval t0 = rdtsc(); S_EMPTY(0); t += (rdtsc() - t0); bzero ((void *)buf, SIZE); } printf ("%d\t%d\n", rounds, (unsigned int) t/200); } }
static void adapter_ready(int err, const bdaddr_t *addr) { if (err < 0) { error("Adapter initialization failed: %s", strerror(-err)); exit(EXIT_FAILURE); } bacpy(&adapter_bdaddr, addr); if (quit_timeout > 0) { g_source_remove(quit_timeout); quit_timeout = 0; } info("Adapter initialized"); hal_ipc = ipc_init(BLUEZ_HAL_SK_PATH, sizeof(BLUEZ_HAL_SK_PATH), HAL_SERVICE_ID_MAX, true, ipc_disconnected, NULL); if (!hal_ipc) { error("Failed to initialize IPC"); exit(EXIT_FAILURE); } ipc_register(hal_ipc, HAL_SERVICE_ID_CORE, cmd_handlers, G_N_ELEMENTS(cmd_handlers)); }
void vparams_init(struct agent_core_t *core) { struct agent_plugin_t *plug; struct vparams_priv_t *priv; ALLOC_OBJ(priv); plug = plugin_find(core,"vparams"); priv->logger = ipc_register(core,"logger"); priv->vadmin = ipc_register(core,"vadmin"); plug->data = (void *)priv; http_register_url(core, "/param/", M_PUT | M_GET, vparams_reply, core); http_register_url(core, "/paramjson/", M_GET, vparams_reply, core); http_register_url(core, "/help/param", M_GET, help_reply, strdup(PARAM_HELP)); }
void vbackends_init(struct agent_core_t *core) { struct agent_plugin_t *plug; struct vbackends_priv_t *priv; ALLOC_OBJ(priv); plug = plugin_find(core,"vbackends"); priv->logger = ipc_register(core,"logger"); priv->vadmin = ipc_register(core,"vadmin"); plug->data = (void *)priv; http_register_url(core, "/backend/", M_PUT, vbackends_reply, core); http_register_url(core, "/backendjson/", M_GET, vbackends_reply, core); http_register_url(core, "/help/backend", M_GET, help_reply, strdup(BACKENDS_HELP)); }
void vcl_init(struct agent_core_t *core) { struct agent_plugin_t *plug; struct vcl_priv_t *priv; ALLOC_OBJ(priv); plug = plugin_find(core,"vcl"); priv->logger = ipc_register(core,"logger"); priv->vadmin = ipc_register(core,"vadmin"); plug->data = (void *)priv; mk_help(core, priv); http_register_url(core, "/vcljson/", M_GET, vcl_reply, core); http_register_url(core, "/vcl/", M_DELETE | M_PUT | M_GET | M_POST, vcl_reply, core); http_register_url(core, "/vclactive", M_GET , vcl_reply, core); http_register_url(core, "/vcldeploy/", M_PUT , vcl_reply, core); http_register_url(core, "/help/vcl", M_GET, help_reply, priv->help); }
bool bt_a2dp_sink_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode) { DBG(""); hal_ipc = ipc; ipc_register(hal_ipc, HAL_SERVICE_ID_A2DP_SINK, cmd_handlers, G_N_ELEMENTS(cmd_handlers)); return true; }
void vcl_init(struct agent_core_t *core) { struct agent_plugin_t *plug; struct vcl_priv_t *priv; ALLOC_OBJ(priv); plug = plugin_find(core,"vcl"); priv->logger = ipc_register(core,"logger"); priv->vadmin = ipc_register(core,"vadmin"); plug->data = (void *)priv; mk_help(core, priv); http_register_path(core, "/vcljson", M_GET, vcl_json, core); http_register_path(core, "/vcl", M_GET, vcl_listshow, core); http_register_path(core, "/vcl", M_PUT | M_POST, vcl_push, core); http_register_path(core, "/vcl", M_DELETE, vcl_delete, core); http_register_path(core, "/vclactive", M_GET , vcl_active, core); http_register_path(core, "/vcldeploy", M_PUT , vcl_deploy, core); http_register_path(core, "/help/vcl", M_GET, help_reply, priv->help); }
void html_init(struct agent_core_t *core) { struct agent_plugin_t *plug; struct html_priv_t *priv = malloc(sizeof(struct html_priv_t)); plug = plugin_find(core,"html"); priv->logger = ipc_register(core,"logger"); plug->data = (void *)priv; plug->start = NULL; http_register_url(core, "/html/", M_GET, html_reply, core); }
bool bt_health_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode) { DBG(""); bacpy(&adapter_addr, addr); hal_ipc = ipc; ipc_register(hal_ipc, HAL_SERVICE_ID_HEALTH, cmd_handlers, G_N_ELEMENTS(cmd_handlers)); return true; }
void http_init(struct agent_core_t *core) { struct agent_plugin_t *plug; struct http_priv_t *priv; ALLOC_OBJ(priv); plug = plugin_find(core, "http"); priv->logger = ipc_register(core, "logger"); plug->data = (void *)priv; plug->start = http_start; }
void http_init(struct agent_core_t *core) { struct agent_plugin_t *plug; struct http_priv_t *priv = malloc(sizeof(struct http_priv_t)); assert(priv); plug = plugin_find(core,"http"); assert(plug); priv->logger = ipc_register(core,"logger"); plug->data = (void *)priv; plug->start = http_start; priv->listener = NULL; priv->help_page = NULL; }
static bool bt_audio_register(ipc_disconnect_cb disconnect) { DBG(""); audio_ipc = ipc_init(BLUEZ_AUDIO_SK_PATH, sizeof(BLUEZ_AUDIO_SK_PATH), AUDIO_SERVICE_ID_MAX, false, disconnect, NULL); if (!audio_ipc) return false; ipc_register(audio_ipc, AUDIO_SERVICE_ID, audio_handlers, G_N_ELEMENTS(audio_handlers)); return true; }
bool bt_pan_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode) { sdp_record_t *nap_rec, *panu_rec; int err; DBG(""); bacpy(&adapter_addr, addr); nap_rec = nap_record(); if (bt_adapter_add_record(nap_rec, SVC_HINT_NETWORKING) < 0) { sdp_record_free(nap_rec); error("Failed to allocate PAN-NAP sdp record"); return false; } panu_rec = panu_record(); if (bt_adapter_add_record(panu_rec, SVC_HINT_NETWORKING) < 0) { sdp_record_free(nap_rec); sdp_record_free(panu_rec); error("Failed to allocate PAN-PANU sdp record"); return false; } err = bnep_init(); if (err < 0) { error("Failed to init BNEP"); bt_adapter_remove_record(nap_rec->handle); bt_adapter_remove_record(panu_rec->handle); return false; } err = register_nap_server(); if (err < 0) { error("Failed to register NAP server"); bt_adapter_remove_record(nap_rec->handle); bt_adapter_remove_record(panu_rec->handle); bnep_cleanup(); return false; } nap_rec_id = nap_rec->handle; panu_rec_id = panu_rec->handle; hal_ipc = ipc; ipc_register(hal_ipc, HAL_SERVICE_ID_PAN, cmd_handlers, G_N_ELEMENTS(cmd_handlers)); return true; }
bool bt_a2dp_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode) { GError *err = NULL; sdp_record_t *rec; DBG(""); bacpy(&adapter_addr, addr); server = bt_io_listen(connect_cb, NULL, NULL, NULL, &err, BT_IO_OPT_SOURCE_BDADDR, &adapter_addr, BT_IO_OPT_PSM, AVDTP_PSM, BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM, BT_IO_OPT_MASTER, true, BT_IO_OPT_INVALID); if (!server) { error("Failed to listen on AVDTP channel: %s", err->message); g_error_free(err); return false; } rec = a2dp_record(); if (!rec) { error("Failed to allocate A2DP record"); goto fail; } if (bt_adapter_add_record(rec, SVC_HINT_CAPTURING) < 0) { error("Failed to register A2DP record"); sdp_record_free(rec); goto fail; } record_id = rec->handle; hal_ipc = ipc; ipc_register(hal_ipc, HAL_SERVICE_ID_A2DP, cmd_handlers, G_N_ELEMENTS(cmd_handlers)); if (bt_audio_register(audio_disconnected)) return true; fail: g_io_channel_shutdown(server, TRUE, NULL); g_io_channel_unref(server); server = NULL; return false; }
bool bt_hid_register(struct ipc *ipc, const bdaddr_t *addr, uint8_t mode) { GError *err = NULL; DBG(""); bacpy(&adapter_addr, addr); ctrl_io = bt_io_listen(connect_cb, NULL, NULL, NULL, &err, BT_IO_OPT_SOURCE_BDADDR, &adapter_addr, BT_IO_OPT_PSM, L2CAP_PSM_HIDP_CTRL, BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW, BT_IO_OPT_INVALID); if (!ctrl_io) { error("hidhost: Failed to listen on control channel: %s", err->message); g_error_free(err); return false; } intr_io = bt_io_listen(connect_cb, NULL, NULL, NULL, &err, BT_IO_OPT_SOURCE_BDADDR, &adapter_addr, BT_IO_OPT_PSM, L2CAP_PSM_HIDP_INTR, BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW, BT_IO_OPT_INVALID); if (!intr_io) { error("hidhost: Failed to listen on interrupt channel: %s", err->message); g_error_free(err); g_io_channel_shutdown(ctrl_io, TRUE, NULL); g_io_channel_unref(ctrl_io); ctrl_io = NULL; return false; } hal_ipc = ipc; ipc_register(hal_ipc, HAL_SERVICE_ID_HIDHOST, cmd_handlers, G_N_ELEMENTS(cmd_handlers)); return true; }
void echo_init(struct agent_core_t *core) { struct echo_priv_t *priv; struct agent_plugin_t *plug; /* * Allocate the private data structure we'll keep using. */ ALLOC_OBJ(priv); /* * Find our pre-allocated data structure. This is only used to * define start-functions (which we don't have), module-specific * private data and an IPC for the module (which we don't use). */ plug = plugin_find(core, "echo"); /* * Register with the logger. */ priv->logger = ipc_register(core, "logger"); /* * Store our private data somewhere we can reach it, and set our * start function to NULL since echo is only triggered by HTTP * requests. */ plug->data = (void *)priv; /* * Register the url /echo for the methods POST, PUT and GET. When a * request like that is encountered, the echo_reply function will * be called with "priv" as the last argument. */ http_register_path(core, "/echo", M_POST | M_PUT | M_GET, echo_reply, priv); }
int main(int argc, char *const argv[]) { int error = 0; log_debug("Parsing options"); Options *opts = parse_opt(argc, argv); if (!opts) { show_banner(); show_help(); return -1; } log_set_level(opts->loglevel); if (opts->logfile) { log_set_logfile(opts->logfile); log_set_logfile_level(LOG_LEVEL_MAX); } #ifdef HAVE_VSYSLOG if (opts->syslog) { log_set_syslog("daliserver"); } #endif if (opts->background) { daemonize(opts->pidfile); } else { show_banner(); } log_info("Starting daliserver"); log_debug("Initializing dispatch queue"); DispatchPtr dispatch = dispatch_new(); if (!dispatch) { error = -1; } else { //dispatch_set_timeout(dispatch, 100); UsbDaliPtr usb = NULL; if (!opts->dryrun) { log_debug("Initializing USB connection"); usb = usbdali_open(NULL, dispatch, opts->usbbus, opts->usbdev); if (!usb) { error = -1; } } if (opts->dryrun || usb) { log_debug("Initializing server"); ServerPtr server = server_open(dispatch, opts->address, opts->port, DEFAULT_NET_FRAMESIZE, net_frame_handler, usb); if (!server) { error = -1; } else { server_set_connection_destroy_callback(server, net_dequeue_connection, usb); if (usb) { usbdali_set_outband_callback(usb, dali_outband_handler, server); usbdali_set_inband_callback(usb, dali_inband_handler); } log_debug("Creating shutdown notifier"); killsocket = ipc_new(); if (!killsocket) { error = -1; } else { ipc_register(killsocket, dispatch); log_info("Server ready, waiting for events"); running = 1; signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); while (running && dispatch_run(dispatch, usbdali_get_timeout(usb))); log_info("Shutting daliserver down"); ipc_free(killsocket); } server_close(server); } if (usb) { usbdali_close(usb); } } dispatch_free(dispatch); } free_opt(opts); log_info("Exiting"); return error; }
int main(int argc, char *argv[]) { GOptionContext *context; GError *err = NULL; guint signal; context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); if (g_option_context_parse(context, &argc, &argv, &err) == FALSE) { if (err != NULL) { g_printerr("%s\n", err->message); g_error_free(err); } else g_printerr("An unknown error occurred\n"); exit(EXIT_FAILURE); } g_option_context_free(context); if (option_version == TRUE) { printf("%s\n", VERSION); exit(EXIT_SUCCESS); } signal = setup_signalfd(); if (!signal) return EXIT_FAILURE; __btd_log_init("*", 0); if (!set_capabilities()) { __btd_log_cleanup(); g_source_remove(signal); return EXIT_FAILURE; } bluetooth_start_timeout = g_timeout_add_seconds(STARTUP_GRACE_SECONDS, quit_eventloop, NULL); if (bluetooth_start_timeout == 0) { error("Failed to init startup timeout"); __btd_log_cleanup(); g_source_remove(signal); return EXIT_FAILURE; } if (!bt_bluetooth_start(option_index, adapter_ready)) { __btd_log_cleanup(); g_source_remove(bluetooth_start_timeout); g_source_remove(signal); return EXIT_FAILURE; } /* Use params: mtu = 0, flags = 0 */ start_sdp_server(0, 0); ipc_register(HAL_SERVICE_ID_CORE, cmd_handlers, G_N_ELEMENTS(cmd_handlers)); DBG("Entering main loop"); event_loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(event_loop); g_source_remove(signal); if (bluetooth_start_timeout > 0) g_source_remove(bluetooth_start_timeout); cleanup_services(); ipc_cleanup(); stop_sdp_server(); bt_bluetooth_cleanup(); g_main_loop_unref(event_loop); ipc_unregister(HAL_SERVICE_ID_CORE); info("Exit"); __btd_log_cleanup(); return EXIT_SUCCESS; }