31
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <fcntl.h>
|
|
19 |
#include <string.h>
|
|
20 |
#include "test-utils.h"
|
|
21 |
|
|
22 |
void handle_error(char* str)
|
|
23 |
{
|
|
24 |
FILE* fp = fopen("C:\\error.txt", "a+");
|
|
25 |
if(fp)
|
|
26 |
{
|
|
27 |
fwrite(str, strlen(str), 1, fp);
|
|
28 |
fclose(fp);
|
|
29 |
}
|
|
30 |
}
|
|
31 |
int main()
|
|
32 |
{
|
|
33 |
DBusError error;
|
|
34 |
DBusConnection* connection;
|
|
35 |
DBusMessage* msg;
|
|
36 |
DBusObjectPathVTable vtable =
|
|
37 |
{
|
|
38 |
NULL,NULL,NULL
|
|
39 |
};
|
|
40 |
|
|
41 |
char* str;
|
|
42 |
char buf[80];
|
|
43 |
char* buf1;
|
|
44 |
//fifo file used by test cases: signal, dbus_signal
|
|
45 |
const char* fifopath = "C:\\signalfifo.file";
|
|
46 |
int err;
|
|
47 |
int fd;
|
|
48 |
dbus_error_init(&error);
|
|
49 |
|
|
50 |
connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
|
|
51 |
|
|
52 |
if(dbus_error_is_set(&error))
|
|
53 |
{
|
|
54 |
sprintf(buf, "\nError Occured :: %s\n%s", error.name, error.message);
|
|
55 |
handle_error(buf);
|
|
56 |
return 1;
|
|
57 |
}
|
|
58 |
|
|
59 |
dbus_bus_add_match(connection, "type='signal',interface='Test.Signal.Send'",&error);
|
|
60 |
|
|
61 |
if(dbus_error_is_set(&error))
|
|
62 |
{
|
|
63 |
sprintf(buf, "\nError :: %s\n%s", error.name, error.message);
|
|
64 |
handle_error(buf);
|
|
65 |
return 1;
|
|
66 |
}
|
|
67 |
/*
|
|
68 |
if(!dbus_connection_register_object_path (connection, "/Test/Signal/Object", &vtable, NULL))
|
|
69 |
{
|
|
70 |
return 1;
|
|
71 |
}
|
|
72 |
|
|
73 |
if(!dbus_bus_request_name (connection, "test.Signal.Send", DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &error) == -1)
|
|
74 |
{
|
|
75 |
return 1;
|
|
76 |
}
|
|
77 |
*/
|
|
78 |
fd = open(fifopath, O_WRONLY);
|
|
79 |
if (fd > 0)
|
|
80 |
{
|
|
81 |
buf1 = "done";
|
|
82 |
err = write(fd, buf1, strlen(buf1));
|
|
83 |
close(fd);
|
|
84 |
}
|
|
85 |
while(TRUE)
|
|
86 |
{
|
|
87 |
dbus_connection_read_write(connection, 0);
|
|
88 |
|
|
89 |
msg = dbus_connection_pop_message(connection);
|
|
90 |
|
|
91 |
if(msg == NULL)
|
|
92 |
{
|
|
93 |
sleep(1);
|
|
94 |
continue;
|
|
95 |
}
|
|
96 |
|
|
97 |
printf( "Message Detected");
|
|
98 |
|
|
99 |
if(DBUS_MESSAGE_TYPE_SIGNAL == dbus_message_get_type(msg))
|
|
100 |
{
|
|
101 |
printf( "\nMessage is Signal.");
|
|
102 |
}
|
|
103 |
|
|
104 |
if(DBUS_MESSAGE_TYPE_METHOD_CALL == dbus_message_get_type(msg))
|
|
105 |
{
|
|
106 |
printf( "Message is Method call.");
|
|
107 |
}
|
|
108 |
|
|
109 |
if(dbus_message_is_signal(msg, "Test.Signal.Send", "first"))
|
|
110 |
{
|
|
111 |
printf("\n\nGot the new Signal.\n");
|
|
112 |
if(!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
|
|
113 |
{
|
|
114 |
return 1;
|
|
115 |
}
|
|
116 |
printf( "\nSTRING received is %s", str);
|
|
117 |
break;
|
|
118 |
}
|
|
119 |
dbus_message_unref(msg);
|
|
120 |
}
|
|
121 |
|
|
122 |
printf( "\nCreating Message");
|
|
123 |
strcat(str, "simple_Server");
|
|
124 |
msg = dbus_message_new_signal("/Test/Signal/Object1", "Test.Signal.Send1", "second");
|
|
125 |
|
|
126 |
if(!msg)
|
|
127 |
{
|
|
128 |
handle_error("\nmsg is NULL.");
|
|
129 |
return 1;
|
|
130 |
}
|
|
131 |
|
|
132 |
if(!dbus_message_append_args(msg, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
|
|
133 |
{
|
|
134 |
handle_error("\nAppending arg fail.");
|
|
135 |
return 1;
|
|
136 |
}
|
|
137 |
dbus_connection_send(connection, msg, NULL);
|
|
138 |
dbus_connection_flush(connection);
|
|
139 |
dbus_connection_unref(connection);
|
|
140 |
return 0;
|
|
141 |
}
|