]> rtime.felk.cvut.cz Git - orte.git/blob - orte/examples/hello/HelloWorldPublisher.c
12908ebb7203b624cddfade5b93d65aa4d43ff41
[orte.git] / orte / examples / hello / HelloWorldPublisher.c
1 /*
2  *  $Id: HelloWorldPublisher.c,v 0.0.0.1 2003/12/26
3  *
4  *  DEBUG:  section                     HelloWorldPublisher
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 #ifdef HAVE_CONFIG_H
23   #include <orte_config.h>
24 #endif
25 #include "orte_api.h"
26 #ifdef CONFIG_ORTE_RTL
27   #include <linux/module.h>
28   #include <posix/pthread.h>
29   #define printf rtl_printf
30 #elif defined CONFIG_ORTE_RTAI
31   #include <linux/module.h>
32   #include <rtai/compat.h>  
33   #define printf rt_printk
34 #else
35   #include <stdio.h>
36 #endif
37
38 ORTEDomain        *d=NULL;
39 char              instance2Send[64];
40 int               counter=0;
41
42 void
43 sendCallBack(const ORTESendInfo *info,void *vinstance, void *sendCallBackParam) {
44   char *instance=(char*)vinstance;
45
46   switch (info->status) {
47     case NEED_DATA:
48       printf("Sampling publication, count %d\n", counter);
49       sprintf(instance,"Hello Universe! (%d)",counter++);
50       break;
51     case CQL:  //criticalQueueLevel
52       break;
53   }
54 }
55
56 void *
57 publisherCreate(void *arg) {
58   ORTEPublication     *p;
59   NtpTime             persistence, delay;
60
61   ORTETypeRegisterAdd(d,"HelloMsg",NULL,NULL,64);
62   NTPTIME_BUILD(persistence,3);
63   NTPTIME_BUILD(delay,1); 
64   p=ORTEPublicationCreate(
65        d,
66       "Example HelloMsg",
67       "HelloMsg",
68       &instance2Send,
69       &persistence,
70       1,
71       sendCallBack,
72       NULL,
73       &delay);
74   return arg;
75 }
76
77
78 #ifndef CONFIG_ORTE_RT
79
80 int
81 main(int argc, char *args[]) {
82   ORTEInit();
83   d=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,NULL,NULL,ORTE_FALSE);
84   if (!d) {
85     printf("ORTEDomainAppCreate failed!\n");
86     return 0;
87   }
88   publisherCreate((void*)d);
89   while(1) 
90     ORTESleepMs(1000);
91   return 0;
92 }
93
94 #else
95
96 char *manager="127.0.0.1";
97 MODULE_PARM(manager,"1s");
98 MODULE_PARM_DESC(manager,"IP address of local manager");
99 MODULE_LICENSE("GPL");
100 pthread_t thread;
101
102 void *
103 domainDestroy(void *arg) {
104   if (!d) return NULL;
105   ORTEDomainAppDestroy(d);
106   return arg;
107 }
108
109 int
110 init_module(void) {
111   ORTEDomainProp      dp;
112
113   ORTEDomainPropDefaultGet(&dp);
114   dp.appLocalManager=StringToIPAddress(manager);
115   d=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,&dp,NULL,ORTE_FALSE);
116   if (d) 
117     pthread_create(&thread,NULL,&publisherCreate,NULL);
118   else
119     printf("ORTEDomainAppCreate failed!\n");
120   return 0;
121 }
122
123
124 void
125 cleanup_module(void) {
126   if (!d) return;
127   pthread_join(thread,NULL);
128   pthread_create(&thread,NULL,&domainDestroy,NULL);
129   pthread_join(thread,NULL);
130 }
131
132 #endif
133
134