c_char* cmx_readerSnapshotRead( const c_char* snapshot) { cmx_readerSnapshot s; c_char* result; c_char* temp; s = cmx_readerSnapshotLookup(snapshot); result = NULL; if(s != NULL){ temp = (c_char*)(c_iterObject(s->samples, 0)); if(temp != NULL){ result = (c_char*)(os_strdup(temp)); } } return result; }
static void printEnum( c_enumeration _this, toolActionData actionData) { c_object o; c_long i, size; c_constant constant; o = c_iterObject(actionData->stack, 0); size = c_enumerationCount(_this); i = *(c_long *)o; if ((i < 0) || (i > size)) { printf("(%d) \"Bad enumeration value\"\n", i); } else { constant = c_enumeration(_this)->elements[i]; printf("%s",_METANAME(constant)); } }
u_domainId_t u_waitsetGetDomainId( u_waitset _this) { os_result osr; u_domainId_t domainId = -1; u_waitsetEntry entry; osr = os_mutexLock_s(&_this->mutex); if (osr == os_resultSuccess) { if (c_iterLength(_this->entries) == 1) { entry = c_iterObject(_this->entries, 0); domainId = u_observableGetDomainId(u_observable(entry)); } os_mutexUnlock(&_this->mutex); } return domainId; }
static v_message findUnregisterMessage( c_iter msgs, v_message tmpl) { c_long i; v_message result = NULL; if(msgs && tmpl){ for(i=0; i<c_iterLength(msgs) && !result; i++){ result = (v_message)(c_iterObject(msgs, i)); if(v_gidCompare(result->writerGID, tmpl->writerGID) != C_EQ){ result = NULL; } } } return result; }
c_bool idl_keyDefIncludesType( idl_keyDef keyDef, const char *typeName) { #define KEY_SCOPE_MAX_SIZE (512) char key_scope[KEY_SCOPE_MAX_SIZE]; char key_tmp[KEY_SCOPE_MAX_SIZE]; c_long li; idl_keyMap keyMap; c_metaObject typeScope; li = 0; /* check all key definition list elements */ while (li < c_iterLength (keyDef->keyList)) { keyMap = c_iterObject (keyDef->keyList, li); /* Start the key scope with the key itself. */ key_scope[0] = '\0'; strncpy(key_scope, keyMap->typeName, KEY_SCOPE_MAX_SIZE); key_scope[KEY_SCOPE_MAX_SIZE - 1] = '\0'; /* Run down this keys' scope. */ for (typeScope = keyMap->scope; typeScope != NULL; typeScope = typeScope->definedIn) { if (typeScope->name != NULL) { /* Add current scope to key scope and check it all against the given type. */ key_tmp[0] = '\0'; snprintf(key_tmp, KEY_SCOPE_MAX_SIZE, "%s_%s", typeScope->name, key_scope); if (strcmp(typeName, key_tmp) == 0) { return TRUE; } /* Update the key scope to the current one. */ key_scope[0] = '\0'; strncpy(key_scope, key_tmp, KEY_SCOPE_MAX_SIZE); key_scope[KEY_SCOPE_MAX_SIZE - 1] = '\0'; } } li++; } return FALSE; #undef KEY_SCOPE_MAX_SIZE }
static void printHistory ( c_iter history, c_long cursor) { c_type type; c_object o; c_char *name, *ename; o = c_iterObject(history,cursor-1); type = c_getType(o); name = c_metaScopedName(c_metaObject(type)); printf("<0x%x> %s",(HEXVALUE)o,name); if (c_checkType(o, "v_entity") == o) { ename = v_entityName(o); if (ename != NULL) { printf(" /* %s */", ename); } } printf("\n"); }
static u_result waitset_notify ( const u_waitset _this, void *eventArg) { u_result result = U_RESULT_OK; c_ulong length; assert(_this != NULL); length = c_iterLength(_this->entries); if (length == 1) { /* Single Domain Mode. */ result = u_waitsetEntryTrigger(c_iterObject(_this->entries,0), eventArg); } else { /* Multi Domain Mode (or no Domain). */ os_condSignal(&_this->cv); result = U_RESULT_OK; } return result; }
void d_nameSpacesRequestListenerReportNameSpaces( d_nameSpacesRequestListener listener) { c_long count, i; d_networkAddress addr; d_nameSpaces ns; d_admin admin; d_publisher publisher; c_iter nameSpaces; assert(d_listenerIsValid(d_listener(listener), D_NAMESPACES_REQ_LISTENER)); if(listener){ addr = d_networkAddressUnaddressed(); admin = d_listenerGetAdmin(d_listener(listener)); assert (admin); publisher = d_adminGetPublisher(admin); /* Get list of namespaces */ nameSpaces = updateNameSpaces(listener); count = c_iterLength(nameSpaces); for(i=0; i<count; i++){ ns = d_nameSpaces(c_iterObject(nameSpaces, i)); d_messageInit(d_message(ns), admin); d_messageSetAddressee(d_message(ns), addr); d_publisherNameSpacesWrite(publisher, ns, addr); } d_networkAddressFree(addr); /* Free namespace list */ cleanNameSpaces (nameSpaces); } return; }
cms_client cms_serviceLookupClient( cms_service cms, struct soap* soap, const c_char* uri) { int i; cms_client client; cms_client result; result = NULL; os_mutexLock(&cms->clientMutex); for(i=0; i<c_iterLength(cms->clients) && result == NULL; i++) { client = cms_client(c_iterObject(cms->clients, i)); if(client->ip == soap->ip) { if(cms_thread(client)->terminate == FALSE) { result = client; } } } if( (result == NULL) && (((c_ulong)c_iterLength(cms->clients)) < cms->configuration->maxClients)) { result = cms_clientNew(soap->ip, cms, uri); cms->clients = c_iterInsert(cms->clients, result); cms_clientStart(result); cms_serviceUpdateStatistics(cms); if(cms->configuration->verbosity >= 4) { OS_REPORT_4(OS_INFO, CMS_CONTEXT, 0, "Client thread started for IP: %d.%d.%d.%d", (int)(result->ip>>24)&0xFF, (int)(result->ip>>16)&0xFF, (int)(result->ip>>8)&0xFF, (int)(result->ip&0xFF)); }
void d_nameSpacesRequestListenerAction( d_listener listener, d_message message) { d_durability durability; d_admin admin; d_fellow fellow; d_publisher publisher; c_ulong i, count; d_nameSpaces ns; d_networkAddress addr; d_nameSpacesRequest request; c_bool added; c_iter nameSpaces; assert(d_listenerIsValid(d_listener(listener), D_NAMESPACES_REQ_LISTENER)); admin = d_listenerGetAdmin(listener); durability = d_adminGetDurability(admin); addr = d_networkAddressNew(message->senderAddress.systemId, message->senderAddress.localId, message->senderAddress.lifecycleId); fellow = d_adminGetFellow(admin, addr); publisher = d_adminGetPublisher(admin); d_printTimedEvent(durability, D_LEVEL_FINE, D_THREAD_NAMESPACES_REQUEST_LISTENER, "Received nameSpacesRequest from fellow %d.\n", message->senderAddress.systemId); /* Update nameSpaces list for listener */ nameSpaces = updateNameSpaces(d_nameSpacesRequestListener(listener)); if(!fellow){ fellow = d_fellowNew(addr, message->senderState); d_fellowUpdateStatus(fellow, message->senderState, v_timeGet()); added = d_adminAddFellow(admin, fellow); if(added == FALSE){ d_fellowFree(fellow); fellow = d_adminGetFellow(admin, addr); assert(fellow); } else { fellow = d_adminGetFellow(admin, addr); d_printTimedEvent(durability, D_LEVEL_FINE, D_THREAD_NAMESPACES_REQUEST_LISTENER, "Fellow %d unknown, added to administration and requesting nameSpaces.\n", message->senderAddress.systemId); request = d_nameSpacesRequestNew(admin); d_messageSetAddressee(d_message(request), addr); d_publisherNameSpacesRequestWrite(publisher, request, addr); d_nameSpacesRequestFree(request); } } d_fellowUpdateStatus(fellow, message->senderState, v_timeGet()); count = c_iterLength(nameSpaces); for(i=0; i<count; i++){ ns = d_nameSpaces(c_iterObject(nameSpaces, i)); d_messageInit(d_message(ns), admin); d_messageSetAddressee(d_message(ns), addr); d_publisherNameSpacesWrite(publisher, ns, addr); } cleanNameSpaces (nameSpaces); d_fellowFree(fellow); d_networkAddressFree(addr); return; }
static void printCollection( c_collectionType type, toolActionData actionData) { c_long size, i, offset, esize; c_object o; c_voidp p; c_object arrayElement; c_type subtype; c_bool isRef; o = c_iterObject(actionData->stack, 0); switch (type->kind) { case C_ARRAY: case C_SEQUENCE: /* Walk over all entries */ switch (type->kind) { case C_ARRAY: if (type->maxSize == 0) { size = c_arraySize((c_array)o); } else { size = type->maxSize; } break; case C_SEQUENCE: size = c_arraySize((c_array)o); break; default: size = 0; assert(FALSE); break; } if (c_typeIsRef(type->subType)) { esize = sizeof(c_voidp); isRef = TRUE; } else { esize = type->subType->size; isRef = FALSE; } p = o; offset = 0; for (i=0; i<size; i++) { iprintf("Element (%d) Offset (%d)\n",i,offset); arrayElement = isRef ? *((c_object *)p) : (c_object) p; if (arrayElement != NULL) { OBJECT_PUSH(actionData, arrayElement); if (isRef) { subtype = c_getType(arrayElement); printType(subtype, actionData); } else { iprintf(" "); printType(type->subType, actionData); } printf("\n"); OBJECT_POP(actionData); } else { iprintf(" <0x0>\n"); } p = C_DISPLACE(p, esize); offset += esize; } break; case C_STRING: printf(" \"%s\"",(c_char *)o); break; case C_SET: case C_LIST: case C_BAG: case C_DICTIONARY: case C_QUERY: { if (o != NULL) { /* Walk over the elements */ c_walk(o, (c_action)printCollectionAction, actionData); if (c_count(o) == 0) { iprintf("<EMPTY>"); } } else { iprintf("<NULL>"); } } break; case C_SCOPE: c_scopeWalk(o, printCollectionAction, actionData); break; default: printf("Specified type <0x"PA_ADDRFMT"> is not a valid collection type\n", (os_address)type); break; } }
/* This operation scans through the list of items within the 'stac' pragma. * For each structure that is identified it will locate the corresponding * meta structure. It will then locate each member mentioned in the 'stac' * pragma within the member list of said meta structure. It will verify the * located member is indeed a character array. * It will then proceed to replace the meta data describing the located member * with new meta data with as goal to have the new meta data identify the member * as a string instead of as a character array. * All replaced meta data is stored in out variables to facilitate restore the * member list of the meta structure back into it's original configuration. * This operation is needed then the meta data of the found structure is * converted to XML. As the XML generation code is located in the database and * we do not want the database to get knowledge of the 'stac' pragma. */ c_iter idl_stacDefConvertAll( idl_stacDef stacDef) { os_uint32 size; os_uint32 i; idl_stacMap stacMapItem; c_structure structure; c_iter memberNames; os_uint32 memberNamesSize; os_uint32 j; os_char* memberName; os_int32 memberIndex; c_member member; c_member newMember; os_uint32* replacedIndex; idl_stacDefReplaceInfo replaceData; c_iter replaceInfo = NULL; c_base base; c_iter boundedStringToBeConverted; os_boolean stacCanBeApplied = OS_TRUE; os_boolean onlyExclusionlistings; if(stacDef) { /* Create collections to hold the original members and their respective * indexes in the member collection so we can easily restore the meta * structure to it's original configuration at a later time. */ replaceInfo = c_iterNew(NULL); size = c_iterLength (stacDef->stacList); for(i = 0; i < size; i++) { stacMapItem = c_iterObject (stacDef->stacList, i); /* find the matching structure in the meta data */ structure = idl_stacDefFindMetaStructureResolved( stacMapItem->scope, stacMapItem->typeName); assert(structure); replaceData = os_malloc(C_SIZEOF(idl_stacDefReplaceInfo)); replaceData->structure = structure; replaceData->replacedIndexes = c_iterNew(NULL); replaceData->replacedMembers = c_iterNew(NULL); memberNames = c_splitString(stacMapItem->stacList, ","); onlyExclusionlistings = idl_stacDefOnlyExclusionsDefined(stacMapItem->stacList); memberNamesSize = c_iterLength(memberNames); boundedStringToBeConverted = c_iterNew(NULL); if(memberNamesSize == 0 || onlyExclusionlistings) { os_uint32 membersSize; membersSize = c_arraySize(structure->members); for(j = 0; j < membersSize; j++) { member = c_member(structure->members[j]); memberName = c_specifier(member)->name; /* check if this member is in the list of member names when * the member names list contains exclusion listings */ if((onlyExclusionlistings && c_iterResolve(memberNames, idl_stacDefNamesAreEqual, memberName) == NULL) || memberNamesSize == 0) { stacCanBeApplied = idl_stacDefCanStacBeAppliedToMember(c_specifier(member)->type); if(stacCanBeApplied) { /* this is a bounded string, so we want to convert */ c_iterInsert(boundedStringToBeConverted, member); } } } } else { for(j = 0; j < memberNamesSize; j++) { memberName = c_iterTakeFirst(memberNames); if(memberName[0] == '!') { printf("FATAL ERROR | #pragma stac: Illegal syntax combination detected. " "The pragma stac definition for structure %s contains both normal " "member listings (without the '!' character in front of them) as " "well as exclusion member listings (with the '!' character in front " "of them). This has no relevant meaning, please see the deployment manual " "for information on usage of pragma stac.\n" "Ignoring the following member defintion: '%s'\n", c_metaScopedName(c_metaObject(structure)), memberName); exit(-2); } memberIndex = idl_stacDefFindMemberIndexByName( structure->members, memberName); if(memberIndex == -1) { printf("FATAL ERROR | #pragma stac: Unable to locate member %s " "within structure %s.\n", memberName, c_metaScopedName(c_metaObject(structure))); exit(-2); } member = structure->members[memberIndex]; /* Verify the member is a bounded string as required */ stacCanBeApplied = idl_stacDefCanStacBeAppliedToMember(c_specifier(member)->type); if(!stacCanBeApplied) { printf("FATAL ERROR | #pragma stac: Member %s within structure " "%s is not a bounded string (note: may be embedded within an array or sequence) as required.\n", memberName, c_metaScopedName(c_metaObject(structure))); assert(0); exit(-2); } /* this is a bounded string, so we want to convert */ c_iterInsert(boundedStringToBeConverted, member); } } while(c_iterLength(boundedStringToBeConverted) > 0) { member = c_iterTakeFirst(boundedStringToBeConverted); memberIndex = idl_stacDefFindMemberIndexByName( structure->members, c_specifier(member)->name); assert(memberIndex != -1); newMember = c_metaDefine(c_metaObject(structure), M_MEMBER); base = c_getBase(member); c_specifier(newMember)->name = c_stringNew(base, c_specifier(member)->name); c_specifier(newMember)->type = idl_stacDefConvertStacApprovedMember(structure, c_specifier(member)->type); if(!c_specifier(newMember)->type) { printf("FATAL ERROR | #pragma stac: An internal error occured. Member %s within structure " "%s failed to convert from a bounded string to a character array.\n", c_specifier(newMember)->name, c_metaScopedName(c_metaObject(structure))); assert(0); exit(-2); } structure->members[memberIndex] = newMember; c_iterInsert(replaceData->replacedMembers, member); replacedIndex = os_malloc(sizeof(os_uint32)); *replacedIndex = (os_uint32)memberIndex; c_iterInsert(replaceData->replacedIndexes, replacedIndex); } c_iterInsert(replaceInfo, replaceData); } } return replaceInfo; }
u_result u_waitsetWaitAction ( const u_waitset _this, u_waitsetAction action, void *arg, const os_duration timeout) { u_result result = U_RESULT_OK; os_result osr; c_ulong length; assert(_this != NULL); assert(action != NULL); assert(OS_DURATION_ISPOSITIVE(timeout)); osr = os_mutexLock_s(&_this->mutex); if (osr == os_resultSuccess) { if (!_this->alive) { result = U_RESULT_ALREADY_DELETED; } if (result == U_RESULT_OK) { if (!_this->waitBusy) { /* Wait for possible detach to complete. * If you don't do that, it's possible that this wait call sets * the waitBusy flag before the detach can wake up of its waitBusy * loop, meaning that the detach will block at least until the * waitset is triggered again. */ while (_this->detachCnt > 0) { os_condWait(&_this->waitCv, &_this->mutex); } _this->waitBusy = TRUE; length = c_iterLength(_this->entries); if (length == 1) { /* Single Domain Mode. */ u_waitsetEntry entry = c_iterObject(_this->entries,0); os_mutexUnlock(&_this->mutex); result = u_waitsetEntryWait(entry, action, arg, timeout); os_mutexLock(&_this->mutex); _this->waitBusy = FALSE; os_condBroadcast(&_this->waitCv); os_mutexUnlock(&_this->mutex); if ((result == U_RESULT_OK) && (_this->alive == FALSE)) { result = U_RESULT_ALREADY_DELETED; } } else { /* Multi Domain Mode (or no Domain). */ if (OS_DURATION_ISINFINITE(timeout)) { os_condWait(&_this->cv, &_this->mutex); osr = os_resultSuccess; } else { osr = os_condTimedWait(&_this->cv, &_this->mutex, timeout); } _this->waitBusy = FALSE; os_condBroadcast(&_this->waitCv); switch (osr) { case os_resultSuccess: if (_this->alive == TRUE) { result = U_RESULT_OK; } else { result = U_RESULT_ALREADY_DELETED; } break; case os_resultTimeout: result = U_RESULT_TIMEOUT; break; default: result = U_RESULT_INTERNAL_ERROR; OS_REPORT(OS_ERROR, "u_waitsetWaitAction", result, "os_condWait failed for waitset 0x" PA_ADDRFMT, (PA_ADDRCAST)_this); break; } os_mutexUnlock(&_this->mutex); } } else { os_mutexUnlock(&_this->mutex); result = U_RESULT_PRECONDITION_NOT_MET; } } else { os_mutexUnlock(&_this->mutex); } } else { result = U_RESULT_INTERNAL_ERROR; OS_REPORT(OS_ERROR, "u_waitsetWaitAction", result, "os_mutexLock failed for waitset 0x" PA_ADDRFMT, (PA_ADDRCAST)_this); } return result; }
static c_char* getPersistentPartitionExpression( d_admin admin, d_durability durability) { c_char *result, *expr; d_nameSpace ns; d_durabilityKind dkind; c_ulong length; c_long i, j; c_iter nameSpaces; result = NULL; assert (admin); /* Collect namespaces */ nameSpaces = d_adminNameSpaceCollect(admin); if(admin){ length = 0; j = 0; for(i=0; i<c_iterLength(nameSpaces); i++){ ns = d_nameSpace(c_iterObject(nameSpaces, i)); dkind = d_nameSpaceGetDurabilityKind(ns); if((dkind == D_DURABILITY_PERSISTENT) || (dkind == D_DURABILITY_ALL)){ expr = d_nameSpaceGetPartitions(ns); if(j==0){ length += strlen(expr); } else { length += strlen(expr) + 1; /*for the comma*/ } os_free(expr); j++; } } if(length > 0){ result = (c_char*)(os_malloc(length + 1)); result[0] = '\0'; j = 0; for(i=0; i<c_iterLength(nameSpaces); i++){ ns = d_nameSpace(c_iterObject(nameSpaces, i)); dkind = d_nameSpaceGetDurabilityKind(ns); if((dkind == D_DURABILITY_PERSISTENT) || (dkind == D_DURABILITY_ALL)){ expr = d_nameSpaceGetPartitions(ns); if(j != 0){ os_strcat(result, ","); } os_strcat(result, expr); os_free(expr); j++; } } } d_adminNameSpaceCollectFree(admin, nameSpaces); } if(result){ d_printTimedEvent(durability, D_LEVEL_FINE, D_THREAD_PERISTENT_DATA_LISTENER, "Persistent partition expression is: '%s'\n", result); } else { d_printTimedEvent(durability, D_LEVEL_FINE, D_THREAD_PERISTENT_DATA_LISTENER, "Persistent partition expression is empty.\n"); } return result; }
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); } }
void idl_registerType ( c_base base, const char *basename, c_iter typeNames ) { sd_serializer metaSer; sd_serializedData serData; char *metaDescription = NULL; char *typeName; c_char *fname; c_metaObject type; int i; fname = os_malloc((size_t)((int)strlen(basename)+20)); snprintf (fname, (size_t)((int)strlen(basename)+20), "%s_register.h", basename); idl_fileSetCur (idl_fileOutNew (fname, "w")); if (idl_fileCur () == NULL) { idl_reportOpenError (fname); } idl_registerHeaderFile (basename); idl_fileOutFree (idl_fileCur()); snprintf (fname, (size_t)((int)strlen(basename)+20), "%s_register.c", basename); idl_fileSetCur (idl_fileOutNew (fname, "w")); if (idl_fileCur () == NULL) { idl_reportOpenError (fname); } idl_registerBodyHeader (basename); for (i = 0; i < c_iterLength(typeNames); i++) { typeName = c_iterObject(typeNames, i); type = c_metaResolve ((c_metaObject)base, (const char *)typeName); if (type) { metaSer = sd_serializerXMLTypeinfoNew (base, TRUE); if (metaSer) { serData = sd_serializerSerialize (metaSer, c_object(type)); if (serData) { metaDescription = sd_serializerToString (metaSer, serData); if (metaDescription) { idl_registerBody (typeName, metaDescription); os_free (metaDescription); } } sd_serializerFree (metaSer); } } else { printf ("Specified type %s not found\n", typeName); } } idl_fileOutPrintf (idl_fileCur(), "\n"); idl_fileOutPrintf (idl_fileCur(), "void\n"); idl_fileOutPrintf (idl_fileCur(), "%s__register_types (c_base base)\n", basename); idl_fileOutPrintf (idl_fileCur(), "{\n"); for (i = 0; i < c_iterLength(typeNames); i++) { typeName = c_iterObject(typeNames, i); idl_fileOutPrintf (idl_fileCur(), " %s__register_type (base);\n", idl_cScopedTypeName(typeName)); } idl_fileOutPrintf (idl_fileCur(), "}\n"); idl_fileOutFree (idl_fileCur()); os_free (fname); }
/* * Check if each usage of a char array as a key has a corresponding * "#pragma cats" declaration. */ static c_bool idl_checkCatsUsage( c_base base, const char* filename) { char errorBuffer [IDL_MAX_ERRORSIZE]; idl_keyDef keyDef = idl_keyDefDefGet(); c_long keyMapIdx; idl_keyMap keyMap; c_type type; c_structure structure; c_iter keysList; os_uint32 keysListSize; os_uint32 keyIdx; c_char* keyName; os_uint32 i; c_iter keyNameList; os_uint32 keyNameListSize; c_structure tmpStructure; c_specifier sp; c_type subType; c_string typeName; c_type spType; if (keyDef != NULL) { /* check all key definition list elements */ for (keyMapIdx = 0; keyMapIdx < c_iterLength(keyDef->keyList); keyMapIdx++) { keyMap = c_iterObject(keyDef->keyList, keyMapIdx); /* if a keylist is defined for the type */ if (keyMap->keyList && strlen(keyMap->keyList) > 0) { /* find meteobject for the type */ type = c_type(c_metaResolveType(keyMap->scope, keyMap->typeName)); if (!type) { snprintf(errorBuffer, IDL_MAX_ERRORSIZE-1, errorText[idl_UndeclaredIdentifier], keyMap->typeName); idl_printError(filename, errorBuffer); return OS_FALSE; } /* type can be a typedef. Determine the actual type. */ type = c_typeActualType(type); /* type should be a structure */ if (c_baseObject(type)->kind != M_STRUCTURE) { snprintf(errorBuffer, IDL_MAX_ERRORSIZE-1, errorText[idl_IllegalKeyFields]); idl_printError(filename, errorBuffer); return OS_FALSE; } structure = c_structure(type); /* for each key in keyList, check if type is a char array */ keysList = c_splitString(keyMap->keyList, ","); keysListSize = c_iterLength(keysList); for(keyIdx = 0; keyIdx < keysListSize; keyIdx++) { keyName = c_iterTakeFirst(keysList); /* We might be dealing with a field of a field definition in * the keylist, so let's split this up */ keyNameList = c_splitString(keyName, "."); keyNameListSize = c_iterLength(keyNameList); tmpStructure = structure; for(i = 0; i < keyNameListSize; i++) { keyName = c_iterTakeFirst(keyNameList); /* Now get the actual member defined by the name */ sp = c_specifier(c_metaFindByName( c_metaObject(tmpStructure), keyName, CQ_FIXEDSCOPE | CQ_MEMBER | CQ_CASEINSENSITIVE)); if(sp) { spType = c_typeActualType(sp->type); /* If the member is a structure, we need to * recurse deeper. */ if(c_baseObject(spType)->kind == M_STRUCTURE) { tmpStructure = c_structure(spType); } /* If the member is a collection then we need to * ensure it is not a character array, but if it * is we need to ensure a corresponding CATS pragma * can be located */ else if(c_baseObject(spType)->kind == M_COLLECTION && c_collectionType(spType)->kind == C_ARRAY) { subType = c_typeActualType(c_collectionType(spType)->subType); if(c_baseObject(subType)->kind == M_PRIMITIVE && c_primitive(subType)->kind == P_CHAR) { typeName = c_metaName(c_metaObject(tmpStructure)); /* check if there is corresponding catsDef */ if (!idl_isCatsDefFor(c_metaObject(tmpStructure)->definedIn, typeName, keyName)) { snprintf( errorBuffer, IDL_MAX_ERRORSIZE-1, errorText[idl_NoCorrespondingCats], c_metaObject(structure)->name, keyName); idl_printError(filename, errorBuffer); return OS_FALSE; } c_free(typeName); } } } } } } } } return OS_TRUE; }
/* Find the stac list related to the specified typename in the specified scope */ os_boolean idl_stacListItemIsDefined ( idl_stacDef stacDef, idl_scope scope, const char *typeName, const char* itemName) { c_ulong li; c_long si; idl_stacMap stacMap; c_metaObject typeScope; os_boolean isDefined = OS_FALSE; if(stacDef) { li = 0; /* check all stac definition list elements */ while (li < c_iterLength (stacDef->stacList) && !isDefined) { stacMap = c_iterObject (stacDef->stacList, li); if (strcmp(typeName, stacMap->typeName) == 0) { /* if the typename equals, check if the scope compares */ if ((idl_scopeStackSize(scope) == 0) && (stacMap->scope->definedIn == NULL)) { /* We're in the global scope */ /* If no members were defined for this type, then we will * interprete this as a request for all bounded string * members to be converted to a char array internally. */ if(strlen(stacMap->stacList) == 0) { isDefined = OS_TRUE; } else if(idl_stacDefOnlyExclusionsDefined(stacMap->stacList)) { if(idl_stacDefIsFieldExcluded(stacMap->stacList, itemName)) { isDefined = OS_FALSE; } else { isDefined = OS_TRUE; } } else { isDefined = idl_stacListItemIsMemberLocated(stacMap->stacList, itemName); } } if(!isDefined) { si = idl_scopeStackSize (scope)-1; typeScope = stacMap->scope; while (si >= 0) { /* for each scope element */ if (idl_scopeElementType(idl_scopeIndexed (scope, si)) == idl_tModule && strcmp (typeScope->name, idl_scopeElementName(idl_scopeIndexed (scope, si))) == 0) { /* the scope is a module and the scope name compares */ si--; if (typeScope) { typeScope = typeScope->definedIn; } if (si == -1) { /* bottom of the stack is reached */ if (typeScope == NULL || typeScope->name == NULL) { /* the typeScope has reached the bottom too, * thus the scopes are equal */ /* If no members were defined for this type, then we will * interprete this as a request for all bounded string * members to be converted to a char array internally. */ if(strlen(stacMap->stacList) == 0) { isDefined = OS_TRUE; } else if(idl_stacDefOnlyExclusionsDefined(stacMap->stacList)) { if(idl_stacDefIsFieldExcluded(stacMap->stacList, itemName)) { isDefined = OS_FALSE; } else { isDefined = OS_TRUE; } } else { isDefined = idl_stacListItemIsMemberLocated(stacMap->stacList, itemName); } } } } else { si = -1; } } } } li++; } } return isDefined; }
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; }
u_result u_waitsetWaitAction2 ( const u_waitset _this, u_waitsetAction2 action, void *arg, const os_duration timeout) { u_result result = U_RESULT_OK; os_result osr; c_ulong length; struct checkArg a; a.action = action; a.arg = arg; a.count = 0; assert(_this != NULL); assert(OS_DURATION_ISPOSITIVE(timeout)); osr = os_mutexLock_s(&_this->mutex); if (osr == os_resultSuccess) { if (!_this->alive) { result = U_RESULT_ALREADY_DELETED; OS_REPORT(OS_ERROR, "u_waitsetWaitAction2", result, "Precondition not met: Waitset is already deleted"); } if (_this->waitBusy) { result = U_RESULT_PRECONDITION_NOT_MET; OS_REPORT(OS_ERROR, "u_waitsetWaitAction2", result, "Precondition not met: A Wait call is already active on this Waitset"); } if (result == U_RESULT_OK) { /* Wait for possible detach to complete. * If you don't do that, it's possible that this wait call sets * the waitBusy flag before the detach can wake up of its waitBusy * loop, meaning that the detach will block at least until the * waitset is triggered again. */ while (_this->detachCnt > 0) { os_condWait(&_this->waitCv, &_this->mutex); } length = c_iterLength(_this->entries); if (length == 1) { /* Single Domain Mode. */ u_waitsetEntry entry = c_iterObject(_this->entries,0); _this->waitBusy = TRUE; os_mutexUnlock(&_this->mutex); result = u_waitsetEntryWait2(entry, action, arg, timeout); os_mutexLock(&_this->mutex); _this->waitBusy = FALSE; if (_this->notifyDetached) { result = U_RESULT_DETACHING; _this->notifyDetached = OS_FALSE; } os_condBroadcast(&_this->waitCv); os_mutexUnlock(&_this->mutex); if ((result == U_RESULT_OK) && (_this->alive == FALSE)) { result = U_RESULT_ALREADY_DELETED; OS_REPORT(OS_ERROR, "u_waitsetWaitAction2", result, "Precondition not met: Waitset is already deleted"); } } else { /* Multi Domain Mode (or no Domain). */ a.count = 0; /* For each Domain test Conditions. */ (void)c_iterWalkUntil(_this->entries, check_entry_conditions, &a); /* Test Guard Conditions */ if ((a.count == 0) && (!action(NULL,arg))) { a.count++; } /* If No Conditions are true then wait. */ if (a.count == 0) { _this->waitBusy = TRUE; if (OS_DURATION_ISINFINITE(timeout)) { os_condWait(&_this->cv, &_this->mutex); osr = os_resultSuccess; } else { osr = os_condTimedWait(&_this->cv, &_this->mutex, timeout); } _this->waitBusy = FALSE; os_condBroadcast(&_this->waitCv); switch (osr) { case os_resultSuccess: if (_this->alive == TRUE) { if (_this->notifyDetached) { result = U_RESULT_DETACHING; _this->notifyDetached = OS_FALSE; } else { result = U_RESULT_OK; } } else { result = U_RESULT_ALREADY_DELETED; OS_REPORT(OS_ERROR, "u_waitsetWaitAction2", result, "Precondition not met: Waitset is already deleted"); } break; case os_resultTimeout: result = U_RESULT_TIMEOUT; break; default: result = U_RESULT_INTERNAL_ERROR; OS_REPORT(OS_ERROR, "u_waitsetWaitAction2", result, "os_condWait failed for waitset 0x" PA_ADDRFMT, (PA_ADDRCAST)_this); break; } } os_mutexUnlock(&_this->mutex); } } else { os_mutexUnlock(&_this->mutex); } } else { result = U_RESULT_INTERNAL_ERROR; OS_REPORT(OS_ERROR, "u_waitsetWaitAction2", result, "os_mutexLock failed for waitset 0x" PA_ADDRFMT, (PA_ADDRCAST)_this); } return result; }