v_collection v_querySource( v_query q) { v_collection c; if (q == NULL) { return NULL; } assert(C_TYPECHECK(q,v_query)); c = v_collection(q->source); if (c == NULL) { OS_REPORT_1(OS_ERROR, "v_querySource failed",0, "Query (0x%x) without source detected", q); assert(FALSE); return NULL; } switch(v_objectKind(c)) { case K_DATAREADER: case K_DATAVIEW: c_keep(c); break; case K_DATAREADERQUERY: case K_DATAVIEWQUERY: c = v_querySource(v_query(c)); break; default: OS_REPORT_1(OS_ERROR, "v_querySource failed",0, "illegal source kind (%d) detected", v_objectKind(c)); assert(FALSE); return NULL; } return c; }
u_instanceHandle u_instanceHandleFix( u_instanceHandle _this, v_collection reader) { u_instanceHandleTranslator translator; struct v_publicationInfo *data; v_topic topic; v_message message; v_public instance; translator.handle = _this; if (translator.lid.lifecycleId & HANDLE_GLOBAL_MASK) { /* Is a GID therefore fix handle by lookup. */ while (v_objectKind(v_entity(reader)) == K_QUERY || v_objectKind(v_entity(reader)) == K_DATAREADERQUERY || v_objectKind(v_entity(reader)) == K_DATAVIEWQUERY) { /* If the entity derives from a query entity it can be cast to a v_query */ reader = v_querySource(v_query(reader)); } while (v_objectKind(v_entity(reader)) == K_DATAVIEW) { reader = v_collection(v_dataViewGetReader(v_dataView(reader))); } topic = v_dataReaderGetTopic(v_dataReader(reader)); message = v_topicMessageNew(topic); data = (c_voidp)C_DISPLACE(message, v_topicDataOffset(topic)); data->key = u_instanceHandleToGID(_this); instance = (v_public)v_dataReaderLookupInstance(v_dataReader(reader), message); translator.handle = u_instanceHandleNew(instance); c_free(instance); c_free(topic); c_free(message); } return translator.handle; }
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); } }
void cmx_readerDataTypeAction( v_entity entity, c_voidp args) { sd_serializer ser; sd_serializedData data; c_type type; v_dataReader r; v_query query; v_topic topic; struct cmx_readerArg *arg; arg = (struct cmx_readerArg *)args; type = NULL; switch(v_object(entity)->kind){ case K_DATAREADER: r = v_dataReader(entity); v_observerLock(v_observer(r)); topic = v_dataReaderGetTopic(r); type = v_topicDataType(topic); c_free(topic); v_observerUnlock(v_observer(r)); break; case K_DATAREADERQUERY: query = v_query(entity); r = v_dataReader(v_querySource(query)); v_observerLock(v_observer(r)); topic = v_dataReaderGetTopic(r); type = v_topicDataType(topic); c_free(topic); v_observerUnlock(v_observer(r)); c_free(r); break; case K_NETWORKREADER: OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0, "Resolving data type of networkReader unsupported.\n"); assert(FALSE); break; case K_GROUPQUEUE: OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0, "Resolving data type of groupQueue unsupported.\n"); assert(FALSE); break; default: OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0, "Trying to resolve dataType of unknown reader type.\n"); assert(FALSE); break; } if(type != NULL){ ser = sd_serializerXMLMetadataNew(c_getBase(type)); data = sd_serializerSerialize(ser, type); arg->result = sd_serializerToString(ser, data); sd_serializedDataFree(data); sd_serializerFree(ser); } }
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); } }