示例#1
0
u_result
u_dispatcherGetEventMask(
    u_dispatcher _this,
    c_ulong *eventMask)
{
    v_observer ko;
    u_result result = U_RESULT_OK;

    if ((_this != NULL) && (eventMask != NULL)) {
        result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko));
        if (result == U_RESULT_OK) {
            assert(ko);
            *eventMask = v_observerGetEventMask(ko);
            result = u_entityRelease(u_entity(_this));
            if (result != U_RESULT_OK) {
                OS_REPORT(OS_ERROR, "u_dispatcherGetEventMask", 0,
                          "Release observer failed.");
            }
        } else {
            OS_REPORT(OS_WARNING, "u_dispatcherGetEventMask", 0,
                      "Failed to claim Dispatcher.");
        }
    } else {
        OS_REPORT(OS_ERROR,"u_dispatcherGetEventMask",0,
                  "Illegal parameter.");
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
示例#2
0
u_result
u_serviceRenewLease(
    u_service _this,
    v_duration leasePeriod)
{
    u_result r;
    v_service kernelService;

    if (_this == NULL) {
        r = U_RESULT_ILL_PARAM;
    } else {
        r = u_entityReadClaim(u_entity(_this), (v_entity*)(&kernelService));
        if(r == U_RESULT_OK)
        {
            assert(kernelService);
            v_serviceRenewLease(kernelService, leasePeriod);
            r = u_entityRelease(u_entity(_this));
        } else {
            OS_REPORT(OS_WARNING,
                      "u_serviceRenewLease", 0,
                      "Failed to claim service.");
        }
    }
    return r;
}
示例#3
0
c_bool
u_topicContentFilterValidate (
    u_topic _this,
    q_expr expr,
    c_value params[])
{
    v_topic topic;
    c_type type;
    c_bool result;
    q_expr subexpr, term;
    int i;
    v_filter filter;
    u_result uResult;

    result = FALSE;
    filter = NULL;
    uResult = u_entityReadClaim(u_entity(_this), (v_entity*)(&topic));
    if (uResult == U_RESULT_OK) {
        assert(topic);
        type = v_topicMessageType(topic);
        i = 0;
        subexpr = q_getPar(expr, i); /* get rid of Q_EXPR_PROGRAM */
        while ((term = q_getPar(subexpr, i++)) != NULL) {
            if (q_getTag(term) == Q_EXPR_WHERE) {
                filter = v_filterNew(topic, term, params);
            }
        }
        u_entityRelease(u_entity(_this));
    }
    if (filter != NULL) {
        result = TRUE;
        c_free(filter);
    }
    return result;
}
示例#4
0
u_result
u_dispatcherNotify(
    u_dispatcher _this)
{
    v_observer ko;
    u_result result = U_RESULT_OK;

    if (_this != NULL) {
         result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko));
        if (result == U_RESULT_OK) {
            assert(ko);
            /* Wakeup the dispatch thread */
            v_observerLock(ko);
            v_observerNotify(ko, NULL, NULL);
            v_observerUnlock(ko);
            result = u_entityRelease(u_entity(_this));
            if (result != U_RESULT_OK) {
                OS_REPORT(OS_ERROR, "u_dispatcherNotify", 0,
                          "Release observer failed.");
            }
        } else {
            OS_REPORT(OS_WARNING, "u_dispatcherNotify", 0,
                      "Failed to claim Dispatcher.");
        }
    } else {
        OS_REPORT(OS_ERROR,"u_dispatcherNotify",0,
                  "Illegal parameter.");
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
示例#5
0
u_result
u_readerGetDeadlineMissedStatus(
    u_reader _this,
    c_bool reset,
    v_statusAction action,
    c_voidp arg)
{
    v_reader reader;
    u_result result;

    result = U_RESULT_PRECONDITION_NOT_MET;
    if (_this != NULL) {
        result = u_entityReadClaim(u_entity(_this), (v_entity*)(&reader));
        if (result == U_RESULT_OK){
            result = u_resultFromKernel(
                         v_readerGetDeadlineMissedStatus(reader,
                                                         reset,
                                                         (v_statusAction)action,
                                                         arg));
            u_entityRelease(u_entity(_this));
        }  else {
            OS_REPORT(OS_ERROR, "u_readerDeadlineMissedStatus", 0,
                      "Illegal handle detected");
        }
    }
    return result;
}
示例#6
0
u_subscriber
u_subscriberNew(
    u_participant p,
    const c_char *name,
    v_subscriberQos qos,
    c_bool enable)
{
    u_subscriber _this = NULL;
    v_subscriber ks;
    v_participant kp = NULL;
    u_result result;

    if (name == NULL) {
        name = "No name specified";
    }
    if (p != NULL) {
        result = u_entityWriteClaim(u_entity(p),(v_entity*)(&kp));
        if (result == U_RESULT_OK) {
            assert(kp);
            ks = v_subscriberNew(kp,name,qos,enable);
            if (ks != NULL) {
                _this = u_entityAlloc(p,u_subscriber,ks,TRUE);
                if (_this != NULL) {
                    result = u_subscriberInit(_this,p);
                    if (result != U_RESULT_OK) {
                        OS_REPORT_1(OS_ERROR, "u_subscriberNew", 0,
                                    "Initialisation failed. "
                                    "For DataReader: <%s>.", name);
                        (void)u_subscriberFree(_this);
                        _this = NULL;
                    }
                } else {
                    OS_REPORT_1(OS_ERROR, "u_subscriberNew", 0,
                                "Create user proxy failed. "
                                "For Subscriber: <%s>.", name);
                }
                c_free(ks);
            } else {
                OS_REPORT_1(OS_ERROR, "u_subscriberNew", 0,
                            "Create kernel entity failed. "
                            "For Subscriber: <%s>.", name);
            }
            result = u_entityRelease(u_entity(p));
            if (result != U_RESULT_OK) {
                OS_REPORT_1(OS_WARNING, "u_subscriberNew", 0,
                            "Could not release participant."
                            "However subscriber <%s> is created.", name);
            }
        } else {
            OS_REPORT_1(OS_WARNING, "u_subscriberNew", 0,
                        "Claim Participant failed. "
                        "For Subscriber: <%s>.", name);
        }
    } else {
        OS_REPORT_1(OS_ERROR,"u_subscriberNew",0,
                    "No Participant specified. "
                    "For Subscriber: <%s>", name);
    }
    return _this;
}
示例#7
0
u_result
u_readerGetMatchedPublications (
    u_reader _this,
    v_statusAction action,
    c_voidp arg)
{
    v_dataReader reader;
    v_spliced spliced;
    v_kernel kernel;
    u_result result;
    c_iter participants;
    v_participant participant;

    result = U_RESULT_PRECONDITION_NOT_MET;
    if (_this != NULL) {
        result = u_entityReadClaim(u_entity(_this), (v_entity*)(&reader));

        if ((result == U_RESULT_OK) && (reader != NULL)) {
            kernel = v_objectKernel(reader);

            participants = v_resolveParticipants(kernel, V_SPLICED_NAME);
            assert(c_iterLength(participants) == 1);
            participant = v_participant(c_iterTakeFirst(participants));
            spliced = v_spliced(participant);
            c_free(participant);
            c_iterFree(participants);

            result = u_resultFromKernel(
                         v_splicedGetMatchedPublications(spliced, v_dataReader(reader), action, arg));
            u_entityRelease(u_entity(_this));
        }
    }
    return result;
}
示例#8
0
u_groupQueue
u_groupQueueNew(
    u_subscriber s,
    const c_char *name,
    c_ulong queueSize,
    v_readerQos qos)
{
    u_participant p;
    u_groupQueue _this = NULL;
    v_subscriber ks = NULL;
    v_groupQueue kn;
    u_result result;

    if (name != NULL) {
        if (s != NULL) {
            result = u_entityWriteClaim(u_entity(s),(v_entity*)(&ks));
            if (result == U_RESULT_OK) {
                assert(ks);
                kn = v_groupQueueNew(ks,name,queueSize,qos);
                if (kn != NULL) {
                    p = u_entityParticipant(u_entity(s));
                    _this = u_entityAlloc(p,u_groupQueue,kn,TRUE);
                    if (_this != NULL) {
                        result = u_groupQueueInit(_this,s);
                        if (result != U_RESULT_OK) {
                            OS_REPORT_1(OS_ERROR, "u_groupQueueNew", 0,
                                        "Initialisation failed. "
                                        "For groupQueue: <%s>.", name);
                            u_groupQueueFree(_this);
                        }
                    } else {
                        OS_REPORT_1(OS_ERROR, "u_groupQueueNew", 0,
                                    "Create proxy failed. "
                                    "For groupQueue: <%s>.", name);
                    }
                    c_free(kn);
                } else {
                    OS_REPORT_1(OS_ERROR, "u_groupQueueNew", 0,
                                "Create kernel entity failed. "
                                "For groupQueue: <%s>.", name);
                }
                result = u_entityRelease(u_entity(s));
            } else {
                OS_REPORT_2(OS_WARNING, "u_groupQueueNew", 0,
                            "Claim Subscriber (0x%x) failed. "
                            "For groupQueue: <%s>.", s, name);
            }
        } else {
            OS_REPORT_1(OS_ERROR,"u_groupQueueNew",0,
                        "No Subscriber specified. "
                        "For groupQueue: <%s>", name);
        }
    } else {
        OS_REPORT(OS_ERROR,"u_groupQueueNew",0,
                  "No name specified.");
    }
    return _this;
}
示例#9
0
static void *
dispatch(
    void *o)
{
    u_dispatcher _this;
    v_observer claim;
    struct listenerExecArg arg;
    u_result result;

    _this = u_dispatcher(o);
    if (_this != NULL) {
        if (_this->startAction) {
            _this->startAction(_this, _this->actionData);
        }
        os_mutexLock(&_this->mutex);
        result = u_entityReadClaim(u_entity(_this), (v_entity*)(&claim));
        if(result == U_RESULT_OK) {
            assert(claim);
            while ((!(_this->event & V_EVENT_OBJECT_DESTROYED)) &&
                   (_this->listeners != NULL) &&
                   (c_iterLength(_this->listeners) > 0)) {

                os_mutexUnlock(&_this->mutex);
                _this->event = v_observerWait(claim);
                os_mutexLock(&_this->mutex);
                if (!(_this->event & V_EVENT_OBJECT_DESTROYED)) {
                    /* do not call listeners when  object is destroyed! */
                    arg.mask = 0;
                    arg.o = _this;
                    c_iterWalk(_this->listeners,
                               (c_iterWalkAction)listenerExecute,
                               &arg);
                }
            }
            _this->threadId = OS_THREAD_ID_NONE;
            result = u_entityRelease(u_entity(_this));
            if (result != U_RESULT_OK) {
                OS_REPORT(OS_ERROR, "u_dispatcher::dispatch", 0,
                          "Release observer failed.");
            }
        } else {
            OS_REPORT(OS_WARNING, "u_dispatcher::dispatch", 0,
                      "Failed to claim Dispatcher.");
        }
        os_mutexUnlock(&_this->mutex);
        if (_this->stopAction) {
            _this->stopAction(_this, _this->actionData);
        }
    } else {
        OS_REPORT(OS_ERROR, "u_dispatcher::dispatch", 0,
                  "No dispatcher specified.");
    }
    return NULL;
}
示例#10
0
u_partition
u_partitionNew(
    u_participant p,
    const c_char *name,
    v_partitionQos qos)
{
    u_partition _this = NULL;
    v_kernel ke = NULL;
    v_partition kd;
    u_result result;

    if (name == NULL) {
        name = "No partition specified";
    }
    if (p != NULL) {
        result = u_entityWriteClaim(u_entity(u_participantDomain(p)),(v_entity*)(&ke));
        if ((result == U_RESULT_OK) && (ke != NULL)) {
            kd = v_partitionNew(ke,name,qos);
            if (kd != NULL) {
                _this = u_entityAlloc(p,u_partition,kd,FALSE);
                if (_this != NULL) {
                    result = u_partitionInit(_this);
                    if (result != U_RESULT_OK) {
                        OS_REPORT_1(OS_ERROR, "u_partitionNew", 0,
                                    "Initialisation failed. "
                                    "For Partition: <%s>.", name);
                        u_partitionFree(_this);
                    }
                } else {
                    OS_REPORT_1(OS_ERROR, "u_partitionNew", 0,
                                "Create proxy failed. "
                                "For Partition: <%s>.", name);
                }
                c_free(kd);
            } else {
                OS_REPORT_1(OS_ERROR, "u_partitionNew", 0,
                            "Create kernel entity failed. "
                            "For Partition: <%s>", name);
            }
            result = u_entityRelease(u_entity(u_participantDomain(p)));
        } else {
            OS_REPORT_1(OS_WARNING, "u_partitionNew", 0,
                        "Claim Participant failed. "
                        "For Partition: <%s>", name);
        }
    } else {
        OS_REPORT_1(OS_ERROR,"u_partitionNew",0,
                    "No Participant specified. "
                    "For Partition: <%s>", name);
    }
    return _this;
}
示例#11
0
u_result
u_dispatcherDeinit(
    u_dispatcher _this)
{
    v_observer ko;
    u_listener listener;
    os_threadId tid;
    u_result result = U_RESULT_OK;

    if (_this != NULL) {
        os_mutexLock(&_this->mutex);
        listener = u_listener(c_iterTakeFirst(_this->listeners));
        while (listener != NULL) {
            u_listenerFree(listener);
            listener = u_listener(c_iterTakeFirst(_this->listeners));
        }
        c_iterFree(_this->listeners);
        _this->listeners = NULL; /* Flags the dispatch thread to stop */
        if (os_threadIdToInteger(_this->threadId) != 0U) {
            tid = _this->threadId;
            result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko));
            if(result != U_RESULT_OK) {
                /* This is a valid situation when a participant has been
                 * freed prior to the freeing of a dispatcher within the
                 * participant.
                 */
                os_mutexUnlock(&_this->mutex);
                os_threadWaitExit(tid, NULL);
                os_mutexDestroy(&_this->mutex);
                /*return U_RESULT_INTERNAL_ERROR;*/
            } else {
                /* Wakeup the dispatch thread */
                v_observerLock(ko);
                v_observerNotify(ko, NULL, NULL);
                v_observerUnlock(ko);
                u_entityRelease(u_entity(_this));
                os_mutexUnlock(&_this->mutex);
                os_threadWaitExit(tid, NULL);
                os_mutexDestroy(&_this->mutex);
            }
        } else {
            os_mutexUnlock(&_this->mutex);
            os_mutexDestroy(&_this->mutex);
        }
        result = u_entityDeinit(u_entity(_this));
    } else {
        OS_REPORT(OS_ERROR,"u_dispatcherDeinit",0,
                  "Illegal parameter.");
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
示例#12
0
u_result
u_dispatcherRemoveListener(
    u_dispatcher _this,
    u_dispatcherListener listener)
{
    u_listener ul;
    v_observer ko;
    os_threadId tid;
    u_result result = U_RESULT_OK;
    struct compareArg arg;

    if ((_this != NULL) && (listener != NULL)) {
        os_mutexLock(&_this->mutex);
        arg.listener = listener;
        ul = (u_listener) c_iterResolve(_this->listeners, compare, &arg);
        tid = _this->threadId;
        if (ul != NULL) {
            c_iterTake(_this->listeners, ul);
            if (c_iterLength(_this->listeners) == 0) {
                result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko));
                if(result == U_RESULT_OK) {
                    assert(ko);
                    /* Wakeup the dispatch thread */
                    v_observerLock(ko);
                    v_observerNotify(ko, NULL, NULL);
                    v_observerUnlock(ko);
                    result = u_entityRelease(u_entity(_this));
                    if (result != U_RESULT_OK) {
                        OS_REPORT(OS_ERROR, "u_dispatcherRemoveListener", 0,
                                  "Release observer failed.");
                    }
                } else {
                    OS_REPORT(OS_WARNING, "u_dispatcherRemoveListener", 0,
                              "Failed to claim Dispatcher.");
                }
            }
            u_listenerFree(ul);
        }
        os_mutexUnlock(&_this->mutex);
        if ((c_iterLength(_this->listeners) == 0)
            && (os_threadIdToInteger(tid) != 0U)) {
            os_threadWaitExit(tid, NULL);
        }
    } else {
        OS_REPORT(OS_ERROR,"u_dispatcherInsertListener",0,
                  "Illegal parameter.");
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
示例#13
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;
}
示例#14
0
c_string
u_topicGetTopicKeys (
    u_topic _this)
{
    v_topic topic;
    c_string keys = NULL;
    u_result uResult = u_entityReadClaim(u_entity(_this), (v_entity*)(&topic));
    if (uResult == U_RESULT_OK) {
        assert(topic);
        keys = v_topicKeyExpr(topic);
        c_keep(keys);
        u_entityRelease(u_entity(_this));
    }
    return keys;
}
示例#15
0
c_type
u_topicGetUserType (
    u_topic _this)
{
    v_topic topic;
    c_type type = NULL;
    u_result uResult = u_entityReadClaim(u_entity(_this), (v_entity*)(&topic));
    if (uResult == U_RESULT_OK) {
        assert(topic);
        type = v_topicGetUserType(topic);
        c_keep(type);
        u_entityRelease(u_entity(_this));
    }
    return type;
}
示例#16
0
u_result
u_topicDisposeAllData (u_topic _this)
{
    v_topic topic;
    u_result result;
    v_result r;

    result = u_entityWriteClaim(u_entity(_this), (v_entity*)(&topic));
    if (result == U_RESULT_OK) {
        assert(topic);
        r = v_topicDisposeAllData(topic);
        u_entityRelease(u_entity(_this));
        result = u_resultFromKernel(r);
    }
    return result;
}
示例#17
0
u_result
u_groupFlush(
    u_group group)
{
    v_group kgroup;
    u_result result;

    result = u_entityReadClaim(u_entity(group), (v_entity*)(&kgroup));
    if (result == U_RESULT_OK) {
        v_groupFlush(kgroup);
        u_entityRelease(u_entity(group));
    } else {
        OS_REPORT(OS_ERROR, "u_groupFlush", 0, "Could not claim group.");
    }
    return result;
}
示例#18
0
u_result
u_subscriberUnSubscribe(
    u_subscriber _this,
    const c_char *partitionExpr)
{
    v_subscriber ks = NULL;
    u_result result;

    result= u_entityReadClaim(u_entity(_this),(v_entity*)(&ks));
    if (result == U_RESULT_OK) {
        assert(ks);
        v_subscriberUnSubscribe(ks,partitionExpr);
        result = u_entityRelease(u_entity(_this));
    } else {
        OS_REPORT(OS_WARNING, "u_subscriberUnSubscribe", 0,
                  "Could not claim subscriber.");
    }
    return result;
}
示例#19
0
u_result
u_topicGetAllDataDisposedStatus (
    u_topic _this,
    c_bool reset,
    v_statusAction action,
    c_voidp arg)
{
    v_topic topic;
    u_result result;
    v_result r;

    result = u_entityReadClaim(u_entity(_this), (v_entity*)(&topic));
    if (result == U_RESULT_OK) {
        assert(topic);
        r = v_topicGetAllDataDisposedStatus(topic,reset,action,arg);
        u_entityRelease(u_entity(_this));
        result = u_resultFromKernel(r);
    }
    return result;
}
示例#20
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;
}
示例#21
0
u_result
u_serviceEnableStatistics(
    u_service service,
    const char *categoryName)
{
    v_service s;
    u_result result = U_RESULT_UNDEFINED;

    if (service != NULL) {
        result = u_entityReadClaim(u_entity(service), (v_entity*)(&s));
        if (result == U_RESULT_OK) {
            assert(s);
            v_enableStatistics(v_objectKernel(s), categoryName);
            result = u_entityRelease(u_entity(service));
        } else {
            OS_REPORT(OS_WARNING, "u_serviceEnableStatistics", 0,
                      "Could not claim service.");
        }
    }
    return result;
}
示例#22
0
/**************************************************************
 * Public functions
 **************************************************************/
