static void
_run_iteration (DBusConnection *conn)
{
  DBusPendingCall *echo_pending;
  DBusPendingCall *dbus_pending;
  DBusMessage *method;
  DBusMessage *reply;
  char *echo = "echo";

  /* send the first message */
  method = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService",
                                         "/org/freedesktop/TestSuite",
                                         "org.freedesktop.TestSuite",
                                         "Echo");

  dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL);
  dbus_connection_send_with_reply (conn, method, &echo_pending, -1);
  dbus_message_unref (method);
  
  /* send the second message */
  method = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
                                         DBUS_PATH_DBUS,
                                         "org.freedesktop.Introspectable",
                                         "Introspect");

  dbus_connection_send_with_reply (conn, method, &dbus_pending, -1);
  dbus_message_unref (method);

  /* block on the second message (should return immediately) */
  dbus_pending_call_block (dbus_pending);

  /* block on the first message */
  /* if it does not return immediately chances 
     are we hit the block in poll bug */
  dbus_pending_call_block (echo_pending);

  /* check the reply only to make sure we
     are not getting errors unrelated
     to the block in poll bug */
  reply = dbus_pending_call_steal_reply (echo_pending);

  if (reply == NULL)
    {
      printf ("Failed: Reply is NULL ***\n");
      exit (1);
    }

  if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
    {
      printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply));
      exit (1);
    } 

  dbus_message_unref (reply);
  dbus_pending_call_unref (dbus_pending);
  dbus_pending_call_unref (echo_pending);
  
}
Beispiel #2
0
void prefer_3g(DBusConnection * conn)
{
	DBusMessage *msg;
	DBusPendingCall *pending;
	int prefer = PREFER_3G;

	/* Send a D-Bus command to set preferred mode */

	msg = dbus_message_new_method_call("org.freedesktop.ModemManager",	/* Destination */
					   "/org/freedesktop/ModemManager/Modems/0",	/* Object Path */
					   "org.freedesktop.ModemManager.Modem.Gsm.Network",	/* Interface */
					   "SetAllowedMode");	/* Method */
	if (NULL == msg) {
		syslog(LOG_ERR, "Message Null\n");
		syslog(LOG_ERR, "Message Null prefer_3g\n");
		exit(1);
	}

	/* Append the arguments required by the D-Bus send command */

	if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &prefer,
				      DBUS_TYPE_INVALID)) {
		syslog(LOG_ERR, "Out Of Memory!\n");
		exit(1);
	}

	if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
		syslog(LOG_ERR, "Out Of Memory!\n");
		exit(1);
	}
	dbus_connection_flush(conn);
	dbus_message_unref(msg);
	dbus_pending_call_block(pending);
	msg = dbus_pending_call_steal_reply(pending);
}
int dc_frame_buffer_get(struct razer_daemon_controller *controller)
{
	DBusMessage *msg;
	DBusMessageIter args;
	msg = dbus_message_new_method_call("org.voyagerproject.razer.daemon","/","org.voyagerproject.razer.daemon.frame_buffer","get");
	if(!msg)
		dc_error_close(controller,"Error creating Message\n");
	if(!dbus_connection_send_with_reply(controller->dbus,msg,&controller->pending,-1))
		dc_error_close(controller,"Out of memory!\n"); 
	if(!controller->pending)
		dc_error_close(controller,"No pending call\n"); 
	dbus_connection_flush(controller->dbus);
	dbus_message_unref(msg);

	int uid = -1;

	dbus_pending_call_block(controller->pending);
	msg = dbus_pending_call_steal_reply(controller->pending);
	if(!msg)
		dc_error_close(controller,"Empty reply\n"); 
	dbus_pending_call_unref(controller->pending);
	if(!dbus_message_iter_init(msg,&args))
		dc_error_close(controller,"Message has no arguments!\n"); 
	else if(dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_INT32) 
		dc_error_close(controller,"Argument is not an int!\n"); 
	else
		dbus_message_iter_get_basic(&args,&uid);
	dbus_message_unref(msg);   
	return(uid);
}
Beispiel #4
0
/**
 * send data for dbus method call
 */
static int networkmanager_dbus_send(DBusMessage** msg, DBusConnection* dbus_connection)
{
	DBusPendingCall* pending;
	int success;

	// send dbus message
	// -1 is the default time out. Other time outs can be configured in milli seconds.
	success = dbus_connection_send_with_reply(dbus_connection, *msg, &pending, -1);
	if(!success)
	{
		printf("networkmanager_dbus_send dbus send error\n");
		return 0;
	}
	if(pending == NULL)
	{
		printf ("networkmanager_dbus_send dbus calling error\n");
		return 0;
	}

	dbus_connection_flush(dbus_connection);
	dbus_message_unref(*msg);
	dbus_pending_call_block(pending);
	*msg = dbus_pending_call_steal_reply(pending);
	dbus_pending_call_unref(pending);

	if(*msg == NULL)
		return 0;

	return 1;
}
Beispiel #5
0
static DBusMessage *excute_method_a(DBusConnection *conn, DBusMessage* msg)
{
    DBusPendingCall* pending;

    if (NULL == msg) {
        printf("Message NULL\n");
        return NULL;
    }

    if (!dbus_connection_send_with_reply(conn, msg, &pending, -1))
    {
        printf("Out Of Memory!");
        return NULL;
    }

    if (NULL == pending) {
        printf("Pending Call Null");
        return NULL;
    }

    dbus_connection_flush(conn);
    dbus_message_unref(msg);

    dbus_pending_call_block(pending);
    msg = dbus_pending_call_steal_reply(pending);
    if (NULL == msg) {
        printf("Reply Null\n");
    }
    dbus_pending_call_unref(pending);

    return msg;
}
Beispiel #6
0
static enum PLAYBACK_STATUS mediaplayer_get_status(const char *id) {
	DBusMessage* msg;
	DBusMessageIter args, var;
	DBusPendingCall* pending;
	static const char *prop="PlaybackStatus";
	char *status;
	char player[256];
	enum PLAYBACK_STATUS ret=PLAYBACK_STATUS_STOPPED;
	
