First public contribution.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #include <dbus/dbus.h>
27 #define LOG_FILE "c:\\logs\\dbus_signal_log1.txt"
28 #include "std_log_result.h"
29 #define LOG_FILENAME_LINE __FILE__, __LINE__
33 void create_xml(int result)
38 testResultXml("dbus_signal");
42 int handle_error(DBusError* error)
44 std_log(LOG_FILENAME_LINE, "%s", error->name);
45 std_log(LOG_FILENAME_LINE, "%s", error->message);
46 dbus_error_free(error);
54 DBusConnection* connection;
57 dbus_int32_t arg_int32 = 1010;
58 DBusObjectPathVTable vtable =
62 char* str = "DBus Testing. hjgfyh34348#$!%^45678901730952698376092869876DBus Testing. hjgfyh34348#$!%^~!@#$%^&*()_+`-=<>?:{},./;'[]45678901730952698376092869876";
63 FILE* fp[MAX_SIGNALS]={NULL};
67 char names[][40]={"test.Signal.Send3 ",
69 "test.Signal.Send5 "};
70 char obj_path[][40]={"/Test/Signal/Object3",
71 "/Test/Signal/Object4",
72 "/Test/Signal/Object5"};
74 const char* fifopath = "C:\\signalfifo.file";
76 err = mkfifo(fifopath, 0666);
79 // probably file already exists, delete the file
82 err = mkfifo(fifopath, 0666);
90 for(cnt=0;cnt< MAX_SIGNALS;cnt++)
92 #if defined(__WINSCW__) || defined(__WINS__)
93 strcpy(exe_param,"Z:\\sys\\bin\\Simple_Server.exe ");
95 strcpy(exe_param,"C:\\sys\\bin\\Simple_Server.exe ");
97 strcat(exe_param, names[cnt]);
98 strcat(exe_param, obj_path[cnt]);
99 fp[cnt] = popen(exe_param, "r");
102 std_log(LOG_FILENAME_LINE, "fp %d is NULL", cnt);
106 //wait till the server is up
107 fd = open(fifopath, O_RDONLY);
110 err = read(fd, buf, 20);
115 std_log(LOG_FILENAME_LINE, "Error in FIFO open().");
119 if (strcmp("done", buf))
121 std_log(LOG_FILENAME_LINE,"done is not returned from server.");
127 dbus_error_init(&error);
128 connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
130 if(!connection || dbus_error_is_set(&error))
131 return handle_error(&error);
133 msg = dbus_message_new_signal("/Test/Signal/Object", "Test.Signal.Send", "first");
138 std_log(LOG_FILENAME_LINE, "msg is NULL");
143 if(!dbus_message_append_args(msg, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
145 std_log(LOG_FILENAME_LINE, "Fail to append args");
149 dbus_bus_add_match(connection, "type='signal',interface='Test.Signal.Send1'",&error);
151 if(dbus_error_is_set(&error))
152 return handle_error(&error);
154 std_log(LOG_FILENAME_LINE, "Registering path");
155 if(!dbus_connection_register_object_path (connection, "/Test/Signal/Object1", &vtable, NULL))
157 std_log(LOG_FILENAME_LINE, "Registering path fail");
161 std_log(LOG_FILENAME_LINE, "Requesting name");
162 if(!dbus_bus_request_name (connection, "test.Signal.Send1", DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &error) == -1)
164 std_log(LOG_FILENAME_LINE, "Requesting name fail");
169 dbus_connection_send(connection, msg, NULL);
170 dbus_connection_flush(connection);
172 dbus_message_unref(msg);
175 std_log(LOG_FILENAME_LINE, "First part over");
180 dbus_connection_read_write(connection, 0);
182 msg = dbus_connection_pop_message(connection);
189 std_log(LOG_FILENAME_LINE, "Message Detected");
191 if(dbus_message_is_signal(msg, "Test.Signal.Send1", "second"))
193 if(!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
195 std_log(LOG_FILENAME_LINE, "Error while retriving arguments :: %s", error.name);
196 dbus_error_free(&error);
200 std_log(LOG_FILENAME_LINE, "Got %d MSG : %s", cnt, str);
206 dbus_message_unref(msg);
209 dbus_connection_close(connection);
210 dbus_connection_unref(connection);
212 for(cnt=0;cnt<MAX_SIGNALS;cnt++)
216 std_log(LOG_FILENAME_LINE, "Test Successful");