Esempio n. 1
0
c_char*
cmx_participantNew(
    const c_char* uri,
    const c_char* domainId,
    c_long timeout,
    const c_char* name,
    const c_char* qos)
{
    u_participant p;
    u_result ur;
    u_domainId_t did;
    int pos;
    c_char* result;
    const c_char* context;

    if (*domainId == '\0') {
        did = U_DOMAIN_ID_ANY;
    } else if (sscanf (domainId,"%d%n", &did, &pos) != 1 || domainId[pos] != '\0') {
        OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0,
                   "cmx_participantNew failed (reason: illegal argument: domainId \"%s\").",
                   domainId);
        return NULL;
    }

    p = u_participantNew(uri, did, timeout > 0 ? (unsigned)timeout : 0, name, NULL, TRUE);
    if(p == NULL){
        /* Error reported by u_participantNew() */
        goto err_u_participantNew;
    }

    if(qos && *qos){
        if((ur = u_entitySetXMLQos(u_entity(p), qos)) != U_RESULT_OK) {
            context = "u_entitySetXMLQos";
            goto err_entity;
        }
    }

    if((ur = u_entityEnable(u_entity(p))) != U_RESULT_OK) {
        context = "u_entityEnable";
        goto err_entity;
    }


    if((ur = cmx_entityRegister(u_object(p), NULL, &result)) != U_RESULT_OK) {
        context = "cmx_entityRegister";
        goto err_entity;
    }
    return result;

/* Error handling */
err_entity:
    OS_REPORT(OS_ERROR, CM_XML_CONTEXT, 0,
            "cmx_participantNew failed (reason: %s returned %u).",
            context, ur);
    u_objectFree(u_object(p));
err_u_participantNew:
    return NULL;
}
Esempio n. 2
0
u_result
u_dispatcherInsertListener(
    u_dispatcher _this,
    u_dispatcherListener listener,
    c_voidp userData)
{
    u_listener ul;
    os_threadAttr attr;
    v_observer ke;
    u_result result = U_RESULT_OK;
    c_char *name;

    if ((_this != NULL) && (listener != NULL)) {
        os_mutexLock(&_this->mutex);
        ul = u_listenerNew(listener,userData);
        _this->listeners = c_iterInsert(_this->listeners,ul);

        if (os_threadIdToInteger(_this->threadId) == 0U) {
            result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ke));
            if(result == U_RESULT_OK) {
                assert(ke);
                name = v_entityName(ke);
                if (name == NULL) {
                    name = "NoName";
                }
                os_threadAttrInit(&attr);
                os_threadCreate(&_this->threadId,
                                name,
                                &attr,dispatch,
                                (void *)_this);
                result = u_entityRelease(u_entity(_this));
                if (result != U_RESULT_OK) {
                    OS_REPORT(OS_ERROR, "u_dispatcherInsertListener", 0,
                              "Release observer failed.");
                }
            } else {
                OS_REPORT(OS_WARNING, "u_dispatcherInsertListener", 0,
                          "Failed to claim Dispatcher.");
            }
        }
        u_entityEnable(u_entity(_this));
        os_mutexUnlock(&_this->mutex);
    } else {
        OS_REPORT(OS_ERROR,"u_dispatcherInsertListener",0,
                  "Illegal parameter.");
        result = U_RESULT_ILL_PARAM;
    }

    return result;
}