	sprintf(player, "%s%s", mpris.base, id);
	if(!(msg=dbus_message_new_method_call(player, mpris.object, dbus.interface_prop, "Get")))
		return ret;
	dbus_message_iter_init_append(msg, &args);
	if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &mpris.interface_player)) {
		dbus_message_unref(msg);
		return ret;
	}
	if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &prop)) {
		dbus_message_unref(msg);
		return ret;
	}
	if(!dbus_connection_send_with_reply(dbus.session.connection, msg, &pending, -1)) {
		dbus_message_unref(msg);
		return ret;
	}
	if(!pending) {
		dbus_message_unref(msg);
		return ret;
	}
	dbus_connection_flush(dbus.session.connection);
	dbus_message_unref(msg);
	dbus_pending_call_block(pending);
	if(!(msg=dbus_pending_call_steal_reply(pending))) {
		dbus_pending_call_unref(pending);
		return ret;
	}
	dbus_pending_call_unref(pending);
	if(!dbus_message_iter_init(msg, &args)) {
		dbus_message_unref(msg);
		return ret;
	}
	if(dbus_message_iter_get_arg_type(&args)!=DBUS_TYPE_VARIANT) {
		dbus_message_unref(msg);
		return ret;
	}
	dbus_message_iter_recurse(&args, &var);
	if(dbus_message_iter_get_arg_type(&var)!=DBUS_TYPE_STRING) {
		dbus_message_unref(msg);
		return ret;
	}
	
	dbus_message_iter_get_basic(&var, &status);
	if(!strcmp(status, "Playing"))
		ret=PLAYBACK_STATUS_PLAYING;
	else if(!strcmp(status, "Paused"))
		ret=PLAYBACK_STATUS_PAUSED;
	
	dbus_message_unref(msg);
	return ret;
}
Beispiel #7
0
int get_active_conn_state(DBusConnection * conn, const char *active_conn)
{
	DBusMessage *msg;
	DBusMessageIter args;
	DBusPendingCall *pending;
	int state;
	const char *param1 = "org.freedesktop.NetworkManager.Connection.Active";
	const char *param2 = "State";

	msg = dbus_message_new_method_call("org.freedesktop.NetworkManager",	/* Destination */
					   active_conn,	/* Object path */
					   "org.freedesktop.DBus.Properties",	/* Interface */
					   "Get");	/* Method */
	if (NULL == msg) {
		syslog(LOG_ERR, "Message Null\n");
		syslog(LOG_ERR, "Message Null get_active_conn_state\n");
		exit(1);
	}
	if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &param1,
				      DBUS_TYPE_STRING, &param2,
				      DBUS_TYPE_INVALID)) {
		syslog(LOG_ERR, "Out Of Memory!\n");
		exit(1);
	}

	if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
		syslog(LOG_ERR, "Out Of Memory!\n");
		exit(1);
	}
	dbus_connection_flush(conn);
	dbus_message_unref(msg);
	dbus_pending_call_block(pending);
	msg = dbus_pending_call_steal_reply(pending);
	if (NULL == msg) {
		syslog(LOG_ERR, "Reply Null\n");
		exit(1);
	}

	dbus_pending_call_unref(pending);
	if (!dbus_message_iter_init(msg, &args))
		syslog(LOG_ERR, "Message has no arguments!\n");
	else {
		int arg_type = dbus_message_iter_get_arg_type(&args);
		if (arg_type == DBUS_TYPE_VARIANT) {
			read_variant(&args, &state);
			dbus_message_unref(msg);
			return state;
		}
		if (arg_type == DBUS_TYPE_STRING) {
			char str_ptr[100];
			read_string(&args, str_ptr);
			syslog(LOG_ERR, "paths.c:%s\n", str_ptr);
			return -1;
		}

	}
	dbus_message_unref(msg);
	return -1;
}
Beispiel #8
0
static void
recvReply(DBusPendingCall* pending)
{
    DBusMessage* msg = NULL;
    DBusMessageIter args;

    printf("Wait for call complete\n");
    dbus_pending_call_block(pending);

    msg = dbus_pending_call_steal_reply(pending);
    if (msg == NULL) {
        printf("Reply NULL\n");
        exit(-1);
    }
 
    dbus_pending_call_unref(pending);

    printf("Get reply message\n");
    if (!dbus_message_iter_init(msg, &args))
        printf("Message has no arguments!\n");
    else {
        int type = dbus_message_iter_get_arg_type(&args);

        switch (type) {
        case DBUS_TYPE_STRING:
        {
            char* tmp;
            dbus_message_iter_get_basic(&args, &tmp);
            printf("Reply: %c - %s\n", type, tmp);
            break;
        }

        case DBUS_TYPE_UINT32:
        {
            dbus_uint32_t id;
            dbus_message_iter_get_basic(&args, &id);
            printf("Reply: %c - %d\n", type, id);
            break;
        }

        default:
            printf("TODO: handle more dbus data type\n");
        }
    }

    if (dbus_message_iter_next(&args)){
        printf("Message has more arguments\n");
    }

    printf("Cleaning up reply message\n");
    dbus_message_unref(msg);
}
Beispiel #9
0
void get_device_properties(DBusConnection * conn, char dev[], int *type)
{
	DBusMessage *msg;
	DBusMessageIter args;
	DBusPendingCall *pending;
	const char *param1 = "org.freedesktop.NetworkManager.Device";
	const char *param2 = "DeviceType";

	msg = dbus_message_new_method_call("org.freedesktop.NetworkManager",	/* Destination */
					   dev,	/* Object Path */
					   "org.freedesktop.DBus.Properties",	/* Interface */
					   "Get");	/* Method name */
	if (NULL == msg) {
		syslog(LOG_ERR, "Message Null\n");
		syslog(LOG_ERR, "Message Null get_device_properties\n");
		exit(1);
	}

	if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &param1,
				      DBUS_TYPE_STRING, &param2,
				      DBUS_TYPE_INVALID)) {
		syslog(LOG_ERR, "Out Of Memory!\n");
		exit(1);
	}

	if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
		syslog(LOG_ERR, "Out Of Memory!\n");
		exit(1);
	}
	dbus_connection_flush(conn);
	dbus_message_unref(msg);
	dbus_pending_call_block(pending);
	msg = dbus_pending_call_steal_reply(pending);
	if (NULL == msg) {
		syslog(LOG_ERR, "Reply Null\n");
		exit(1);
	}

	dbus_pending_call_unref(pending);
	if (!dbus_message_iter_init(msg, &args))
		syslog(LOG_ERR, "Message has no arguments!\n");
	else {
		int arg_type = dbus_message_iter_get_arg_type(&args);
		if (arg_type != DBUS_TYPE_INVALID)
			read_variant(&args, type);
	}
	dbus_message_unref(msg);

}
Beispiel #10
0
int ep_unregister (DBusConnection *c)
{
    DBusMessage     *msg = NULL, *reply = NULL;
    DBusPendingCall *pend;
    int              success = 0;
    char             polrule[512];

    (void) c;

    /* first, let's remove the filter */
    
    snprintf(polrule, sizeof(polrule), "type='signal',interface='%s',"
             "path='%s/%s'", POLICY_DBUS_INTERFACE, POLICY_DBUS_PATH, POLICY_DECISION);
        
    dbus_connection_remove_filter(connection, filter, NULL);
    dbus_bus_remove_match(connection, polrule, NULL);

    /* then unregister */

    msg = dbus_message_new_method_call(POLICY_DBUS_NAME,
            POLICY_DBUS_PATH,
            POLICY_DBUS_INTERFACE,
            "unregister");

    if (msg == NULL) {
        goto failed;
    }

    success = dbus_connection_send_with_reply(connection, msg, &pend, 1000);
    if (!success) {
        goto failed;
    }
    dbus_pending_call_block(pend);
    reply = dbus_pending_call_steal_reply(pend);

    if (!reply || dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) {
        goto failed;
    }

    success = 1;

    /* intentional fallthrough */

 failed:
    dbus_message_unref(msg);
    return success;
}
Beispiel #11
0
void get_device_properties_string(DBusConnection * conn, char *dev_path,
                                  char *prop, char *modem_path)
{
        DBusMessage *msg;
        DBusMessageIter args;
        DBusPendingCall *pending;
        const char *service = "org.freedesktop.NetworkManager.Device";

        msg = dbus_message_new_method_call("org.freedesktop.NetworkManager",
                                           dev_path,
                                           "org.freedesktop.DBus.Properties",
                                           "Get");

        if (NULL == msg) {
                syslog(LOG_ERR, "Message Null\n");
                exit(1);
        }
        if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &service,
                                      DBUS_TYPE_STRING, &prop,
                                      DBUS_TYPE_INVALID)) {
                syslog(LOG_ERR, "Out Of Memory!\n");
                exit(1);
        }
        if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
                syslog(LOG_ERR, "Out Of Memory!\n");
                exit(1);
        }
        dbus_connection_flush(conn);
	dbus_message_unref(msg);
        dbus_pending_call_block(pending);
        msg = dbus_pending_call_steal_reply(pending);
        if (NULL == msg) {
                syslog(LOG_ERR, "Reply Null\n");
                exit(1);
        }
        dbus_pending_call_unref(pending);
        if (!dbus_message_iter_init(msg, &args)) {
                syslog(LOG_ERR, "Message has no arguments!\n");
                memset(modem_path, 0, sizeof(modem_path));
        } else
                read_variant_string(&args, modem_path);

        dbus_message_unref(msg);
}
Beispiel #12
0
message_ptr_t StubBase::get_property(const char* name)
{
   message_ptr_t msg = make_message(dbus_message_new_method_call(busname().c_str(), objectpath(), "org.freedesktop.DBus.Properties", "Get"));
   DBusPendingCall* pending = nullptr;

   DBusMessageIter iter;
   dbus_message_iter_init_append(msg.get(), &iter);

   encode(iter, iface(), name);

   dbus_connection_send_with_reply(conn(), msg.get(), &pending, DBUS_TIMEOUT_USE_DEFAULT);

   dbus_pending_call_block(pending);

   msg.reset(dbus_pending_call_steal_reply(pending));
   dbus_pending_call_unref(pending);

   return msg;
}
Beispiel #13
0
message_ptr_t StubBase::send_request_and_block(const char* method_name, std::function<void(DBusMessageIter&)>&& f, bool is_oneway)
{
    message_ptr_t msg = make_message(dbus_message_new_method_call(busname().c_str(), objectpath(), iface(), method_name));
    DBusPendingCall* pending = nullptr;
    message_ptr_t rc(nullptr, &dbus_message_unref);

    DBusMessageIter iter;
    dbus_message_iter_init_append(msg.get(), &iter);
    
    f(iter);

    if (!is_oneway)
    {
        int timeout = disp().request_timeout();

        if (detail::request_specific_timeout.count() > 0)
            timeout = detail::request_specific_timeout.count();

        dbus_connection_send_with_reply(disp().conn_, msg.get(), &pending, timeout);

        detail::request_specific_timeout = std::chrono::milliseconds(0);

        dbus_pending_call_block(pending);

        rc = make_message(dbus_pending_call_steal_reply(pending));
        dbus_pending_call_unref(pending);

        CallState cs(*rc);

        if (!cs)
           cs.throw_exception();
    }
    else
    {
       // otherwise server would stop reading requests after a while
       dbus_message_set_no_reply(msg.get(), TRUE);

       dbus_connection_send(disp().conn_, msg.get(), nullptr);
       dbus_connection_flush(disp().conn_);
    }

    return rc;
}
Beispiel #14
0
DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, DBusError *error, int timeout)
{
    const char *method = NULL;
    DBusMessage *reply = NULL;
    DBusPendingCall* pending = NULL;

    CRM_ASSERT(dbus_message_get_type (msg) == DBUS_MESSAGE_TYPE_METHOD_CALL);
    method = dbus_message_get_member (msg);

    if (timeout <= 0) {
        timeout = DBUS_TIMEOUT_USE_DEFAULT;
    }

    // send message and get a handle for a reply
    if (!dbus_connection_send_with_reply (connection, msg, &pending, timeout/* -1 is default timeout, aka. DBUS_TIMEOUT_USE_DEFAULT */)) {
        if(error) {
            dbus_error_init(error);
            error->message = "Call to dbus_connection_send_with_reply() failed";
            error->name = "org.clusterlabs.pacemaker.SendFailed";
        }
        crm_err("Error sending %s request", method);
        return NULL;
    }

    dbus_connection_flush(connection);

    if(pending) {
        /* block until we receive a reply */
        dbus_pending_call_block(pending);

        /* get the reply message */
        reply = dbus_pending_call_steal_reply(pending);
    }

    pcmk_dbus_find_error(method, pending, reply, error);

    if(pending) {
        /* free the pending message handle */
        dbus_pending_call_unref(pending);
    }

    return reply;
}
static void
_method_call (DBusConnection *conn,
              int             timeout_milliseconds)
{
    DBusPendingCall *pending;
    DBusMessage *method;
    DBusMessage *reply;
    char *echo = "echo";

    /* send the message */
    method = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService",
                                           "/org/freedesktop/TestSuite",
                                           "org.freedesktop.TestSuite",
                                           "DelayEcho");

    dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL);
    dbus_connection_send_with_reply (conn, method, &pending, timeout_milliseconds);
    dbus_message_unref (method);

    /* block on the message */
    dbus_pending_call_block (pending);

    /* check the reply only to make sure we
       are not getting errors unrelated
       to the block in poll bug */
    reply = dbus_pending_call_steal_reply (pending);

    if (reply == NULL)
    {
        printf ("Bail out! Reply is NULL ***\n");
        exit (1);
    }

    if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
    {
        printf ("Bail out! Reply is error: %s ***\n", dbus_message_get_error_name (reply));
        exit (1);
    }

    dbus_message_unref (reply);
    dbus_pending_call_unref (pending);
}
Beispiel #16
0
static int cdbus_msg_recv(DBusConnection *conn,
			  DBusPendingCall *pending,
			  DBusMessage **msg_out)
{
	DBusMessage *msg;

	/* block until we receive a reply */
	dbus_pending_call_block(pending);

	/* get the reply message */
	msg = dbus_pending_call_steal_reply(pending);
	if (msg == NULL) {
		fprintf(stderr, "Reply Null\n");
		return -ENOMEM;
	}
	/* free the pending message handle */
	dbus_pending_call_unref(pending);
	*msg_out = msg;

	return 0;
}
Beispiel #17
0
void get_connection_apn(DBusConnection * conn, char *conn_path,
                        char *conn_settings)
{
        DBusMessage *msg;
        DBusMessageIter args;
        DBusPendingCall *pending;
        msg = dbus_message_new_method_call("org.freedesktop.NetworkManager",    /* Destination */
                                           conn_path,   /* Object Path */
                                           "org.freedesktop.NetworkManager.Settings.Connection",        /* Interface */
                                           "GetSettings");      /* Method name */
        if (NULL == msg) {
                syslog(LOG_ERR, "Message Null\n");
                syslog(LOG_ERR, "Message Null get_device_properties\n");
                exit(1);
        }

        if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
                syslog(LOG_ERR, "Out Of Memory!\n");
                exit(1);
        }

        dbus_connection_flush(conn);
        dbus_message_unref(msg);
        dbus_pending_call_block(pending);
        msg = dbus_pending_call_steal_reply(pending);
	if (NULL == msg) {
                syslog(LOG_ERR, "Reply Null\n");
                exit(1);
        }

        dbus_pending_call_unref(pending);
        if (!dbus_message_iter_init(msg, &args))
                syslog(LOG_ERR, "Message has no arguments!\n");
        else {
                int arg_type = dbus_message_iter_get_arg_type(&args);
                if (arg_type != DBUS_TYPE_INVALID)
                        read_gsm(&args, conn_settings);
        }
        dbus_message_unref(msg);
}
Beispiel #18
0
bool BashProxy::AddLogEntry(const type::BashLogEntry &log_entry) {
  BOOST_LOG_TRIVIAL(debug) << "bash:detail:BashProxy:AddLogEntry: Function call";
  BOOST_LOG_TRIVIAL(debug) << "bash:detail:BashProxy:AddLogEntry: Call params: "
    << "agent_name=" << log_entry.agent_name << " ; "
    << "time=" << log_entry.utc_time << " ; "
    << "user_id=" << log_entry.user_id << " ; "
    << "command=" << log_entry.command;

  DBusMessage *message;
  message = CreateMethodCall("org.chyla.slas.server",
                             "/org/chyla/slas/bash",
                             "org.chyla.slas.bash",
                             "AddLogEntry");

  DBusMessageIter args;
  InitArgument(message, &args);
  AppendArgument(&args, log_entry.agent_name.c_str());
  AppendArgument(&args, log_entry.utc_time.GetTime().GetHour());
  AppendArgument(&args, log_entry.utc_time.GetTime().GetMinute());
  AppendArgument(&args, log_entry.utc_time.GetTime().GetSecond());
  AppendArgument(&args, log_entry.utc_time.GetDate().GetDay());
  AppendArgument(&args, log_entry.utc_time.GetDate().GetMonth());
  AppendArgument(&args, log_entry.utc_time.GetDate().GetYear());
  AppendArgument(&args, log_entry.user_id);
  AppendArgument(&args, log_entry.command.c_str());

  DBusPendingCall *reply_handle;
  bus_->SendMessage(message, &reply_handle);

  dbus_message_unref(message);

  dbus_pending_call_block(reply_handle);

  message = GetReplyMessage(reply_handle);

  dbus_pending_call_unref(reply_handle);

  dbus_message_unref(message);
}
Beispiel #19
0
void comm_dbus_request_umount(int run_id) {
	DBusMessage *dm;
	DBusPendingCall *pending;
	char *argc;
	
	argc = malloc(11);
	sprintf(argc, "%i", run_id);
	dm = dbus_message_new_method_call(DBP_DBUS_DAEMON_PREFIX,
	    DBP_DBUS_DAEMON_OBJECT, DBP_DBUS_DAEMON_PREFIX, "UMount");
	if (!dm)
		fprintf(stderr, "unable to create message\n");
	dbus_message_append_args(dm, DBUS_TYPE_STRING, &argc, DBUS_TYPE_INVALID);
	dbus_message_append_args(dm, DBUS_TYPE_STRING, &argc, DBUS_TYPE_INVALID);
	dbus_connection_send_with_reply(dc, dm, &pending, -1);
	if (!pending)
		fprintf(stderr, "unable to send message\n");
	dbus_connection_flush(dc);
	dbus_pending_call_block(pending);
	dbus_message_unref(dm);

	return;
}
Beispiel #20
0
int dbus_call_method(DBusConnection* dbus_connection, const char* bus_name,
	const char* path, const char* iface, const char* method,
	char** params, char** ret)
{
	DBusMessage *message;
	DBusMessageIter args;
	DBusPendingCall* pending;
	int param_index, param_count = sizeof(params) / sizeof(char*);

	message = dbus_message_new_method_call(
		bus_name,
		path,
		iface,
		method);

	dbus_message_iter_init_append(message, &args);
	for (param_index = 0; param_index < param_count; param_index++) {
		dbus_message_iter_append_basic(
			&args, DBUS_TYPE_STRING,
			&params[param_index]);
	}

	dbus_connection_send_with_reply(dbus_connection, message, &pending, -1);
	dbus_connection_flush(dbus_connection);
	dbus_message_unref(message);

	dbus_pending_call_block(pending);
	if (ret) message = dbus_pending_call_steal_reply(pending);
	dbus_pending_call_unref(pending);

	if (ret) {
		dbus_message_iter_init(message, &args);
		dbus_message_iter_get_basic(&args, ret);
		dbus_message_unref(message);
	}

	return RET_OK;
}
int dc_render_node_create(struct razer_daemon_controller *controller,int effect_uid,char *name,char *description)
{
	DBusMessage *msg;
	DBusMessageIter args;
	msg = dbus_message_new_method_call("org.voyagerproject.razer.daemon","/","org.voyagerproject.razer.daemon.render_node","create");
	if(!msg)
		dc_error_close(controller,"Error creating Message\n");
	dbus_message_iter_init_append(msg,&args);
	if(!dbus_message_iter_append_basic(&args,DBUS_TYPE_INT32,&effect_uid))
		dc_error_close(controller,"Out of memory!\n"); 
	if(!dbus_message_iter_append_basic(&args,DBUS_TYPE_STRING,&name))
		dc_error_close(controller,"Out of memory!\n"); 
	if(!dbus_message_iter_append_basic(&args,DBUS_TYPE_STRING,&description))
		dc_error_close(controller,"Out of memory!\n"); 
	if(!dbus_connection_send_with_reply(controller->dbus,msg,&controller->pending,-1))
		dc_error_close(controller,"Out of memory!\n"); 
	if(!controller->pending)
		dc_error_close(controller,"No pending call\n"); 
	dbus_connection_flush(controller->dbus);
	dbus_message_unref(msg);

	int render_node_uid = -1;

	dbus_pending_call_block(controller->pending);
	msg = dbus_pending_call_steal_reply(controller->pending);
	if(!msg)
		dc_error_close(controller,"Empty reply\n"); 
	dbus_pending_call_unref(controller->pending);
	if(!dbus_message_iter_init(msg,&args))
		dc_error_close(controller,"Message has no arguments!\n"); 
	else if(dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_INT32) 
		dc_error_close(controller,"Argument is not an int!\n"); 
	else
		dbus_message_iter_get_basic(&args,&render_node_uid);
	dbus_message_unref(msg);   
	return(render_node_uid);
}
MateKeyringResult
gkr_operation_block_and_unref (GkrOperation *op)
{
	DBusPendingCall *pending;
	g_return_val_if_fail (op, BROKEN);

	while ((int) gkr_operation_get_result (op) == INCOMPLETE) {
		if (op->pending) {
			/*
			 * DBus has strange behavior that can complete a pending call
			 * in another thread and somehow does this without calling our
			 * on_pending_call_notify. So guard against this brokenness.
			 */
			pending = op->pending;
			dbus_pending_call_block (pending);
			if (op->pending == pending) {
				g_return_val_if_fail (dbus_pending_call_get_completed (pending), BROKEN);
				on_pending_call_notify (pending, op);
				g_assert (op->pending != pending);
			}
		} else if (op->prompting) {
			dbus_connection_flush (op->conn);
			while (op->prompting && (int) gkr_operation_get_result (op) == INCOMPLETE) {
				if (!dbus_connection_read_write_dispatch (op->conn, 200))
					break;
			}
		} else {
			g_assert_not_reached ();
		}
	}

	/* Make sure we have run our callbacks if complete */
	if (!g_queue_is_empty (&op->callbacks))
		on_complete (op);

	return gkr_operation_unref_get_result (op);
}
void method_callback(DBusPendingCall* pending){
   dbus_bool_t stat;
   dbus_uint32_t level;
   DBusMessage* msg;
   DBusMessageIter args;
   DBusMessageIter list;
   DBusError error;
   char** service_list;
   char* stuff;
   int service_list_len, i;
        
   dbus_error_init (&error);

   // block until we receive a reply
   dbus_pending_call_block(pending);
   
   // get the reply message
   msg = dbus_pending_call_steal_reply(pending);
   if (NULL == msg) {
      fprintf(stderr, "Reply Null\n"); 
      exit(1); 
   }
   // free the pending message handle
   dbus_pending_call_unref(pending);

    /* Extract the data from the reply */
    if (!dbus_message_get_args (msg, &error,
                               DBUS_TYPE_STRING, &service_list,
                               DBUS_TYPE_INVALID )) {
        fprintf (stderr, "Failed to complete 71 get_args call: %s\n", error.message);
        exit (1);
    }

    printf("Got Reply: \n%s\n", service_list);
    // free reply and close connection
    dbus_message_unref(msg);   
}
char *dc_fx_list(struct razer_daemon_controller *controller)
{
	DBusMessage *msg;
	DBusMessageIter args;
	msg = dbus_message_new_method_call("org.voyagerproject.razer.daemon","/","org.voyagerproject.razer.daemon.fx","list");
	if(!msg)
		dc_error_close(controller,"Error creating Message\n");
	if(!dbus_connection_send_with_reply(controller->dbus,msg,&controller->pending,-1))
		dc_error_close(controller,"Out of memory!\n"); 
	if(!controller->pending)
		dc_error_close(controller,"No pending call\n"); 
	dbus_connection_flush(controller->dbus);
	dbus_message_unref(msg);

	char *list = NULL;

	dbus_pending_call_block(controller->pending);
	msg = dbus_pending_call_steal_reply(controller->pending);
	if(!msg)
		dc_error_close(controller,"Empty reply\n"); 
	dbus_pending_call_unref(controller->pending);
	if(!dbus_message_iter_init(msg,&args))
		dc_error_close(controller,"Message has no arguments!\n"); 
	else if(dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING) 
		dc_error_close(controller,"Argument is not a string!\n"); 
	else
		dbus_message_iter_get_basic(&args,&list);
	//if(!dbus_message_iter_next(&args))
	//	dc_error_close(controller,"Message has too few arguments!\n"); 
	//else if(dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_UINT32) 
	//	dc_error_close(controller,"Argument is not int!\n"); 
	//else
	//	dbus_message_iter_get_basic(&args,&level);
	//printf("fx List: %s\n",list);
	dbus_message_unref(msg);   
	return(list);
}
Beispiel #25
0
int get_device_list(DBusConnection * conn, char *dev_list[30])
{
	DBusMessage *msg;
	DBusMessageIter args;
	DBusPendingCall *pending;
	int num_of_dev = 0;

	msg = dbus_message_new_method_call("org.freedesktop.NetworkManager",	/* Destination */
					   "/org/freedesktop/NetworkManager",	/* Object Path */
					   "org.freedesktop.NetworkManager",	/* Interface */
					   "GetDevices");	/* Method */
	if (NULL == msg) {
		syslog(LOG_ERR, "Message Null in \n");
		syslog(LOG_ERR, "Message Null in get_device_list \n");
		exit(1);
	}

	if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) {
		syslog(LOG_ERR, "Out Of Memory!\n");
		exit(1);
	}
	dbus_connection_flush(conn);
	dbus_message_unref(msg);
	dbus_pending_call_block(pending);
	msg = dbus_pending_call_steal_reply(pending);
	if (NULL == msg) {
		syslog(LOG_ERR, "Reply Null\n");
		exit(1);
	}
	dbus_pending_call_unref(pending);
	if (!dbus_message_iter_init(msg, &args))
		syslog(LOG_ERR, "Message has no arguments!\n");
	else
		num_of_dev = read_array(&args, dev_list);
	dbus_message_unref(msg);
	return (num_of_dev);
}
int dc_render_node_parent_get(struct razer_daemon_controller *controller,int render_node_uid)
{
	DBusMessage *msg;
	DBusMessageIter args;
	char *path = str_CreateEmpty();
	path = str_CatFree(path,"/");
	char *suid = str_FromLong(render_node_uid);
	path = str_CatFree(path,suid);
	free(suid);
	msg = dbus_message_new_method_call("org.voyagerproject.razer.daemon",path,"org.voyagerproject.razer.daemon.render_node.parent","get");
	if(!msg)
		dc_error_close(controller,"Error creating Message\n");
	if(!dbus_connection_send_with_reply(controller->dbus,msg,&controller->pending,-1))
		dc_error_close(controller,"Out of memory!\n"); 
	if(!controller->pending)
		dc_error_close(controller,"No pending call\n"); 
	dbus_connection_flush(controller->dbus);
	dbus_message_unref(msg);

	int parent_uid = -1;

	dbus_pending_call_block(controller->pending);
	msg = dbus_pending_call_steal_reply(controller->pending);
	if(!msg)
		dc_error_close(controller,"Empty reply\n"); 
	dbus_pending_call_unref(controller->pending);
	if(!dbus_message_iter_init(msg,&args))
		dc_error_close(controller,"Message has no arguments!\n"); 
	else if(dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_INT32) 
		dc_error_close(controller,"Argument is not an int!\n"); 
	else
		dbus_message_iter_get_basic(&args,&parent_uid);
	dbus_message_unref(msg);   
	free(path);//TODO gets not freed on error
	return(parent_uid);
}
static void* send_msg1(void* data)
{
	DBusConnection* connection;
	DBusError error;
	static int cnt = 1;
	dbus_int32_t no = 5;
	DBusPendingCall* pending;
	DBusMessage* msg1;
	DBusMessage* msg;
	int data_slot = *(int*)data;
	FILE* fp;
	threadData1* thrData;

	dbus_error_init(&error);
	connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
	
	thrData = (threadData1*)dbus_connection_get_data(connection, data_slot);
	if(!thrData)
		return NULL;
	
	pthread_mutex_lock(&thrData->mutex);
	
	msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "simple");
	
	dbus_message_append_args(msg, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID);
	 
	pthread_cond_wait(&thrData->cond,  &thrData->mutex);
	 
	// send message and get a handle for a reply
	   if (!dbus_connection_send_with_reply (connection, msg, &pending, -1)) { // -1 is default timeout
	   thrData->ret = 2;
//	   		exit(1);
	   }   
	   if (NULL == pending) {
	   thrData->ret = 2;
//	      exit(1);
	   } 
	   dbus_connection_flush(connection);
	   
		// free message
	   dbus_message_unref(msg);   
	  
	   // block until we recieve a reply
	   dbus_pending_call_block(pending);
	
	   // get the reply message
	   msg1 = dbus_pending_call_steal_reply(pending);
	   if (NULL == msg1) {
	   thrData->ret = 2;
	
	   }  
	   // free the pending message handle
	   dbus_pending_call_unref(pending);
		 
	  
	   dbus_message_get_args(msg1, &error, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID);
	   
	   fp = fopen("C:\\new.txt", "a+");
	   fprintf(fp, "%d\n", no);
	   fclose(fp);
	    
	   if(no == 9090)
		   {
		   thrData->ret++;
		   }
	   
	 	 
	   // free reply and close connection
	   dbus_message_unref(msg1); 
	   dbus_connection_unref(connection);
	   pthread_mutex_unlock(&thrData->mutex); 
	   return NULL;
}
Beispiel #28
0
/**
 * Initialize a libvlc instance
 * This function initializes a previously allocated libvlc instance:
 *  - CPU detection
 *  - gettext initialization
 *  - message queue, module bank and playlist initialization
 *  - configuration and commandline parsing
 */
