Example #1
0
gboolean
Services_list(Matahari *matahari, DBusGMethodInvocation *context)
{
    GError* error = NULL;
    int i = 0;
    GList *services;
    char **list;

    if (!check_authorization(SERVICES_BUS_NAME ".list", &error, context)) {
        dbus_g_method_return_error(context, error);
        return FALSE;
    }

    // Get list of services
    services = services_list();

    // Convert GList to (char **)
    list = g_new(char *, g_list_length(services) + 1);
    for (; services != NULL; services = services->next)
        list[i++] = strdup(services->data);
    list[i] = NULL; // Sentinel

    dbus_g_method_return(context, list);
    g_strfreev(list);
    g_list_free(services);
    return TRUE;
}
Example #2
0
File: tester.c Project: moul/junk
int	main(int ac, char **av)
{
  char	*ret;

  printf("[+] init\n");

  printf("[+] Add service test\n");
  service_add("test", test_service,
	      "super service de test qui sert a rien");
  printf("[+] Add service test\n");
  service_add("test2", test2_service,
	      "super service de test2 qui sert toujours a rien");

  printf("[+] List services\n");
  services_list();

  printf("[+] Call service test\n");
  ret = SERVICE_CALL("test", "bite [%s]\n", "bla");

  printf("[+] test return [%s]\n", ret);

  printf("[+] uninit\n");
  return (0);
  (void)ac;
  (void)av;
}
Example #3
0
gboolean
SrvAgent::invoke_services(qmf::AgentSession session, qmf::AgentEvent event,
                          gpointer user_data)
{
    static const int default_timeout_ms = 60000;
    const std::string& methodName(event.getMethodName());
    if (event.getType() != qmf::AGENT_METHOD) {
        return TRUE;
    }

    qpid::types::Variant::Map& args = event.getArguments();

    if (methodName == "list") {
        _qtype::Variant::List s_list;
        GList *gIter = NULL;
        GList *services = services_list();

        for (gIter = services; gIter != NULL; gIter = gIter->next) {
            s_list.push_back((const char *) gIter->data);
        }

        event.addReturnArgument("agents", s_list);

    } else if (methodName == "enable" || methodName == "disable") {
        svc_action_t *op = services_action_create(
	    args["name"].asString().c_str(), methodName.c_str(), 0,
	    default_timeout_ms);

        action_async(SRV_SERVICES, session, event, op, false);
	return TRUE;

    } else if (methodName == "start"
	       || methodName == "stop"
	       || methodName == "status") {
        svc_action_t *op = services_action_create(
                args["name"].asString().c_str(), methodName.c_str(), 0, args["timeout"].asInt32());

        action_async(SRV_SERVICES, session, event, op, true);
	return TRUE;

    } else {
        session.raiseException(event, MH_NOT_IMPLEMENTED);
        return TRUE;
    }

    session.methodSuccess(event);
    return TRUE;
}