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(); }
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 gint deregister_handler( ThreadArgs *ta ) { gint err; fd_set open_sockets; fd_set error_set; h_in_t* core = NULL;; err = NoTA_System_ResourceMng_R01_01_Deregister_req(ta->cp, ta->sid, (uint8_t*)dereg_cert, (uint16_t)strlen(dereg_cert)); if(err < 0) return err; FD_ZERO(&open_sockets); FD_ZERO(&error_set); FD_SET(ta->socket, &open_sockets); FD_SET(ta->socket, &error_set); core = Hgetinstance(); // whiteboard_log_debug("register_handler: entering select loop, fd: %d, core: %p\n", ta->socket, core); while(deregConfReceived==0) { err = Hselect(core, ta->socket+1, &open_sockets, NULL, &error_set, NULL); if(err < 0) { perror("select: "); break; } if(FD_ISSET(ta->socket, &error_set)) { whiteboard_log_debug("Error on socket\n"); break; } else if(FD_ISSET(ta->socket, &open_sockets)) { err = nota_stub_handle_incoming(ta->cp); if(err < 0) { perror("Receive:"); whiteboard_log_debug("Closing client(%d)\n",err); break; } } else { whiteboard_log_debug("Error on select\n"); break; } } return err; }
/* ***************************************************** * Check the predicate value of every triple to discover * conflict with protection stuff properties * return the type of the op * OP_NORMAL: no protection property found * OP_PROTECTION: one or more protection property found * */ int check_op_type_on_predicate( s_scheduler_item* op) { whiteboard_log_debug("CHECK INSERT_GRAPH\n"); if(checkProtectionOnPredicate_GSList(op->req->insert_graph))return OP_PROTECTION; whiteboard_log_debug("CHECK REMOVE_GRAPH\n"); if(checkProtectionOnPredicate_GSList(op->req->remove_graph))return OP_PROTECTION; return OP_NORMAL; }//int check_op_type_on_predicate( s_scheduler_item* op)
/** * 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; }
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(); }
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(); }
LCLine* LCTable_getLine( LCTable* t, LCLine* l ) { if(l==NULL)return NULL; LCLine *i=t->line; int il=0; //whiteboard_log_debug("LCTable_getLine:\n"); if(i!=NULL) do { //whiteboard_log_debug("LCTable_getLine:line content:il=%d\n",il); //LCLine_print(i); if( strcmp(i->I,l->I)==0 && strcmp(i->P,l->P)==0 && strcmp(i->Pi,l->Pi)==0 && strcmp(i->KP,l->KP)==0 ) return i; i=i->next; il++; if(il>t->size && i!=NULL){whiteboard_log_debug("\n*** ERROR:LCTable_getLine:while:inconsistent value for 'size':il=%d\n",il);break;} }while(i!=NULL);//do return NULL; }//LCLine* LCTable_getLCLine( LCTable* t, LCLine* l )
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(); }
/** * 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 whiteboard_cmd_unref(WhiteBoardCmd *self) { whiteboard_log_debug_fb(); g_return_if_fail(self != NULL); if (g_atomic_int_dec_and_test(&self->refcount) == FALSE) { whiteboard_log_debug("WhiteBoardCmd refcount dec: %d.\n", self->refcount); } else { whiteboard_log_debug("WhiteBoardCmd refcount zeroed.\n"); whiteboard_cmd_destroy(self); } whiteboard_log_debug_fe(); }
/** * Print the table "lct" **/ void LCTable_print( LCTable *lct ) { if(lct==NULL)return; LCLine *i=lct->line; int il=0; if(i==NULL)return; whiteboard_log_debug("/%31s|%31s|%31s|%31s\\\n","-","-","-","-"); whiteboard_log_debug("|%31s|%31s|%31s|%31s|\n"," I"," P"," Pi"," KP"); whiteboard_log_debug("|%31s|%31s|%31s|%31s|\n","-","-","-","-"); do {LCLine_print(i); i=i->next; il++; if(il>lct->size && i!=NULL){whiteboard_log_debug("\n*** ERROR:LCTable_print:while:inconsistent value for 'size':il=%d\n",il);break;} }while(i!=NULL);//do whiteboard_log_debug("\\%31s|%31s|%31s|%31s/\n","-","-","-","-"); }//void LCTable_print( LCTable *lct )
/** * Checks if all the operations (insert,remove) are protection consistent * In details, it checks every couple SUB-PRE or PRE-OBJ on the LC table. * It looks for a line on the LC table. * The owner of every line found is compared to the owner of the operation sent. * If , at least, one owner in the LC table does not match the owner of * the operation sent (KP ID) a protection incensistency fault is found. * In this case return FALSE (0). * Otherwise, if ALL the owners in the LC tablematch the KP ID, returns TRUE (1) * */ boolean isInsertRemoveOperationConsistent( s_scheduler_item* op) { //whiteboard_log_debug("*** UNDER CONSTRUCTION!!! boolean isInsertRemoveOperationConsistent( s_scheduler_item* op)\n"); if(LCT==NULL) LCT=LCTable_new(); GSList *list[2]; list[0]=op->req->insert_graph; list[1]=op->req->remove_graph; ssTriple_t *triple; int ig=0; for(;ig<2;ig++) while( list[ig]!=NULL ) { triple=list[ig]->data; LCLine *l=LCTable_getLCLineByIPi(LCT,triple->subject , triple->predicate); if(l!=NULL) if( braces_strcmp(l->KP,(char*)op->header->kp_id) != 0) {whiteboard_log_debug("*** PROTECTION FAULT: isInsertRemoveOperationConsistent():\n\t KP id differ from KP's line (line found by I-Pi, sub-pred)\n"); whiteboard_log_debug("\tl->KP=%s,op->header->kp_id=%s\n",l->KP,op->header->kp_id); return FALSE; } l=LCTable_getLCLineByIPi(LCT,triple->object , triple->predicate); if(l!=NULL) if( braces_strcmp(l->KP,(char*)op->header->kp_id) != 0) {whiteboard_log_debug("*** PROTECTION FAULT: isInsertRemoveOperationConsistent():\n\t KP id differ from KP's line (line found by I-Pi, obj-pred)\n"); whiteboard_log_debug("\tl->KP=%s,op->header->kp_id=%s\n",l->KP,op->header->kp_id); return FALSE; } list[ig]=list[ig]->next; }//while( list[ig]!=NULL ) return TRUE; }//boolean isInsertRemoveOperationConsistent( s_scheduler_item* op)
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 gint sib_service_controller_start( GMainContext *context) { gint retval = -1; whiteboard_log_debug_fb(); SIBService *service = sib_service_get(context); sib_service_lock(service); if (service->ctrl_running == FALSE) { if (sib_controller_start(service->controller) == 0) { service->ctrl_running = TRUE; if(sib_controller_search(service->controller ) < 0) { whiteboard_log_debug("Could not search for services\n"); } else { g_timeout_add( SIB_CONTROLLER_SEARCH_TIMEOUT, sib_service_controller_search_timeout, service ); retval = 0; } } else { whiteboard_log_debug("Error starting SIB controller\n"); service->ctrl_running = FALSE; retval = -1; } } else { whiteboard_log_debug("SIB Controller already started\n"); } sib_service_unlock(service); whiteboard_log_debug_fe(); return retval; }
void kp_server_handle_subscription_ind( SibObject *context, guchar *spaceid, guchar *nodeid, gint msgnum, gint seqnum, guchar *subscription_id, guchar *results_new, guchar *results_obsolete, gpointer user_data) { KPServer *self = NULL; whiteboard_log_debug_fb(); self = (KPServer *)user_data; g_mutex_lock(self->send_lock); whiteboard_log_debug("SubscribeInd ->\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("\tseqnum: %d\n", seqnum); whiteboard_log_debug("\tsubid: %s\n", subscription_id); whiteboard_log_debug("\tbresults_new: %s\n", results_new); whiteboard_log_debug("\tbresults_obs: %s\n", results_obsolete); if( SibAccessNota_Subscription_ind(self->cp, (uint8_t *) nodeid, (uint16_t) strlen( (gchar *)nodeid), (uint8_t *) spaceid, (uint16_t) strlen( (gchar *)spaceid), (uint16_t) msgnum, (uint16_t) seqnum, (uint8_t *) subscription_id, (uint16_t) strlen( (gchar *)subscription_id), (uint8_t *) results_new, (uint16_t) strlen( (gchar *)results_new), (uint8_t *) results_obsolete, (uint16_t) strlen( (gchar *)results_obsolete)) < 0 ) { whiteboard_log_warning("Subsription ind sending failed\n"); } else { whiteboard_log_debug("Subscription ind sent\n"); } g_mutex_unlock(self->send_lock); whiteboard_log_debug_fe(); }
/** * It contributes to the overall consistency avoiding unwanted data deletion. * It is necessary because the KP doesn't know the Protection entity instance * and doesn't know if it is still protecting other properties of the same instance * * It removes the triples with AR_Property and AR_Owner from the remove graph * Return the new valid remove graph * * rg = Remove Graph **/ GSList* removeGraphSafeProtectionRemove( GSList* list ) { ssTriple_t *triple; GSList* l=list; whiteboard_log_debug("############################################\n"); whiteboard_log_debug("removeGraphSafeProtectionRemove()\n"); whiteboard_log_debug("list content ##############################\n"); println_GSList(list); while( l!=NULL ) { triple=l->data; if( strcmp(triple->predicate,AR_PROPERTY)==0 || strcmp(triple->predicate,AR_OWNER)==0 ) { l = g_slist_remove( list, triple ); } else l=l->next; }//while( list!=NULL ) whiteboard_log_debug("list content ##############################\n"); println_GSList(list); whiteboard_log_debug("end content ##############################\n"); whiteboard_log_debug("############################################\n"); return list; }//void removeGraphSafeProtectionRemove( GSList* rg, ProtectionDescriptor *pd )
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(); }
static void sib_controller_resolver_failure( GaServiceResolver *context, GError *error, gpointer userdata) { whiteboard_log_debug_fb(); if(error) { whiteboard_log_debug("Resolver failure: %s\n", error->message); } whiteboard_log_debug_fe(); }
void whiteboard_cmd_ref(WhiteBoardCmd *self) { whiteboard_log_debug_fb(); g_return_if_fail(self != NULL); if (g_atomic_int_get(&self->refcount) > 0) { /* Refcount is something sensible */ g_atomic_int_inc(&self->refcount); whiteboard_log_debug("WhiteBoardCmd refcount inc: %d.\n", self->refcount); } else { /* Refcount is already zero */ whiteboard_log_debug("WhiteBoardCmd refcount already 0!"); } whiteboard_log_debug_fe(); }
/* ***************************************************** * */ void println_GSList(GSList* list) { char* ssElementType_t_name[4]={ "ssElement_TYPE_URI", "ssElement_TYPE_LIT", "ssElement_TYPE_BNODE", "ssElement_TYPE_eot"}; ssTriple_t *triple; while( list!=NULL ) { triple=list->data; whiteboard_log_debug(" -------------------\n"); whiteboard_log_debug(" subject :%s [%s]\n",triple->subject,ssElementType_t_name[triple->subjType]); whiteboard_log_debug(" predicate :%s\n" ,triple->predicate); whiteboard_log_debug(" object :%s [%s]\n",triple->object,ssElementType_t_name[triple->objType]); list=list->next; }//while( list!=NULL ) }//void println_GList(GList* list)
static gboolean sib_service_controller_search_timeout( gpointer user_data) { gboolean retval = FALSE; SIBService *self = (SIBService *)user_data; if(self->ctrl_running && (sib_controller_search(self->controller ) == 0 ) ) { retval = TRUE; } else { whiteboard_log_debug("Controller not running or sib_controller_search failed\n"); } return retval; }
/* ***************************************************** * */ void printOpContent( s_scheduler_item* op) {char* query_type_name[8]={ "QueryTypeInvalid", "QueryTypeTemplate", "QueryTypeWQLValues", "QueryTypeWQLNodeTypes", "QueryTypeWQLRelated", "QueryTypeWQLIsType", "QueryTypeWQLIsSubType", "QueryTypeSPARQL"}; char* encoding_type_name[3]={ "EncodingInvalid", "EncodingM3XML", "EncodingRDFXML"}; whiteboard_log_debug("------------------------------------\n"); whiteboard_log_debug("OP COntent:\n"); whiteboard_log_debug("KP ID:%s\n",(char*)op->header->kp_id); whiteboard_log_debug("credentials:%s\n",(char*)op->req->credentials); whiteboard_log_debug("encoding:%s\n",encoding_type_name[op->req->encoding]); whiteboard_log_debug("INSERT_GRAPH\n");println_GSList(op->req->insert_graph); whiteboard_log_debug("REMOVE_GRAPH\n");println_GSList(op->req->remove_graph); //whiteboard_log_debug("insert_str:%s\n",(char*)op->req->insert_str); //whiteboard_log_debug("remove_str:%s\n",(char*)op->req->remove_str); whiteboard_log_debug("query_type:%s\n", query_type_name[op->req->type]); whiteboard_log_debug("query_str:%s\n",(char*)op->req->query_str); whiteboard_log_debug("------------------------------------\n"); return; }//PrintOpContent(op)
gboolean whiteboard_cmd_append(WhiteBoardCmd* self, const gchar** key, const gchar** value) { gboolean retval = FALSE; whiteboard_log_debug_fb(); g_return_val_if_fail(self != NULL, FALSE); g_return_val_if_fail(key != NULL, FALSE); g_return_val_if_fail(value != NULL, FALSE); whiteboard_log_debug("Appending key (%s) and value (%s)\n", *key, *value); retval = dbus_message_append_args(self->msg, DBUS_TYPE_STRING, key, DBUS_TYPE_STRING, value, DBUS_TYPE_INVALID); whiteboard_log_debug_fe(); return retval; }
/* ***************************************************** * */ void ProtectionCompatibilityFilter( s_scheduler_item* op) { whiteboard_log_debug("---->:int ProtectionCompatibilityCheck( s_scheduler_item* op)\n"); printOpContent(op); //op->header->tr_type=M3_PROTECTION_FAULT; //printf("*** OP protection policy incompatible ***\n"); int op_type; switch(op_type = check_op_type_on_predicate(op)) {case OP_NORMAL: whiteboard_log_debug("*** NORMAL OP RECOGNIZED!\n"); if( !isInsertRemoveOperationConsistent(op) ) {op->header->tr_type=M3_PROTECTION_FAULT; whiteboard_log_debug("*** ProtectionCompatibilityFilter():\n\tPROTECTION FAULT: insert or remove operation NOT protection consistent!\n"); // op->rsp->status = ss_OperationFailed; } break; case OP_PROTECTION: whiteboard_log_debug("*** PROTECTION OP RECOGNIZED!\n"); if( isProtectionRequestConsistent(op) == FALSE ) { whiteboard_log_debug("*** ProtectionCompatibilityFilter():\n\tPROTECTION FAULT! Operation NOT protection consistent! LC Table UNCHANGED!\n"); // op->rsp->status = ss_OperationFailed; }//if( isProtectionRequestConsistent(op) == FALSE ) else whiteboard_log_debug("*** LC Table UPDATED!\n"); break; default:whiteboard_log_debug("*** OP NOT RECOGNIZED!\n"); }//switch(op_type) LCTable_print(LCT); }//ProtectionCompatibilityCheck( s_scheduler_item* op)
/** * Stop a UPnP service. * * @param service The service to stop * @return -1 on errors, 0 on success */ gint sib_service_stop(SIBService* service) { 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) { /* Ensure that there are no servers left in the cache */ whiteboard_log_debug("Cleaning SIBServer list\n"); //sib_service_lock(service); while (service->siblist != NULL ) { GList *item = service->siblist; service->siblist = g_list_remove_link(service->siblist, item); sib_server_unref((SIBServer*)item->data); g_list_free(item); } // sib_service_unlock(service); sib_controller_stop(service->controller); service->ctrl_running = FALSE; g_main_loop_quit(service->main_loop); } whiteboard_log_debug_fe(); return 0; }
/** * Update every occurence of the P value into the op structure **/ void scheduler_item_updateP( s_scheduler_item* op , char* P_from_table ) { whiteboard_log_debug("*** void scheduler_item_updateP( s_scheduler_item* op , char* P_from_table )\n"); GSList *list[2]; list[0]=op->req->insert_graph; list[1]=op->req->remove_graph; ssTriple_t *triple; int ig=0; for(;ig<2;ig++) while( list[ig]!=NULL ) { triple=list[ig]->data; if( strcmp(triple->predicate,AR_PROPERTY)==0 ) {whiteboard_log_debug("*** scheduler_item_updateP:\n\t OBJ:UPDATE P from: %s to:%s\n",triple->object,P_from_table); free(triple->object); triple->object=malloc(strlen(P_from_table)+1); strcpy(triple->object,P_from_table); }//if( strcmp(triple->predicate,AR_PROPERTY)==0 ) if( strcmp(triple->predicate,AR_OWNER)==0 ||strcmp(triple->predicate,AR_TARGET)==0 ) {whiteboard_log_debug("*** scheduler_item_updateP:\n\t SUB:UPDATE P from: %s to:%s\n",triple->subject,P_from_table); free(triple->subject); triple->subject=malloc(strlen(P_from_table)+1); strcpy(triple->subject,P_from_table); }// if( strcmp(triple->predicate,AR_OWNER)==0 ... list[ig]=list[ig]->next; }//while( list!=NULL ) whiteboard_log_debug("\n############################################\n"); whiteboard_log_debug("START OP############################################\n"); printOpContent(op); whiteboard_log_debug("END OP############################################\n"); }//void updatePofOP( s_scheduler_item* op , P_from_table )
gint nota_rm_handler_register_sib(NotaRMHandler *self, gchar *uuid) { ThreadArgs *ta = NULL; int ret = -1; whiteboard_log_debug_fb(); #if USE_RM==1 ta = g_new0(ThreadArgs,1); ta->handler = self; ta->uuid = g_strdup(uuid); ret = GPOINTER_TO_INT(nota_rm_handler_register_sib_thread(ta)); if(ret == 0) { ret = self->sid; whiteboard_log_debug("Got SID %d\n", ret); } #else ret = TEST_SID; #endif whiteboard_log_debug_fe(); return ret; }
KPServer *kp_server_new(int fd, KPListener *listener) { KPServer *self = NULL; h_in_t *core = Hgetinstance(); SibObject *object = NULL; gchar tmp[37]; uuid_t u1; int err = -1; whiteboard_log_debug_fb(); uuid_generate(u1); uuid_unparse(u1, tmp); object = SIB_OBJECT( sib_object_new( tmp, /*uuid*/ NULL, /* control channel uuid */ NULL, /* main_context */ "N/A", /* Friendly name */ "Not implemented")); /* desription */ g_return_val_if_fail(object != NULL,NULL); self = g_new0(KPServer,1); self->sib = object; self->fd = fd; self->cp = nota_stub_context_pointer_initialize(core, fd); if(self->cp) { err = SibAccessNota_service_new_connection(self->cp); if(err < 0) { whiteboard_log_debug("Could not initialize connection"); nota_stub_context_pointer_free( self->cp); } else { whiteboard_log_debug("Connection created for fd %d\n",fd); self->cp->user_pointer = listener; } } else { whiteboard_log_debug("Could not initialize context"); } if(err<0) { Hclose(core, fd); g_object_unref( G_OBJECT(self->sib)); g_free(self); self=NULL; } else { self->send_lock = g_mutex_new(); // connect callback handlers g_signal_connect( G_OBJECT(object), SIB_OBJECT_SIGNAL_JOIN_CNF, (GCallback)kp_server_handle_join_cnf, self); g_signal_connect( G_OBJECT(object), SIB_OBJECT_SIGNAL_LEAVE_CNF, (GCallback)kp_server_handle_leave_cnf, self); g_signal_connect( G_OBJECT(object), SIB_OBJECT_SIGNAL_INSERT_CNF, (GCallback)kp_server_handle_insert_cnf, self); g_signal_connect( G_OBJECT(object), SIB_OBJECT_SIGNAL_REMOVE_CNF, (GCallback)kp_server_handle_remove_cnf, self); g_signal_connect( G_OBJECT(object), SIB_OBJECT_SIGNAL_UPDATE_CNF, (GCallback)kp_server_handle_update_cnf, self); g_signal_connect( G_OBJECT(object), SIB_OBJECT_SIGNAL_QUERY_CNF, (GCallback)kp_server_handle_query_cnf, self); g_signal_connect( G_OBJECT(object), SIB_OBJECT_SIGNAL_SUBSCRIBE_CNF, (GCallback)kp_server_handle_subscribe_cnf, self); g_signal_connect( G_OBJECT(object), SIB_OBJECT_SIGNAL_SUBSCRIPTION_IND, (GCallback)kp_server_handle_subscription_ind, self); g_signal_connect( G_OBJECT(object), SIB_OBJECT_SIGNAL_UNSUBSCRIBE_IND, (GCallback)kp_server_handle_unsubscribe_ind, self); g_signal_connect( G_OBJECT(object), SIB_OBJECT_SIGNAL_UNSUBSCRIBE_CNF, (GCallback)kp_server_handle_unsubscribe_cnf, self); g_signal_connect( G_OBJECT(object), SIB_OBJECT_SIGNAL_LEAVE_IND, (GCallback)kp_server_handle_leave_ind, self); whiteboard_log_debug("Connection ready\n"); } whiteboard_log_debug_fe(); return ( (err<0 )?NULL:self); }
static void sib_controller_new_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; GError *err = NULL; SIBServerData *ssdata = NULL; g_return_if_fail(self!=NULL); whiteboard_log_debug("New service: %s, type %s, domain: %s\n", name, type, domain); if( g_ascii_strcasecmp(type, SIB_SERVICE_TYPE) == 0) { ssdata = g_new0(SIBServerData,1); ssdata->uri = (guchar*)g_strdup(name); if(sib_controller_add_service(self,ssdata)) { ssdata->resolver = ga_service_resolver_new(interface, protocol, name, type, domain, AVAHI_PROTO_INET, GA_LOOKUP_NO_FLAGS); if(ssdata->resolver) { if( ga_service_resolver_attach(ssdata->resolver, self->client, &err) == TRUE) { g_signal_connect( G_OBJECT(ssdata->resolver), "found", (GCallback) sib_controller_resolver_found, self); g_signal_connect( G_OBJECT(ssdata->resolver), "failure", (GCallback) sib_controller_resolver_failure, self); } else if(err != NULL) { whiteboard_log_debug("Could not attach avahi service_browser w/ client: %s\n", err->message); g_error_free(err); sib_controller_remove_service(self, ssdata->uri); } } else { whiteboard_log_debug("Could not create avahi service_browser\n"); sib_controller_remove_service(self, ssdata->uri); } } } whiteboard_log_debug_fe(); }