]> rtime.felk.cvut.cz Git - orte.git/blobdiff - orte/examples/hello/HelloWorldSubscriber.c
CygWin, MSVC hack
[orte.git] / orte / examples / hello / HelloWorldSubscriber.c
index f474c0d314df2972837ff4f79bef1fcb38e49965..4359a73106e6d73633db216df03bd1deb99ffde0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  $Id: HelloWorldSubscriber.c,v 0.0.0.1 2003/12/26 
+ *  $Id: HelloWorldSubscriber.c,v 0.0.0.1 2003/12/26
  *
  *  DEBUG:  section                     HelloWorldSubscriber
  *  AUTHOR: Petr Smolik                 petr.smolik@wo.cz
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
- */ 
-
-#include <stdio.h>
-#ifdef __RTL__
+ *
+ */
+#include "orte_api.h"
+#ifdef CONFIG_ORTE_RTL
+  #include <linux/module.h>
   #include <posix/pthread.h>
   #define printf rtl_printf
+#elif defined CONFIG_ORTE_RTAI
+  #include <linux/module.h>
+  #include <rtai/compat.h>  
+  #define printf rt_printk
+#else
+  #include <stdio.h>
 #endif
-#include "orte_api.h"
 
-ORTEDomain        *d;
+
+ORTEDomain        *d = NULL;
 char              instance2Recv[64];
 
 void
 recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam) {
   char *instance=(char*)vinstance;
-  
+
   switch (info->status) {
     case NEW_DATA:
       printf("%s\n",instance);
@@ -44,22 +50,14 @@ recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam)
 }
 
 
-void
-subscriberCreate(void) {
+void *
+subscriberCreate(void *arg) {
   ORTESubscription    *s;
-  ORTEDomainProp      dp; 
   NtpTime             deadline,minimumSeparation;
 
-  ORTEInit();
-  ORTEVerbositySetOptions("ALL,10");
-  ORTEDomainPropDefaultGet(&dp);
-  #ifdef __RTL__
-  dp.appLocalManager=StringToIPAddress("192.168.4.1");
-  #endif
-  d=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,&dp,NULL);
   ORTETypeRegisterAdd(d,"HelloMsg",NULL,NULL,64);
-  NTPTIME_BUILD(deadline,15); 
-  NTPTIME_BUILD(minimumSeparation,0); 
+  NTPTIME_BUILD(deadline,10);
+  NTPTIME_BUILD(minimumSeparation,0);
   s=ORTESubscriptionCreate(
        d,
        IMMEDIATE,
@@ -71,26 +69,73 @@ subscriberCreate(void) {
        &minimumSeparation,
        recvCallBack,
        NULL);
+  return arg;
 }
 
-#ifndef __RTL__
-int 
+
+#ifndef CONFIG_ORTE_RT
+
+int
 main(int argc, char *args[]) {
-  subscriberCreate();
-  while (1) 
+  ORTEInit();
+  d=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,NULL,NULL,ORTE_FALSE);
+  if (!d) {
+    printf("ORTEDomainAppCreate failed!\n");
+    return 0;
+  }
+  subscriberCreate(NULL);
+  while (1)
     ORTESleepMs(1000);
   return 0;
 }
+
 #else
-pthread_t t;
-int 
+char *verbosity="";
+MODULE_PARM(verbosity,"1s");
+MODULE_PARM_DESC(verbosity,"set verbosity level SECTION, up to LEVEL:...");
+char *manager="127.0.0.1";
+MODULE_PARM(manager,"s");
+MODULE_PARM_DESC(manager,"IP address of local manager");
+MODULE_LICENSE("GPL");
+pthread_t thread;
+
+void *
+domainDestroy(void *arg) {
+  if (!d) return NULL;
+  ORTEDomainAppDestroy(d);
+  return arg;
+}
+
+int
 init_module(void) {
-  subscriberCreate();
+  ORTEDomainProp      dp;
+
+  ORTEInit();
+  ORTEDomainPropDefaultGet(&dp);
+  ORTEVerbositySetOptions(verbosity);
+  dp.appLocalManager=StringToIPAddress(manager);
+  d=ORTEDomainAppCreate(ORTE_DEFAULT_DOMAIN,&dp,NULL,ORTE_FALSE);
+  if (d) {
+    if (pthread_create(&thread,NULL,&subscriberCreate,NULL)!=0)
+      printf("pthread_create failed!\n");    
+  } else
+    printf("ORTEDomainAppCreate failed!\n");
   return 0;
 }
-void 
+
+
+void
 cleanup_module(void) {
-  ORTEDomainAppDestroy(d);
+  if (!d) return;
+  pthread_join(thread,NULL);
+  pthread_create(&thread,NULL,&domainDestroy,NULL);
+  pthread_join(thread,NULL);
 }
+
 #endif
 
+
+
+
+
+