connman-list-services.c

Client to list networks/services from connman.

Client to list networks/services from connman.

//Compile with:
// gcc -o connman-list-services connman-list-services.c `pkg-config --cflags --libs eldbus ecore`
#include "Eldbus.h"
#include <Ecore.h>
static void
on_services_get(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
{
Eldbus_Message_Iter *array, *entry;
const char *errname, *errmsg;
if (eldbus_message_error_get(msg, &errname, &errmsg))
{
fprintf(stderr, "Error: %s %s\n", errname, errmsg);
return;
}
if (!eldbus_message_arguments_get(msg, "a(oa{sv})", &array))
{
fprintf(stderr, "Error: could not get array\n");
return;
}
while (eldbus_message_iter_get_and_next(array, 'r', &entry))
{
Eldbus_Message_Iter *properties, *dict_entry;
const char *path;
if (!eldbus_message_iter_arguments_get(entry, "oa{sv}", &path, &properties))
{
fprintf(stderr, "Error: could not get entry contents\n");
return;
}
printf("service: %s\n", path);
while (eldbus_message_iter_get_and_next(properties, 'e', &dict_entry))
{
const char *key;
if (!eldbus_message_iter_arguments_get(dict_entry, "sv", &key,
&variant))
{
fprintf(stderr,
"Error: could not get property contents\n");
return;
}
printf("\t%s: type %s\n", key,
/* TODO: get the value from variant */
}
}
}
int
main(void)
{
Eldbus_Proxy *manager;
Eldbus_Pending *pending;
conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
if (!conn)
{
fprintf(stderr, "Error: could not get system bus\n");
return EXIT_FAILURE;
}
obj = eldbus_object_get(conn, "net.connman", "/");
if (!obj)
{
fprintf(stderr, "Error: could not get object\n");
return EXIT_FAILURE;
}
manager = eldbus_proxy_get(obj, "net.connman.Manager");
if (!manager)
{
fprintf(stderr, "Error: could not get proxy\n");
return EXIT_FAILURE;
}
pending = eldbus_proxy_call(manager, "GetServices", on_services_get, NULL,
-1, "");
if (!pending)
{
fprintf(stderr, "Error: could not call\n");
return EXIT_FAILURE;
}
return 0;
}
EAPI int ecore_shutdown(void)
Shuts down connections, signal handlers sockets etc.
Definition: ecore.c:371
EAPI int ecore_init(void)
Sets up connections, signal handlers, sockets etc.
Definition: ecore.c:230
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1311
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
void eldbus_connection_unref(Eldbus_Connection *conn)
Decrement connection reference count.
Definition: eldbus_core.c:1306
Eldbus_Connection * eldbus_connection_get(Eldbus_Connection_Type type)
Establish a connection to bus and integrate it with the ecore main loop.
Definition: eldbus_core.c:1102
struct _Eldbus_Message_Iter Eldbus_Message_Iter
Represents an iterator over a complex message type (array, dict, struct, or variant).
Definition: Eldbus.h:181
struct _Eldbus_Message Eldbus_Message
Represents the way data is sent and received in DBus.
Definition: Eldbus.h:173
EAPI int eldbus_shutdown(void)
Shutdown eldbus.
Definition: eldbus_core.c:246
struct _Eldbus_Pending Eldbus_Pending
Represents a message that has been sent but has not yet reached its destination.
Definition: Eldbus.h:188
EAPI int eldbus_init(void)
Initialize eldbus.
Definition: eldbus_core.c:128
Eina_Bool eldbus_message_iter_get_and_next(Eldbus_Message_Iter *iter, char signature,...)
Useful when iterating over arrays.
Definition: eldbus_message.c:736
char * eldbus_message_iter_signature_get(Eldbus_Message_Iter *iter)
Returns the current signature of a message iterator.
Definition: eldbus_message.c:605
Eina_Bool eldbus_message_iter_arguments_get(Eldbus_Message_Iter *iter, const char *signature,...)
Get data from Eldbus_Message_Iter, for each complete type must have a pointer to store his value,...
Definition: eldbus_message.c:842
Eina_Bool eldbus_message_error_get(const Eldbus_Message *msg, const char **name, const char **text)
Get the error text and name from a Eldbus_Message.
Definition: eldbus_message.c:233
Eina_Bool eldbus_message_arguments_get(const Eldbus_Message *msg, const char *signature,...)
Get the arguments from an Eldbus_Message.
Definition: eldbus_message.c:274
Eldbus_Object * eldbus_object_get(Eldbus_Connection *conn, const char *bus, const char *path)
Get an object of the given bus and path.
Definition: eldbus_object.c:188
void eldbus_object_unref(Eldbus_Object *obj)
Decrease object reference.
Definition: eldbus_object.c:250
Eldbus_Pending * eldbus_proxy_call(Eldbus_Proxy *proxy, const char *member, Eldbus_Message_Cb cb, const void *cb_data, double timeout, const char *signature,...)
Call a method in proxy.
Definition: eldbus_proxy.c:621
Eldbus_Proxy * eldbus_proxy_get(Eldbus_Object *obj, const char *interface)
Get a proxy of the following interface name in a Eldbus_Object.
Definition: eldbus_proxy.c:208
void eldbus_proxy_unref(Eldbus_Proxy *proxy)
Decrease proxy reference.
Definition: eldbus_proxy.c:263
struct _Eldbus_Connection Eldbus_Connection
Represents a connection of one the type of connection with the DBus daemon.
Definition: Eldbus.h:227
struct _Eldbus_Proxy Eldbus_Proxy
Represents a client object bound to an interface.
Definition: Eldbus.h:221
struct _Eldbus_Object Eldbus_Object
Represents an object path already attached with bus name or unique id.
Definition: Eldbus.h:233