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.
22 #include <orte_config.h>
25 #ifdef CONFIG_ORTE_RTAI
26 #include <linux/module.h>
28 #include <rtai_sched.h>
38 #include <sys/types.h>
49 #ifndef CONFIG_ORTE_RT
51 onMgrAppRemoteNew(const struct ORTEAppInfo *appInfo, void *param) {
52 printf("%s 0x%x-0x%x was accepted\n",
53 (appInfo->appId & 0x3)==MANAGER ? "manager" : "application",
54 appInfo->hostId,appInfo->appId);
59 onMgrAppDelete(const struct ORTEAppInfo *appInfo, void *param) {
60 printf("%s 0x%x-0x%x was deleted\n",
61 (appInfo->appId & 0x3)==MANAGER ? "manager" : "application",
62 appInfo->hostId,appInfo->appId);
66 pthread_mutex_t mutex;
67 void sig_usr(int signo) {
68 if ((signo==SIGTERM) || (signo==SIGINT)) {
69 pthread_mutex_unlock(&mutex);
72 void waitForEndingCommand(void) {
73 pthread_mutex_init(&mutex, NULL);
74 pthread_mutex_lock(&mutex);
75 signal(SIGTERM,sig_usr);
76 signal(SIGINT,sig_usr);
77 pthread_mutex_lock(&mutex);
79 static int daemon_init(void) {
82 if ((pid = fork()) < 0) {
86 exit(0); /* parent vanishes */
98 static void usage(void) {
99 printf("usage: ORTEManager <parameters> \n");
100 printf(" -p, --peer <IPAdd:IPAdd:...> possible locations of fellow managers\n");
101 printf(" -k, --key <IPAdd> manager's additional key\n");
102 printf(" -d, --domain <domain> working manager domain\n");
103 printf(" -v, --verbosity <level> set verbosity level SECTION, up to LEVEL:...\n");
104 printf(" examples: ORTEManager -v 51,7:32,5 sections 51 and 32\n");
105 printf(" ORTEManager -v ALL,7 all sections up to level 7\n");
106 printf(" -R, --refresh <s> refresh period in second(s)\n");
107 printf(" -P, --purge <s> purge time in second(s)\n");
109 printf(" -D, --daemon start program like daemon\n");
111 printf(" -E, --expiration <s> expiration time of manager in second(s)\n");
112 printf(" -e, --events register event system\n");
113 printf(" -l, --logfile <filename> set log file name\n");
114 printf(" -V, --version show version\n");
115 printf(" -h, --help this usage screen\n");
118 int main(int argc,char *argv[]) {
119 static struct option long_opts[] = {
122 { "domain",1,0, 'd' },
123 { "verbosity",1,0, 'v' },
124 { "refresh",1,0, 'R' },
125 { "purge",1,0, 'P' },
127 { "daemon",1,0, 'D' },
129 { "expiration",1,0, 'E' },
130 { "events",0,0, 'e' },
131 { "logfile",1,0, 'l' },
132 { "version",0,0, 'V' },
133 { "help", 0, 0, 'h' },
138 int32_t opt,domain=ORTE_DEFAULT_DOMAIN;
139 Boolean daemon=ORTE_FALSE,start_sending_thread=ORTE_FALSE;
140 ORTEDomainAppEvents *events=NULL;
143 start_sending_thread=ORTE_TRUE;
147 ORTEDomainPropDefaultGet(&dp);
149 while ((opt = getopt_long(argc, argv, "k:p:d:v:R:E:P:l:VhDe",&long_opts[0], NULL)) != EOF) {
152 dp.mgrs=strdup(optarg);
155 dp.mgrAddKey=StringToIPAddress(strdup(optarg));
158 domain=strtol(optarg,NULL,0);
161 ORTEVerbositySetOptions(optarg);
164 NtpTimeAssembFromMs(dp.baseProp.refreshPeriod,strtol(optarg,NULL,0),0);
167 NtpTimeAssembFromMs(dp.baseProp.purgeTime,strtol(optarg,NULL,0),0);
170 NtpTimeAssembFromMs(dp.baseProp.expirationTime,strtol(optarg,NULL,0),0);
173 events=(ORTEDomainAppEvents*)malloc(sizeof(ORTEDomainAppEvents));
174 ORTEDomainInitEvents(events);
175 events->onMgrNew=onMgrAppRemoteNew;
176 events->onAppRemoteNew=onMgrAppRemoteNew;
177 events->onMgrDelete=onMgrAppDelete;
178 events->onAppDelete=onMgrAppDelete;
181 ORTEVerbositySetLogFile(optarg);
184 printf("Ocera Real-Time Ethernet (%s).\n",dp.version);
193 exit(opt == 'h' ? 0 : 1);
197 d=ORTEDomainMgrCreate(domain,&dp,events,ORTE_TRUE);
206 ORTEDomainStart(d,ORTE_TRUE,ORTE_FALSE,ORTE_FALSE);
207 if (!start_sending_thread) {
208 ORTEAppSendThread(d);
210 ORTEDomainStart(d,ORTE_FALSE,ORTE_FALSE,ORTE_TRUE);
213 waitForEndingCommand();
214 ORTEDomainMgrDestroy(d);
222 MODULE_LICENSE("GPL");
226 createManager(void) {
228 ORTEVerbositySetOptions("ALL,2");
229 d=ORTEDomainMgrCreate(ORTE_DEFAULT_DOMAIN,NULL,NULL,ORTE_FALSE);
238 cleanup_module(void) {
240 ORTEDomainMgrDestroy(d);