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>
29 #define LOG_FILE "c:\\logs\\signal_log1.txt"
30 #include "std_log_result.h"
31 #define LOG_FILENAME_LINE __FILE__, __LINE__
33 void create_xml(int result)
38 testResultXml("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);
89 for(cnt=0;cnt< MAX_SIGNALS;cnt++)
91 #if defined(__WINSCW__) || defined(__WINS__)
92 strcpy(exe_param,"Z:\\sys\\bin\\Simple_Server.exe ");
94 strcpy(exe_param,"C:\\sys\\bin\\Simple_Server.exe ");
96 strcat(exe_param, names[cnt]);
97 strcat(exe_param, obj_path[cnt]);
98 fp[cnt] = popen(exe_param, "r");
101 std_log(LOG_FILENAME_LINE, "fp %d is NULL", cnt);
105 //wait till the server is up
106 fd = open(fifopath, O_RDONLY);
109 err = read(fd, buf, 20);
114 std_log(LOG_FILENAME_LINE, "Error in FIFO open().");
118 if (strcmp("done", buf))
120 std_log(LOG_FILENAME_LINE,"done is not returned from server.");
127 dbus_error_init(&error);
128 connection = dbus_bus_get(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");
137 std_log(LOG_FILENAME_LINE,"msg is NULL");
142 if(!dbus_message_append_args(msg, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
144 std_log(LOG_FILENAME_LINE, "Fail to append args");
148 dbus_bus_add_match(connection, "type='signal',interface='Test.Signal.Send1'",&error);
150 if(dbus_error_is_set(&error))
151 return handle_error(&error);
153 std_log(LOG_FILENAME_LINE, "Registering path");
154 if(!dbus_connection_register_object_path (connection, "/Test/Signal/Object1", &vtable, NULL))
156 std_log(LOG_FILENAME_LINE, "Registering path fail");
160 std_log(LOG_FILENAME_LINE, "Requesting name");
161 if(!dbus_bus_request_name (connection, "test.Signal.Send1", DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &error) == -1)
163 std_log(LOG_FILENAME_LINE, "Requesting name fail");
168 dbus_connection_send(connection, msg, NULL);
169 dbus_connection_flush(connection);
171 dbus_message_unref(msg);
174 std_log(LOG_FILENAME_LINE, "First part over");
179 dbus_connection_read_write(connection, 0);
181 msg = dbus_connection_pop_message(connection);
188 std_log(LOG_FILENAME_LINE, "Message Detected");
190 if(dbus_message_is_signal(msg, "Test.Signal.Send1", "second"))
192 if(!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
194 std_log(LOG_FILENAME_LINE, "Error while retriving arguments :: %s", error.name);
195 dbus_error_free(&error);
199 std_log(LOG_FILENAME_LINE, "Got %d MSG : %s", cnt, str);
205 dbus_message_unref(msg);
208 dbus_connection_unref(connection);
209 for(cnt=0;cnt<MAX_SIGNALS;cnt++)
213 std_log(LOG_FILENAME_LINE, "Test Successful");