2 * $Id: ORTEManager.c,v 0.0.0.1 2003/10/07
4 * DEBUG: section Manager
5 * AUTHOR: Petr Smolik petr.smolik@wo.cz
7 * ORTE - OCERA Real-Time Ethernet http://www.ocera.org/
8 * --------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
29 #include <sys/types.h>
39 onMgrAppRemoteNew(const struct ORTEAppInfo *appInfo, void *param) {
40 printf("%s 0x%x-0x%x was accepted\n",
41 (appInfo->appId & 0x3)==MANAGER ? "manager" : "application",
42 appInfo->hostId,appInfo->appId);
47 onMgrAppDelete(const struct ORTEAppInfo *appInfo, void *param) {
48 printf("%s 0x%x-0x%x was deleted\n",
49 (appInfo->appId & 0x3)==MANAGER ? "manager" : "application",
50 appInfo->hostId,appInfo->appId);
54 pthread_mutex_t mutex;
55 void sig_usr(int signo) {
56 if ((signo==SIGTERM) || (signo==SIGINT)) {
57 pthread_mutex_unlock(&mutex);
60 void waitForEndingCommand(void) {
61 pthread_mutex_init(&mutex, NULL);
62 pthread_mutex_lock(&mutex);
63 signal(SIGTERM,sig_usr);
64 signal(SIGINT,sig_usr);
65 pthread_mutex_lock(&mutex);
67 static int daemon_init(void) {
70 if ((pid = fork()) < 0) {
74 exit(0); /* parent vanishes */
86 static void usage(void) {
87 printf("usage: ORTEManager <parameters> \n");
88 printf(" -p, --peer <IPAdd:IPAdd:...> possible locations of fellow managers\n");
89 printf(" -k, --key <IPAdd> manager's additional key\n");
90 printf(" -d, --domain <domain> working manager domain\n");
91 printf(" -v, --verbosity <level> set verbosity level SECTION, up to LEVEL:...\n");
92 printf(" examples: ORTEManager -v 51,7:32,5 sections 51 and 32\n");
93 printf(" ORTEManager -v ALL,7 all sections up to level 7\n");
94 printf(" -R, --refresh <s> refresh period in second(s)\n");
95 printf(" -P, --purge <s> purge time in second(s)\n");
97 printf(" -D, --daemon start program like daemon\n");
99 printf(" -E, --expiration <s> expiration time of manager in second(s)\n");
100 printf(" -e, --events register event system\n");
101 printf(" -l, --logfile <filename> set log file name\n");
102 printf(" -V, --version show version\n");
103 printf(" -h, --help this usage screen\n");
106 int main(int argc,char *argv[]) {
107 static struct option long_opts[] = {
110 { "domain",1,0, 'd' },
111 { "verbosity",1,0, 'v' },
112 { "refresh",1,0, 'R' },
113 { "purge",1,0, 'P' },
115 { "daemon",1,0, 'D' },
117 { "expiration",1,0, 'E' },
118 { "events",0,0, 'e' },
119 { "logfile",1,0, 'l' },
120 { "version",0,0, 'V' },
121 { "help", 0, 0, 'h' },
126 int32_t opt,domain=ORTE_DEFAULT_DOMAIN;
127 Boolean daemon=ORTE_FALSE,start_sending_thread=ORTE_FALSE;
128 ORTEDomainAppEvents *events=NULL;
131 start_sending_thread=ORTE_TRUE;
135 ORTEDomainPropDefaultGet(&dp);
137 while ((opt = getopt_long(argc, argv, "k:p:d:v:R:E:P:l:VhDe",&long_opts[0], NULL)) != EOF) {
140 dp.mgrs=strdup(optarg);
143 dp.mgrAddKey=StringToIPAddress(strdup(optarg));
146 domain=strtol(optarg,NULL,0);
149 ORTEVerbositySetOptions(optarg);
152 NtpTimeAssembFromMs(dp.baseProp.refreshPeriod,strtol(optarg,NULL,0),0);
155 NtpTimeAssembFromMs(dp.baseProp.purgeTime,strtol(optarg,NULL,0),0);
158 NtpTimeAssembFromMs(dp.baseProp.expirationTime,strtol(optarg,NULL,0),0);
161 events=(ORTEDomainAppEvents*)malloc(sizeof(ORTEDomainAppEvents));
162 ORTEDomainInitEvents(events);
163 events->onMgrNew=onMgrAppRemoteNew;
164 events->onAppRemoteNew=onMgrAppRemoteNew;
165 events->onMgrDelete=onMgrAppDelete;
166 events->onAppDelete=onMgrAppDelete;
169 ORTEVerbositySetLogFile(optarg);
171 printf("Ocera Real-Time Ethernet (%s).\n",dp.version);
180 exit(opt == 'h' ? 0 : 1);
184 d=ORTEDomainMgrCreate(domain,&dp,events,start_sending_thread);
193 if (!start_sending_thread)
194 ORTEAppSendThread(d);
197 waitForEndingCommand();
198 ORTEDomainMgrDestroy(d);