jni_topic jni_lookupTopic( jni_participant p, const char* name) { c_iter topics; jni_topic topic, temp; int found; topic = NULL; if((name != NULL) && (p != NULL)){ topics = c_iterCopy(p->topics); found = 0; temp = jni_topic(c_iterTakeFirst(topics)); while( (temp != NULL) && (!found)){ if(strcmp(jni_topicDescription(temp)->name, name) == 0){ topic = temp; found = 1; } temp = jni_topic(c_iterTakeFirst(topics)); } c_iterFree(topics); } return topic; }
const c_char* jni_nameServiceResolveURI( c_long domainId) { const c_char* result; c_iter copy; jni_mapping mapping; c_bool found; result = NULL; if(mappings != NULL){ copy = c_iterCopy(mappings); found = FALSE; mapping = jni_mapping(c_iterTakeFirst(copy)); while((mapping != NULL) && (found == FALSE)){ if(mapping->domainId == domainId){ result = mapping->uri; found = TRUE; } mapping = jni_mapping(c_iterTakeFirst(copy)); } c_iterFree(copy); } /* if not found or mapping == NULL then result == NULL */ return result; }
static c_bool jni_participantMayTopicBeDeleted( jni_participant p, const c_char* topicName) { c_iter pubCopy, subCopy; jni_subscriber sub; jni_publisher pub; jni_writer writer; jni_reader reader; c_bool mayDelete; pubCopy = c_iterCopy(p->publishers); pub = jni_publisher(c_iterTakeFirst(pubCopy)); mayDelete = TRUE; while((pub != NULL) && mayDelete){ writer = jni_publisherLookupWriter(pub, topicName); if(writer != NULL){ mayDelete = FALSE; } pub = jni_publisher(c_iterTakeFirst(pubCopy)); } c_iterFree(pubCopy); if(mayDelete){ subCopy = c_iterCopy(p->subscribers); sub = jni_subscriber(c_iterTakeFirst(subCopy)); while((sub != NULL) && mayDelete){ reader = jni_subscriberLookupReader(sub, topicName); if(reader != NULL){ mayDelete = FALSE; } sub = jni_subscriber(c_iterTakeFirst(subCopy)); } c_iterFree(subCopy); } return mayDelete; }
jni_result jni_participantAddPartition( jni_participant p, const c_char* partitionName) { jni_result r; c_iter partCopy; jni_partition partition, partNew; int found; r = JNI_RESULT_OK; if((p == NULL) || (partitionName == NULL)){ r = JNI_RESULT_BAD_PARAMETER; } else if((strcmp(partitionName, "*") == 0) || (strcmp(partitionName, "") == 0)){ /*DO NOTHING*/ } else{ /*Check if the partitionName already exists.*/ partCopy = c_iterCopy(p->partitions); partition = jni_partition(c_iterTakeFirst(partCopy)); found = 0; while((partition != NULL) && (!found)){ if(strcmp(partition->name, partitionName) == 0){ found = 1; } partition = jni_partition(c_iterTakeFirst(partCopy)); } c_iterFree(partCopy); if(!found){ partNew = jni_partitionNew(p, partitionName, NULL); if(partNew == NULL){ r = JNI_RESULT_ERROR; } else{ p->partitions = c_iterInsert(p->partitions, partNew); } } } return r; }
c_bool jni_nameServiceAddDomain( const c_char* uri) { c_bool result; const c_char* uri2; jni_mapping mapping; c_long domainId; c_iter copy; result = FALSE; uri2 = NULL; if(mappings != NULL){ copy = c_iterCopy(mappings); mapping = jni_mapping(c_iterTakeFirst(copy)); while((mapping != NULL) && (uri2 == NULL)){ if(strcmp(mapping->uri, uri) == 0){ uri2 = uri; } mapping = jni_mapping(c_iterTakeFirst(copy)); } c_iterFree(copy); if(uri2 == NULL){ mapping = jni_mapping(os_malloc(C_SIZEOF(jni_mapping))); domainId = c_iterLength(mappings); mapping->domainId = domainId; mapping->uri = (c_char*)(os_malloc(strlen(uri) + 1)); os_strcpy(mapping->uri, uri); c_iterInsert(mappings, mapping); } else { /*URI already exists, do nothing.*/ } result = TRUE; } return result; }
gapi_returnCode_t gapi_guardCondition_set_trigger_value( gapi_guardCondition _this, const gapi_boolean value) { _GuardCondition guardcondition = (_GuardCondition)_this; _WaitSet waitset; gapi_waitSet wsh; gapi_returnCode_t result; c_iter wsHandles; wsHandles = NULL; guardcondition = gapi_quardConditionClaim(_this, NULL); if (guardcondition != NULL) { if (value) { guardcondition->triggerValue = TRUE; wsHandles = c_iterCopy(_Condition(guardcondition)->waitsets); _EntityRelease(guardcondition); wsh = (gapi_waitSet)c_iterTakeFirst(wsHandles); while (wsh != NULL) { waitset = gapi_waitSetClaim(wsh, &result); if (waitset) { _WaitSetNotify(waitset, (_Condition)guardcondition); _EntityRelease(waitset); } wsh = (gapi_waitSet)c_iterTakeFirst(wsHandles); } c_iterFree(wsHandles); } else { guardcondition->triggerValue = FALSE; _EntityRelease(guardcondition); } } return GAPI_RETCODE_OK; }
jni_result jni_deleteParticipantEntities( jni_participant p) { jni_result r; c_iter pubCopy, subCopy, topCopy, partCopy; jni_publisher pub; jni_subscriber sub; jni_topic top; jni_partition partition; int proceed; assert(p != NULL); proceed = 1; r = JNI_RESULT_OK; if(p->publishers != NULL){ pubCopy = c_iterCopy(p->publishers); pub = jni_publisher(c_iterTakeFirst(pubCopy)); while( (pub != NULL) && proceed){ r = jni_deletePublisherEntities(pub); if(r != JNI_RESULT_OK){ c_iterFree(pubCopy); proceed = 0; } if(proceed){ r = jni_deletePublisher(p, pub); if(r != JNI_RESULT_OK){ c_iterFree(pubCopy); proceed = 0; } } pub = jni_publisher(c_iterTakeFirst(pubCopy)); } if(proceed){ c_iterFree(pubCopy); c_iterFree(p->publishers); p->publishers = c_iterNew(NULL); } } if((p->subscribers != NULL) && proceed){ subCopy = c_iterCopy(p->subscribers); sub = jni_subscriber(c_iterTakeFirst(subCopy)); while((sub != NULL) && proceed){ r = jni_deleteSubscriberEntities(sub); if(r != JNI_RESULT_OK){ c_iterFree(subCopy); proceed = 0; } if(proceed){ r = jni_deleteSubscriber(p, sub); if(r != JNI_RESULT_OK){ c_iterFree(subCopy); proceed = 0; } } sub = jni_subscriber(c_iterTakeFirst(subCopy)); } if(proceed){ c_iterFree(subCopy); c_iterFree(p->subscribers); p->subscribers = c_iterNew(NULL); } } if((p->topics != NULL) && proceed){ topCopy = c_iterCopy(p->topics); top = jni_topic(c_iterTakeFirst(topCopy)); while((top != NULL) && proceed){ r = jni_deleteTopic(p, top); if(r != JNI_RESULT_OK){ c_iterFree(topCopy); proceed = 0; } top = jni_topic(c_iterTakeFirst(topCopy)); } if(proceed){ c_iterFree(topCopy); c_iterFree(p->topics); p->topics = c_iterNew(NULL); } } if((p->partitions != NULL) && proceed){ partCopy = c_iterCopy(p->partitions); partition = jni_partition(c_iterTakeFirst(partCopy)); while((partition != NULL) && proceed){ r = jni_partitionFree(partition); if(r != JNI_RESULT_OK){ c_iterFree(partCopy); proceed = 0; } partition = jni_partition(c_iterTakeFirst(partCopy)); } if(proceed){ c_iterFree(partCopy); c_iterFree(p->partitions); p->partitions = c_iterNew(NULL); } } return r; }
void cms_serviceFree( cms_service cms) { cms_client client; c_iter clientCopy; c_ulong i, size; if(cms != NULL) { if(cms->configuration != NULL) { if(cms->configuration->verbosity >= 2) { OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "Terminating CMSOAP service..."); } } if(cms->uservice != NULL) { u_serviceChangeState(cms->uservice, STATE_TERMINATING); } cms->terminate = TRUE; if(cms->leaseThread != NULL) { cms_threadFree(cms->leaseThread); } if(cms->garbageCollector != NULL) { cms_threadFree(cms->garbageCollector); } if(cms->soap != NULL) { cms->soap->attributes = NULL; soap_destroy(cms->soap); soap_end(cms->soap); soap_done(cms->soap); free(cms->soap); } if(cms->clients != NULL) { os_mutexLock(&cms->clientMutex); clientCopy = c_iterCopy(cms->clients); os_mutexUnlock(&cms->clientMutex); if(c_iterLength(cms->clients) > 0) { if(cms->configuration->verbosity >= 2) { OS_REPORT_1(OS_WARNING, CMS_CONTEXT, 0, "Terminating CMSOAPService, but %d client(s) is/are still connected.", c_iterLength(cms->clients)); } } size = c_iterLength(clientCopy); for(i=0; i<size; i++) { client = cms_client(c_iterObject(clientCopy, i)); cms_thread(client)->terminate = TRUE; } for(i=0; i<size; i++) { client = cms_client(c_iterObject(clientCopy, i)); cms_clientFree(client); } c_iterFree(clientCopy); os_mutexLock(&cms->clientMutex); c_iterFree(cms->clients); os_mutexUnlock(&cms->clientMutex); os_mutexDestroy(&cms->clientMutex); } if(cms->configuration != NULL) { if(cms->configuration->verbosity >= 4) { OS_REPORT(OS_INFO, CMS_CONTEXT, 0, "CMSOAP service terminated."); } } cms_configurationFree(cms->configuration); if(cms->uservice != NULL) { cmx_deregisterAllEntities(); u_serviceChangeState(cms->uservice, STATE_TERMINATED); u_serviceFree(cms->uservice); } cmx_detach(); os_free(cms); } }