gint kp_server_send_leave( KPServer *self, guchar *spaceid, guchar *nodeid, gint msgnum) { gint retval; whiteboard_log_debug_fb(); retval = sib_object_send_leave( self->sib, spaceid, nodeid, msgnum); whiteboard_log_debug_fb(); return retval; }
/** * Attempt to iterate to the next DBusMessage argument, while checking that * the new argument isn't WHITEBOARD_CMD_DATA_END * * @param iter An iterator */ static gboolean whiteboard_cmd_iter_next_internal(WhiteBoardCmdIter* iter) { const gchar* str = NULL; whiteboard_log_debug_fb(); /* Jump to the next item, fail if there are no more items */ if (dbus_message_iter_next(&iter->iter) == FALSE) { whiteboard_log_debug_fe(); return FALSE; } /* Check that the current item is a string, fail if not */ if (dbus_message_iter_get_arg_type(&iter->iter) != DBUS_TYPE_STRING) { whiteboard_log_debug_fe(); return FALSE; } /* Check that the current item is not an end marker */ dbus_message_iter_get_basic(&iter->iter, &str); if (str == NULL || strcmp(str, WHITEBOARD_CMD_DATA_END) == 0) { whiteboard_log_debug_fe(); return FALSE; } whiteboard_log_debug_fe(); return TRUE; }
gboolean whiteboard_cmd_iter_init(WhiteBoardCmd* self, WhiteBoardCmdIter* iter) { gint arg_type = 0; const gchar* str = NULL; whiteboard_log_debug_fb(); g_return_val_if_fail(self != NULL, FALSE); g_return_val_if_fail(iter != NULL, FALSE); iter->data = self; dbus_message_iter_init(self->msg, &iter->iter); /* Skip all arguments before the begin marker */ while ( (arg_type = dbus_message_iter_get_arg_type(&iter->iter)) != DBUS_TYPE_INVALID) { if (arg_type == DBUS_TYPE_STRING) { dbus_message_iter_get_basic(&iter->iter, &str); if (str != NULL && strcmp(str, WHITEBOARD_CMD_DATA_BEGIN) == 0) { dbus_message_iter_next(&iter->iter); return TRUE; } } dbus_message_iter_next(&iter->iter); } whiteboard_log_debug_fe(); return FALSE; }
void register_sib_cb(SibObject* context, SibObjectHandle *handle, gchar *uri, gpointer user_data) { NotaRMHandler *rm = (NotaRMHandler *)user_data; gint ret = -1; gint sid = -1; whiteboard_log_debug_fb(); sid = nota_rm_handler_register_sib(rm, uri); if(sid<0) { whiteboard_log_debug("Registering sib: %s to RM failed\n", uri); ret = -1; sib_object_send_register_sib_return(handle, ret); } else { ret = 0; sib_object_send_register_sib_return(handle, ret); whiteboard_log_debug("Creating listener for SID: %d\n",sid); kplistener = kp_listener_new(sid, nota_rm_handler_get_maxfd(rm)); } whiteboard_log_debug_fe(); }
static void sib_service_device_listener(SIBDeviceStatus status, SIBServerData *ssdata, gpointer user_data) { SIBService *service = NULL; whiteboard_log_debug_fb(); service = (SIBService *)user_data; g_return_if_fail(service != NULL); switch(status) { case SIBDeviceStatusAdded: whiteboard_log_debug("SIBDeviceStatusAdded: %s<%s>\n", ssdata->name,ssdata->uri ); g_return_if_fail(ssdata!= NULL); sib_service_add_server(service,ssdata->uri,ssdata->name, ssdata->sid, ssdata->port); break; case SIBDeviceStatusRemoved: whiteboard_log_debug("SIBDeviceStatusRemoved: %s<%s>\n",ssdata->name,ssdata->uri ); sib_service_remove_server(service,ssdata->uri); break; case SIBDeviceStatusInvalid: whiteboard_log_debug("SIBDeviceStatusInvalid: %s<%s>\n",ssdata->name,ssdata->uri ); sib_service_remove_server(service,ssdata->uri); break; default: whiteboard_log_error("Unknown SIBDeviceStatus for server: %s\n",ssdata->uri ); break; } whiteboard_log_debug_fe(); }
WhiteBoardCmdRequest* whiteboard_cmd_new_request(const gchar* method, const gchar* target_uuid) { WhiteBoardCmd* self = NULL; const gchar* begin = WHITEBOARD_CMD_DATA_BEGIN; whiteboard_log_debug_fb(); g_return_val_if_fail(method != NULL, NULL); g_return_val_if_fail(target_uuid != NULL, NULL); self = g_new0(WhiteBoardCmd, 1); g_return_val_if_fail(self != NULL, NULL); self->refcount = 1; self->msg = dbus_message_new_method_call(WHITEBOARD_DBUS_SERVICE, WHITEBOARD_DBUS_OBJECT, WHITEBOARD_DBUS_INTERFACE, WHITEBOARD_DBUS_METHOD_CUSTOM_COMMAND); g_return_val_if_fail(self->msg != NULL, NULL); whiteboard_cmd_append_method_name(self, method); whiteboard_cmd_append_target_uuid(self, target_uuid); dbus_message_append_args(self->msg, DBUS_TYPE_STRING, &begin, DBUS_TYPE_INVALID); whiteboard_log_debug_fe(); return (WhiteBoardCmdRequest*) self; }
void kp_server_handle_remove_cnf( SibObject *context, guchar *spaceid, guchar *nodeid, gint msgnum, gint success, gpointer user_data) { KPServer *self = NULL; whiteboard_log_debug_fb(); self = (KPServer *)user_data; g_mutex_lock(self->send_lock); whiteboard_log_debug("RemoveCnf ->\n"); whiteboard_log_debug("\tspaceid: %s\n", spaceid); whiteboard_log_debug("\tnodeid: %s\n", nodeid); whiteboard_log_debug("\tmsgnum: %d\n", msgnum); whiteboard_log_debug("\tsuccess: %d\n", success); if( SibAccessNota_Remove_cnf(self->cp, (uint8_t *) nodeid, (uint16_t) strlen( (gchar *)nodeid), (uint8_t *) spaceid, (uint16_t) strlen( (gchar *)spaceid), (uint16_t) msgnum, (sibstatus_t) success) < 0 ) { whiteboard_log_warning("Remove cnf sending failed\n"); } else { whiteboard_log_debug("Remove cnf sent\n"); } g_mutex_unlock(self->send_lock); whiteboard_log_debug_fe(); }
void kp_server_handle_leave_ind( SibObject *context, guchar *spaceid, guchar *nodeid, gint msgnum, gint status, gpointer user_data) { KPServer *self = NULL; whiteboard_log_debug_fb(); self = (KPServer *)user_data; g_mutex_lock(self->send_lock); if( SibAccessNota_Leave_ind(self->cp, (uint8_t *) nodeid, (uint16_t) strlen( (gchar *)nodeid), (uint8_t *) spaceid, (uint16_t) strlen( (gchar *)spaceid), (uint16_t) msgnum, status) < 0 ) { whiteboard_log_warning("Leave ind sending failed\n"); } else { whiteboard_log_debug("Leave ind sent\n"); } g_mutex_unlock(self->send_lock); whiteboard_log_debug_fe(); }
static void sib_controller_resolver_found( GaServiceResolver *context, gint interface, gint protocol, gchar *name, gchar *type, gchar *domain, gchar *host_name, AvahiAddress *avahi_address, gint port, AvahiStringList *txt, gint flags, gpointer userdata) { whiteboard_log_debug_fb(); SIBController *self = (SIBController *)userdata; g_return_if_fail( self!= NULL); SIBServerData *ssdata = NULL; ssdata = sib_controller_get_service(self, (guchar *)name); if(ssdata) { ssdata->ip = g_new0(gchar, AVAHI_ADDRESS_STR_MAX); avahi_address_snprint(ssdata->ip, AVAHI_ADDRESS_STR_MAX*sizeof(gchar), avahi_address); ssdata->name = (guchar *)g_strdup(host_name); ssdata->port = port; whiteboard_log_debug("Service %s resolved: %s, %d\n", name, ssdata->ip, port); self->listener( SIBDeviceStatusAdded, ssdata, self->listener_data ); } whiteboard_log_debug_fe(); }
/** * Unlock a SIBService instance after a critical operation * * @param self The SIBService instance to unlock */ void sib_service_unlock(SIBService* self) { whiteboard_log_debug_fb(); g_return_if_fail(self != NULL); g_mutex_unlock(self->mutex); whiteboard_log_debug_fe(); }
static void sib_controller_removed_service_cb( GaServiceBrowser *context, gint interface, gint protocol, gchar *name, gchar *type, gchar *domain, gint flags, gpointer userdata) { whiteboard_log_debug_fb(); SIBController *self = (SIBController *)userdata; g_return_if_fail(self!=NULL); whiteboard_log_debug("Removed service: %s, type %s, domain: %s\n", name, type, domain); SIBServerData *ssdata = sib_controller_get_service(self, (guchar *)name); if( ssdata ) { if( ssdata->ip ) // assume that if ip is filled, resolver has finished { // notify listener self->listener( SIBDeviceStatusRemoved, ssdata, self->listener_data ); } sib_controller_remove_service(self, (guchar *)name); } whiteboard_log_debug_fe(); }
// TODO: change UDN to SIB_identifier gint sib_service_add_server(SIBService* service , guchar *udn, guchar *name, gint sid, gint port ) { SIBServer *server = NULL; whiteboard_log_debug_fb(); sib_service_lock(service); server = sib_service_find_server(service, udn); if (server == NULL) { server = sib_server_new(service, udn, name, sid, port); if (server != NULL) { //upnpserver_subscribe(server); service->siblist = g_list_append(service->siblist, server); } } sib_service_unlock(service); whiteboard_log_debug_fe(); return 0; }
/** * Remove a server from the service by the server's UDN. * * @param service The service to remove from * @param udn The UDN of the server to remove * @return -1 on errors, 0 on success */ gint sib_service_remove_server(SIBService* service, guchar *udn ) { GList* item = NULL; gint retval = -1; whiteboard_log_debug_fb(); g_return_val_if_fail(service != NULL, -1); sib_service_lock(service); item = g_list_find_custom(service->siblist, udn, sib_server_compare_udn); if (item != NULL) { sib_server_unref((SIBServer*) item->data); service->siblist = g_list_remove_link(service->siblist, item); retval = 0; } else { whiteboard_log_debug("Device %s is not in our server list. Ignored.\n", udn); } sib_service_unlock(service); whiteboard_log_debug_fe(); return retval; }
void nota_rm_handler_destroy(NotaRMHandler *self) { h_in_t *core = Hgetinstance(); whiteboard_log_debug_fb(); if(self->sid) { nota_rm_handler_deregister_service(self); } if(self->dereg_cert) { g_free(self->dereg_cert); } if(self->dereg_act) { g_free(self->dereg_act); } if(self->cp) { nota_stub_context_pointer_free(self->cp); } if(self->fd > 0 ) { Hclose(core, self->fd); self->fd = -1; } g_free(self); whiteboard_log_debug_fe(); }
gint kp_server_send_join( KPServer *self, guchar *spaceid, guchar *nodeid, gint msgnum, guchar *credentials) { gint retval; whiteboard_log_debug_fb(); retval = sib_object_send_join( self->sib, spaceid, nodeid, msgnum, credentials); whiteboard_log_debug_fe(); return retval; }
gint kp_server_send_update( KPServer *self, guchar *spaceid, guchar *nodeid, gint msgnum, EncodingType encoding, guchar *insert_graph, guchar *remove_graph) { gint retval; whiteboard_log_debug_fb(); retval = sib_object_send_update( self->sib, spaceid, nodeid, msgnum, encoding, insert_graph, remove_graph); whiteboard_log_debug_fe(); return retval; }
gint kp_server_handle_incoming( KPServer *self) { gint retval; whiteboard_log_debug_fb(); retval = nota_stub_handle_incoming( self->cp ); whiteboard_log_debug_fe(); return retval; }
gint kp_server_send_unsubscribe( KPServer *self, guchar *spaceid, guchar *nodeid, gint msgnum, guchar *subscription_id) { gint retval; whiteboard_log_debug_fb(); retval = sib_object_send_unsubscribe( self->sib, spaceid, nodeid, msgnum, subscription_id); whiteboard_log_debug_fe(); return retval; }
gint kp_server_send_subscribe( KPServer *self, guchar *spaceid, guchar *nodeid, gint msgnum, QueryType type, guchar *query) { gint retval; whiteboard_log_debug_fb(); retval = sib_object_send_subscribe( self->sib, spaceid, nodeid, msgnum, type, query); whiteboard_log_debug_fe(); return retval; }
gint sib_controller_set_listener(SIBController *self, SIBControllerListener listener, gpointer user_data) { whiteboard_log_debug_fb(); g_return_val_if_fail( self != NULL, -1); self->listener = listener; self->listener_data = user_data; whiteboard_log_debug_fe(); return 0; }
/** * Get the SIBService singleton. * * @return SIBService* */ SIBController* sib_controller_get() { whiteboard_log_debug_fb(); if (controller_singleton == NULL) { controller_singleton = sib_controller_new(); } whiteboard_log_debug_fe(); return controller_singleton; }
static void sib_controller_all_for_now_cb( GaServiceBrowser *context, gpointer userdata) { whiteboard_log_debug_fb(); whiteboard_log_debug_fe(); }
/** * Get the SIBService singleton. * * @return SIBService* */ SIBService* sib_service_get() { whiteboard_log_debug_fb(); if (service_singleton == NULL) { service_singleton = sib_service_new(); serverthread_init(service_singleton); } whiteboard_log_debug_fe(); return service_singleton; }
static void whiteboard_cmd_append_method_name(WhiteBoardCmd* self, const gchar* method) { whiteboard_log_debug_fb(); dbus_message_append_args(self->msg, DBUS_TYPE_STRING, &method, DBUS_TYPE_INVALID); whiteboard_log_debug_fe(); }
NotaRMHandler *nota_rm_handler_new(SIBMaxFd *maxfd) { NotaRMHandler *self = NULL; whiteboard_log_debug_fb(); self = g_new0(NotaRMHandler, 1); self->fd = -1; self->maxfd = maxfd; whiteboard_log_debug_fe(); return self; }
static void whiteboard_cmd_append_target_uuid(WhiteBoardCmd* self, const gchar* uuid) { whiteboard_log_debug_fb(); dbus_message_append_args(self->msg, DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID); whiteboard_log_debug_fe(); }
gint create_rm_socket(NotaRMHandler *self) { nota_addr_t addr = { SID_RM, 0}; h_in_t *core = Hgetinstance(); whiteboard_log_debug_fb(); if(!core) { whiteboard_log_debug("Could not get H_IN core pointer.\n"); return -1; } self->fd = Hsocket(core, AF_NOTA, SOCK_STREAM, 0); if(self->fd <=0) { whiteboard_log_debug("Could not get H_IN socket.\n"); self->fd = -1; return -1; } if( Hconnect(core, self->fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { whiteboard_log_debug("Could not connect\n"); Hclose(core, self->fd); self->fd = -1; return -1; } whiteboard_log_debug("Socket connected(%d)\n", self->fd); self->cp = nota_stub_context_pointer_initialize(core, self->fd); if(!self->cp) { whiteboard_log_debug("Could not create STUB context pointer\n"); Hclose(core, self->fd); self->fd = -1; return -1; } whiteboard_log_debug("STUB context inialized\n"); if( NoTA_System_ResourceMng_R01_01_user_new_connection(self->cp) < 0) { whiteboard_log_debug("could not add to stub\n"); nota_stub_context_pointer_free(self->cp); self->cp = NULL; Hclose(core, self->fd); self->fd = -1; return -1; } self->cp->user_pointer = self; sib_maxfd_set(self->maxfd, self->fd); whiteboard_log_debug(" Stub connected for socket: %d\n", self->fd); whiteboard_log_debug_fe(); return 0; }
static void sib_service_shutdown_cb(WhiteBoardNode* context, gpointer user_data) { SIBService* service = NULL; whiteboard_log_debug_fb(); service = sib_service_get(); sib_service_stop(service); whiteboard_log_debug_fe(); }
/** * Stop a controller * * @param controller The controller to stop * @return -1 on errors, 0 on success */ gint sib_controller_stop(SIBController* controller) { whiteboard_log_debug_fb(); g_return_val_if_fail(controller != NULL, -1); whiteboard_log_debug_fe(); return 0; }
/** * Start a UPnP service. This function will block until the service is stopped. * * @param service The service to start * @return -1 on errors, 0 on success */ gint sib_service_start(SIBService* service) { gint retval = 0; whiteboard_log_debug_fb(); g_return_val_if_fail(service != NULL, -1); g_return_val_if_fail(service->main_loop != NULL, -1); if (g_main_loop_is_running(service->main_loop) == TRUE) { whiteboard_log_debug("sib_service_start(): main loop running\n"); whiteboard_log_debug_fe(); return -1; } else { /* TODO: control channel uuid define */ service->control_channel = WHITEBOARD_SIB_ACCESS(whiteboard_sib_access_new(NULL, (guchar *)"unique_whiteboard_sib_nota_cc_id", NULL, (guchar *)"SIB Access", (guchar *)"Not yet done")); g_signal_connect(G_OBJECT(service->control_channel), WHITEBOARD_SIB_ACCESS_SIGNAL_REFRESH, (GCallback) sib_service_refresh_cb, NULL); g_signal_connect(G_OBJECT(service->control_channel), WHITEBOARD_SIB_ACCESS_SIGNAL_SHUTDOWN, (GCallback) sib_service_shutdown_cb, NULL); retval = sib_service_controller_start( g_main_loop_get_context(service->main_loop) ); if(retval < 0) { whiteboard_log_error("SIB Controller start failed\n"); retval = -1; // exit(1); } whiteboard_log_debug("RUnning main loop\n"); g_main_loop_run(service->main_loop); } whiteboard_log_debug_fe(); return retval; }