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