-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_data.c
103 lines (86 loc) · 2.26 KB
/
get_data.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "get_data.h"
void create_get_data()
{
if (sc_bus_init(SC_BUS_THREADED_IOLOOP, SC_BUS_TRACE_LEVEL_WARNING, NULL) < 0)
{
printf( "ERROR sc_bus_init" );
}
if (sc_bus_declare_name(DIAGNOSTIC_MENU_DBUS_SERVICE_DBUS) < 0)
{
printf( "ERROR sc_bus_declare_name" );
}
}
void destroy_get_data()
{
sc_bus_undeclare_name(DIAGNOSTIC_MENU_DBUS_SERVICE_DBUS);
sc_bus_exit();
}
void set_method(char* mtd)
{
method = mtd;
}
char* get_method_value_by_string()
{
DBusMessage *msg;
DBusMessage *reply;
DBusMessageIter iter_base;
char *param;
dbus_bool_t result = FALSE;
msg = dbus_message_new_method_call(DIAGNOSTIC_MENU_DBUS_SERVICE_DBUS, DIAGNOSTIC_MENU_DBUS_PATH_DBUS,DIAGNOSTIC_MENU_DBUS_INTERFACE_MONITORING, method.c_str());
if (msg == NULL)
{
printf( "dbus_message_new_method_call failed on no memory" );
return "";
}
if (sc_bus_method_call (msg, NULL, NULL, (void *)&reply) < 0)
{
printf( "sc_bus_method_call for " method " failed" );
return "";
}
result = dbus_message_iter_init(reply, &iter_base);
if(result == FALSE)
{
printf( "dbus_message_iter_init for " method " failed" );
return "";
}
dbus_message_iter_get_basic(&iter_base, ¶m);
dbus_message_unref (reply);
printf(::string data(param);
return data;
}
char* get_method_value_by_array(int length)
{
DBusMessage *msg;
DBusMessage *reply;
DBusMessageIter iter_base,sub;
char *param;
msg = dbus_message_new_method_call(DIAGNOSTIC_MENU_DBUS_SERVICE_DBUS, DIAGNOSTIC_MENU_DBUS_PATH_DBUS,DIAGNOSTIC_MENU_DBUS_INTERFACE_MONITORING, method.c_str());
if (msg == NULL)
{
printf( "dbus_message_new_method_call failed on no memory" );
return "";
}
if (sc_bus_method_call (msg, NULL, NULL, (void *)&reply) < 0)
{
printf("sc_bus_method_call for " " failed" );
return "";
}
dbus_message_iter_init(reply, &iter_base);
if (dbus_message_iter_get_arg_type(&iter_base)==DBUS_TYPE_ARRAY)
{
dbus_message_iter_recurse (&iter_base, &sub);
if (dbus_message_iter_get_arg_type(&sub)==DBUS_TYPE_BYTE)
{
dbus_message_iter_get_fixed_array (&sub, ¶m, &length);
printf("%ss",string data(param));
return data;
}
}
return "";
}
int main(){
//get_data get_data;
create_get_data();
destroy_get_data();
return 0;
}