jni_participant jni_participantNew( const c_char* uri, const char* name, long domainId, v_qos qos) { jni_participant p; u_participant up; up = u_participantNew(uri, 0, name, qos, TRUE); p = NULL; if(up != NULL){ p = jni_participant(os_malloc((size_t)(C_SIZEOF(jni_participant)))); p->uparticipant = up; p->domainId = domainId; p->publishers = c_iterNew(NULL); p->subscribers = c_iterNew(NULL); p->topics = c_iterNew(NULL); p->partitions = c_iterNew(NULL); } return p; }
cms_client cms_clientNew( unsigned long ip, cms_service service) { cms_client client; os_result osr; client = os_malloc(sizeof *client); if(client != NULL){ if (cms_threadInit(cms_thread(client), "cms_client", &service->configuration->clientScheduling)) { cms_object(client)->kind = CMS_CLIENT; cms_thread(client)->did = service->did; cms_thread(client)->uri = os_strdup(service->uri); client->ip = ip; client->initCount = 0; client->service = service; client->internalFree = FALSE; osr = os_mutexInit(&client->soapMutex, NULL); client->soapEnvs = c_iterNew(NULL); if(osr == os_resultSuccess){ osr = os_mutexInit(&client->conditionMutex, NULL); if(osr == os_resultSuccess){ osr = os_condInit(&client->condition, &client->conditionMutex, NULL ); if(osr == os_resultSuccess){ osr = os_mutexInit(&client->threadMutex, NULL); if(osr == os_resultSuccess){ client->threads = c_iterNew(NULL); } else { cms_clientFree(client); } } } else { cms_clientFree(client); } } else { cms_clientFree(client); } } else { cms_clientFree(client); client = NULL; } } if(client == NULL){ if(service->configuration->verbosity >= 1){ OS_REPORT(OS_ERROR, CMS_CONTEXT, 0, "cms_clientNew: client could not be initialized."); } } return client; }
c_iter v_serviceTakeNewGroups( v_service service) { c_iter result; v_group group; c_set newGroups; assert(service != NULL); assert(C_TYPECHECK(service, v_service)); result = c_iterNew(NULL); v_observerLock(v_observer(service)); newGroups = (c_set)v_observer(service)->eventData; if (newGroups != NULL) { group = v_group(c_take(newGroups)); while (group != NULL) { c_iterInsert(result, group); group = v_group(c_take(newGroups)); } } v_observerUnlock(v_observer(service)); return result; }
c_iter u_cfElementGetAttributes( u_cfElement element) { u_result r; v_cfElement ke; v_cfAttribute attr; c_iter ka; c_iter attributes; u_participant p; attributes = c_iterNew(NULL); if (element != NULL) { r = u_cfNodeReadClaim(u_cfNode(element), (v_cfNode*)(&ke)); if (r == U_RESULT_OK) { p = u_cfNodeParticipant(u_cfNode(element)); ka = v_cfElementGetAttributes(ke); attr = c_iterTakeFirst(ka); while (attr != NULL) { c_iterInsert(attributes, u_cfAttributeNew(p, attr)); attr = c_iterTakeFirst(ka); } c_iterFree(ka); u_cfNodeRelease(u_cfNode(element)); } } return attributes; }
/* Create source */ c_iter idl_fileMapGetObjects( const idl_fileMap fileMap, const char *fileName) { idl_file file; c_iter result; result = 0; if(fileMap != NULL) { /* Lookup file */ file = c_iterResolve(fileMap->files, idl_fileCompare, (c_iterResolveCompareArg)fileName); if (file) { result = c_iterNew(0); /* Walk metaobjects in filemap, add to source. */ if(file->contains) { c_iterWalk(file->contains, (c_iterWalkAction)idl_fileMapFillList, result); } } } return result; }
c_iter v_serviceTakeNewGroups( v_service service) { c_iter result; v_group group; c_set newGroups; assert(service != NULL); assert(C_TYPECHECK(service, v_service)); result = c_iterNew(NULL); OSPL_BLOCK_EVENTS(service); newGroups = service->newGroups; if (newGroups != NULL) { group = v_group(c_take(newGroups)); while (group != NULL) { c_iterInsert(result, group); group = v_group(c_take(newGroups)); } } OSPL_UNBLOCK_EVENTS(service); return result; }
v_index v_indexNew( v_dataReader reader, q_expr expr, v_indexNewAction action, c_voidp arg) { v_index index; c_iter indexList; void *ptr; assert(C_TYPECHECK(reader,v_dataReader)); indexList = c_iterNew(NULL); index = v__indexNew(reader, expr, indexList, action, arg); /* Clean up iterator */ do { ptr = c_iterTakeFirst(indexList); } while (ptr != NULL); c_iterFree(indexList); assert(C_TYPECHECK(index,v_index)); return index; }
void v_subscriberRemoveReader( v_subscriber s, v_reader r) { v_reader found; v_partition d; c_iter iter; assert(s != NULL); assert(r != NULL); iter = c_iterNew(NULL); c_lockWrite(&s->lock); found = c_remove(s->readers,r,NULL,NULL); v_partitionAdminWalk(s->partitions,collectPartitions,iter); while ((d = c_iterTakeFirst(iter)) != NULL) { /* ES, dds1576: The unsubscribe here is performed for all partitions, * however for the K_DATAREADER class not all partitions were * actually subscribed too. Instead of verifying if a partition was * subscribed too or not, the unsubscribe is just executed every time * as this is 'cheaper' then performing the access check again. * If a partition was not subscribed too then the unsubcribe will have no * effect. */ v_readerUnSubscribe(r,d); c_free(d); } c_lockUnlock(&s->lock); c_iterFree(iter); c_free(found); }
void v_subscriberAddReader( v_subscriber s, v_reader r) { v_reader found; v_partition d; c_iter iter; assert(s != NULL); assert(r != NULL); iter = c_iterNew(NULL); c_lockWrite(&s->lock); v_partitionAdminWalk(s->partitions,collectPartitions,iter); while ((d = c_iterTakeFirst(iter)) != NULL) { v_readerSubscribe(r,d); c_free(d); } found = c_setInsert(s->readers,r); c_lockUnlock(&s->lock); if (found != r) { OS_REPORT_1(OS_ERROR, "v_subscriberAddReader", 0, "shared <%s> name already defined", r->qos->share.name); } c_iterFree(iter); }
static c_bool cms_serviceInitSOAP( cms_service cms) { struct soap* soap; c_bool success; c_long master; success = FALSE; soap = (struct soap*)(malloc(sizeof(struct soap))); soap_init2(soap, SOAP_IO_KEEPALIVE | SOAP_IO_FLUSH, SOAP_IO_KEEPALIVE | SOAP_IO_FLUSH); cms->soap = soap; cms->soap->accept_timeout = 3; #ifdef PIKEOS_POSIX cms->soap->bind_flags = 0; #else cms->soap->bind_flags = SO_REUSEADDR; #endif master = soap_bind(cms->soap, NULL, cms->configuration->port, cms->configuration->backlog); if(master < 0) { if(cms->configuration->verbosity >= 1) { OS_REPORT_1(OS_ERROR, CMS_CONTEXT, 0, "Could not bind to port %d", cms->configuration->port); } } else { cms->clients = c_iterNew(NULL); success = TRUE; } return success; }
/* Create a new file map */ idl_fileMap idl_fileMapNew(void) { /* QAC EXPECT 5007; will not use wrapper */ idl_fileMap fileMap = os_malloc((size_t)C_SIZEOF(idl_fileMap)); fileMap->files = c_iterNew(0); return fileMap; }
/* Create a new key definition list */ idl_keyDef idl_keyDefNew ( void) { idl_keyDef keyDef = os_malloc(C_SIZEOF(idl_keyDef)); keyDef->keyList = c_iterNew (0); return keyDef; }
/* Create a new stac definition list */ idl_stacDef idl_stacDefNew ( void) { idl_stacDef stacDef = os_malloc(C_SIZEOF(idl_stacDef)); stacDef->stacList = c_iterNew (0); return stacDef; }
/* Create a new file, identified by fileName */ static idl_file idl_fileNew( const char *fileName) { /* QAC EXPECT 5007; will not use wrapper */ idl_file file = os_malloc ((size_t)C_SIZEOF(idl_file)); file->fileName = os_strdup(fileName); file->contains = c_iterNew(0); return file; }
c_long q_countVar( q_expr e) { c_long nrOfVar; c_iter list; list = c_iterNew(NULL); q_countVarWalk(e,list); nrOfVar = c_iterLength(list); c_iterFree(list); return nrOfVar; }
idl_constExpression idl_constExpressionNew ( idl_exprKind expression) { idl_constExpression constExpr = os_malloc (C_SIZEOF(idl_constExpression)); if (constExpr) { memset (constExpr, 0, C_SIZEOF(idl_constExpression)); idl_operandInit (idl_operand(constExpr), idl_cExpr); constExpr->kind = expression; constExpr->operands = c_iterNew (NULL); } return constExpr; }
/* Create a new file, identified by fileName */ static idl_file idl_fileNew( const char *fileName, const char *inclName) { /* QAC EXPECT 5007; will not use wrapper */ idl_file file = os_malloc (C_SIZEOF(idl_file)); file->fileName = os_strdup(fileName); if (inclName) { file->inclName = os_strdup(inclName); } else { file->inclName = os_strdup(""); } file->contains = c_iterNew(0); return file; }
jni_nameService jni_nameServiceNew() { u_result r; if(ns == NULL){ r = u_userInitialise(); if(r == U_RESULT_OK){ ns = jni_nameService(os_malloc((size_t)(C_SIZEOF(jni_nameService)))); mappings = c_iterNew(NULL); ns->refCount = 1; } } else{ ns->refCount++; } return ns; }
c_iter u_cfElementXPath( u_cfElement element, const c_char *xpathExpr) { u_result r; v_cfElement ke; v_cfNode vChild; c_iter vChildren; c_iter children; u_participant p; u_cfNode proxy; children = c_iterNew(NULL); if ((element != NULL) && (xpathExpr != NULL)) { r = u_cfNodeReadClaim(u_cfNode(element), (v_cfNode*)(&ke)); if (r == U_RESULT_OK) { p = u_cfNodeParticipant(u_cfNode(element)); vChildren = v_cfElementXPath(ke, xpathExpr); vChild = c_iterTakeFirst(vChildren); while (vChild != NULL) { switch(v_cfNodeKind(vChild)) { case V_CFELEMENT: proxy = u_cfNode(u_cfElementNew(p, v_cfElement(vChild))); break; case V_CFATTRIBUTE: proxy = u_cfNode(u_cfAttributeNew(p, v_cfAttribute(vChild))); break; case V_CFDATA: proxy = u_cfNode(u_cfDataNew(p,v_cfData(vChild))); break; default: proxy = NULL; break; } children = c_iterInsert(children, proxy); vChild = c_iterTakeFirst(vChildren); } c_iterFree(vChildren); u_cfNodeRelease(u_cfNode(element)); } } return children; }
c_iter u_cfElementGetChildren( u_cfElement element) { u_result r; v_cfElement ke; v_cfNode child; u_cfNode proxy; c_iter kc; c_iter children; u_participant p; children = c_iterNew(NULL); if (element != NULL) { r = u_cfNodeReadClaim(u_cfNode(element), (v_cfNode*)(&ke)); if (r == U_RESULT_OK) { p = u_cfNodeParticipant(u_cfNode(element)); kc = v_cfElementGetChildren(ke); child = c_iterTakeFirst(kc); while (child != NULL) { switch(v_cfNodeKind(child)) { case V_CFELEMENT: proxy = u_cfNode(u_cfElementNew(p, v_cfElement(child))); break; case V_CFATTRIBUTE: proxy = u_cfNode(u_cfAttributeNew(p, v_cfAttribute(child))); break; case V_CFDATA: proxy = u_cfNode(u_cfDataNew(p,v_cfData(child))); break; default: proxy = NULL; break; } c_iterInsert(children, proxy); child = c_iterTakeFirst(kc); } c_iterFree(kc); u_cfNodeRelease(u_cfNode(element)); } } return children; }
d_groupCreationQueue d_groupCreationQueueNew( d_admin admin) { d_groupCreationQueue queue; os_result osr; os_threadAttr attr; assert(admin); queue = d_groupCreationQueue(os_malloc(C_SIZEOF(d_groupCreationQueue))); if(queue) { d_lockInit(d_lock(queue), D_GROUP_CREATION_QUEUE, d_groupCreationQueueDeinit); if(queue) { queue->groups = c_iterNew(NULL); queue->terminate = FALSE; queue->admin = admin; queue->groupsToCreateVolatile = 0; queue->groupsToCreateTransient = 0; queue->groupsToCreatePersistent = 0; osr = os_threadAttrInit(&attr); if(osr == os_resultSuccess) { osr = os_threadCreate(&queue->actionThread, "groupCreationThread", &attr, (void*(*)(void*))d_groupCreationQueueRun, (void*)queue); if(osr != os_resultSuccess) { d_groupCreationQueueFree(queue); queue = NULL; } } else { d_groupCreationQueueFree(queue); queue = NULL; } } } return queue; }
c_iter v_partitionAdminRemove( v_partitionAdmin da, const c_char *partitionExpr) { /* partitionExpr: expression or absolute partition name */ c_iter partitions; v_partition d; partitions = NULL; c_mutexLock(&da->mutex); if (v_partitionExpressionIsAbsolute(partitionExpr)) { v__partitionAdminRemove(da, partitionExpr, &d); partitions = c_iterNew(d); } else { if (v_partitionAdminRemoveExpression(da, partitionExpr)) { partitions = v_resolvePartitions(v_objectKernel(da), partitionExpr); c_iterWalk(partitions, removePartition, (c_voidp)da->partitions); } /* else expression already member */ } c_mutexUnlock(&da->mutex); return partitions; }
/* TODO: NOT THREAD SAFE */ static c_iter updateNameSpaces( d_nameSpacesRequestListener listener) { d_admin admin; c_ulong total; c_iter nameSpaces; struct updateNsWalkData walkData; admin = d_listenerGetAdmin (d_listener(listener)); /* Update nameSpaces */ nameSpaces = c_iterNew (NULL); walkData.listener = listener; walkData.nameSpaces = nameSpaces; d_adminNameSpaceWalk (admin, updateNameSpacesWalk, &walkData); total = c_iterLength (walkData.nameSpaces); /* Update totals */ c_iterWalk (walkData.nameSpaces, updateNameSpacesTotalWalk, &total); return walkData.nameSpaces; }
c_voidp cmc_entitySetNew( c_iter ventities, c_voidp kernel_uri) { cmc_entitySet entitySet; cmc_entity centity; v_entity entity; entitySet = cmc_entitySet(os_malloc((size_t)(C_SIZEOF(cmc_entitySet)))); entitySet->entities = c_iterNew(NULL); cm_baseObject(entitySet)->kind = CMC_ENTITY_SET; if(ventities != NULL){ entity = v_entity(c_iterTakeFirst(ventities)); while(entity != NULL){ centity = cmc_entity(cmc_entityNew(entity, kernel_uri)); c_iterInsert(entitySet->entities, centity); entity = v_entity(c_iterTakeFirst(ventities)); } } return entitySet; }
static c_bool cms_serviceInitGarbageCollector( cms_service cms) { c_bool success; success = FALSE; cms->clientGarbage = c_iterNew(NULL); cms->garbageCollector = cms_threadNew("cms_garbageCollector", &cms->configuration->garbageScheduling); if(cms->garbageCollector != NULL) { success = cms_threadStart(cms->garbageCollector, (void*(*)(void*))cms_serviceCollectGarbage, (void*)cms); if(success != TRUE) { if(cms->configuration->verbosity >= 1) { OS_REPORT(OS_ERROR, CMS_CONTEXT, 0, "cms_serviceNew: garbage collector could not be started."); } } } return success; }
static u_result attachAndMonitor( const u_participant participant, const struct builtin_datareader_set *drset) { u_waitset waitset; u_dataReader dataReader; c_iter readers; u_result result; c_long i, length; result = U_RESULT_INTERNAL_ERROR; readers = NULL; length = 0; /*Create waitset.*/ waitset = u_waitsetNew(participant); if(waitset){ /*Set event mask of the waitset.*/ result = u_waitsetSetEventMask(waitset, V_EVENT_DATA_AVAILABLE | V_EVENT_NEW_GROUP | V_EVENT_SERVICESTATE_CHANGED); if(result == U_RESULT_OK){ result = u_dispatcherSetEventMask( (u_dispatcher)participant, V_EVENT_NEW_GROUP | V_EVENT_SERVICESTATE_CHANGED); if(result == U_RESULT_OK){ v_serviceFillNewGroups(service); result = u_waitsetAttach( waitset, (u_entity)participant, (u_entity)participant); if(result != U_RESULT_OK){ in_printf(IN_LEVEL_SEVERE, "Could not attach datareader to waitset.\n"); } } else { in_printf(IN_LEVEL_SEVERE, "Could not set event mask of participant."); } if(result == U_RESULT_OK){ readers = c_iterNew(drset->participant_dr); readers = c_iterInsert(readers, drset->publication_dr); readers = c_iterInsert(readers, drset->subscription_dr); result = U_RESULT_OK; length = c_iterLength(readers); for(i=0; i<length && (result == U_RESULT_OK); i++){ dataReader = (u_dataReader)(c_iterObject(readers, i)); /*Set event mask of the datareader to trigger on available data.*/ result = u_dispatcherSetEventMask( (u_dispatcher)dataReader, V_EVENT_DATA_AVAILABLE); if(result == U_RESULT_OK){ /*Attach reader to the waitset.*/ result = u_waitsetAttach( waitset, (u_entity)dataReader, (u_entity)dataReader); if(result != U_RESULT_OK){ in_printf(IN_LEVEL_SEVERE, "Could not attach datareader to waitset.\n"); } } else { in_printf(IN_LEVEL_SEVERE, "Could not set event mask of datareader.\n"); } } } } else { in_printf(IN_LEVEL_SEVERE, "Could not set event mask of waitset.\n"); } if(result == U_RESULT_OK){ /*Start monitoring the creation/deletion of entities.*/ result = startMonitoring(participant, waitset, drset); } u_waitsetDetach(waitset, u_entity(participant)); if(readers){ /*Detach all datareaders from the waitset.*/ for(i=0; i<length; i++){ u_waitsetDetach(waitset, (u_entity)(c_iterObject(readers, i))); } c_iterFree(readers); } /*Delete the waitset.*/ result = u_waitsetFree(waitset); if(result != U_RESULT_OK){ in_printf(IN_LEVEL_SEVERE, "Deletion of waitset failed.\n"); } } else { in_printf(IN_LEVEL_SEVERE, "Could not create waitset.\n"); } return result; }
d_waitset d_waitsetNew( d_subscriber subscriber, c_bool runToCompletion, c_bool timedWait) { d_durability durability; d_admin admin; u_participant uparticipant; os_threadAttr attr; os_result osr; c_ulong mask; d_waitset waitset = NULL; assert(d_objectIsValid(d_object(subscriber), D_SUBSCRIBER) == TRUE); if(subscriber){ waitset = d_waitset(os_malloc(C_SIZEOF(d_waitset))); if(waitset) { d_lockInit(d_lock(waitset), D_WAITSET, d_waitsetDeinit); admin = d_subscriberGetAdmin(subscriber); durability = d_adminGetDurability(admin); uparticipant = u_participant(d_durabilityGetService(durability)); waitset->terminate = FALSE; waitset->subscriber = subscriber; waitset->entities = c_iterNew(NULL); waitset->runToCompletion = runToCompletion; waitset->timedWait = timedWait; if(runToCompletion == TRUE){ waitset->uwaitset = u_waitsetNew(uparticipant); mask = V_EVENT_DATA_AVAILABLE; mask |= V_EVENT_NEW_GROUP; mask |= V_EVENT_HISTORY_DELETE; mask |= V_EVENT_HISTORY_REQUEST; mask |= V_EVENT_PERSISTENT_SNAPSHOT; mask |= V_EVENT_TRIGGER; u_waitsetSetEventMask(waitset->uwaitset, mask); osr = os_threadAttrInit(&attr); if(osr == os_resultSuccess) { osr = os_threadCreate(&waitset->thread, "waitsetThread", &attr, d_waitsetEventHandlerRunToCompletion, waitset); } if(osr != os_resultSuccess) { d_waitsetFree(waitset); } waitset->threads = NULL; } else { waitset->threads = c_iterNew(NULL); waitset->uwaitset = NULL; waitset->thread = OS_THREAD_ID_NONE; } } } return waitset; }
void cmx_readerSnapshotNewAction( v_entity e, c_voidp args) { v_dataReader reader; c_iter instances; v_dataReaderInstance instance; v_dataReaderSample sample, prev; v_query query; c_bool release; sd_serializer ser; sd_serializedData data; struct cmx_readerSnapshotArg* arg; release = FALSE; arg = (struct cmx_readerSnapshotArg*)args; reader = NULL; instances = NULL; ser = NULL; switch(v_object(e)->kind){ case K_DATAREADER: reader = v_dataReader(e); arg->success = TRUE; arg->snapshot = cmx_readerSnapshot(os_malloc(C_SIZEOF(cmx_readerSnapshot))); v_observerLock(v_observer(reader)); if(reader->index->objects){ instances = c_select(reader->index->notEmptyList, 0); } break; case K_QUERY: case K_DATAREADERQUERY: query = v_query(e); reader = v_dataReader(v_querySource(query)); if(reader != NULL){ release = TRUE; arg->success = TRUE; arg->snapshot = cmx_readerSnapshot(os_malloc(C_SIZEOF(cmx_readerSnapshot))); v_observerLock(v_observer(reader)); switch(v_object(query)->kind){ case K_DATAREADERQUERY: if(v_dataReaderQuery(query)->instanceQ){ instances = c_select((c_collection)(v_dataReaderQuery(query)->instanceQ), 0); } break; default: OS_REPORT_1(OS_ERROR, CM_XML_CONTEXT, 0, "cmx_readerSnapshotNewAction unknown kind (%d).", v_object(query)->kind); break; } } break; default: break; } if(arg->success == TRUE){ arg->snapshot->samples = c_iterNew(NULL); } if(instances != NULL){ instance = v_dataReaderInstance(c_iterTakeFirst(instances)); while(instance != NULL){ sample = c_keep(v_dataReaderInstanceHead(instance)); if(sample != NULL){ prev = sample->prev; sample->prev = NULL; if(ser == NULL){ ser = sd_serializerXMLNewTyped(c_getType(c_object(sample))); } data = sd_serializerSerialize(ser, c_object(sample)); arg->snapshot->samples = c_iterInsert(arg->snapshot->samples, sd_serializerToString(ser, data)); sd_serializedDataFree(data); sample->prev = prev; c_free(sample); } c_free(instance); instance = v_dataReaderInstance(c_iterTakeFirst(instances)); } c_iterFree(instances); } if(reader != NULL){ v_observerUnlock(v_observer(reader)); if(release == TRUE){ c_free(reader); } } if(ser != NULL){ sd_serializerFree(ser); } }
static c_bool d_instanceInject( c_object o, c_voidp arg) { d_instance instance; d_sample sample; v_message message, storeMessage, unregisterMsg; struct d_instanceInjectArg* inj; v_writeResult wr; os_time oneSec; c_iter unregisterMessagesToInject; c_bool success; assert(o != NULL); assert(C_TYPECHECK(o, d_instance)); instance = d_instance(o); inj = (struct d_instanceInjectArg*)(arg); unregisterMessagesToInject = c_iterNew(NULL); sample = d_sample(instance->oldest); while ((sample != NULL) && (inj->result == D_STORE_RESULT_OK)) { storeMessage = d_sampleGetMessage(sample); /* copy message */ c_cloneIn(inj->messageType, storeMessage, (c_voidp*)&(message)); /* inject message */ wr = v_groupWriteNoStream(inj->vgroup, message, NULL, V_NETWORKID_LOCAL); oneSec.tv_sec = 1; oneSec.tv_nsec = 0; while(wr == V_WRITE_REJECTED){ wr = v_groupWriteNoStream(inj->vgroup, message, NULL, V_NETWORKID_LOCAL); os_nanoSleep(oneSec); } if((wr != V_WRITE_SUCCESS) && (wr != V_WRITE_REGISTERED) && (wr != V_WRITE_UNREGISTERED)) { OS_REPORT_1(OS_ERROR, D_CONTEXT, 0, "Unable to write persistent data to group. (result: '%d')\n", wr); inj->result = D_STORE_RESULT_ERROR; } else { /* If a sample is written or registered, add unregister action */ unregisterMsg = findUnregisterMessage(unregisterMessagesToInject, message); if(!unregisterMsg){ unregisterMsg = createUnregisterMessage (inj->vgroup, message); /* Add the newly created unregister message to the list of extra messages to inject */ unregisterMessagesToInject = c_iterAppend ( unregisterMessagesToInject, unregisterMsg); } /* Set valid sequence number */ if (message->sequenceNumber >= unregisterMsg->sequenceNumber) { unregisterMsg->sequenceNumber = message->sequenceNumber + 1; } } sample = sample->newer; } if(inj->result == D_STORE_RESULT_OK){ oneSec.tv_sec = 1; oneSec.tv_nsec = 0; /* inject the extra unregister messages */ unregisterMsg = v_message(c_iterTakeFirst(unregisterMessagesToInject)); while (unregisterMsg) { wr = v_groupWriteNoStream(inj->vgroup, unregisterMsg, NULL, V_NETWORKID_LOCAL); while(wr == V_WRITE_REJECTED){ wr = v_groupWriteNoStream(inj->vgroup, unregisterMsg, NULL, V_NETWORKID_LOCAL); os_nanoSleep(oneSec); } unregisterMsg = v_message(c_iterTakeFirst(unregisterMessagesToInject)); } c_iterFree(unregisterMessagesToInject); } if(inj->result == D_STORE_RESULT_OK){ success = TRUE; } else { success = FALSE; } return success; }
c_iter v_cfElementXPath( v_cfElement element, const c_char *xpathExpr) { c_iter result; const c_char *posInExpr; const c_char *slash; char *attribEnd; c_ulong length; struct getChildrenArg arg; c_long nrToProcess; v_cfNode node; assert(C_TYPECHECK(element, v_cfElement)); assert(xpathExpr != NULL); result = c_iterNew(element); nrToProcess = 1; posInExpr = xpathExpr; slash = strchr(posInExpr, XPATH_SEPERATOR); while (nrToProcess > 0) { node = c_iterTakeFirst(result); nrToProcess--; if (node->kind == V_CFELEMENT) { /* do not process data elements */ if (slash) { length = C_ADDRESS(slash) - C_ADDRESS(posInExpr); } else { length = strlen(posInExpr); } arg.children = c_iterNew(NULL); arg.tagName = (c_char *)os_malloc(length + 1U); os_strncpy(arg.tagName, posInExpr, length); arg.tagName[length] = 0; /* Look for selection criteria based on attribute value * Example XPath expression: * /aaa/bbb[@name='value']/ccc or /aaa/bbb[@name!='value']/ccc */ arg.attribName = strchr(arg.tagName, '['); if (arg.attribName != NULL) { *arg.attribName = '\0'; arg.attribName = &(arg.attribName[1]); assert(*arg.attribName == '@'); arg.attribName = &(arg.attribName[1]); arg.attribValue = strchr(arg.attribName, '!'); if (arg.attribValue != NULL) { arg.attribNegate = TRUE; *arg.attribValue = '\0'; arg.attribValue = &arg.attribValue[1]; assert(*arg.attribValue == '='); } else { arg.attribNegate = FALSE; arg.attribValue = strchr(arg.attribName, '='); } assert(arg.attribValue != NULL); *arg.attribValue = '\0'; arg.attribValue = &arg.attribValue[1]; assert(*arg.attribValue == '\''); arg.attribValue = &(arg.attribValue[1]); attribEnd = strchr(arg.attribValue, '\''); assert(attribEnd != NULL); *attribEnd = '\0'; assert(attribEnd[1] == ']'); } c_walk(v_cfElement(node)->children, getChildren, &arg); os_free(arg.tagName); if (slash) { nrToProcess += c_iterLength(arg.children); } /* now append */ node = v_cfNode(c_iterTakeFirst(arg.children)); while (node != NULL) { c_iterAppend(result, node); node = v_cfNode(c_iterTakeFirst(arg.children)); } c_iterFree(arg.children); if (slash) { posInExpr = (const c_char *)(C_ADDRESS(slash) + 1U); slash = strchr(posInExpr, XPATH_SEPERATOR); } } } return result; }