]> rtime.felk.cvut.cz Git - orte.git/blob - orte/examples/multicast/m_subscriber.c
changed name to Open Real-time Ethernet, some source header arranging
[orte.git] / orte / examples / multicast / m_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 ORTEDomain        *d = NULL;
35 char              instance2Recv[64];
36
37 int maxDataSize(ORTEGetMaxSizeParam *gms) {
38   return gms->max_size;
39 }
40
41 void
42 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
43   char *instance=(char*)vinstance;
44
45   switch (info->status) {
46     case NEW_DATA:
47       printf("%s\n",instance);
48       break;
49     case DEADLINE:
50       printf("deadline occurred\n");
51       break;
52   }
53 }
54
55
56 void *
57 subscriberCreate(void *arg) {
58   ORTESubscription    *s;
59   NtpTime             deadline,minimumSeparation;
60
61   ORTETypeRegisterAdd(d,"HelloMsg",NULL,NULL,maxDataSize,sizeof(instance2Recv));
62   NTPTIME_BUILD(deadline,10);
63   NTPTIME_BUILD(minimumSeparation,0);
64   s=ORTESubscriptionCreate(
65        d,
66        IMMEDIATE,
67        BEST_EFFORTS,
68        "Example HelloMsg",
69        "HelloMsg",
70        &instance2Recv,
71        &deadline,
72        &minimumSeparation,
73        recvCallBack,
74        NULL,
75        StringToIPAddress("225.0.0.2"));
76   return arg;
77 }
78
79 int
80 main(int argc, char *args[]) {
81   ORTEDomainProp dp;
82   
83   ORTEInit();
84   ORTEDomainPropDefaultGet(&dp);
85   dp.multicast.enabled=ORTE_TRUE;
86   dp.multicast.ipAddress=StringToIPAddress("225.0.0.1");
87   ORTEVerbositySetOptions("ALL.10");
88   d=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,&dp,NULL,ORTE_FALSE);
89   if (!d) {
90     printf("ORTEDomainAppCreate failed!\n");
91     return 0;
92   }
93   subscriberCreate(NULL);
94   while (1)
95     ORTESleepMs(1000);
96   return 0;
97 }
98