int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
                         const char *ppsz_argv[] )
{
    libvlc_priv_t *priv = libvlc_priv (p_libvlc);
    char *       psz_modules = NULL;
    char *       psz_parser = NULL;
    char *       psz_control = NULL;
    playlist_t  *p_playlist = NULL;
    char        *psz_val;

    /* System specific initialization code */
    system_Init();

    /* Initialize the module bank and load the configuration of the
     * main module. We need to do this at this stage to be able to display
     * a short help if required by the user. (short help == main module
     * options) */
    module_InitBank ();

    /* Get command line options that affect module loading. */
    if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, NULL ) )
    {
        module_EndBank (false);
        return VLC_EGENERIC;
    }
    priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" );

    /* Find verbosity from VLC_VERBOSE environment variable */
    {
        char *env = getenv( "VLC_VERBOSE" );
        if( env != NULL )
            priv->i_verbose = atoi( env );
    }

    /* Announce who we are (TODO: only first instance?) */
    msg_Dbg( p_libvlc, "VLC media player - %s", VERSION_MESSAGE );
    msg_Dbg( p_libvlc, "%s", COPYRIGHT_MESSAGE );
    msg_Dbg( p_libvlc, "revision %s", psz_vlc_changeset );
    msg_Dbg( p_libvlc, "configured with %s", CONFIGURE_LINE );

    /* Load the builtins and plugins into the module_bank.
     * We have to do it before config_Load*() because this also gets the
     * list of configuration options exported by each module and loads their
     * default values. */
    size_t module_count = module_LoadPlugins (p_libvlc);

    /*
     * Override default configuration with config file settings
     */
    if( !var_InheritBool( p_libvlc, "ignore-config" ) )
    {
        if( var_InheritBool( p_libvlc, "reset-config" ) )
            config_SaveConfigFile( p_libvlc ); /* Save default config */
        else
            config_LoadConfigFile( p_libvlc );
    }

    /*
     * Override configuration with command line settings
     */
    int vlc_optind;
    if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) )
    {
#ifdef WIN32
        MessageBox (NULL, TEXT("The command line options could not be parsed.\n"
                    "Make sure they are valid."), TEXT("VLC media player"),
                    MB_OK|MB_ICONERROR);
#endif
        module_EndBank (true);
        return VLC_EGENERIC;
    }
    priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" );

    /*
     * Support for gettext
     */
