Exemple #1
0
u_result
u_serviceWatchSpliceDaemon(
    u_service service,
    u_serviceSplicedaemonListener listener,
    c_voidp usrData)
{
    u_result r;
    watchSplicedAdmin admin;
    c_ulong mask;

    r = U_RESULT_OK;
    if (service == NULL) {
        r = U_RESULT_ILL_PARAM;
    } else {
        admin = watchSplicedAdmin(service->privateData);
        u_dispatcherGetEventMask(u_dispatcher(service), &mask);
        if (listener == NULL) {
            mask &= ~V_EVENT_SERVICESTATE_CHANGED;
            u_dispatcherRemoveListener(u_dispatcher(service),u_serviceSpliceListener);
            admin->callback = NULL;
            admin->usrData = NULL;
        } else {
            admin->callback = listener;
            admin->usrData = usrData;
            mask |= V_EVENT_SERVICESTATE_CHANGED;
            r = u_dispatcherInsertListener(u_dispatcher(service), u_serviceSpliceListener, admin);
        }
        u_dispatcherSetEventMask(u_dispatcher(service), mask);
    }

    return r;
}
Exemple #2
0
u_result
u_serviceDeinit(
    u_service service)
{
    u_result r;
    watchSplicedAdmin admin;
    if (service != NULL) {

        u_dispatcherRemoveListener(u_dispatcher(service),
                                   u_serviceSpliceListener);
        admin = watchSplicedAdmin(service->privateData);
        if (admin) {
            admin->callback = NULL;
            admin->usrData = NULL;
            if (admin->serviceManager != NULL) {
                u_serviceManagerFree(admin->serviceManager);
            }
            os_free(admin);
        }
        service->privateData = NULL;
        r = u_participantDeinit(u_participant(service));
    } else {
        OS_REPORT(OS_ERROR,"u_serviceDeinit",0,
                  "Illegal parameter.");
        r = U_RESULT_ILL_PARAM;
    }
    return r;
}
Exemple #3
0
u_result
u_readerInit(
    u_reader _this)
{
    u_result result;
    os_result osResult;
    os_mutexAttr osMutexAttr;

    if (_this != NULL) {
        result = u_dispatcherInit(u_dispatcher(_this));
        if (result == U_RESULT_OK) {
            _this->queries = NULL;
            osResult = os_mutexAttrInit(&osMutexAttr);
            if (osResult == os_resultSuccess) {
                osMutexAttr.scopeAttr = OS_SCOPE_PRIVATE;
                osResult = os_mutexInit(&_this->mutex, &osMutexAttr);
                if (osResult != os_resultSuccess) {
                    result = U_RESULT_INTERNAL_ERROR;
                }
            }
            u_entity(_this)->flags |= U_ECREATE_INITIALISED;
        }
    } else {
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
Exemple #4
0
u_result
u_readerDeinit(
    u_reader _this)
{
    u_result result;
    u_query query;

    if (_this != NULL) {
        result = u_dispatcherDeinit(u_dispatcher(_this));
        if (result == U_RESULT_OK) {
            os_mutexLock(&_this->mutex);
            if (_this->queries) {
                query = c_iterObject(_this->queries,0);
                while (query) {
                    os_mutexUnlock(&_this->mutex);
                    result = u_queryFree(query);
                    os_mutexLock(&_this->mutex);
                    query = c_iterObject(_this->queries,0);
                }
                c_iterFree(_this->queries);
                _this->queries = NULL;
            }
            os_mutexUnlock(&_this->mutex);
            os_mutexDestroy(&_this->mutex);
        }
    } else {
        result = U_RESULT_ILL_PARAM;
    }

    return result;
}
Exemple #5
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;
}
Exemple #6
0
u_result
u_subscriberDeinit(
    u_subscriber _this)
{
    u_result result;
    u_dataReader reader;
    c_iter list;

    if (_this != NULL) {
        result = u_participantRemoveSubscriber(_this->participant,_this);
        if (result == U_RESULT_OK) {
            _this->participant = NULL;
            if (_this->readers) {
                list = _this->readers;
                _this->readers = NULL;
                u_entityUnlock(u_entity(_this));
                reader = c_iterTakeFirst(list);
                while (reader) {
                    /* Readers should not exist at this point!
                     * This loop corrects this erronous state.
                     */
                    result = u_dataReaderFree(reader);
                    u_entityDereference(u_entity(_this));
                    reader = c_iterTakeFirst(list);
                }
                c_iterFree(list);
                result = u_entityLock(u_entity(_this));
            }
            result = u_dispatcherDeinit(u_dispatcher(_this));
        }
    } else {
        OS_REPORT_1(OS_ERROR,
                    "u_subscriberDeinit",0,
                    "Illegal parameter: _this = 0x%x.",
                    _this);
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
Exemple #7
0
u_result
u_subscriberInit(
    u_subscriber _this,
    u_participant p)
{
    u_result result;

    if (_this != NULL) {
        result = u_dispatcherInit(u_dispatcher(_this));
        if (result == U_RESULT_OK) {
            _this->readers = NULL;
            _this->participant = p;
            result = u_participantAddSubscriber(p,_this);
        }
    } else {
        OS_REPORT_2(OS_ERROR,
                    "u_subscriberInit",0,
                    "Illegal parameter: _this = 0x%x, participant = 0x%x.",
                    _this,p);
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
Exemple #8
0
u_result
u_topicInit(
    u_topic _this,
    const c_char *name,
    u_participant p)
{
    u_result result;

    if (_this != NULL) {
        result = u_dispatcherInit(u_dispatcher(_this));
        if (result == U_RESULT_OK) {
            _this->name = os_strdup(name);
            _this->participant = p;
            u_entity(_this)->flags |= U_ECREATE_INITIALISED;
/* Note: redefinitions of the a topic are added to the list. */
            result = u_participantAddTopic(p,_this);
        }
    } else {
        OS_REPORT(OS_ERROR,"u_topicInit",0, "Illegal parameter.");
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
Exemple #9
0
u_result
u_topicDeinit(
    u_topic _this)
{
    u_result result;

    if (_this != NULL) {
        result = u_participantRemoveTopic(_this->participant, _this);
        if (result == U_RESULT_OK) {
            result = u_dispatcherDeinit(u_dispatcher(_this));
            if (result == U_RESULT_OK) {
                if (_this->name) {
                    os_free(_this->name);
                    _this->name = NULL;
                }
            } else {
                OS_REPORT_1(OS_WARNING,
                            "u_topicDeinit", 0,
                            "Operation u_dispatcherDeinit failed. "
                            "Topic = 0x%x",
                            _this);
            }
        } else {
            OS_REPORT_2(OS_WARNING,
                        "u_topicDeinit", 0,
                        "The Topic (0x%x) could not be removed "
                        "from the Participant (0x%x).",
                        _this, _this->participant);
        }
    } else {
        OS_REPORT(OS_ERROR,
                  "u_topicDeinit", 0,
                  "Illegal parameter: Topic == NULL.");
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
Exemple #10
0
c_bool
d_readerListenerStart(
    d_readerListener listener)
{
    c_bool result;
    u_dispatcher dispatcher;
    u_result ur;
    d_waitsetAction action;
    c_bool wsResult;
    d_waitset waitset;
    d_admin admin;
    d_subscriber subscriber;

    assert(listener);
    result = FALSE;
    assert(d_objectIsValid(d_object(listener), D_LISTENER));

    if(listener){
        d_listenerLock(d_listener(listener));
        dispatcher  = u_dispatcher(listener->dataReader);
        action      = d_readerListenerAction;

        if(d_listener(listener)->attached == FALSE){
            ur = u_dispatcherSetEventMask(dispatcher, V_EVENT_DATA_AVAILABLE);

            if(ur == U_RESULT_OK){
                listener->value = NULL;
                listener->message = NULL;

                admin       = d_listenerGetAdmin(d_listener(listener));
                subscriber  = d_adminGetSubscriber(admin);
                waitset     = d_subscriberGetWaitset(subscriber);

                listener->waitsetData = d_waitsetEntityNew(
                            listener->name,
                            dispatcher, action,
                            V_EVENT_DATA_AVAILABLE, listener->attr, listener);

                wsResult    = d_waitsetAttach(waitset, listener->waitsetData);

                if(wsResult == TRUE) {
                    ur = U_RESULT_OK;
                } else {
                    ur = U_RESULT_ILL_PARAM;
                }

                if(ur == U_RESULT_OK){
                    d_listener(listener)->attached = TRUE;
                    result = TRUE;
                    d_listenerUnlock(d_listener(listener));
                    u_dispatcherNotify(dispatcher);
                } else {
                    d_listenerUnlock(d_listener(listener));
                }

            } else {
                d_listenerUnlock(d_listener(listener));
            }
        } else {
            d_listenerUnlock(d_listener(listener));
            result = TRUE;
        }
    }
    return result;
}
Exemple #11
0
cms_service
cms_serviceNew(
    const c_char* name,
    const c_char* uri)
{
    cms_service service;
    c_bool success;
    const c_char* init;

    C_STRUCT(v_participantQos) q;
    struct sockaddr_in addr;
    socklen_t len;
    os_result errcode;
    char* ipTagStr = NULL;
    char* xmlStr = NULL;
    u_result result;
    os_result res;
    os_ifAttributes *ifList;
    os_uint32 nofIf, i;

    service = NULL;


    if(uri != NULL) {
        init = cmx_initialise();

        if(strcmp(init, CMS_RESULT_OK) == 0) {
            service = cms_service(os_malloc(C_SIZEOF(cms_service)));
            cms_object(service)->kind   = CMS_SERVICE;
            service->terminate          = FALSE;
            service->leaseThread        = NULL;
            service->clients            = NULL;
            service->soap               = NULL;
            service->configuration      = NULL;
            service->garbageCollector   = NULL;

            service->uservice = u_serviceNew(uri, CMSERVICE_ATTACH_TIMEOUT, name, NULL, U_SERVICE_CMSOAP, NULL);

            if(service->uservice != NULL) {
                /*disable all events.*/
                u_dispatcherSetEventMask(u_dispatcher(service->uservice), 0);

                u_entityAction(u_entity(service->uservice), cms_serviceActionGroups, NULL);

                u_serviceChangeState(service->uservice, STATE_INITIALISING);
                success = cms_serviceInit(name, service);

                result = u_participantQosInit((v_participantQos)&q);
                if (result == U_RESULT_OK) {
                    /* Insert service information in userData QoS */
                    len = sizeof(struct sockaddr);
                    errcode = os_sockGetsockname (service->soap->master, (struct sockaddr*)&addr, len);
                    if(errcode == os_resultSuccess) {
                        OS_REPORT_1(OS_INFO, CMS_CONTEXT, 0, "SOAP service is reachable via port %d",ntohs(addr.sin_port));

                        ifList = os_malloc(MAX_INTERFACES * sizeof(*ifList));

#ifdef WITH_IPV6
                        res = os_sockQueryIPv6Interfaces(ifList, (os_uint32)MAX_INTERFACES, &nofIf);
#else
                        res = os_sockQueryInterfaces(ifList, (os_uint32)MAX_INTERFACES, &nofIf);
#endif
                        /* SOAP userdata layout:
                         * <TunerService>
                         * <Ip>x.x.x.x:port</Ip> [<Ip>x.x.x.x</Ip>]...
                         * </TunerService>
                         */
                        if (res == os_resultSuccess) {
                            os_char tmp[64];
                            int chars;
                            for (i = 0; i < nofIf; i++) {
                                /* ignore the local loopback interface */
                                if (!os_sockaddrIsLoopback((os_sockaddr*)&ifList[i].address)) {
                                    os_sprintf(tmp,"%s",inet_ntoa(((os_sockaddr_in*)&ifList[i].address)->sin_addr));
                                    if (strcmp(tmp,"0.0.0.0") != 0) {
                                        chars = os_sprintf(tmp, IP_TAG,
                                                           inet_ntoa(((os_sockaddr_in*)&ifList[i].address)->sin_addr),
                                                           ntohs(addr.sin_port));
                                        if (chars > 0) {
                                            if (ipTagStr) {
                                                ipTagStr = os_realloc(ipTagStr, strlen(ipTagStr) + chars + 1);
                                            } else {
                                                ipTagStr = os_malloc(chars + 1);
                                                *ipTagStr = '\0';
                                            }
                                            ipTagStr = os_strcat(ipTagStr, tmp);
                                        }
                                    }
                                }
                            }
                        } else {
                            if(service->configuration->verbosity >= 1) {
                                OS_REPORT(OS_WARNING, CMS_CONTEXT, 0,"Could not get SOAP ip address.");
                            }
                            ipTagStr = os_malloc((strlen(IP_TAG) + INET6_ADDRSTRLEN_EXTENDED));
                            os_sprintf (ipTagStr, IP_TAG, "127.0.0.1", ntohs(addr.sin_port));
                        }
                        os_free(ifList);

                        xmlStr = os_malloc(strlen(ipTagStr) + strlen(SOAP_TAG)+1);
                        os_sprintf (xmlStr, SOAP_TAG, ipTagStr);
                        os_free(ipTagStr);

                        q.userData.size = strlen(xmlStr);
                        q.userData.value = os_malloc(q.userData.size);
                        memcpy(q.userData.value, xmlStr, q.userData.size);

                        if(service->configuration->verbosity >= 5) {
                            OS_REPORT_1(OS_INFO, CMS_CONTEXT, 0, "SOAP userData: %s", xmlStr);
                        }
                        os_free(xmlStr);
                    } else {
                        q.userData.size = 0;
                        q.userData.value = NULL;
                        if(service->configuration->verbosity >= 1) {
                            OS_REPORT(OS_WARNING, CMS_CONTEXT, 0, "Could not get SOAP port.");
                        }
                    }

                    result = u_entitySetQoS(u_entity(service->uservice), (v_qos)&q);
                    if (result != U_RESULT_OK) {
                        if(service->configuration->verbosity >= 1) {
                            OS_REPORT(OS_WARNING, CMS_CONTEXT, 0,"Could not update the participantQos for publication of the SOAP ip address and port.");
                        }
                    }
                    os_free(q.userData.value);
                } else {
                    if(service->configuration->verbosity >= 1) {
                        OS_REPORT(OS_WARNING, CMS_CONTEXT, 0,"Could not initiate participantQos for SOAP service ip address and port publication.");
                    }
                }

                if(success == FALSE) {
                    cms_serviceFree(service);
                    service = NULL;
                } else {
                    u_serviceWatchSpliceDaemon(service->uservice,
                                               cms_serviceSplicedaemonListener,
                                               service);
                    u_serviceChangeState(service->uservice, STATE_OPERATIONAL);
                }
            } else {
                OS_REPORT(OS_ERROR, CMS_CONTEXT, 0,
                          "cms_serviceNew: user layer service could not be created.");

                cms_serviceFree(service);
                service = NULL;
            }
        } else {
            if(service && service->configuration->verbosity >= 1) {
                OS_REPORT(OS_ERROR, CMS_CONTEXT, 0,
                          "cms_serviceNew: C&M API could not be initialized.");
            }
        }
    } else {
        if(service && service->configuration->verbosity > 0) {
            OS_REPORT(OS_ERROR, CMS_CONTEXT, 0, "cms_serviceNew: no uri supplied.");
        }
    }
    return service;
}