c_bool
u_serviceChangeState(
    u_service service,
    v_serviceStateKind newState)
{
    u_result r;
    v_service s;
    c_bool result = FALSE;

    if (service != NULL) {
        result = u_entityReadClaim(u_entity(service), (v_entity*)(&s));
        if (result == U_RESULT_OK) {
            assert(s);

            /* start or stop the Termination Monitor Thread */
            if (newState == STATE_TERMINATING) {
                if (service->stt == NULL) {
                    service->stt = u_serviceTerminationThreadNew();
                }
            }
            if (newState == STATE_TERMINATED) {
                if (service->stt != NULL) {
                    r = u_serviceTerminationThreadFree(service->stt);
                    if (r != U_RESULT_OK) {
                        OS_REPORT_1(OS_ERROR, "u_serviceChangeState", 0,
                                   "Failed to clean up the Service Termination Thread for process %d",os_procIdSelf());
                    }
                    service->stt = NULL;
                }
            }
            result = v_serviceChangeState(s, newState);
            r = u_entityRelease(u_entity(service));
        } else {
            OS_REPORT(OS_WARNING, "u_serviceChangeState", 0,
                      "Could not claim service.");
        }
    }

    return result;
}
示例#23
0
c_char *
u_serviceGetName(
    u_service service)
{
    c_char *name;
    u_result result;
    v_service s;

    name = NULL;
    if (service != NULL) {
        result = u_entityReadClaim(u_entity(service), (v_entity*)(&s));
        if (result == U_RESULT_OK) {
            assert(s);
            name = os_strdup(v_serviceGetName(s));
            u_entityRelease(u_entity(service));
        } else {
            OS_REPORT(OS_WARNING, "u_serviceGetName", 0,
                      "Could not claim service.");
        }
    }
    return name;
}
示例#24
0
u_result
u_dispatcherInit(
    u_dispatcher _this)
{
    v_observer ko;
    os_mutexAttr mutexAttr;
    u_result result = U_RESULT_OK;

    if (_this != NULL) {
        result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko));
        if(result == U_RESULT_OK) {
            assert(ko);
            os_mutexAttrInit(&mutexAttr);
            mutexAttr.scopeAttr = OS_SCOPE_PRIVATE;
            os_mutexInit(&_this->mutex,&mutexAttr);
            _this->listeners = NULL;
            _this->threadId = OS_THREAD_ID_NONE;
            _this->startAction = NULL;
            _this->stopAction = NULL;
            _this->actionData = NULL;
            _this->event = 0;
            u_entity(_this)->flags |= U_ECREATE_INITIALISED;
            result = u_entityRelease(u_entity(_this));
            if (result != U_RESULT_OK) {
                OS_REPORT(OS_ERROR, "u_dispatcherInit", 0,
                          "Release observer failed.");
            }
        } else {
            OS_REPORT(OS_WARNING,"u_dispatcherInit",0,
                      "Failed to claim kernel object");
        }
    } else {
        OS_REPORT(OS_ERROR,"u_dispatcherInit",0,
                  "Illegal parameter.");
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
示例#25
0
u_topic
u_topicNew(
    u_participant p,
    const c_char *name,
    const c_char *typeName,
    const c_char *keyList,
    v_topicQos qos)
{
    u_topic _this = NULL;
    v_topic kt;
    v_kernel kk;
    u_result result;

    if (name != NULL) {
        if (p != NULL) {
            result = u_entityWriteClaim(u_entity(p->domain),(v_entity*)(&kk));
            if (result == U_RESULT_OK) {
                assert(kk);
                kt = v_topicNew(kk,name,typeName,keyList,qos);
                if (kt != NULL) {
                    _this = u_entityAlloc(p,u_topic,kt,FALSE);
                    if (_this != NULL) {
                      /* This call is moved to u_entityNew to support
                       * proxy Topics. This move does not comply with
                       * the constructor pattern used by all other
                       * Entities, so this need to be fixed.
                       *
                    result = u_topicInit(_this,name,p);
                       */

                        if (result == U_RESULT_OK) {
                            v_entitySetUserData(v_entity(kt), _this);
                        } else {
                            OS_REPORT_1(OS_ERROR, "u_topicNew", 0,
                                        "Initialisation failed. "
                                        "For Topic: <%s>", name);
                            u_topicFree(_this);
                        }
                    } else {
                        OS_REPORT_1(OS_ERROR, "u_topicNew", 0,
                                    "Create user proxy failed. "
                                    "For Topic: <%s>", name);
                    }
                    c_free(kt);
                } else {
                    OS_REPORT_1(OS_WARNING, "u_topicNew", 0,
                                "Create kernel entity failed. "
                                "For Topic: <%s>", name);
                }
                result = u_entityRelease(u_entity(p->domain));
            } else {
                OS_REPORT_1(OS_WARNING, "u_topicNew", 0,
                            "Claim Kernel failed. "
                            "For Topic: <%s>", name);
            }
        } else {
            OS_REPORT_1(OS_ERROR,"u_topicNew",0,
                        "No Participant specified. "
                        "For Topic: <%s>", name);
        }
    } else {
        OS_REPORT(OS_ERROR,"u_topicNew",0,
                  "No name specified.");
    }
    return _this;
}
示例#26
0
u_group
u_groupNew(
    u_participant participant,
    const c_char *partitionName,
    const c_char *topicName,
    v_duration timeout)
{
    u_result r;
    v_participant kparticipant;
    v_kernel kernel;
    v_topic ktopic;
    v_partition kpartition;
    v_group kgroup;
    c_iter topics;
    os_time delay;
    u_group group = NULL;

    if ((partitionName != NULL) && (topicName != NULL)) {
        if (participant != NULL) {
            r = u_entityWriteClaim(u_entity(participant), (v_entity*)(&kparticipant));
            if (r == U_RESULT_OK){
                assert(kparticipant);
                kernel = v_objectKernel(kparticipant);
                topics = v_resolveTopics(kernel,topicName);
                if (c_iterLength(topics) == 0) {
                    c_iterFree(topics);
                    delay.tv_sec = timeout.seconds;
                    delay.tv_nsec = timeout.nanoseconds;
                    os_nanoSleep(delay);
                    topics = v_resolveTopics(v_objectKernel(kparticipant),
                                             topicName);
                }
                if (c_iterLength(topics) > 1) {
                    OS_REPORT_1(OS_WARNING, "u_groupNew", 0,
                                "Internal error: "
                                "Multiple topics found with name = <%s>.",
                                topicName);
                }

                ktopic = c_iterTakeFirst(topics);

                /* If ktopic == NULL, the topic definition is unknown.
                 * This is not critical since it may become known in the near future.
                 * In that case the caller is responsible for retrying to create this group,
                 * and log something if, eventually, the group still cannot be created.
                 */
                if (ktopic != NULL) {
                    kpartition = v_partitionNew(kernel, partitionName, NULL);
                    if (kpartition != NULL) {
                        kgroup = v_groupSetCreate(kernel->groupSet, kpartition, ktopic);
                        if (kgroup != NULL) {
                            group = u_groupCreate(kgroup, participant);
                            if (group == NULL) {
                                OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                                            "Create proxy failed. "
                                            "For Partition <%s> and Topic <%s>.",
                                            partitionName, topicName);
                            }
                            c_free(kgroup);
                        } else {
                            OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                                        "Create kernel entity failed. "
                                        "For Partition <%s> and Topic <%s>.",
                                        partitionName, topicName);
                        }
                        c_free(kpartition);
                    } else {
                        OS_REPORT_2(OS_ERROR,"u_groupNew", 0,
                                    "Failed to create partition. "
                                    "For Partition <%s> and Topic <%s>.",
                                    partitionName, topicName);
                    }
                    c_free(ktopic);
                }
                ktopic = c_iterTakeFirst(topics);
                while (ktopic != NULL) {
                    c_free(ktopic);
                    ktopic = c_iterTakeFirst(topics);
                }
                c_iterFree(topics);
                r = u_entityRelease(u_entity(participant));
            } else {
                OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                            "Claim kernel participant failed."
                            "For Partition <%s> and Topic <%s>.",
                            partitionName, topicName);
            }
        } else {
            OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                        "No participant specified. "
                        "For Partition <%s> and Topic <%s>.",
                        partitionName, topicName);
        }
    } else {
        OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                    "Illegal parameter."
                    "partitionName = <0x%x>, topicName = <0x%x>.",
                    partitionName, topicName);
    }
    return group;
}
示例#27
0
文件: u_group.c 项目: xrl/opensplice
u_group
u_groupNew(
    u_participant participant,
    const c_char *partitionName,
    const c_char *topicName,
    v_duration timeout)
{
    u_result r;
    v_participant kparticipant;
    v_kernel kernel;
    v_topic ktopic;
    v_partition kpartition;
    v_group kgroup;
    c_iter topics;
    os_time delay;
    u_group group = NULL;

    if ((partitionName != NULL) && (topicName != NULL)) {
        if (participant != NULL) {
            r = u_entityWriteClaim(u_entity(participant), (v_entity*)(&kparticipant));
            if (r == U_RESULT_OK){
                assert(kparticipant);
                kernel = v_objectKernel(kparticipant);
                topics = v_resolveTopics(kernel,topicName);
                if (c_iterLength(topics) == 0) {
                    c_iterFree(topics);
                    delay.tv_sec = timeout.seconds;
                    delay.tv_nsec = timeout.nanoseconds;
                    os_nanoSleep(delay);
                    topics = v_resolveTopics(v_objectKernel(kparticipant),
                                             topicName);
                }
                if (c_iterLength(topics) > 1) {
                    OS_REPORT_1(OS_WARNING, "u_groupNew", 0,
                                "Internal error: "
                                "Multiple topics found with name = <%s>.",
                                topicName);
                }
                ktopic = c_iterTakeFirst(topics);
                if (ktopic != NULL) {
                    kpartition = v_partitionNew(kernel, partitionName, NULL);
                    if (kpartition != NULL) {
                        kgroup = v_groupSetCreate(kernel->groupSet, kpartition, ktopic);
                        if (kgroup != NULL) {
                            group = u_groupCreate(kgroup, participant);
                            if (group == NULL) {
                                OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                                            "Create proxy failed. "
                                            "For Partition <%s> and Topic <%s>.",
                                            partitionName, topicName);
                            }
                            c_free(kgroup);
                        } else {
                            OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                                        "Create kernel entity failed. "
                                        "For Partition <%s> and Topic <%s>.",
                                        partitionName, topicName);
                        }
                        c_free(kpartition);
                    } else {
                        OS_REPORT_2(OS_ERROR,"u_groupNew", 0,
                                    "Failed to create partition. "
                                    "For Partition <%s> and Topic <%s>.",
                                    partitionName, topicName);
                    }
                    c_free(ktopic);
                }else {
                    OS_REPORT_2(OS_ERROR,"u_groupNew", 0,
                                    "Topic not (yet) known. "
                                    "For Partition <%s> and Topic <%s>.",
                                    partitionName, topicName);
                }
                ktopic = c_iterTakeFirst(topics);
                while (ktopic != NULL) {
                    c_free(ktopic);
                    ktopic = c_iterTakeFirst(topics);
                }
                c_iterFree(topics);
                r = u_entityRelease(u_entity(participant));
            } else {
                OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                            "Claim kernel participant failed."
                            "For Partition <%s> and Topic <%s>.",
                            partitionName, topicName);
            }
        } else {
            OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                        "No participant specified. "
                        "For Partition <%s> and Topic <%s>.",
                        partitionName, topicName);
        }
    } else {
        OS_REPORT_2(OS_ERROR,"u_groupNew",0,
                    "Illegal parameter."
                    "partitionName = <0x%x>, topicName = <0x%x>.",
                    partitionName, topicName);
    }
    return group;
}
示例#28
0
/**************************************************************
 * constructor/destructor
 **************************************************************/
