]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/ORTEDomainApp.c
updated email address - petr@smoliku.cz
[orte.git] / orte / liborte / ORTEDomainApp.c
1 /*
2  *  $Id: ORTEDomainApp.c,v 0.0.0.1      2003/08/21 
3  *
4  *  DEBUG:  section 21                  Domain application
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 "orte_all.h"
33
34 /*****************************************************************************/
35 ORTEDomain * 
36 ORTEDomainAppCreate(int domain, ORTEDomainProp *prop,
37                     ORTEDomainAppEvents *events,Boolean suspended) {
38   ORTEDomain            *d;
39
40   debug(21,10) ("ORTEDomainAppCreate: start\n");
41
42   d=ORTEDomainCreate(domain,prop,events,ORTE_FALSE);
43   if (!d)
44     return NULL;
45   
46   //Start threads
47   if (!suspended) {
48     ORTEDomainStart(d,                                  /* domain */
49                     ORTE_TRUE,                          /* recvUnicastMetarafficThread */
50                     d->domainProp.multicast.enabled,    /* recvMulticastMetarafficThread */
51                     ORTE_TRUE,                          /* recvUnicastUserdataThread */
52                     d->domainProp.multicast.enabled,    /* recvMulticastUserdataThread */
53                     ORTE_TRUE);                         /* sendThread */
54   }
55   debug(21,10) ("ORTEDomainAppCreate: finished\n");
56   return d;
57 }
58
59 /*****************************************************************************/
60 Boolean
61 ORTEDomainAppDestroy(ORTEDomain *d) {
62   Boolean ret;
63
64   debug(21,10) ("ORTEDomainAppDestroy: start\n");
65
66   ret=ORTEDomainDestroy(d,ORTE_FALSE);
67
68   debug(21,10) ("ORTEDomainAppDestroy: finished\n");
69   return ret;
70 }
71
72 /*****************************************************************************/
73 Boolean 
74 ORTEDomainAppSubscriptionPatternAdd(ORTEDomain *d,const char *topic,
75     const char *type,ORTESubscriptionPatternCallBack subscriptionCallBack, 
76     void *param) {
77   PatternNode *pnode;
78   
79   if (!d) return ORTE_FALSE;
80   pnode=(PatternNode*)MALLOC(sizeof(PatternNode));
81   strcpy((char *)pnode->topic,topic);
82   strcpy((char *)pnode->type,type);
83   pnode->subscriptionCallBack=subscriptionCallBack;
84   pnode->param=param;
85   pthread_rwlock_wrlock(&d->patternEntry.lock);
86   Pattern_insert(&d->patternEntry,pnode);
87   pthread_rwlock_unlock(&d->patternEntry.lock);
88   return ORTE_TRUE;
89 }
90
91 /*****************************************************************************/
92 Boolean 
93 ORTEDomainAppSubscriptionPatternRemove(ORTEDomain *d,const char *topic,
94     const char *type) {
95   PatternNode *pnode;
96   
97   if (!d) return ORTE_FALSE;
98   pthread_rwlock_wrlock(&d->patternEntry.lock);
99   ul_list_for_each(Pattern,&d->patternEntry,pnode) {
100     if ((strcmp((const char *)pnode->topic, (const char*)topic)==0) &&
101         (strcmp((const char *)pnode->type, (const char*)type)==0)) {
102       Pattern_delete(&d->patternEntry,pnode);
103       FREE(pnode);
104       return ORTE_TRUE;
105     }
106   }
107   pthread_rwlock_unlock(&d->patternEntry.lock);
108   return ORTE_FALSE;
109 }
110
111 /*****************************************************************************/
112 Boolean 
113 ORTEDomainAppSubscriptionPatternDestroy(ORTEDomain *d) {
114   PatternNode *pnode;
115   
116   if (!d) return ORTE_FALSE;
117   pthread_rwlock_wrlock(&d->patternEntry.lock);
118   while((pnode=Pattern_cut_first(&d->patternEntry))) {
119     FREE(pnode);
120   }
121   pthread_rwlock_unlock(&d->patternEntry.lock);
122   return ORTE_TRUE;
123 }