#if defined( ENABLE_NLS ) \
     && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
    vlc_bindtextdomain (PACKAGE_NAME);
#endif
    /*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
    msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );

    if (config_PrintHelp (VLC_OBJECT(p_libvlc)))
    {
        module_EndBank (true);
        return VLC_EEXITSUCCESS;
    }

    if( module_count <= 1 )
    {
        msg_Err( p_libvlc, "No plugins found! Check your VLC installation.");
        module_EndBank (true);
        return VLC_ENOITEM;
    }

#ifdef HAVE_DAEMON
    /* Check for daemon mode */
    if( var_InheritBool( p_libvlc, "daemon" ) )
    {
        char *psz_pidfile = NULL;

        if( daemon( 1, 0) != 0 )
        {
            msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
            module_EndBank (true);
            return VLC_EEXIT;
        }
        b_daemon = true;

        /* lets check if we need to write the pidfile */
        psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
        if( psz_pidfile != NULL )
        {
            FILE *pidfile;
            pid_t i_pid = getpid ();
            msg_Dbg( p_libvlc, "PID is %d, writing it to %s",
                               i_pid, psz_pidfile );
            pidfile = vlc_fopen( psz_pidfile,"w" );
            if( pidfile != NULL )
            {
                utf8_fprintf( pidfile, "%d", (int)i_pid );
                fclose( pidfile );
            }
            else
            {
                msg_Err( p_libvlc, "cannot open pid file for writing: %s (%m)",
                         psz_pidfile );
            }
        }
        free( psz_pidfile );
    }
