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.
24 #ifndef CONFIG_ORTE_RT
26 onMgrAppRemoteNew(const struct ORTEAppInfo *appInfo, void *param) {
27 printf("%s 0x%x-0x%x was accepted\n",
28 (appInfo->appId & 0x3)==MANAGER ? "manager" : "application",
29 appInfo->hostId,appInfo->appId);
34 onMgrAppDelete(const struct ORTEAppInfo *appInfo, void *param) {
35 printf("%s 0x%x-0x%x was deleted\n",
36 (appInfo->appId & 0x3)==MANAGER ? "manager" : "application",
37 appInfo->hostId,appInfo->appId);
40 #ifdef CONFIG_ORTE_UNIX
41 pthread_mutex_t mutex;
42 void sig_usr(int signo) {
43 if ((signo==SIGTERM) || (signo==SIGINT)) {
44 pthread_mutex_unlock(&mutex);
47 void waitForEndingCommand(void) {
48 pthread_mutex_init(&mutex, NULL);
49 pthread_mutex_lock(&mutex);
50 signal(SIGTERM,sig_usr);
51 signal(SIGINT,sig_usr);
52 pthread_mutex_lock(&mutex);
54 static int daemon_init(void) {
57 if ((pid = fork()) < 0) {
61 exit(0); /* parent vanishes */
73 static void usage(void) {
74 printf("usage: ORTEManager <parameters> \n");
75 printf(" -p, --peer <IPAdd:IPAdd:...> possible locations of fellow managers\n");
76 printf(" -k, --key <IPAdd:IPAdd:...> manualy assigned manager's keys\n");
77 printf(" -d, --domain <domain> working manager domain\n");
78 printf(" -v, --verbosity <level> set verbosity level SECTION, up to LEVEL:...\n");
79 printf(" examples: ORTEManager -v 51.7:32.5 sections 51 and 32\n");
80 printf(" ORTEManager -v ALL.7 all sections up to level 7\n");
81 printf(" -R, --refresh <s> refresh period in second(s)\n");
82 printf(" -P, --purge <s> purge time in second(s)\n");
83 #ifdef CONFIG_ORTE_UNIX
84 printf(" -D, --daemon start program like daemon\n");
86 printf(" -E, --expiration <s> expiration time of manager in second(s)\n");
87 printf(" -e, --events register event system\n");
88 printf(" -l, --logfile <filename> set log file name\n");
89 printf(" -V, --version show version\n");
90 printf(" -h, --help this usage screen\n");
93 int main(int argc,char *argv[]) {
94 static struct option long_opts[] = {
97 { "domain",1,0, 'd' },
98 { "verbosity",1,0, 'v' },
99 { "refresh",1,0, 'R' },
100 { "purge",1,0, 'P' },
101 #ifdef CONFIG_ORTE_UNIX
102 { "daemon",1,0, 'D' },
104 { "expiration",1,0, 'E' },
105 { "events",0,0, 'e' },
106 { "logfile",1,0, 'l' },
107 { "version",0,0, 'V' },
108 { "help", 0, 0, 'h' },
113 int32_t opt,domain=ORTE_DEFAULT_DOMAIN;
114 Boolean daemon=ORTE_FALSE;
115 ORTEDomainAppEvents *events=NULL;
118 ORTEDomainPropDefaultGet(&dp);
120 while ((opt = getopt_long(argc, argv, "k:p:d:v:R:E:P:l:VhDe",&long_opts[0], NULL)) != EOF) {
123 dp.mgrs=strdup(optarg);
126 dp.keys=strdup(optarg);
129 domain=strtol(optarg,NULL,0);
132 ORTEVerbositySetOptions(optarg);
135 NtpTimeAssembFromMs(dp.baseProp.refreshPeriod,strtol(optarg,NULL,0),0);
138 NtpTimeAssembFromMs(dp.baseProp.purgeTime,strtol(optarg,NULL,0),0);
141 NtpTimeAssembFromMs(dp.baseProp.expirationTime,strtol(optarg,NULL,0),0);
144 events=(ORTEDomainAppEvents*)malloc(sizeof(ORTEDomainAppEvents));
145 ORTEDomainInitEvents(events);
146 events->onMgrNew=onMgrAppRemoteNew;
147 events->onAppRemoteNew=onMgrAppRemoteNew;
148 events->onMgrDelete=onMgrAppDelete;
149 events->onAppDelete=onMgrAppDelete;
152 ORTEVerbositySetLogFile(optarg);
155 printf("Ocera Real-Time Ethernet (%s).\n",dp.version);
164 exit(opt == 'h' ? 0 : 1);
168 d=ORTEDomainMgrCreate(domain,&dp,events,ORTE_TRUE);
172 #ifdef CONFIG_ORTE_UNIX
177 ORTEDomainStart(d,ORTE_TRUE,ORTE_FALSE,ORTE_FALSE);
178 #ifndef CONFIG_ORTE_UNIX
179 d->taskSend.terminate=ORTE_FALSE;
180 ORTEAppSendThread(d);
182 ORTEDomainStart(d,ORTE_FALSE,ORTE_FALSE,ORTE_TRUE);
184 #ifdef CONFIG_ORTE_UNIX
185 waitForEndingCommand();
186 ORTEDomainMgrDestroy(d);
199 MODULE_PARM(verbosity,"1s");
200 MODULE_PARM_DESC(verbosity,"set verbosity level SECTION, up to LEVEL:...");
202 MODULE_PARM(peer,"1s");
203 MODULE_PARM_DESC(peer,"possible locations of fellow managers");
204 MODULE_LICENSE("GPL");
209 domainDestroy(void *arg) {
211 ORTEDomainMgrDestroy(d);
221 ORTEDomainPropDefaultGet(&dp);
222 ORTEVerbositySetOptions(verbosity);
224 d=ORTEDomainMgrCreate(ORTE_DEFAULT_DOMAIN,&dp,NULL,ORTE_FALSE);
228 cleanup_module(void) {
230 pthread_create(&thread,NULL,&domainDestroy,NULL);
231 pthread_join(thread,NULL);