Пример #1
0
static void
printWalkHistory (
    c_object o,
    c_iterActionArg arg)
{
    c_type type;
    c_char *name, *ename;

    if (o) {
        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);
            }
        } else if (c_checkType(o, "c_metaObject") == o) {
            ename = c_metaScopedName(o);
            if (ename != NULL) {
                printf(" /* %s */", ename);
                os_free(ename);
            }
        }
        printf("\n");
    } else {
        printf("<0x0>\n");
    }
}
Пример #2
0
c_structure
idl_stacDefFindMetaStructureResolved(
    c_metaObject scope,
    const char *typeName)
{
    c_baseObject object;
    c_structure structure;

    object = c_baseObject(c_metaResolve(scope, typeName));

    if(!object)
    {
        printf("FATAL ERROR | #pragma stac: Trying to locate structure '%s' in "
            "scope '%s'. But no such object exists.\n",
            typeName, c_metaScopedName(c_metaObject(scope)));
        exit(-2);
    }
    /* Resolve typedefs */
    idl_stacDefResolveTypeDef(object);
    /* The final object (after typedef resolving) should be a structure */
    if(object->kind != M_STRUCTURE)
    {
        printf("FATAL ERROR | #pragma stac: Trying to locate structure '%s' in "
            "scope '%s'. But the identified object is not a structure.\n",
            typeName, c_metaScopedName(c_metaObject(scope)));
        exit(-2);
    }
    structure = c_structure(object);

    return structure;
}
Пример #3
0
static void
toolAction (
    d_storeMMFKernel kernel,
    c_voidp addr)
{
    c_base base;
    c_type type;
    c_char *name;
    c_object o;
    c_address offset;
    c_long size;
    struct toolActionData actionData;

    actionData.fin = stdin;
    actionData.fout = stdout;
    actionData.depth = 0;
    actionData.stack = NULL;

    base = c_getBase(kernel);
    o = c_baseCheckPtr(base, addr);
    if (o) {
        type = c_getType(o);
        size = c_typeSize(type);
        if (o != addr) {
            offset = C_ADDRESS(addr) - C_ADDRESS(o);
            if (offset < (c_address)size) {
                printf("Warning: address is %lu bytes in %s "
                       "object starting at 0x"PA_ADDRFMT"\n",
                       offset, _METANAME(type), (os_address)o);
                OBJECT_PUSH(&actionData, o);
                tryPrintOffset(o,&actionData,offset);
                OBJECT_POP(&actionData);
            } else {
                printf("Warning: address is %lu bytes in "
                       "memory starting at 0x"PA_ADDRFMT"\n",
                   offset, (os_address)o);
            }
        } else {
            name = c_metaScopedName(c_metaObject(type));
            printf("Object <0x"PA_ADDRFMT"> refCount=%d size=%d type is: <0x"PA_ADDRFMT"> %s\n",
                   (os_address)o, c_refCount(o), size, (os_address)type, name);
            os_free(name);
            OBJECT_PUSH(&actionData, o);
            printType(type, &actionData);
            printf("\n");
            OBJECT_POP(&actionData);
        }
    } else {
        printf("Address <0x"PA_ADDRFMT"> is not a Database Object\n",
               (os_address)addr);
    }
}
Пример #4
0
static void
idl_checkFinalized(
    c_baseObject o,
    int* unfinalCount) {
    char* name;

    switch(o->kind) {
    case M_STRUCTURE:
    case M_UNION:
        if(!c_isFinal(c_metaObject(o))) {
            name = c_metaScopedName(c_metaObject(o));
            printf("missing implementation for struct\\union %s.\n", name);
            (*unfinalCount)++;
            free(name);
        }
        break;
    default:
        break;
    }
}
Пример #5
0
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");
}
Пример #6
0
c_char *
u_topicTypeName(
    u_topic t)
{
    v_topic kt;
    u_result r;
    c_char *name;


    r = u_entityReadClaim(u_entity(t),(v_entity*)(&kt));
    if (r == U_RESULT_OK) {
        assert(kt);
        name = (c_char *)c_metaScopedName(c_metaObject(v_topicDataType(kt)));
        u_entityRelease(u_entity(t));
    } else {
        OS_REPORT(OS_WARNING, "u_topicTypeName", 0,
                  "Could not claim topic.");
        name = NULL;
    }
    return name;
}
Пример #7
0
static void
printCollectionAction(
    c_metaObject mo,
    c_scopeWalkActionArg arg)
{
    c_type type;
    c_object o = c_metaObject (mo);
    toolActionData actionData = (toolActionData)arg;
    c_char *name;

    if (o != NULL) {
        type = c_getType(o);
        name = c_metaScopedName(c_metaObject(type));
        iprintf("Object <0x"PA_ADDRFMT"> refCount=%d type is: <0x"PA_ADDRFMT"> %s\n",
                (os_address)o, c_refCount(o), (os_address)type, name);
        os_free(name);
        OBJECT_PUSH(actionData, o);
        printType(type, actionData);
        printf("\n");
        OBJECT_POP(actionData);
    }
}
Пример #8
0
os_char *
u_topicTypeName(
    const u_topic _this)
{
    v_topic kt;
    u_result r;
    os_char *name;

    assert(_this);

    r = u_topicReadClaim(_this, &kt, C_MM_RESERVATION_ZERO);
    if (r == U_RESULT_OK) {
        assert(kt);
        name = (c_char *)c_metaScopedName(c_metaObject(v_topicDataType(kt)));
        u_topicRelease(_this, C_MM_RESERVATION_ZERO);
    } else {
        OS_REPORT(OS_WARNING, "u_topicTypeName", r,
                  "Could not claim topic.");
        name = NULL;
    }
    return name;
}
Пример #9
0
static c_bool
printCollectionAction(
    c_object o,
    c_voidp arg)
{
    c_type type;
    toolActionData actionData = (toolActionData)arg;
    c_char *name;

    if (o != NULL) {
        type = c_getType(o);
        name = c_metaScopedName(c_metaObject(type));
        iprintf("Object <0x%x> type is: <0x%x> %s\n",
                (HEXVALUE)o, (HEXVALUE)type, name);
        os_free(name);
        OBJECT_PUSH(actionData, o);
        printType(type, actionData);
        printf("\n");
        OBJECT_POP(actionData);
    }
    return TRUE;
}
Пример #10
0
d_storeResult
d_groupInfoDataInject(
    d_groupInfo _this,
    const d_store store,
    d_group group)
{
    d_storeResult result;
    struct d_instanceInjectArg inject;
    c_type mmfMessageType;
    c_char* typeName;

    if(_this && group){
        inject.vgroup = d_groupGetKernelGroup(group);

        mmfMessageType = d_topicInfoGetMessageType(_this->topic);
        typeName = c_metaScopedName(c_metaObject(mmfMessageType));

        inject.messageType = c_type(c_metaResolveType(
                c_metaObject(c_getBase(inject.vgroup)), typeName));

        if(inject.messageType){
            inject.result = D_STORE_RESULT_OK;

            c_tableWalk(_this->instances, d_instanceInject, &inject);

            c_free(inject.messageType);
            result = inject.result;
        } else {
            result = D_STORE_RESULT_PRECONDITION_NOT_MET;
        }
        c_free(inject.vgroup);
        c_free(mmfMessageType);
        os_free(typeName);
    } else {
        result = D_STORE_RESULT_ILL_PARAM;
    }
    return result;
}
Пример #11
0
void
v_serviceInit(
    v_service service,
    const c_char *name,
    const c_char *extStateName,
    v_serviceType serviceType,
    v_participantQos qos,
    c_bool enable)
{
    c_char *typeName;
    os_duration lp = 300*OS_DURATION_SECOND;
    v_kernel kernel;
    v_serviceManager manager;

    assert(service != NULL);
    assert(serviceType != V_SERVICETYPE_NONE);
    assert(C_TYPECHECK(service, v_service));
    assert(C_TYPECHECK(qos, v_participantQos));
    assert(name != NULL);

    kernel = v_objectKernel(service);
    manager = v_getServiceManager(kernel);

    /* v_participantInit writes the DCPSParticipant and CMParticipant topics, but
     * it downcasts to v_service to extract serviceType, and hence needs it available.
     */
    service->serviceType = serviceType;
    v_participantInit(v_participant(service), name, qos);
    if(enable) {
        (void)v_entityEnable(v_entity(service));
    }
    service->state = v_serviceManagerRegister(manager, service, extStateName);
    service->lease = v_leaseMonotonicNew(kernel, lp);
    service->newGroups = NULL;
    if(service->lease)
    {
        v_result result;

        result = v_leaseManagerRegister(
            kernel->livelinessLM,
            service->lease,
            V_LEASEACTION_SERVICESTATE_EXPIRED,
            v_public(service->state),
            FALSE/*do not repeat */);
        if(result != V_RESULT_OK)
        {
            c_free(service->lease);
            service->lease = NULL;
            OS_REPORT(OS_FATAL, "v_service", result,
                "A fatal error was detected when trying to register the liveliness lease "
                "to the liveliness lease manager of the kernel. The result code was %d.", result);
        }
    } else
    {
        OS_REPORT(OS_FATAL, "v_service", V_RESULT_INTERNAL_ERROR,
            "Unable to create a liveliness lease! Most likely not enough shared "
            "memory available to complete the operation.");
    }
    if(service->lease)/* aka everything is ok so far */
    {
        v_result result;
        c_iter participants;
        v_participant splicedParticipant;


        participants = v_resolveParticipants(kernel, V_SPLICED_NAME);
        assert(c_iterLength(participants) == 1 || 0 == strcmp(name, V_SPLICED_NAME));
        splicedParticipant = v_participant(c_iterTakeFirst(participants));
        if(splicedParticipant)
        {
            result = v_leaseManagerRegister(
                v_participant(service)->leaseManager,
                v_service(splicedParticipant)->lease,
                V_LEASEACTION_SERVICESTATE_EXPIRED,
                v_public(v_service(splicedParticipant)->state),
                FALSE /* only observing, do not repeat */);
            if(result != V_RESULT_OK)
            {
                c_free(service->lease);
                service->lease = NULL;
                OS_REPORT(OS_FATAL, "v_service", result,
                    "A fatal error was detected when trying to register the spliced's liveliness lease "
                    "to the lease manager of participant %p (%s). The result code was %d.", (void*)service, name, result);
            }
            c_free(splicedParticipant);
        }
        c_iterFree(participants);
    }

    if (service->state != NULL) {
      /* check if state has correct type */
        typeName = c_metaScopedName(c_metaObject(c_getType(c_object(service->state))));
        if (extStateName == NULL) {
            extStateName = VSERVICESTATE_NAME;
        }
        if (strcmp(typeName, extStateName) == 0) {
            /* Splicedaemon may not observer itself! */
            if (strcmp(name, V_SPLICED_NAME) != 0) {
                v_serviceState splicedState;
                splicedState = v_serviceManagerGetServiceState(manager, V_SPLICED_NAME);
                (void)OSPL_ADD_OBSERVER(splicedState, service, V_EVENT_SERVICESTATE_CHANGED, NULL);
            }
        } else {
            OS_REPORT(OS_ERROR, "v_service",
                V_RESULT_ILL_PARAM, "Requested state type (%s) differs with existing state type (%s)",
                extStateName, typeName);
            c_free(service->state);
            service->state = NULL;
        }
        os_free(typeName);
    }
}
Пример #12
0
d_topicInfo
d_topicInfoNew(
    d_storeMMFKernel kernel,
    const v_topic vtopic)
{
    d_topicInfo topic;
    c_base base, ddsBase;
    c_type type, srcDataType;
    c_string name;

    if(kernel && vtopic){
        base = c_getBase(kernel);
        ddsBase = c_getBase(vtopic);
        type = c_resolve(base,"durabilityModule2::d_topicInfo");

        if(type){
            topic = c_new(type);
            c_free(type);

            if(topic){
                topic->name = c_stringNew(base, v_entity(vtopic)->name);

                srcDataType = v_topicDataType(vtopic);

                name = c_metaScopedName(c_metaObject(srcDataType));
                topic->typeName = c_stringNew(base, name);
                assert(topic->typeName);
                os_free(name);

                topic->dataType = cloneType(ddsBase, base, srcDataType);
                assert(topic->dataType);

                topic->keyExpr = c_stringNew(base, vtopic->keyExpr);
                assert(topic->keyExpr);

                topic->messageType = messageTypeNew(base, topic->typeName);
                assert(topic->messageType);

                topic->keyType = createTopicKeyType(topic->messageType,
                        topic->keyExpr);
                assert(topic->keyType);

                topic->instanceKeyExpr = createInstanceKeyExpr(base, vtopic);

                topic->sampleType = createSampleType(
                        topic->messageType, topic->name);
                assert(topic->sampleType);

                topic->instanceType = createInstanceType(
                        topic->messageType, topic);
                assert(topic->instanceType);

                topic->qos = cloneObject(ddsBase, base, vtopic->qos);
                assert(topic->qos);
            }
        } else {
            OS_REPORT(OS_ERROR,
                    "d_topicInfoNew",0,
                    "Failed to allocate d_topicInfo.");
            topic = NULL;
        }
    } else {
        OS_REPORT(OS_ERROR,
                "d_topicInfoNew",0,
                "Illegal constructor parameter.");
        topic = NULL;
    }
    return topic;
}
Пример #13
0
c_type
idl_stacDefConvertStacApprovedMember(
    c_structure structure,
    c_type orgMemberType)
{
    c_type dereffedOrgType;
    c_metaObject o = NULL;
    c_type newType;
    os_char buffer[1024];
    c_metaObject found;

    memset(buffer, 0, 1024);
    dereffedOrgType = c_typeActualType(c_type(idl_stacDefResolveTypeDef(c_baseObject(orgMemberType))));
    if(c_baseObject(dereffedOrgType)->kind == M_COLLECTION)
    {
        o = c_metaObject(c_metaDefine(c_metaObject(structure), M_COLLECTION));
        /* Can be a string or an array or a sequence */
        if(c_collectionType(dereffedOrgType)->kind == OSPL_C_STRING)
        {
            if((c_collectionType(dereffedOrgType)->maxSize != 0))
            {
                c_collectionType(o)->kind = OSPL_C_ARRAY;
                c_collectionType(o)->subType = c_type(c_metaResolve(c_metaObject(structure), "c_char"));
                /* increase maxSize with 1 to accomodate the '\0' char found in strings */
                c_collectionType(o)->maxSize = c_collectionType(dereffedOrgType)->maxSize + 1;
                os_sprintf(
                    buffer,
                    "C_ARRAY<%s,%d>",
                    c_metaObject(c_collectionType(o)->subType)->name,
                    c_collectionType(o)->maxSize/*use maxSize of new c_type, must be the same*/);
            }
            else
            {
                printf("FATAL ERROR | #pragma stac: Trying to apply stac algorithm to listed members of struct %s, but "
                       "encountered an internal error. The conversion algorithm (idl_stacDefConvertStacApprovedMember) "
                       "has become out of synch with the verification algorithm (idl_stacDefCanStacBeAppliedToMember).\n",
                       c_metaScopedName(c_metaObject(structure)));
                assert(0);
                exit(-2);
            }
        }
        else if(c_collectionType(dereffedOrgType)->kind == OSPL_C_ARRAY)
        {
            c_collectionType(o)->kind = OSPL_C_ARRAY;
            /* increase maxSize with 1 to accomodate the '\0' char found in strings */
            c_collectionType(o)->maxSize = c_collectionType(dereffedOrgType)->maxSize;
            c_collectionType(o)->subType = idl_stacDefConvertStacApprovedMember(structure, c_collectionType(dereffedOrgType)->subType);
            os_sprintf(
                buffer,
                "C_ARRAY<%s,%d>",
                c_metaObject(c_collectionType(o)->subType)->name,
                c_collectionType(o)->maxSize/*use maxSize of new c_type, must be the same*/);
        }
        else if(c_collectionType(dereffedOrgType)->kind == OSPL_C_SEQUENCE)
        {
            c_collectionType(o)->kind = OSPL_C_SEQUENCE;
            /* increase maxSize with 1 to accomodate the '\0' char found in strings */
            c_collectionType(o)->maxSize = c_collectionType(dereffedOrgType)->maxSize;
            c_collectionType(o)->subType = idl_stacDefConvertStacApprovedMember(structure, c_collectionType(dereffedOrgType)->subType);
            os_sprintf(
                buffer,
                "C_SEQUENCE<%s,%d>",
                c_metaObject(c_collectionType(o)->subType)->name,
                c_collectionType(o)->maxSize/*use maxSize of new c_type, must be the same*/);
        }
        else
        {
            printf("FATAL ERROR | #pragma stac: Trying to apply stac algorithm to listed members of struct %s, but "
                   "encountered an internal error. The conversion algorithm (idl_stacDefConvertStacApprovedMember) "
                   "has become out of synch with the verification algorithm (idl_stacDefCanStacBeAppliedToMember).\n",
                   c_metaScopedName(c_metaObject(structure)));
            assert(0);
            exit(-2);
        }
    }
    else
    {
        printf("FATAL ERROR | #pragma stac: Trying to apply stac algorithm to listed members of struct %s, but "
               "encountered an internal error. The conversion algorithm (idl_stacDefConvertStacApprovedMember) "
               "has become out of synch with the verification algorithm (idl_stacDefCanStacBeAppliedToMember).\n",
               c_metaScopedName(c_metaObject(structure)));
        assert(0);
        exit(-2);
    }
    if(o)
    {
        c_metaObject(o)->definedIn = c_metaObject(structure);
        c_metaFinalize(o);
        found = c_metaBind(c_metaObject(structure), &buffer[0], o);
        c_free(o);
        newType = c_type(found);
    }
    else
    {
        printf("FATAL ERROR | #pragma stac: Trying to apply stac algorithm to listed members of struct %s, but "
               "encountered an internal error. The conversion algorithm (idl_stacDefConvertStacApprovedMember) "
               "has become out of synch with the verification algorithm (idl_stacDefCanStacBeAppliedToMember).\n",
               c_metaScopedName(c_metaObject(structure)));
        assert(0);
        exit(-2);
    }
    return newType;
}
Пример #14
0
/* 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;
}
Пример #15
0
void
v_serviceInit(
    v_service service,
    v_serviceManager manager,
    const c_char *name,
    const c_char *extStateName,
    v_participantQos qos,
    v_statistics stats)
{
    c_char *typeName;
    v_duration lp = {300, 0};
    v_kernel kernel;

    assert(service != NULL);
    assert(C_TYPECHECK(service, v_service));
    assert(C_TYPECHECK(qos, v_participantQos));
    assert(name != NULL);

    kernel = v_objectKernel(service);
    v_participantInit(v_participant(service), name, qos, stats, TRUE);
    service->state = v_serviceManagerRegister(manager, service, extStateName);
    service->lease = v_leaseNew(kernel, lp);
    if(service->lease)
    {
        v_result result;

        result = v_leaseManagerRegister(
            kernel->livelinessLM,
            service->lease,
            V_LEASEACTION_SERVICESTATE_EXPIRED,
            v_public(service->state),
            FALSE/*do not repeat */);
        if(result != V_RESULT_OK)
        {
            c_free(service->lease);
            service->lease = NULL;
            OS_REPORT_1(OS_ERROR, "v_service", 0,
                "A fatal error was detected when trying to register the liveliness lease "
                "to the liveliness lease manager of the kernel. The result code was %d.", result);
        }
    } else
    {
        OS_REPORT(OS_ERROR, "v_service", 0,
            "Unable to create a liveliness lease! Most likely not enough shared "
            "memory available to complete the operation.");
    }
    if(service->lease)/* aka everything is ok so far */
    {
        v_result result;
        c_iter participants;
        v_participant splicedParticipant;


        participants = v_resolveParticipants(kernel, V_SPLICED_NAME);
        assert(c_iterLength(participants) == 1 || 0 == strcmp(name, V_SPLICED_NAME));
        splicedParticipant = v_participant(c_iterTakeFirst(participants));
        if(splicedParticipant)
        {
            result = v_leaseManagerRegister(
                v_participant(service)->leaseManager,
                v_service(splicedParticipant)->lease,
                V_LEASEACTION_SERVICESTATE_EXPIRED,
                v_public(v_service(splicedParticipant)->state),
                FALSE /* only observing, do not repeat */);
            if(result != V_RESULT_OK)
            {
                c_free(service->lease);
                service->lease = NULL;
                OS_REPORT_3(OS_ERROR, "v_service", 0,
                    "A fatal error was detected when trying to register the spliced's liveliness lease "
                    "to the lease manager of participant %p (%s). The result code was %d.", service, name, result);
            }
        }
        c_iterFree(participants);
    }

    if (service->state != NULL) {
      /* check if state has correct type */
        typeName = c_metaScopedName(c_metaObject(c_getType(c_object(service->state))));
        if (extStateName == NULL) {
            extStateName = VSERVICESTATE_NAME;
        }
        if (strcmp(typeName, extStateName) == 0) {
            if (strcmp(name, V_SPLICED_NAME) != 0) {
                /* Splicedaemon may not observer itself! */
                v_serviceWatchSplicedaemon(service);
            }
        } else {
            OS_REPORT_2(OS_ERROR, "v_service",
                0, "Requested state type (%s) differs with existing state type (%s)",
                extStateName, typeName);
            c_free(service->state);
            service->state = NULL;
        }
        os_free(typeName);
    }
}