1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ofdbus/dbus/tsrc/testapps/exes/signal/src/signal.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,216 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include<stdio.h>
1.23 +#include <dbus/dbus.h>
1.24 +#include <stdlib.h>
1.25 +#include <string.h>
1.26 +#include <fcntl.h>
1.27 +#include <unistd.h>
1.28 +#include <sys/stat.h>
1.29 +
1.30 +#define MAX_SIGNALS 3
1.31 +
1.32 +#define LOG_FILE "c:\\logs\\signal_log1.txt"
1.33 +#include "std_log_result.h"
1.34 +#define LOG_FILENAME_LINE __FILE__, __LINE__
1.35 +
1.36 +void create_xml(int result)
1.37 + {
1.38 + if(result)
1.39 + assert_failed = 1;
1.40 +
1.41 + testResultXml("signal");
1.42 + close_log_file();
1.43 + }
1.44 +
1.45 +int handle_error(DBusError* error)
1.46 + {
1.47 + std_log(LOG_FILENAME_LINE,"%s", error->name);
1.48 + std_log(LOG_FILENAME_LINE,"%s", error->message);
1.49 + dbus_error_free(error);
1.50 + create_xml(1);
1.51 + return 1;
1.52 + }
1.53 +
1.54 +
1.55 +int main()
1.56 +{
1.57 + DBusConnection* connection;
1.58 + DBusError error;
1.59 + DBusMessage* msg;
1.60 + dbus_int32_t arg_int32 = 1010;
1.61 + DBusObjectPathVTable vtable =
1.62 + {
1.63 + NULL,NULL,NULL
1.64 + };
1.65 + char* str = "DBus Testing. hjgfyh34348#$!%^45678901730952698376092869876DBus Testing. hjgfyh34348#$!%^~!@#$%^&*()_+`-=<>?:{},./;'[]45678901730952698376092869876";
1.66 + FILE* fp[MAX_SIGNALS]={NULL};
1.67 + char buf[20] = "";
1.68 + int cnt=0;
1.69 + char exe_param[100];
1.70 + char names[][40]={"test.Signal.Send3 ",
1.71 + "test.Signal.Send4 ",
1.72 + "test.Signal.Send5 "};
1.73 + char obj_path[][40]={"/Test/Signal/Object3",
1.74 + "/Test/Signal/Object4",
1.75 + "/Test/Signal/Object5"};
1.76 + int fd;
1.77 + const char* fifopath = "C:\\signalfifo.file";
1.78 + int err;
1.79 + err = mkfifo(fifopath, 0666);
1.80 + if (err != 0)
1.81 + {
1.82 + // probably file already exists, delete the file
1.83 + unlink(fifopath);
1.84 + // try once more..
1.85 + err = mkfifo(fifopath, 0666);
1.86 + if (err != 0)
1.87 + {
1.88 + create_xml(1);
1.89 + return 1;
1.90 + }
1.91 + }
1.92 + for(cnt=0;cnt< MAX_SIGNALS;cnt++)
1.93 + {
1.94 + #if defined(__WINSCW__) || defined(__WINS__)
1.95 + strcpy(exe_param,"Z:\\sys\\bin\\Simple_Server.exe ");
1.96 + #else
1.97 + strcpy(exe_param,"C:\\sys\\bin\\Simple_Server.exe ");
1.98 + #endif
1.99 + strcat(exe_param, names[cnt]);
1.100 + strcat(exe_param, obj_path[cnt]);
1.101 + fp[cnt] = popen(exe_param, "r");
1.102 + if(!fp[cnt])
1.103 + {
1.104 + std_log(LOG_FILENAME_LINE, "fp %d is NULL", cnt);
1.105 + create_xml(1);
1.106 + return 1;
1.107 + }
1.108 + //wait till the server is up
1.109 + fd = open(fifopath, O_RDONLY);
1.110 + if (fd> 0)
1.111 + {
1.112 + err = read(fd, buf, 20);
1.113 + close(fd);
1.114 + }
1.115 + else
1.116 + {
1.117 + std_log(LOG_FILENAME_LINE, "Error in FIFO open().");
1.118 + create_xml(1);
1.119 + return 1;
1.120 + }
1.121 + if (strcmp("done", buf))
1.122 + {
1.123 + std_log(LOG_FILENAME_LINE,"done is not returned from server.");
1.124 + create_xml(1);
1.125 + return 1;
1.126 + }
1.127 + }
1.128 +
1.129 + unlink(fifopath);
1.130 + dbus_error_init(&error);
1.131 + connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
1.132 +
1.133 + if(!connection || dbus_error_is_set(&error))
1.134 + return handle_error(&error);
1.135 +
1.136 + msg = dbus_message_new_signal("/Test/Signal/Object", "Test.Signal.Send", "first");
1.137 +
1.138 + if(!msg)
1.139 + {
1.140 + std_log(LOG_FILENAME_LINE,"msg is NULL");
1.141 + create_xml(1);
1.142 + return 1;
1.143 + }
1.144 +
1.145 + if(!dbus_message_append_args(msg, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
1.146 + {
1.147 + std_log(LOG_FILENAME_LINE, "Fail to append args");
1.148 + create_xml(1);
1.149 + return 1;
1.150 + }
1.151 + dbus_bus_add_match(connection, "type='signal',interface='Test.Signal.Send1'",&error);
1.152 +
1.153 + if(dbus_error_is_set(&error))
1.154 + return handle_error(&error);
1.155 +
1.156 + std_log(LOG_FILENAME_LINE, "Registering path");
1.157 + if(!dbus_connection_register_object_path (connection, "/Test/Signal/Object1", &vtable, NULL))
1.158 + {
1.159 + std_log(LOG_FILENAME_LINE, "Registering path fail");
1.160 + create_xml(1);
1.161 + return 1;
1.162 + }
1.163 + std_log(LOG_FILENAME_LINE, "Requesting name");
1.164 + if(!dbus_bus_request_name (connection, "test.Signal.Send1", DBUS_NAME_FLAG_ALLOW_REPLACEMENT, &error) == -1)
1.165 + {
1.166 + std_log(LOG_FILENAME_LINE, "Requesting name fail");
1.167 + create_xml(1);
1.168 + return 1;
1.169 + }
1.170 +
1.171 + dbus_connection_send(connection, msg, NULL);
1.172 + dbus_connection_flush(connection);
1.173 +
1.174 + dbus_message_unref(msg);
1.175 +
1.176 + str = "";
1.177 + std_log(LOG_FILENAME_LINE, "First part over");
1.178 +
1.179 + cnt=0;
1.180 + while(TRUE)
1.181 + {
1.182 + dbus_connection_read_write(connection, 0);
1.183 +
1.184 + msg = dbus_connection_pop_message(connection);
1.185 +
1.186 + if(msg == NULL)
1.187 + {
1.188 + continue;
1.189 + }
1.190 +
1.191 + std_log(LOG_FILENAME_LINE, "Message Detected");
1.192 +
1.193 + if(dbus_message_is_signal(msg, "Test.Signal.Send1", "second"))
1.194 + {
1.195 + if(!dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
1.196 + {
1.197 + std_log(LOG_FILENAME_LINE, "Error while retriving arguments :: %s", error.name);
1.198 + dbus_error_free(&error);
1.199 + create_xml(1);
1.200 + return 1;
1.201 + }
1.202 + std_log(LOG_FILENAME_LINE, "Got %d MSG : %s", cnt, str);
1.203 + cnt++;
1.204 + if(cnt==MAX_SIGNALS)
1.205 + break;
1.206 + }
1.207 +
1.208 + dbus_message_unref(msg);
1.209 + }
1.210 +
1.211 + dbus_connection_unref(connection);
1.212 + for(cnt=0;cnt<MAX_SIGNALS;cnt++)
1.213 + if(fp[cnt])
1.214 + pclose(fp[cnt]);
1.215 +
1.216 + std_log(LOG_FILENAME_LINE, "Test Successful");
1.217 + create_xml(0);
1.218 + return 0;
1.219 +}