1 /*******************************************************************
2 uLan Communication - addresss server
6 (C) Copyright 1996-2004 by Pavel Pisa - project originator
7 http://cmp.felk.cvut.cz/~pisa
8 (C) Copyright 1996-2004 PiKRON Ltd.
10 (C) Copyright 2002-2004 Petr Smolik
13 The uLan driver project can be used and distributed
14 in compliance with any of next licenses
15 - GPL - GNU Public License
16 See file COPYING for details.
17 - LGPL - Lesser GNU Public License
18 - MPL - Mozilla Public License
19 - and other licenses added by project originator
21 Code can be modified and re-distributed under any combination
22 of the above listed licenses. If contributor does not agree with
23 some of the licenses, he/she can delete appropriate line.
24 WARNING: if you delete all lines, you are not allowed to
25 distribute code or sources in any form.
26 *******************************************************************/
33 #include <sys/types.h>
34 #include <ul_netbase.h>
35 #include <orbit/orbit.h>
39 #define GSA_OFFSET(_type,_member) \
40 ((int)&(((_type*)0)->_member))
45 int terminate_flg = 0;
47 ul_asd_context_t ul_cont[1];
49 void sig_usr(int signo) {
50 if ((signo==SIGTERM) || (signo==SIGINT)) {
55 static int daemon_init(void) {
59 if ((pid = fork()) < 0) {
63 exit(0); /* parent vanishes */
79 printf("usage: ul_asd <parameters>\n");
80 printf(" -d, --uldev <name> name of uLan device [%s]\n", ul_cont->ul_dev_name);
81 printf(" -n, --ns <name> addr of name server\n");
82 printf(" [%s]\n", ul_cont->orbit_ns_addr);
83 printf(" -i, --ip <name> IP address for communication with client(s)\n");
84 printf(" [%s]\n", ul_cont->orbit_orb_iiop_ipname);
85 printf(" -c, --conf <name> name of configuration file [%s]\n", ul_cont->conf_filename);
87 printf(" -D, --daemon starting like deamon\n");
89 printf(" -V, --version show version\n");
90 printf(" -h, --help this usage screen\n");
96 static struct option long_opts[] = {
97 { "uldev", 1, 0, 'd' },
98 { "conf", 1, 0, 'c' },
102 { "daemon", 0, 0, 'D' },
104 { "version",0,0, 'V' },
105 { "help", 0, 0, 'h' },
110 #ifndef HAS_GETOPT_LONG
111 while ((opt = getopt(ul_cont->argc, ul_cont->argv, "d:c:n:i:DVh")) != EOF)
113 while ((opt = getopt_long(ul_cont->argc, ul_cont->argv, "d:c:n:i:DVh",
114 &long_opts[0], NULL)) != EOF)
118 ul_cont->ul_dev_name=optarg;
121 strcpy(ul_cont->conf_filename,optarg);
124 ul_cont->orbit_ns_addr=optarg;
127 ul_cont->orbit_orb_iiop_ipname=optarg;
135 printf("uLan address server - version 0.1\n");
140 exit(opt == 'h' ? 0 : 1);
144 int main(int argc, char *argv[])
148 char *filename="ul_asd.xml";
150 /**********************************************************/
151 /* Initizalization */
152 ul_cont->argc = argc;
153 ul_cont->argv = argv;
154 ul_cont->ul_dev_name=UL_DEV_NAME;
155 ul_cont->orbit_ns_addr=ORBIT_NS_ADDR_DEFAULT;
156 ul_cont->orbit_orb_iiop_ipname=ORBIT_ORBIIOPIPName_DEFAULT;
159 GetWindowsDirectory(basename,sizeof(basename));
161 strcpy(basename,"/etc/ulan/");
163 sprintf(ul_cont->conf_filename,"%s%s",basename,filename);
171 if (ul_asd_server_init(ul_cont)<0)
174 if (ul_asd_net_init(ul_cont)<0)
177 // g_thread_init (NULL);
178 ul_cont->mutex = g_mutex_new ();
180 ul_asd_conf_load(NULL,ul_cont);
182 /**********************************************************/
184 ul_cont->ul_server_thread = g_thread_create ((GThreadFunc) ul_asd_server_run,
188 ul_cont->ul_net_thread = g_thread_create ((GThreadFunc) ul_asd_net_run,
193 /**********************************************************/
194 /* init signal handling */
195 signal(SIGINT, sig_usr);
196 signal(SIGHUP, sig_usr);
198 while(!terminate_flg) {
202 //stop & cleanup server thread
203 ul_asd_server_stop(ul_cont);
204 g_thread_join (ul_cont->ul_server_thread);
205 ul_asd_server_cleanup(ul_cont);
207 //stop & cleanup net thread
208 ul_asd_net_stop(ul_cont);
209 g_thread_join (ul_cont->ul_net_thread);
210 ul_asd_net_cleanup(ul_cont);
212 g_mutex_free (ul_cont->mutex);