-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbus_sender.c
81 lines (60 loc) · 1.58 KB
/
dbus_sender.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include <dbus/dbus.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
static DBusConnection *conn = NULL;
int main()
{
DBusMessage *msg;
DBusMessage *reply;
DBusError error;
char *msg_str = "aaaaaaa";
char *msg_in;
struct timeval start, end;
// gettimeofday(&start, NULL);
dbus_error_init(&error);
conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
if(dbus_error_is_set(&error)){
printf("Error connecting to the daemon bus %s", error.message);
dbus_error_free(&error);
}
dbus_connection_set_exit_on_disconnect(conn, FALSE);
msg = dbus_message_new_method_call("org.eslab.injung",
"/",
"org.eslab.injung",
"Get");
if(NULL == msg){
printf("Message NULL\n");
exit(1);
}
dbus_message_append_args(msg,
DBUS_TYPE_STRING, &(msg_str),
DBUS_TYPE_INVALID);
dbus_error_init(&error);
if(conn == NULL){
printf("Why null? \n");
conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
}
gettimeofday(&start,NULL);
reply = dbus_connection_send_with_reply_and_block(conn, msg, 500, &error);
if(reply == NULL){
printf("Get NULL reply\n");
printf("Error: %s\n", error.message);
}
dbus_error_free(&error);
dbus_message_unref(msg);
dbus_message_get_args(reply,NULL,
DBUS_TYPE_STRING,&(msg_in),
DBUS_TYPE_INVALID);
dbus_message_unref(reply);
printf("Received message: %s\n",msg_in);
// gettimeofday(&end, NULL);
// printf("%ld\n", ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));
return 0;
}