#endif

/* FIXME: could be replaced by using Unix sockets */
#ifdef HAVE_DBUS

#define MPRIS_APPEND "/org/mpris/MediaPlayer2/TrackList/Append"
#define MPRIS_BUS_NAME "org.mpris.MediaPlayer2.vlc"
#define MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2"
#define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList"

    dbus_threads_init_default();

    if( var_InheritBool( p_libvlc, "one-instance" )
    || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" )
      && var_InheritBool( p_libvlc, "started-from-file" ) ) )
    {
        /* Initialise D-Bus interface, check for other instances */
        DBusConnection  *p_conn = NULL;
        DBusError       dbus_error;

        dbus_error_init( &dbus_error );

        /* connect to the session bus */
        p_conn = dbus_bus_get( DBUS_BUS_SESSION, &dbus_error );
        if( !p_conn )
        {
            msg_Err( p_libvlc, "Failed to connect to D-Bus session daemon: %s",
                    dbus_error.message );
            dbus_error_free( &dbus_error );
        }
        else
        {
            /* check if VLC is available on the bus
             * if not: D-Bus control is not enabled on the other
             * instance and we can't pass MRLs to it */
            if( !dbus_bus_name_has_owner( p_conn, MPRIS_BUS_NAME, &dbus_error ) )
            {
                if( dbus_error_is_set( &dbus_error ) )
                {
                    msg_Err( p_libvlc, "D-Bus error: %s", dbus_error.message );
                    dbus_error_free( &dbus_error );
                }
                else
                    msg_Dbg( p_libvlc, "No Media Player is running. "
                            "Continuing normally." );
            }
            else
            {
                int i_input;
                DBusMessage* p_dbus_msg = NULL;
                DBusMessageIter dbus_args;
                DBusPendingCall* p_dbus_pending = NULL;
                dbus_bool_t b_play;

                msg_Warn( p_libvlc, "Another Media Player is running. Exiting");

                for( i_input = vlc_optind; i_input < i_argc;i_input++ )
                {
                    /* Skip input options, we can't pass them through D-Bus */
                    if( ppsz_argv[i_input][0] == ':' )
                    {
                        msg_Warn( p_libvlc, "Ignoring option %s",
                                  ppsz_argv[i_input] );
                        continue;
                    }

                    /* We need to resolve relative paths in this instance */
                    char *psz_mrl;
                    if( strstr( psz_mrl, "://" ) )
                        psz_mrl = strdup( ppsz_argv[i_input] );
                    else
                        psz_mrl = vlc_path2uri( ppsz_argv[i_input], NULL );
                    const char *psz_after_track = MPRIS_APPEND;

                    if( psz_mrl == NULL )
                        continue;
                    msg_Dbg( p_libvlc, "Adds %s to the running Media Player",
                             psz_mrl );

                    p_dbus_msg = dbus_message_new_method_call(
                        MPRIS_BUS_NAME, MPRIS_OBJECT_PATH,
                        MPRIS_TRACKLIST_INTERFACE, "AddTrack" );

                    if ( NULL == p_dbus_msg )
                    {
                        msg_Err( p_libvlc, "D-Bus problem" );
                        free( psz_mrl );
                        system_End( );
                        exit( 1 );
                    }

                    /* append MRLs */
                    dbus_message_iter_init_append( p_dbus_msg, &dbus_args );
                    if ( !dbus_message_iter_append_basic( &dbus_args,
                                DBUS_TYPE_STRING, &psz_mrl ) )
                    {
                        dbus_message_unref( p_dbus_msg );
                        free( psz_mrl );
                        system_End( );
                        exit( 1 );
                    }
                    free( psz_mrl );

                    if( !dbus_message_iter_append_basic( &dbus_args,
                                DBUS_TYPE_OBJECT_PATH, &psz_after_track ) )
                    {
                        dbus_message_unref( p_dbus_msg );
                        system_End( );
                        exit( 1 );
                    }

                    b_play = TRUE;
                    if( var_InheritBool( p_libvlc, "playlist-enqueue" ) )
                        b_play = FALSE;

                    if ( !dbus_message_iter_append_basic( &dbus_args,
                                DBUS_TYPE_BOOLEAN, &b_play ) )
                    {
                        dbus_message_unref( p_dbus_msg );
                        system_End( );
                        exit( 1 );
                    }

                    /* send message and get a handle for a reply */
                    if ( !dbus_connection_send_with_reply ( p_conn,
                                p_dbus_msg, &p_dbus_pending, -1 ) )
                    {
                        msg_Err( p_libvlc, "D-Bus problem" );
                        dbus_message_unref( p_dbus_msg );
                        system_End( );
                        exit( 1 );
                    }

                    if ( NULL == p_dbus_pending )
                    {
                        msg_Err( p_libvlc, "D-Bus problem" );
                        dbus_message_unref( p_dbus_msg );
                        system_End( );
                        exit( 1 );
                    }
                    dbus_connection_flush( p_conn );
                    dbus_message_unref( p_dbus_msg );
                    /* block until we receive a reply */
                    dbus_pending_call_block( p_dbus_pending );
                    dbus_pending_call_unref( p_dbus_pending );
                } /* processes all command line MRLs */

                /* bye bye */
                system_End( );
                exit( 0 );
            }
        }
        /* we unreference the connection when we've finished with it */
        if( p_conn ) dbus_connection_unref( p_conn );
    }

