void v_topicAdapterInit( v_topicAdapter adapter, v_topic topic, v_participant p, const c_char *name) { v_eventMask mask = V_EVENT_ALL_DATA_DISPOSED | V_EVENT_INCONSISTENT_TOPIC; assert(adapter != NULL); assert(p != NULL); assert(C_TYPECHECK(adapter, v_topicAdapter)); assert(C_TYPECHECK(p,v_participant)); assert(C_TYPECHECK(topic,v_topic)); v_entityInit(v_entity(adapter), name); adapter->topic = c_keep(topic); (void)v_entityEnable(v_entity(adapter)); (void)v_observerSetEvent(v_observer(adapter), mask); OSPL_ADD_OBSERVER(topic, adapter, mask, NULL); v_participantAdd(p, v_object(adapter)); v_topic(adapter)->owner = p; }
void v_publicDispose( v_public o) { assert(C_TYPECHECK(o,v_public)); if (o == NULL) { return; } switch(v_objectKind(o)) { case K_PARTICIPANT: v_participantDeinit(v_participant(o)); break; case K_PUBLISHER: v_publisherDeinit(v_publisher(o)); break; case K_SUBSCRIBER: v_subscriberDeinit(v_subscriber(o)); break; case K_WRITER: v_writerDeinit(v_writer(o)); break; case K_DATAREADER: v_dataReaderDeinit(v_dataReader(o)); break; case K_DELIVERYSERVICE:v_deliveryServiceDeinit(v_deliveryService(o)); break; case K_NETWORKREADER: v_networkReaderDeinit(v_networkReader(o)); break; case K_READER: v_readerDeinit(v_reader(o)); break; case K_GROUPQUEUE: v_groupQueueDeinit(v_groupQueue(o)); break; case K_TOPIC: v_topicDeinit(v_topic(o)); break; case K_ENTITY: break; case K_DOMAIN: v_partitionDeinit(v_partition(o)); break; case K_GROUP: v_groupDeinit(v_group(o)); break; case K_SERVICEMANAGER: /* Is never freed! */ break; case K_SPLICED: v_splicedDeinit(v_spliced(o)); break; case K_NETWORKING: case K_DURABILITY: case K_CMSOAP: case K_SERVICE: v_serviceDeinit(v_service(o)); break; case K_SERVICESTATE: /* Is never freed! */ break; case K_CONFIGURATION: break; case K_QUERY: OS_REPORT(OS_ERROR, "v_publicDispose failure", 0, "deinit of abstract class K_QUERY"); break; case K_DATAREADERQUERY: v_dataReaderQueryDeinit(v_dataReaderQuery(o)); break; case K_DATAVIEWQUERY: v_dataViewQueryDeinit(v_dataViewQuery(o)); break; case K_DATAVIEW: v_dataViewDeinit(v_dataView(o)); break; case K_WAITSET: v_waitsetDeinit(v_waitset(o)); break; case K_WRITERINSTANCE: v_writerInstanceDeinit(v_writerInstance(o)); break; case K_DATAREADERINSTANCE: v_dataReaderInstanceDeinit(v_dataReaderInstance(o)); break; case K_DATAVIEWINSTANCE: v_dataViewInstanceDeinit(v_dataViewInstance(o)); break; default: OS_REPORT_1(OS_ERROR,"v_publicDispose failed",0, "illegal entity kind (%d) specified",v_objectKind(o)); assert(FALSE); break; } c_free(o); }
static void resolveOffset( v_entity e, c_voidp arg) { c_long* offset; offset = (c_long*)arg; *offset = v_topic(e)->dataField->offset; return; }
static c_bool indexCompare( void *o, c_iterActionArg arg) { v_index index = v_index(o); v_topic topic = v_topic(arg); v_topic currentTopic = NULL; if (index->entry) { currentTopic = v_dataReaderEntryTopic(index->entry); } return (currentTopic == topic); }
static c_bool alwaysFalse( c_object found, c_object requested, c_voidp arg) { v_topic *topicFound = (v_topic *)arg; assert(topicFound != NULL); assert(*topicFound == NULL); /* Out param */ *topicFound = v_topic(c_keep(found)); return FALSE; }
void v_topicAdapterFree( v_topicAdapter adapter) { v_participant p; assert(C_TYPECHECK(adapter,v_topicAdapter)); p = v_topicAdapterParticipant(adapter); OSPL_REMOVE_OBSERVER(adapter->topic, adapter, V_EVENTMASK_ALL, NULL); OSPL_REMOVE_OBSERVER(adapter, p, V_EVENTMASK_ALL, NULL); if (p != NULL) { v_participantRemove(p,v_object(adapter)); v_topic(adapter)->owner = NULL; } v_entityFree(v_entity(adapter)); }
v_topicAdapter v_topicAdapterNewFromTopicInfo( v_participant p, const struct v_topicInfo *info, c_bool announce) { v_topicAdapter adapter = NULL; v_topicImpl topic; v_kernel kernel; assert(p != NULL); assert(C_TYPECHECK(p,v_participant)); kernel = v_objectKernel(p); topic = v_topicImplNewFromTopicInfo(kernel, info, announce); if (topic) { adapter = v_topicAdapterWrap(p, v_topic(topic)); } return adapter; }
v_topicAdapter v_topicAdapterNew( v_participant p, const c_char *name, const c_char *typeName, const c_char *keyExpr, v_topicQos qos) { v_topicAdapter adapter = NULL; v_topicImpl topic; v_kernel kernel; assert(p != NULL); assert(C_TYPECHECK(p,v_participant)); kernel = v_objectKernel(p); topic = v_topicImplNew(kernel, name, typeName, keyExpr, qos, TRUE); if (topic) { adapter = v_topicAdapterWrap(p, v_topic(topic)); } return adapter; }
/** * PRE: v_observerLock has been called. * * When the text 'intentionally no break' is set after a case label * the class specified by the label has not implemented the notify * method. */ void v_observerNotify( v_observer _this, v_event event, c_voidp userData) { /* This Notify method is part of the observer-observable pattern. * It is designed to be invoked when _this object as observer receives * an event from an observable object. * It must be possible to pass the event to the subclass of itself by * calling <subclass>Notify(_this, event, userData). * This implies that _this cannot be locked within any Notify method * to avoid deadlocks. * For consistency _this must be locked by v_observerLock(_this) before * calling this method. */ c_ulong trigger; assert(_this != NULL); assert(C_TYPECHECK(_this,v_observer)); /* The observer will be made insensitive to event as soon as the * observer is deinitialized. However it may be that destruction * of the observer has started before the deinit of the observer * is called. In that case the V_EVENT_OBJECT_DESTROYED flag will * be set to avoid processing of incomming events. */ if ((_this->eventFlags & V_EVENT_OBJECT_DESTROYED) == 0) { /* The observer is valid so the event can be processed. */ if (event != NULL ) { trigger = event->kind & _this->eventMask; } else { /* NULL-event always notifies observers */ trigger = V_EVENT_TRIGGER; } /* The following code invokes the observers subclass specific * notification method. * This is a bit strange that the observer has knowledge about * the subclass notification methods, a better model is that * subclasses register the notification method to the observer * instead. The reason for this model is that registering a * function pointer is only valid in the process scope and this * method will typically be called from another process. */ if (trigger != 0) { switch (v_objectKind(_this)) { case K_DATAREADER: v_dataReaderNotify(v_dataReader(_this), event, userData); break; case K_WAITSET: v_waitsetNotify(v_waitset(_this), event, userData); break; case K_PARTICIPANT: v_participantNotify(v_participant(_this), event, userData); break; case K_TOPIC: v_topicNotify(v_topic(_this), event, userData); break; case K_QUERY: /* v_queryNotify(v_query(_this), event, userData); */ break; case K_SPLICED: /* intentionally no break */ case K_SERVICE: case K_NETWORKING: case K_DURABILITY: case K_CMSOAP: v_serviceNotify(v_service(_this), event, userData); break; case K_SERVICEMANAGER: v_serviceManagerNotify(v_serviceManager(_this), event, userData); break; case K_WRITER: /* no action for the following observers */ case K_PUBLISHER: case K_SUBSCRIBER: case K_GROUPQUEUE: break; default: OS_REPORT_1(OS_INFO,"Kernel Observer",0, "Notify an unknown observer type: %d", v_objectKind(_this)); break; } /* * Only trigger condition variable if at least * one thread is waiting AND the event is seen for the first time. */ if ((_this->waitCount > 0) && ((trigger == V_EVENT_TRIGGER) || (~_this->eventFlags & trigger))) { _this->eventFlags |= trigger; /* store event */ c_condBroadcast(&_this->cv); } else { _this->eventFlags |= trigger; /* store event */ } } } /* else observer object destroyed, skip notification */ }
v_index v__indexNew( v_dataReader reader, q_expr _from, c_iter indexList, v_indexNewAction action, c_voidp arg) { v_kernel kernel; v_index index; v_topic topic; c_type instanceType; c_iter list; c_char *keyExpr; c_array keyList; c_ulong nrOfTopics; assert(C_TYPECHECK(reader,v_dataReader)); kernel = v_objectKernel(reader); if (q_isId(_from)) { list = v_resolveTopics(kernel,q_getId(_from)); nrOfTopics = c_iterLength(list); if (nrOfTopics == 0) { OS_REPORT(OS_ERROR, "v__indexNew", V_RESULT_ILL_PARAM, "Unknown topic %s", q_getId(_from)); c_iterFree(list); return NULL; } if (nrOfTopics > 1) { OS_REPORT(OS_ERROR, "v__indexNew", V_RESULT_ILL_PARAM, "Multiple topic definitions of: %s", q_getId(_from)); topic = v_topic(c_iterTakeFirst(list)); while (topic != NULL) { c_free(topic); topic = v_topic(c_iterTakeFirst(list)); } c_iterFree(list); return NULL; } topic = c_iterTakeFirst(list); c_iterFree(list); index = v_index(c_iterReadAction(indexList, indexCompare, topic)); if (index == NULL) { /* If the userKey is enabled then the instance type key field type * will be determined from the user key expression and topic. * Otherwise when no user key is specified the default Topic key * type will be used. */ if (v_reader(reader)->qos->userKey.v.enable) { keyExpr = v_reader(reader)->qos->userKey.v.expression; } else { keyExpr = NULL; } instanceType = createInstanceType(topic,keyExpr,&keyList); if (instanceType) { index = v_index(v_objectNew(kernel,K_INDEX)); v_indexInit(index, instanceType, keyList, v_reader(reader)); } c_free(keyList); c_free(instanceType); if (index != NULL) { if (action != NULL && !action(index, topic, arg)) { OS_REPORT(OS_ERROR, "v_indexNew", V_RESULT_INTERNAL_ERROR, "v_indexNewAction failed!"); c_free(index); index = NULL; } else { (void)c_iterAppend(indexList, index); } } } } else { OS_REPORT(OS_ERROR, "v_indexNew failed",V_RESULT_ILL_PARAM, "illegal from clause specified"); assert(FALSE); index = NULL; } return index; }