c_bool v_groupStreamUnSubscribe( v_groupStream stream, v_partition partition) { c_iter list; v_group group; c_bool result; assert(C_TYPECHECK(stream, v_groupStream)); assert(C_TYPECHECK(partition, v_partition)); list = ospl_c_select(stream->groups, 0); group = c_iterTakeFirst(list); result = FALSE; while (group != NULL) { if(strcmp(v_partitionName(partition), v_partitionName(group->partition)) == 0){ result = v_groupStreamUnSubscribeGroup(stream, group); } c_free(group); group = c_iterTakeFirst(list); } c_iterFree(list); return result; }
static c_bool v_partitionAdminRemoveExpression( v_partitionAdmin da, const char *partitionExpr) { c_bool result = FALSE; v_partitionInterest partitionInterest, found; q_expr expr; c_collection q; c_iter list; c_value params[1]; assert(!v_partitionExpressionIsAbsolute(partitionExpr)); expr = (q_expr)q_parse("expression like %0"); params[0] = c_stringValue((char *)partitionExpr); q = c_queryNew(da->partitionInterests, expr, params); q_dispose(expr); list = ospl_c_select(q,0); assert(c_iterLength(list) <= 1); partitionInterest = v_partitionInterest(c_iterTakeFirst(list)); while (partitionInterest) { result = TRUE; found = c_tableRemove(da->partitionInterests, partitionInterest, NULL, NULL); c_free(partitionInterest); c_free(found); partitionInterest = v_partitionInterest(c_iterTakeFirst(list)); } c_free(q); c_iterFree(list); return result; }
c_iter v_resolveMMFGroups( c_set groups, const c_char *partitionExpr, const c_char *topicExpr) { c_collection q; q_expr expr; c_iter list; c_value params[2]; assert(groups != NULL); expr = (q_expr)q_parse("partition.name like %0 and topic.name like %1"); if (expr == NULL) { assert(expr != NULL); return NULL; } params[0] = c_stringValue((c_string)partitionExpr); params[1] = c_stringValue((c_string)topicExpr); q = c_queryNew(groups, expr, params); if (q == NULL) { list = NULL; } else { list = ospl_c_select(q,0); } assert(q != NULL); c_free(q); q_dispose(expr); return list; }
c_iter v_subscriberLookupReaders( v_subscriber s) { c_iter list; assert(s != NULL); c_lockRead(&s->lock); list = ospl_c_select(s->readers,0); c_lockUnlock(&s->lock); return list; }
d_storeResult d_storeMMFKernelBackupRestore( d_storeMMFKernel kernel, const d_store store, const d_nameSpace nameSpace) { c_iter groups; d_groupInfo group; d_groupInfo restore, found; d_storeResult result; OS_UNUSED_ARG(store); if(kernel && nameSpace){ groups = ospl_c_select(kernel->backup, 0); group = d_groupInfo(c_iterTakeFirst(groups)); result = D_STORE_RESULT_OK; while(group && (result == D_STORE_RESULT_OK)){ if(d_nameSpaceIsIn(nameSpace, group->partition, group->topic->name)){ restore = c_remove(kernel->backup, group, NULL, NULL); assert(restore); if(restore){ found = d_groupInfo(c_tableInsert(kernel->groups, restore)); if(found != restore){ c_remove(kernel->groups, found, NULL, NULL); c_free(found); found = d_groupInfo(c_tableInsert(kernel->groups, restore)); assert(found == restore); if(found != restore){ result = D_STORE_RESULT_ERROR; } } } else { result = D_STORE_RESULT_ERROR; } } c_free(group); group = d_groupInfo(c_iterTakeFirst(groups)); } c_iterFree(groups); } else { result = D_STORE_RESULT_ILL_PARAM; } return result; }
void v_serviceFillNewGroups( v_service service) { c_set newGroups; C_STRUCT(v_event) ge; v_group g, oldGroup; c_iter oldGroups; v_kernel kernel; assert(service != NULL); assert(C_TYPECHECK(service, v_service)); kernel = v_objectKernel(service); newGroups = (c_voidp)c_setNew(v_kernelType(kernel, K_GROUP)); if (newGroups != NULL) { addAllGroups(newGroups, kernel->groupSet); v_observerLock(v_observer(service)); g = v_group(c_read(newGroups)); /* need a group for the event */ if(v_observer(service)->eventData != NULL){ oldGroups = ospl_c_select((c_set)v_observer(service)->eventData, 0); oldGroup = v_group(c_iterTakeFirst(oldGroups)); while(oldGroup){ newGroups = c_setInsert(newGroups, oldGroup); c_free(oldGroup); oldGroup = v_group(c_iterTakeFirst(oldGroups)); } c_iterFree(oldGroups); } /* just for safety, when assertion are compiled out, free the prev set */ c_free((c_object)v_observer(service)->eventData); v_observer(service)->eventData = (c_voidp)newGroups; ge.kind = V_EVENT_NEW_GROUP; ge.source = v_publicHandle(v_public(kernel)); ge.userData = g; v_observerNotify(v_observer(service), &ge, NULL); v_observerUnlock(v_observer(service)); c_free(g); } }
d_storeResult d_storeMMFKernelDeleteNonMatchingGroups( d_storeMMFKernel _this, c_string partitionExpr, c_string topicExpr) { d_storeResult result; d_groupInfo group, removed; c_iter groups; c_bool match; if(_this && partitionExpr && topicExpr){ result = D_STORE_RESULT_OK; groups = ospl_c_select(_this->groups, 0); group = d_groupInfo(c_iterTakeFirst(groups)); while(group){ match = d_patternMatch(group->partition, partitionExpr); if(match){ match = d_patternMatch(group->topic->name, topicExpr); } if(!match){ removed = c_remove(_this->groups, group, NULL, NULL); assert(removed == group); if(removed != group){ result = D_STORE_RESULT_MUTILATED; } c_free(removed); } c_free(group); group = d_groupInfo(c_iterTakeFirst(groups)); } c_iterFree(groups); } else { result = D_STORE_RESULT_ILL_PARAM; } return result; }
static c_iter v_resolveMMFNameSpaces( d_storeMMFKernel kernel, const c_char *name) { c_iter list; c_collection q; q_expr expr; c_value params[1]; assert(kernel != NULL); assert(C_TYPECHECK(kernel,v_kernel)); expr = (q_expr)q_parse("name like %0"); params[0] = c_stringValue((char *)name); q = c_queryNew(kernel->nameSpaces,expr,params); q_dispose(expr); list = ospl_c_select(q,0); c_free(q); return list; }
void v_groupStreamDeinit( v_groupStream stream) { c_iter groups; v_group group; assert(C_TYPECHECK(stream, v_groupStream)); v_readerDeinit(v_reader(stream)); groups = ospl_c_select(stream->groups, 0); group = v_group(c_iterTakeFirst(groups)); while(group){ v_groupRemoveStream(group, stream); c_free(group); group = v_group(c_iterTakeFirst(groups)); } c_iterFree(groups); c_free(stream->groups); stream->groups = NULL; }
static c_bool v__partitionAdminRemove( v_partitionAdmin da, const char *partitionName, v_partition *partitionRemoved) { c_bool result; v_partition partition, found; q_expr expr; c_collection q; c_iter list; c_value params[1]; assert(v_partitionExpressionIsAbsolute(partitionName)); expr = (q_expr)q_parse("name like %0"); params[0] = c_stringValue((char *)partitionName); q = c_queryNew(da->partitions, expr, params); q_dispose(expr); list = ospl_c_select(q,0); assert(c_iterLength(list) <= 1); partition = v_partition(c_iterTakeFirst(list)); if (partition) { found = c_tableRemove(da->partitions, partition, NULL, NULL); *partitionRemoved = found; c_free(partition); result = TRUE; } else { *partitionRemoved = NULL; result = FALSE; } c_free(q); c_iterFree(list); return result; }
d_readerRequest d_readerRequestNew( d_admin admin, v_handle source, c_char* filter, c_char** filterParams, c_long filterParamsCount, struct v_resourcePolicy resourceLimits, c_time minSourceTimestamp, c_time maxSourceTimestamp) { d_readerRequest request; c_long i; v_handleResult handleResult; v_reader vreader, *vreaderPtr; c_iter partitions; v_partition partition; v_topic topic; d_group dgroup; c_char *topicName; d_quality quality; request = d_readerRequest(os_malloc(C_SIZEOF(d_readerRequest))); if(request){ d_lockInit(d_lock(request), D_READER_REQUEST, d_readerRequestDeinit); request->admin = admin; request->readerHandle.index = source.index; request->readerHandle.serial = source.serial; request->readerHandle.server = source.server; request->requests = d_tableNew(d_chainCompare, d_chainFree); if(filter){ request->filter = os_strdup(filter); } else { request->filter = NULL; } request->resourceLimits = resourceLimits; request->minSourceTimestamp = minSourceTimestamp; request->maxSourceTimestamp = maxSourceTimestamp; request->filterParamsCount = filterParamsCount; if(filterParamsCount > 0){ request->filterParams = (c_char**)(os_malloc( filterParamsCount*sizeof(c_char*))); for(i=0; i<filterParamsCount; i++){ request->filterParams[i] = os_strdup(filterParams[i]); } } else { request->filterParams = NULL; } request->groups = d_tableNew(d_groupCompare, d_groupFree); handleResult = v_handleClaim(source, (v_object*)(vreaderPtr = &vreader)); if(handleResult == V_HANDLE_OK){ if(v_object(vreader)->kind == K_DATAREADER){ topic = v_dataReaderGetTopic(v_dataReader(vreader)); topicName = v_entity(topic)->name; partitions = ospl_c_select(v_subscriber(vreader->subscriber)->partitions->partitions, 0); partition = v_partition(c_iterTakeFirst(partitions)); while(partition){ quality.seconds = 0; quality.nanoseconds = 0; dgroup = d_groupNew( v_entity(partition)->name, topicName, topic->qos->durability.kind, D_GROUP_KNOWLEDGE_UNDEFINED, quality); d_tableInsert(request->groups, dgroup); c_free(partition); partition = v_partition(c_iterTakeFirst(partitions)); } c_free(topic); } else { d_readerRequestFree(request); request = NULL; } v_handleRelease(source); } else { d_readerRequestFree(request); request = NULL; } } return request; }
void cmx_readerSnapshotNewAction( v_public p, c_voidp args) { v_dataReader reader; c_iter instances; v_dataReaderInstance instance; v_dataReaderSample sample; 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(p)->kind){ case K_DATAREADER: reader = v_dataReader(p); arg->success = TRUE; arg->snapshot = cmx_readerSnapshot(os_malloc(C_SIZEOF(cmx_readerSnapshot))); v_observerLock(v_observer(reader)); if(reader->index->objects){ instances = ospl_c_select(reader->index->notEmptyList, 0); } break; case K_QUERY: case K_DATAREADERQUERY: query = v_query(p); 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 = ospl_c_select((c_collection)(v_dataReaderQuery(query)->instanceQ), 0); } break; default: OS_REPORT(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){ v_dataReaderSample sampleShallowCopy = NULL; instance = v_dataReaderInstance(c_iterTakeFirst(instances)); while(instance != NULL){ v_state ivState = instance->_parent._parent.state & (L_DISPOSED | L_NOWRITERS | L_NEW); sample = v_dataReaderInstanceOldest(instance); if (sample != NULL) { do { v_state state = ivState | ((sample->_parent.sampleState & (L_READ | L_LAZYREAD)) ? L_READ : 0); if (sampleShallowCopy == NULL) { sampleShallowCopy = c_new(c_getType(c_object(sample))); } memcpy(sampleShallowCopy, sample, c_typeSize(c_getType(sampleShallowCopy))); sampleShallowCopy->newer = NULL; sampleShallowCopy->_parent.sampleState &= ~(L_DISPOSED | L_NOWRITERS | L_NEW | L_READ | L_LAZYREAD); sampleShallowCopy->_parent.sampleState |= state; if(ser == NULL){ ser = sd_serializerXMLNewTyped(c_getType(c_object(sampleShallowCopy))); } data = sd_serializerSerialize(ser, c_object(sampleShallowCopy)); arg->snapshot->samples = c_iterInsert(arg->snapshot->samples, sd_serializerToString(ser, data)); sd_serializedDataFree(data); sample = sample->newer; } while (sample != NULL); } c_free(instance); instance = v_dataReaderInstance(c_iterTakeFirst(instances)); } c_iterFree(instances); if (sampleShallowCopy != NULL) { memset(sampleShallowCopy, 0, c_typeSize(c_getType(sampleShallowCopy))); c_free(sampleShallowCopy); } } if(reader != NULL){ v_observerUnlock(v_observer(reader)); if(release == TRUE){ c_free(reader); } } if(ser != NULL){ sd_serializerFree(ser); } }