#undef MPRIS_APPEND
#undef MPRIS_BUS_NAME
#undef MPRIS_OBJECT_PATH
#undef MPRIS_TRACKLIST_INTERFACE

#endif // HAVE_DBUS

    /*
     * Message queue options
     */
    /* Last chance to set the verbosity. Once we start interfaces and other
     * threads, verbosity becomes read-only. */
    var_Create( p_libvlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
    if( var_InheritBool( p_libvlc, "quiet" ) )
    {
        var_SetInteger( p_libvlc, "verbose", -1 );
        priv->i_verbose = -1;
    }
    vlc_threads_setup( p_libvlc );

    if( priv->b_color )
        priv->b_color = var_InheritBool( p_libvlc, "color" );

    vlc_CPU_dump( VLC_OBJECT(p_libvlc) );
    vlc_object_set_name( p_libvlc, "main" );

    priv->b_stats = var_InheritBool( p_libvlc, "stats" );

    /*
     * Initialize hotkey handling
     */
    priv->actions = vlc_InitActions( p_libvlc );

    /* Create a variable for showing the fullscreen interface */
    var_Create( p_libvlc, "intf-toggle-fscontrol", VLC_VAR_BOOL );
    var_SetBool( p_libvlc, "intf-toggle-fscontrol", true );

    /* Create a variable for the Boss Key */
    var_Create( p_libvlc, "intf-boss", VLC_VAR_VOID );

    /* Create a variable for showing the main interface */
    var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL );

    /* Create a variable for showing the right click menu */
    var_Create( p_libvlc, "intf-popupmenu", VLC_VAR_BOOL );

    /* variables for signalling creation of new files */
    var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING );
    var_Create( p_libvlc, "record-file", VLC_VAR_STRING );

    /* some default internal settings */
    var_Create( p_libvlc, "window", VLC_VAR_STRING );
    var_Create( p_libvlc, "user-agent", VLC_VAR_STRING );
    var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" );

    /* Initialize playlist and get commandline files */
    p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) );
    if( !p_playlist )
    {
        msg_Err( p_libvlc, "playlist initialization failed" );
        module_EndBank (true);
        return VLC_EGENERIC;
    }

    /* System specific configuration */
    system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );

