]> rtime.felk.cvut.cz Git - orte.git/blob - orte/examples/reliable/r_subscriber_besteffort.c
updated email address - petr@smoliku.cz
[orte.git] / orte / examples / reliable / r_subscriber_besteffort.c
1 /*
2  *  $Id: subscriberbesteffort.c,v 0.0.0.1 2003/12/27 
3  *
4  *  DEBUG:  section                     Subscriber BestEffort
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
32 #include <stdio.h>
33 #ifdef __RTL__
34   #include <posix/pthread.h>
35 #endif
36 #include "orte.h"
37
38 #ifdef MAIN_RENAMED
39 #define main orte_r_subscriber_besteffort_main
40 #define exit return
41 #endif
42
43 static ORTEDomain        *d;
44 static char              instance2Recv[64];
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 int 
62 main(int argc, char *args[]) {
63   ORTESubscription *s;
64   NtpTime         deadline,minimumSeparation;
65
66   ORTEInit();
67   //ORTEVerbositySetOptions("ALL,10");
68   d=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,NULL,NULL,ORTE_FALSE);
69   ORTETypeRegisterAdd(d,"HelloMsg",NULL,NULL,NULL,sizeof(instance2Recv));
70   NTPTIME_BUILD(deadline,3); 
71   NTPTIME_BUILD(minimumSeparation,0); 
72   s=ORTESubscriptionCreate(
73        d,
74        IMMEDIATE,
75        BEST_EFFORTS,
76        "Reliable HelloMsg",
77        "HelloMsg",
78        &instance2Recv,
79        &deadline,
80        &minimumSeparation,
81        recvCallBack,
82        NULL,
83        IPADDRESS_INVALID);
84   if (s == NULL) {
85     printf("ORTESubscriptionCreate failed\n");
86     return 1;
87   }
88   #ifndef CONFIG_ORTE_RT
89   while (1) 
90     ORTESleepMs(1000);
91   #endif
92   return 0;
93 }
94
95 #ifdef CONFIG_ORTE_RT
96 void 
97 hello_init(void) {
98   main(0,NULL);
99 }
100 void 
101 hello_exit(void) {
102   ORTEDomainAppDestroy(d);
103 }
104 MODULE_LICENSE("GPL");
105 module_init(hello_init);
106 module_exit(hello_exit);
107 #endif
108