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