#if defined(MEDIA_LIBRARY)
    /* Get the ML */
    if( var_GetBool( p_libvlc, "load-media-library-on-startup" ) )
    {
        priv->p_ml = ml_Create( VLC_OBJECT( p_libvlc ), NULL );
        if( !priv->p_ml )
        {
            msg_Err( p_libvlc, "ML initialization failed" );
            return VLC_EGENERIC;
        }
    }
    else
    {
        priv->p_ml = NULL;
    }
#endif

    /* Add service discovery modules */
    psz_modules = var_InheritString( p_libvlc, "services-discovery" );
    if( psz_modules )
    {
        char *p = psz_modules, *m;
        while( ( m = strsep( &p, " :," ) ) != NULL )
            playlist_ServicesDiscoveryAdd( p_playlist, m );
        free( psz_modules );
    }

#ifdef ENABLE_VLM
    /* Initialize VLM if vlm-conf is specified */
    psz_parser = var_CreateGetNonEmptyString( p_libvlc, "vlm-conf" );
    if( psz_parser )
    {
        priv->p_vlm = vlm_New( p_libvlc );
        if( !priv->p_vlm )
            msg_Err( p_libvlc, "VLM initialization failed" );
    }
    free( psz_parser );
#endif

    /*
     * Load background interfaces
     */
    psz_modules = var_CreateGetNonEmptyString( p_libvlc, "extraintf" );
    psz_control = var_CreateGetNonEmptyString( p_libvlc, "control" );

    if( psz_modules && psz_control )
    {
        char* psz_tmp;
        if( asprintf( &psz_tmp, "%s:%s", psz_modules, psz_control ) != -1 )
        {
            free( psz_modules );
            psz_modules = psz_tmp;
        }
    }
    else if( psz_control )
    {
        free( psz_modules );
        psz_modules = strdup( psz_control );
    }

    psz_parser = psz_modules;
    while ( psz_parser && *psz_parser )
    {
        char *psz_module, *psz_temp;
        psz_module = psz_parser;
        psz_parser = strchr( psz_module, ':' );
        if ( psz_parser )
        {
            *psz_parser = '\0';
            psz_parser++;
        }
        if( asprintf( &psz_temp, "%s,none", psz_module ) != -1)
        {
            intf_Create( p_libvlc, psz_temp );
            free( psz_temp );
        }
    }
    free( psz_modules );
    free( psz_control );

    /*
     * Always load the hotkeys interface if it exists
     */
    intf_Create( p_libvlc, "hotkeys,none" );

    if( var_InheritBool( p_libvlc, "file-logging" )
#ifdef HAVE_SYSLOG_H
        && !var_InheritBool( p_libvlc, "syslog" )
#endif
        )
    {
        intf_Create( p_libvlc, "logger,none" );
    }