u_service
u_serviceNew(
    const c_char *uri,
    c_long timeout,
    const c_char *name,
    const c_char *extendedStateName,
    u_serviceKind kind,
    v_qos qos)
{
    u_domain domain;
    v_kernel kk;
    v_service ks;
    v_serviceManager sm;
    u_service s;
    u_result r;
    os_result osr;
    c_bool serviceTermHandlerRequired = FALSE;

    ks = NULL;
    r = u_domainOpen(&domain, uri, timeout);
    if (r != U_RESULT_OK) {
        OS_REPORT_1(OS_ERROR,"u_serviceNew",0,
                  "Failure to open the kernel - return code %d", r);
        return NULL;
    }

    s = NULL;
    if (domain != NULL) {
        r = u_entityWriteClaim(u_entity(domain),(v_entity*)(&kk));
        if (r == U_RESULT_OK) {
            assert(kk);
            sm = v_getServiceManager(kk);
            if (sm != NULL) {
#ifndef INTEGRITY
                if (lockPages(kk, name)) {
                    osr = os_procMLockAll(OS_MEMLOCK_CURRENT|OS_MEMLOCK_FUTURE);
                } else {
                    osr = os_resultSuccess;
                }
                if (osr == os_resultSuccess) {
#endif
                    switch(kind){
                    case U_SERVICE_DDSI:
                    case U_SERVICE_DDSIE:
                    case U_SERVICE_NETWORKING:
                        ks = v_service(v_networkingNew(sm, name,
                                                       extendedStateName,
                                                       (v_participantQos)qos));
                        serviceTermHandlerRequired = TRUE;
                    break;
                    case U_SERVICE_DURABILITY:
                        ks = v_service(v_durabilityNew(sm, name,
                                                       extendedStateName,
                                                       (v_participantQos)qos));
                        serviceTermHandlerRequired = TRUE;
                    break;
                    case U_SERVICE_CMSOAP:
                        ks = v_service(v_cmsoapNew(sm, name,
                                                   extendedStateName,
                                                   (v_participantQos)qos));
                        serviceTermHandlerRequired = TRUE;
                    break;
                    case U_SERVICE_RNR:
                        ks = v_service(v_rnrNew(sm, name,
                                                extendedStateName,
                                                (v_participantQos)qos));
                        serviceTermHandlerRequired = TRUE;
                    break;
                    case U_SERVICE_DBMSCONNECT:
                    case U_SERVICE_INCOGNITO:
                        ks = v_serviceNew(sm, name,
                                          extendedStateName,
                                          (v_participantQos)qos, NULL);
                        serviceTermHandlerRequired = TRUE;
                    break;
                    case U_SERVICE_SPLICED:
                    break;
                    default:
                        OS_REPORT(OS_WARNING,"u_serviceNew",0,
                                  "Failed to start an unknown service kind");
                    break;
                    }
                } else {
                    OS_REPORT(OS_ERROR,"u_serviceNew",0,
                              "Failed to lock memory pages for current process");
                }

                /* Install the service signal handlers if spliced is not within this
                 * same process.  i.e. only do this if each service is in its own
                 * process so signal handlers won't interfere */
                if (serviceTermHandlerRequired && !u_splicedInProcess()) {
                    os_procSetTerminationHandler(serviceTermHandler);
                }

#ifndef INTEGRITY

            } else {
                OS_REPORT(OS_ERROR,"u_serviceNew",0,
                          "Failed to retrieve the Service Manager");
            }
#endif
            if (ks != NULL) {
                s = u_entityAlloc(NULL,u_service,ks,TRUE);
                r = u_serviceInit(s, kind, domain);
                if (r != U_RESULT_OK) {
                    OS_REPORT_1(OS_ERROR,"u_serviceNew",0,
                                "Failed to initialize service: %s", name);
                    u_serviceFree(s);
                    s = NULL;
                }
                callbackService = s;
                (void) os_signalHandlerSetExceptionCallback(u__serviceExceptionCallbackWrapper);
            } else {
                OS_REPORT(OS_WARNING,"u_serviceNew",0,
                          "Failed to retrieve the Service Manager");
            }
            r = u_entityRelease(u_entity(domain));
        }
    }
    return s;
}