]> rtime.felk.cvut.cz Git - orte.git/blob - orte/examples/hello/HelloWorldSubscriber.c
Update of ORTE. Configured to compile for Linux out of box.
[orte.git] / orte / examples / hello / HelloWorldSubscriber.c
1 /*
2  *  $Id: HelloWorldSubscriber.c,v 0.0.0.1 2003/12/26
3  *
4  *  DEBUG:  section                     HelloWorldSubscriber
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 #ifdef HAVE_CONFIG_H
23   #include <orte_config.h>
24 #endif
25
26 #ifdef CONFIG_ORTE_RTL
27   #include <stdio.h>
28   #include <posix/pthread.h>
29   #define printf rtl_printf
30 #elif defined(CONFIG_ORTE_RTAI)
31   #include <linux/module.h>
32   #include <rtai.h>
33   #include <rtai_sched.h>
34   #include <rtai_sem.h>
35   #define printf rt_printk
36 #else
37   #include <stdio.h>
38 #endif
39 #include "orte_api.h"
40
41 ORTEDomain *d=NULL;
42
43 void
44 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
45   char *instance=(char*)vinstance;
46
47   switch (info->status) {
48     case NEW_DATA:
49       printf("%s\n",instance);
50       break;
51     case DEADLINE:
52       printf("deadline occured\n");
53       break;
54   }
55 }
56
57 void
58 subscriberCreate(void) {
59   ORTESubscription    *s;
60   ORTEDomainProp      dp;
61   NtpTime             deadline,minimumSeparation;
62   char                instance2Recv[64];
63
64   ORTEInit();
65 //  ORTEVerbositySetOptions("ALL,5");
66   ORTEDomainPropDefaultGet(&dp);
67   #ifdef CONFIG_ORTE_RTL
68   dp.appLocalManager=StringToIPAddress("192.168.4.1");
69   #endif
70   d=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,&dp,NULL,ORTE_FALSE);
71   if (!d) {
72     printf("ORTEDomainAppCreate failed!\n");
73     return;
74   }
75   ORTETypeRegisterAdd(d,"HelloMsg",NULL,NULL,64);
76   NTPTIME_BUILD(deadline,20);
77   NTPTIME_BUILD(minimumSeparation,0);
78   s=ORTESubscriptionCreate(
79        d,
80        IMMEDIATE,
81        BEST_EFFORTS,
82        "Example HelloMsg",
83        "HelloMsg",
84        &instance2Recv,
85        &deadline,
86        &minimumSeparation,
87        recvCallBack,
88        NULL);
89 }
90
91 #ifndef CONFIG_ORTE_RT
92 int
93 main(int argc, char *args[]) {
94   subscriberCreate();
95   while (1)
96     ORTESleepMs(1000);
97   return 0;
98 }
99 #else
100 MODULE_LICENSE("GPL");
101 int
102 init_module(void) {
103   subscriberCreate();
104   return 0;
105 }
106 void
107 cleanup_module(void) {
108   if (d)
109     ORTEDomainAppDestroy(d);
110 }
111 #endif
112