#ifdef HAVE_SYSLOG_H
    if( var_InheritBool( p_libvlc, "syslog" ) )
    {
        char *logmode = var_CreateGetNonEmptyString( p_libvlc, "logmode" );
        var_SetString( p_libvlc, "logmode", "syslog" );
        intf_Create( p_libvlc, "logger,none" );

        if( logmode )
        {
            var_SetString( p_libvlc, "logmode", logmode );
            free( logmode );
        }
        var_Destroy( p_libvlc, "logmode" );
    }
#endif

    if( var_InheritBool( p_libvlc, "network-synchronisation") )
    {
        intf_Create( p_libvlc, "netsync,none" );
    }

#ifdef __APPLE__
    var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
    var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER );
    var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER );
    var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER );
    var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER );
    var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER );
    var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
    var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
    var_Create( p_libvlc, "drawable-nsobject", VLC_VAR_ADDRESS );
#endif
#if defined (WIN32) || defined (__OS2__)
    var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_INTEGER );
#endif

    /*
     * Get input filenames given as commandline arguments.
     * We assume that the remaining parameters are filenames
     * and their input options.
     */
    GetFilenames( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );

    /*
     * Get --open argument
     */
    psz_val = var_InheritString( p_libvlc, "open" );
    if ( psz_val != NULL )
    {
        playlist_AddExt( p_playlist, psz_val, NULL, PLAYLIST_INSERT, 0,
                         -1, 0, NULL, 0, true, pl_Unlocked );
        free( psz_val );
    }

    return VLC_SUCCESS;
}
Beispiel #29
0
void registerService()
{
    DBusMessage* msg;
    DBusMessageIter args;
    DBusConnection* conn;
    DBusError err;
    DBusPendingCall* pending;
    dbus_uint32_t level;
    int fd;

    char path[PATH_MAX];
    const char *ret_string = 0;

    // initialiset the errors
    dbus_error_init(&err);
    conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
    if (dbus_error_is_set(&err)) {
       fprintf(stderr, "Connection Error (%s)\n", err.message);
       dbus_error_free(&err);
       return;
    }

    // create a new method call and check for errors
    msg = dbus_message_new_method_call("org.bluez",         // target for the method call
                                       "/",                 // object to call on
                                       "org.bluez.Manager", // interface to call on
                                       "DefaultAdapter");   // method name

    if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) {
       fprintf(stderr, "dbus-send failed: Out Of Memory!\n");
       return;
    }

    dbus_connection_flush(conn);

    dbus_message_unref(msg);
    dbus_pending_call_block(pending);
    msg = dbus_pending_call_steal_reply(pending);
    dbus_pending_call_unref(pending);

    if (!dbus_message_iter_init(msg, &args))
       fprintf(stderr, "Message has no arguments!\n");
    else if (DBUS_TYPE_OBJECT_PATH != dbus_message_iter_get_arg_type(&args))
       fprintf(stderr, "Argument is not an object path!\n");
    else
       dbus_message_iter_get_basic(&args, &ret_string);

    if(!ret_string){
        fprintf(stderr, "Failed to get bluez path\n");
        return;
    }

    strcpy(path, ret_string);
    // change path to use any
    strcpy(rindex(path, '/'), "/any");

    printf("Using path: %s\n", path);   

    dbus_message_unref(msg);

    // create a new method call and check for errors
    msg = dbus_message_new_method_call("org.bluez",         // target for the method call
                                       path,                // object to call on
                                       "org.bluez.Service", // interface to call on
                                       "AddRecord");        // method name

    if(!dbus_message_append_args(msg, DBUS_TYPE_STRING, &xmldefn, DBUS_TYPE_INVALID)){
        fprintf(stderr, "Failed to append args\n");
        return;
    }

    // send message and get a handle for a reply
    if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { // -1 is default timeout
       fprintf(stderr, "Out Of Memory!\n");
       exit(1);
    }
    dbus_connection_flush(conn);

    // free message
    dbus_message_unref(msg);

    // block until we receive a reply
    dbus_pending_call_block(pending);

    // get the reply message
    msg = dbus_pending_call_steal_reply(pending);
    if (NULL == msg) {
       fprintf(stderr, "Reply Null\n");
       return;
    }
    // free the pending message handle
    dbus_pending_call_unref(pending);

    // read the parameters
    if (!dbus_message_iter_init(msg, &args))
       fprintf(stderr, "Message has no arguments!\n");
    else if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&args))
       fprintf(stderr, "Argument is not int!\n");
    else
       dbus_message_iter_get_basic(&args, &level);

    printf("Got handle: 0x%x\n", level);

    // free reply
    dbus_message_unref(msg);

    dbus_connection_get_socket(conn, &fd);
    addfd(head, fd, POLLHUP|POLLNVAL, dbus_error, 0x0);
}
Beispiel #30
0
// Synchronous, should probably be fixed
uint8_t SetHUDDisplayMsgReq(
    uint32_t manueverIcon,
    uint16_t manueverDistance,
    uint8_t manueverDistanceUnit,
    uint16_t speedLimit,
    uint8_t speedLimitUnit)
{
    DBusMessage *msg = dbus_message_new_method_call("com.jci.vbs.navi", "/com/jci/vbs/navi",
                                                    "com.jci.vbs.navi","SetHUDDisplayMsgReq");
    DBusPendingCall *pending = nullptr;

    if (!msg) {
        assert(false && "failed to create message");
    }

    DBusMessageIter iter;
    dbus_message_iter_init_append(msg, &iter);

    DBusMessageIter sub;
    if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_STRUCT, nullptr, &sub)) {
       assert(false && "failed to initialize sub-iterator");
    }

    {
        dbus_bool_t result = TRUE;
        result &= dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT32, &manueverIcon);
        result &= dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT16, &manueverDistance);
        result &= dbus_message_iter_append_basic(&sub, DBUS_TYPE_BYTE, &manueverDistanceUnit);
        result &= dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT16, &speedLimit);
        result &= dbus_message_iter_append_basic(&sub, DBUS_TYPE_BYTE, &speedLimitUnit);

        if (!result) {
            assert(false && "failed to append arguments to struct");
        }
    }

    if (!dbus_message_iter_close_container(&iter, &sub)) {
        assert(false && "failed to close container");
    }

    if (!dbus_connection_send_with_reply(service_bus, msg, &pending, -1)) {
        assert(false && "failed to send message");
    }

    dbus_connection_flush(service_bus);
    dbus_message_unref(msg);

    dbus_pending_call_block(pending);
    msg = dbus_pending_call_steal_reply(pending);
    if (!msg) {
       assert(false && "received null reply");
    }

    uint8_t result;
    if (!dbus_message_get_args(msg, nullptr, DBUS_TYPE_BYTE, &result,
                                             DBUS_TYPE_INVALID)) {
        assert(false && "failed to get result");
    }

    dbus_message_unref(msg);

    return result;
}