]> rtime.felk.cvut.cz Git - orte.git/blob - orte/examples/hello/HelloWorldSubscriber.c
f474c0d314df2972837ff4f79bef1fcb38e49965
[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 #include <stdio.h>
23 #ifdef __RTL__
24   #include <posix/pthread.h>
25   #define printf rtl_printf
26 #endif
27 #include "orte_api.h"
28
29 ORTEDomain        *d;
30 char              instance2Recv[64];
31
32 void
33 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
34   char *instance=(char*)vinstance;
35   
36   switch (info->status) {
37     case NEW_DATA:
38       printf("%s\n",instance);
39       break;
40     case DEADLINE:
41       printf("deadline occured\n");
42       break;
43   }
44 }
45
46
47 void
48 subscriberCreate(void) {
49   ORTESubscription    *s;
50   ORTEDomainProp      dp; 
51   NtpTime             deadline,minimumSeparation;
52
53   ORTEInit();
54   ORTEVerbositySetOptions("ALL,10");
55   ORTEDomainPropDefaultGet(&dp);
56   #ifdef __RTL__
57   dp.appLocalManager=StringToIPAddress("192.168.4.1");
58   #endif
59   d=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,&dp,NULL);
60   ORTETypeRegisterAdd(d,"HelloMsg",NULL,NULL,64);
61   NTPTIME_BUILD(deadline,15); 
62   NTPTIME_BUILD(minimumSeparation,0); 
63   s=ORTESubscriptionCreate(
64        d,
65        IMMEDIATE,
66        BEST_EFFORTS,
67        "Example HelloMsg",
68        "HelloMsg",
69        &instance2Recv,
70        &deadline,
71        &minimumSeparation,
72        recvCallBack,
73        NULL);
74 }
75
76 #ifndef __RTL__
77 int 
78 main(int argc, char *args[]) {
79   subscriberCreate();
80   while (1) 
81     ORTESleepMs(1000);
82   return 0;
83 }
84 #else
85 pthread_t t;
86 int 
87 init_module(void) {
88   subscriberCreate();
89   return 0;
90 }
91 void 
92 cleanup_module(void) {
93   ORTEDomainAppDestroy(d);
94 }
95 #endif
96