]> rtime.felk.cvut.cz Git - orte.git/blob - orte/examples/schneider/schneider_subscriber.c
a320f2b583ae6e6918c797d7839d8b630639a8e1
[orte.git] / orte / examples / schneider / schneider_subscriber.c
1 /*
2  *  $Id: m_subscriber.c,v 0.0.1.0       2005/01/03
3  *
4  *  DEBUG:  section                     m_subscriber
5  *
6  *  -------------------------------------------------------------------  
7  *                                ORTE                                 
8  *                      Open Real-Time Ethernet                       
9  *                                                                    
10  *                      Copyright (C) 2001-2006                       
11  *  Department of Control Engineering FEE CTU Prague, Czech Republic  
12  *                      http://dce.felk.cvut.cz                       
13  *                      http://www.ocera.org                          
14  *                                                                    
15  *  Author:              Petr Smolik    petr.smolik@wo.cz             
16  *  Advisor:             Pavel Pisa                                   
17  *  Project Responsible: Zdenek Hanzalek                              
18  *  --------------------------------------------------------------------
19  *
20  *  This program is free software; you can redistribute it and/or modify
21  *  it under the terms of the GNU General Public License as published by
22  *  the Free Software Foundation; either version 2 of the License, or
23  *  (at your option) any later version.
24  *
25  *  This program is distributed in the hope that it will be useful,
26  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  *  GNU General Public License for more details.
29  *
30  */
31 #include "orte.h"
32 #include <stdio.h>
33
34 #ifdef MAIN_RENAMED
35 #define main orte_schneider_subscriber_main
36 #define exit return
37 #endif
38
39 static ORTEDomain        *d = NULL;
40 static char              instance2Recv[64];
41
42 int maxDataSize(ORTEGetMaxSizeParam *gms, int num) {
43   return gms->max_size;
44 }
45
46 static void
47 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
48   char *instance=(char*)vinstance;
49
50   switch (info->status) {
51     case NEW_DATA:
52       printf("%s\n",instance);
53       break;
54     case DEADLINE:
55       printf("deadline occurred\n");
56       break;
57   }
58 }
59
60
61 static void *
62 subscriberCreate(void *arg) {
63   ORTESubscription    *s;
64   NtpTime             deadline,minimumSeparation;
65
66   ORTETypeRegisterAdd(d,"IDA_OCTETSTRING",NULL,NULL,maxDataSize,sizeof(instance2Recv));
67   NTPTIME_BUILD(deadline,10);
68   NTPTIME_BUILD(minimumSeparation,0);
69   s=ORTESubscriptionCreate(
70        d,
71        IMMEDIATE,
72        BEST_EFFORTS,
73        "IDA_TOPIC0001",
74        "IDA_OCTETSTRING",
75        &instance2Recv,
76        &deadline,
77        &minimumSeparation,
78        recvCallBack,
79        NULL,
80 //       StringToIPAddress("225.0.0.2")
81        IPADDRESS_INVALID
82        );
83   if (s == NULL) {
84     printf("ORTESubscriptionCreate failed\n");
85   }
86   return arg;
87 }
88
89 int
90 main(int argc, char *args[]) {
91   ORTEDomainProp dp;
92   
93   ORTEInit();
94   ORTEDomainPropDefaultGet(&dp);
95 //  dp.multicast.enabled=ORTE_TRUE;
96 //  dp.multicast.ipAddress=StringToIPAddress("225.0.0.1");
97   ORTEVerbositySetOptions("ALL.5");
98   d=ORTEDomainAppCreate(1,&dp,NULL,ORTE_FALSE);
99   if (!d) {
100     printf("ORTEDomainAppCreate failed!\n");
101     return 0;
102   }
103   subscriberCreate(NULL);
104   while (1)
105     ORTESleepMs(1000);
106   return 0;
107 }
108