]> rtime.felk.cvut.cz Git - orte.git/blob - orte/examples/spy/ortespy.c
liborte - domain multicast upgrade
[orte.git] / orte / examples / spy / ortespy.c
1 /*
2  *  $Id: ortespy.c,v 0.0.0.1            2003/10/07 
3  *
4  *  DEBUG:  section                     ortespy
5  *  AUTHOR: Petr Smolik                 petr.smolik@wo.cz
6  *
7  *  ORTE - OCERA Real-Time Ethernet     http://www.ocera.org/
8  *  --------------------------------------------------------------------
9  *
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.
14  *  
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.
19  *  
20  */ 
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #ifndef _WIN32
25   #include <signal.h>
26 #endif
27 #include "orte.h"
28 #ifdef HAVE_CONFIG_H
29   #ifdef HAVE_GETOPT_H
30     #include <getopt.h>
31   #endif
32   #ifdef HAVE_UNISTD_H
33     #include <unistd.h> //getopt.h for DarWin, Solaris, ...
34   #endif
35 #else
36   #include <getopt.h>
37 #endif
38 #include "string.h"
39
40 ORTEDomain              *d;
41 NtpTime                 deadline,minimumSeparation;
42 int32_t                 instanceRecv;
43
44 void
45 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
46   char lbuff[MAX_STRING_NTPTIME_LENGTH];
47   char rbuff[MAX_STRING_NTPTIME_LENGTH];
48   switch (info->status) {
49     case NEW_DATA:
50       printf("| %-10s | %-9s | %-9s | %-18s | %-18s |\n",
51              "NEW_DATA",
52              info->topic,
53              info->type,
54              NtpTimeToStringUs(info->localTimeReceived, lbuff),
55              NtpTimeToStringUs(info->remoteTimePublished, rbuff));
56       break;
57     case DEADLINE:
58 //      printf("deadline occurred\n");
59       break;
60   }
61 }
62
63 ORTESubscription*
64 subscriptionCallBack(const char *topic, const char *type, void *param) {
65   ORTETypeRegisterAdd(d,type,NULL,NULL,NULL,0);   
66   if (strcmp(topic,"Red")==0) return NULL;
67   return ORTESubscriptionCreate(
68         d,
69         IMMEDIATE,
70         BEST_EFFORTS,
71         topic,
72         type,
73         &instanceRecv,
74         &deadline,
75         &minimumSeparation,
76         recvCallBack,
77         NULL,
78         IPADDRESS_INVALID);
79 }
80
81 static void usage(void) {
82   printf("usage: ortespy <parameters> \n");
83   printf("  -d, --domain <domain>         working manager domain\n");
84   printf("  -v, --verbosity <level>       set verbosity level SECTION, up to LEVEL:...\n");
85   printf("      examples: ORTEManager -v 51.7:32.5 sections 51 and 32\n");
86   printf("                ORTEManager -v ALL.7     all sections up to level 7\n");
87   printf("  -R, --refresh <s>             refresh period in second(s)\n");
88   printf("  -P, --purge <s>               purge time in second(s)\n");
89   printf("  -e, --expiration <s>          expiration time of manager in second(s)\n");
90   printf("  -I, --metaMulticast <IPAdd>   use multicast IPAddr for metatraffic comm.\n");
91   printf("  -l, --logfile <filename>      set log file name\n");
92   printf("  -V, --version                 show version\n");
93   printf("  -h, --help                    this usage screen\n");
94 }
95
96 int main(int argc,char *argv[]) {
97 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
98   static struct option long_opts[] = {
99     { "domain",1,0, 'd' },
100     { "verbosity",1,0, 'v' },
101     { "refresh",1,0, 'R' },
102     { "purge",1,0, 'P' },
103     { "expiration",1,0, 'E' },
104     { "metaMulticast",1,0, 'I' },
105     { "logfile",1,0, 'l' },
106     { "version",0,0, 'V' },
107     { "help",  0, 0, 'h' },
108     { 0, 0, 0, 0}
109   };
110 #endif
111   ORTEDomainProp          dp; 
112   int                     opt,domain=ORTE_DEFAULT_DOMAIN;
113   
114   ORTEInit();
115   ORTEDomainPropDefaultGet(&dp);
116   NTPTIME_BUILD(deadline,3); 
117   NTPTIME_BUILD(minimumSeparation,0); 
118
119 #if defined HAVE_GETOPT_LONG || defined HAVE_GETOPT_LONG_ORTE
120   while ((opt = getopt_long(argc, argv, "d:v:R:E:I:P:l:Vh",&long_opts[0], NULL)) != EOF) {
121 #else
122   while ((opt = getopt(argc, argv, "d:v:R:E:I:P:l:Vh")) != EOF) {
123 #endif
124     switch (opt) {
125       case 'd':
126         domain=strtol(optarg,NULL,0);
127         break;
128       case 'v':
129         ORTEVerbositySetOptions(optarg);
130         break;
131       case 'R':
132         NtpTimeAssembFromMs(dp.baseProp.refreshPeriod,strtol(optarg,NULL,0),0);
133         break;
134       case 'P':
135         NtpTimeAssembFromMs(dp.baseProp.purgeTime,strtol(optarg,NULL,0),0);
136         break;
137       case 'E':
138         NtpTimeAssembFromMs(dp.baseProp.expirationTime,strtol(optarg,NULL,0),0);
139         break;
140       case 'I':
141         dp.multicast.enabled=ORTE_TRUE;
142         dp.multicast.ipAddress=StringToIPAddress(optarg);
143         break;  
144       case 'l':
145         ORTEVerbositySetLogFile(optarg);
146       case 'V':
147         printf("Ocera Real-Time Ethernet (%s).\n",dp.version);
148         exit(0);
149         break;
150       case 'h':
151       default:
152         usage();
153         exit(opt == 'h' ? 0 : 1);
154     }
155   }
156   //Create application     
157   printf("|------------------------------------------------------------------------------|\n");
158   printf("| %-10s | %-9s | %-9s | %-18s | %-18s |\n", 
159          "status", "type","topic","time received", "time sent");
160   printf("|------------------------------------------------------------------------------|\n");
161   d=ORTEDomainAppCreate(domain,&dp,NULL,ORTE_TRUE);
162   ORTEDomainAppSubscriptionPatternAdd(d,"*","*",subscriptionCallBack,NULL);
163   ORTEDomainStart(d,ORTE_TRUE,ORTE_FALSE,ORTE_TRUE,ORTE_FALSE,ORTE_TRUE);
164   while (1) {
165     ORTESleepMs(1000);
166   }
167   exit(0);
168 }
169