Ejemplo n.º 1
0
/** 
* @brief Attach a service to a glib mainloop.
* 
* @param  sh 
* @param  mainLoop 
* @param  lserror 
* 
* @retval
*/
bool
LSGmainAttach(LSHandle *sh, GMainLoop *mainLoop, LSError *lserror)
{
    _LSErrorIfFail(sh != NULL, lserror);
    _LSErrorIfFail(mainLoop != NULL, lserror);

    LSHANDLE_VALIDATE(sh);

    GMainContext *context = g_main_loop_get_context(mainLoop);
    _LSErrorIfFailMsg(context != NULL, lserror, -1,
                   "%s: %s", __FUNCTION__, ": No maincontext.");

    _LSTransportGmainAttach(sh->transport, context);
    sh->context = g_main_context_ref(context);

    return true;
}
Ejemplo n.º 2
0
void
LSFetchQueueAddConnection(LSFetchQueue *fq, LSHandle *sh)
{
    /* FIXME -- why is this getting called with NULL LSHandle? */
    if (fq && sh)
    {
        fq->sh_list = g_slist_prepend(fq->sh_list, sh);
        
        /* use custom message handler and attach context */
        if ((sh->transport->msg_handler != _LSCustomMessageHandler))
        {
            sh->transport->msg_handler = _LSCustomMessageHandler;
            sh->transport->msg_context = sh;
        }
        _LSTransportGmainAttach(sh->transport, fq->main_context);
    }
}
Ejemplo n.º 3
0
int
main(int argc, char *argv[])
{
    LSError lserror;
    LSErrorInit(&lserror);

    int public = HUB_TYPE_PUBLIC;
    int private = HUB_TYPE_PRIVATE;
    
    if (LSIsRunning(PID_DIR, MONITOR_PID_NAME))
    {
        g_critical("An instance of the monitor is already running");
        exit(EXIT_FAILURE);
    }
    
    mainloop = g_main_loop_new(NULL, FALSE);

    /* send message to hub to let clients know that they should start
     * sending us their messages */
    LSTransportHandlers handler_priv =
    {
        .msg_handler = _LSMonitorMessageHandlerPrivate,
        .msg_context = &private,
        .disconnect_handler = NULL,
        .disconnect_context = NULL,
        .message_failure_handler = NULL,
        .message_failure_context = NULL
    };
    
    LSTransportHandlers handler_pub =
    {
        .msg_handler = _LSMonitorMessageHandlerPublic,
        .msg_context = &public,
        .disconnect_handler = NULL,
        .disconnect_context = NULL,
        .message_failure_handler = NULL,
        .message_failure_context = NULL
    };

    _LSTransportSetupSignalHandler(SIGTERM, _HandleShutdown);
    _LSTransportSetupSignalHandler(SIGINT, _HandleShutdown);

    _HandleCommandline(argc, argv);

    if (list_clients || list_subscriptions || list_malloc)
    {
        handler_priv.msg_handler = _LSMonitorListMessageHandler;
        handler_pub.msg_handler = _LSMonitorListMessageHandler;
    }

    if (!_LSTransportInit(&transport_priv, MONITOR_NAME, &handler_priv, &lserror))
    {
        goto error;
    }
    
    if (!_LSTransportInit(&transport_pub, MONITOR_NAME, &handler_pub, &lserror))
    {
        goto error;
    }
   
    /* connect for "private" messages */ 
    if (!_LSTransportConnect(transport_priv, true, false, &lserror))
    {
        goto error;
    }

    /* connect for "public" messages */
    if (!_LSTransportConnect(transport_pub, true, true, &lserror))
    {
        goto error;
    }
   
    _LSTransportGmainAttach(transport_priv, g_main_loop_get_context(mainloop)); 
    _LSTransportGmainAttach(transport_pub, g_main_loop_get_context(mainloop)); 

    if (_LSTransportGetTransportType(transport_priv) == _LSTransportTypeLocal)
    {
        transport_priv_local = true;

        /* message printing callback */
        //g_idle_add(_LSMonitorIdleHandlerPrivate, NULL);
        private_queue = _LSMonitorQueueNew(false);
        g_timeout_add(500, _LSMonitorIdleHandlerPrivate, private_queue);
    }

    if (_LSTransportGetTransportType(transport_pub) == _LSTransportTypeLocal)
    {
        transport_pub_local = true;
        
        //g_idle_add(_LSMonitorIdleHandlerPublic, NULL);
        public_queue = _LSMonitorQueueNew(true);
        g_timeout_add(500, _LSMonitorIdleHandlerPublic, public_queue);
    }

    if (list_clients || list_subscriptions || list_malloc)
    {
        if (!_LSTransportSendMessageListClients(transport_priv, &lserror))
        {
            goto error;
        }

        if (!_LSTransportSendMessageListClients(transport_pub, &lserror))
        {
            goto error;
        }
    } 
    else
    {
        /* send the message to the hub to tell clients to connect to us */
        if (!LSTransportSendMessageMonitorRequest(transport_priv, &lserror))
        {
            goto error;
        }
        
        if (!LSTransportSendMessageMonitorRequest(transport_pub, &lserror))
        {
            goto error;
        }

        if (debug_output)
        {
            fprintf(stdout, "Debug\tTime\t\tProt\tType\tSerial\t\tSender\t\tDestination\t\tMethod                            \tPayload\n");
        }
        else
        {
            fprintf(stdout, "Time\t\tProt\tType\tSerial\t\tSender\t\tDestination\t\tMethod                            \tPayload\n");
        }
    }

    dup_hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
    LS_ASSERT(dup_hash_table);

    g_main_loop_run(mainloop);
    g_main_loop_unref(mainloop);

    _DisconnectCustomTransport();

    g_hash_table_destroy(dup_hash_table);

    exit(EXIT_SUCCESS);

error:
    LSErrorPrint(&lserror, stderr);
    LSErrorFree(&lserror);
    exit(EXIT_FAILURE);
}