]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/objectEntry.c
bug in CDRStream format -> now u_int8_t used
[orte.git] / orte / liborte / objectEntry.c
1     /*
2  *  $Id: objectEntry.c,v 0.0.0.1   2003/09/10
3  *
4  *  DEBUG:  section 8                   Functions with database of objects
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 #include "orte.h"
23
24 /*****************************************************************************/
25 // Implementation of GAVL functions
26 GAVL_CUST_NODE_INT_IMP(ObjectEntryHID, ObjectEntry, ObjectEntryHID, HostId,
27     objRoot, hidNode, hid, gavl_cmp_int)
28 GAVL_CUST_NODE_INT_IMP(ObjectEntryAID, ObjectEntryHID, ObjectEntryAID, AppId,
29     aidRoot, aidNode, aid, gavl_cmp_int)
30 GAVL_CUST_NODE_INT_IMP(ObjectEntryOID, ObjectEntryAID, ObjectEntryOID, ObjectId,
31     oidRoot, oidNode, oid, gavl_cmp_int)
32   
33 /*****************************************************************************/
34 void
35 objectEntryRefreshApp(ORTEDomain *d,ObjectEntryOID *objectEntryOID) {
36   if (!objectEntryOID) return;
37   if ((objectEntryOID->oid!=OID_APP) ||
38       (objectEntryOID->guid.aid==AID_UNKNOWN) ||
39       (!gavl_cmp_guid(&objectEntryOID->guid,&d->guid))) return;
40   eventDetach(d,
41           objectEntryOID->objectEntryAID,
42           &objectEntryOID->expirationPurgeTimer,
43           0);
44   eventAdd(d,
45           objectEntryOID->objectEntryAID,
46           &objectEntryOID->expirationPurgeTimer,
47           0,
48           "ExpirationTimer",
49           objectEntryExpirationTimer,
50           NULL,
51           objectEntryOID,
52           &((AppParams*)objectEntryOID->attributes)->expirationTime);
53   debug(8,3) ("refreshed: 0x%x-0x%x\n",
54               objectEntryOID->objectEntryHID->hid,
55               objectEntryOID->objectEntryAID->aid);
56 }
57
58 /*****************************************************************************/
59 ObjectEntryOID *
60 objectEntryFind(ORTEDomain *d,GUID_RTPS *guid) {
61   ObjectEntryHID *objectEntryHID;
62   ObjectEntryAID *objectEntryAID;
63
64   objectEntryHID=ObjectEntryHID_find(&d->objectEntry,&guid->hid);
65   if (objectEntryHID==NULL) return NULL;
66   objectEntryAID=ObjectEntryAID_find(objectEntryHID,&guid->aid);
67   if (objectEntryAID==NULL) return NULL;
68   return ObjectEntryOID_find(objectEntryAID,&guid->oid);
69 }
70
71 /*
72  * objectEntryAdd - Add a object to structure objectEntry
73  * @objectEntry: pointer to root structure 
74  * @guid: pointer to guid of object (hid,aid,oid)
75  *
76  * Return pointer to objectEntryOID
77  */
78 ObjectEntryOID *
79 objectEntryAdd(ORTEDomain *d,GUID_RTPS *guid,void *params) {
80   ObjectEntryHID *objectEntryHID;
81   ObjectEntryAID *objectEntryAID;
82   ObjectEntryOID *objectEntryOID;
83
84   debug(8,10) ("objectEntry: start\n");
85   objectEntryHID=ObjectEntryHID_find(&d->objectEntry,&guid->hid);
86   //not exists Host -> create 
87   if (objectEntryHID==NULL) {
88     objectEntryHID=(ObjectEntryHID*)MALLOC(sizeof(ObjectEntryHID));
89     //initialization items of structure objectEntryHID
90     ObjectEntryAID_init_root_field(objectEntryHID);
91     objectEntryHID->hid=guid->hid;
92     //insert
93     ObjectEntryHID_insert(&d->objectEntry,objectEntryHID);
94     debug(8,5) ("objectEntry: Host  : %#10.8x created\n",guid->hid);
95   }
96   objectEntryAID=ObjectEntryAID_find(objectEntryHID,&guid->aid);
97   //not exists Application -> create 
98   if (objectEntryAID==NULL) {
99     objectEntryAID=(ObjectEntryAID*)MALLOC(sizeof(ObjectEntryAID));
100     //init items of structure objectEntryAID
101     objectEntryAID->aid=guid->aid;
102     ObjectEntryOID_init_root_field(objectEntryAID);
103     //init structure htimUnicast
104     htimerUnicastCommon_init_queue(objectEntryAID);
105     ul_htim_queue_init_detached(&objectEntryAID->htimUnicast.commonNode.htim);
106     htimerUnicastSendMetatraffic_init_queue(objectEntryAID);
107     ul_htim_queue_init_detached(&objectEntryAID->htimUnicast.sendMetatrafficNode.htim);
108     htimerUnicastSendUserData_init_queue(objectEntryAID);
109     ul_htim_queue_init_detached(&objectEntryAID->htimUnicast.sendUserDataNode.htim);
110     //insert
111     ObjectEntryAID_insert(objectEntryHID,objectEntryAID);
112     debug(8,5) ("objectEntry: App   : %#10.8x created\n",guid->aid);
113   }
114   objectEntryOID=ObjectEntryOID_find(objectEntryAID,&guid->oid);
115   //not exists Object -> create 
116   if (objectEntryOID==NULL) {
117     objectEntryOID=(ObjectEntryOID*)MALLOC(sizeof(ObjectEntryOID));
118     //initialization items of structure objectEntryOID
119     objectEntryOID->guid=*guid;
120     objectEntryOID->oid=guid->oid;
121     objectEntryOID->objectEntryAID=objectEntryAID;
122     objectEntryOID->objectEntryHID=objectEntryHID;
123     objectEntryOID->attributes=params;
124     ul_htim_queue_init_detached(&objectEntryOID->expirationPurgeTimer.htim);
125     ul_htim_queue_init_detached(&objectEntryOID->sendCallBackDelayTimer.htim);
126     //insert
127     ObjectEntryOID_insert(objectEntryAID,objectEntryOID);
128     debug(8,5) ("objectEntry: Object: %#10.8x created\n",guid->oid);
129   }
130   debug(8,10) ("objectEntry: finished\n");
131   return objectEntryOID;
132 }
133
134 /*
135  * objectEntryDestroy - Destroy a object from structure objectEntry
136  * @objectEntry: pointer to root structure 
137  * @obejctEntryOID: pointer to the deleted objectEntryOID
138  *
139  * return 0-no obj. was deleted, 1-OID was deleted,2-OID,AID was deleted,
140  *        3-OID,AID,HID was deleted
141  */
142 int
143 objectEntryDelete(ORTEDomain *d,ObjectEntryOID *objectEntryOID) {
144   ObjectEntryHID *objectEntryHID;
145   ObjectEntryAID *objectEntryAID;
146   int            result=0;
147
148   debug(8,10) ("objectEntryDelete: start\n");
149   if (!objectEntryOID) return result;
150   objectEntryHID=objectEntryOID->objectEntryHID;
151   objectEntryAID=objectEntryOID->objectEntryAID;
152   //Destroy object on level OID
153   eventDetach(d,
154           objectEntryOID->objectEntryAID,
155           &objectEntryOID->expirationPurgeTimer,
156           0);
157   eventDetach(d,
158           objectEntryOID->objectEntryAID,
159           &objectEntryOID->sendCallBackDelayTimer,
160           0);
161   FREE(objectEntryOID->attributes);
162   ObjectEntryOID_delete(objectEntryAID,objectEntryOID);
163   debug(8,5) ("objectEntry: Object: %#10.8x deleted\n",objectEntryOID->oid);
164   FREE(objectEntryOID);
165   result=1;
166   //Destroy object on level AID
167   if (ObjectEntryOID_is_empty(objectEntryAID)) {
168     ObjectEntryAID_delete(objectEntryHID,objectEntryAID);
169     debug(8,5) ("objectEntry: App   : %#10.8x deleted\n",objectEntryAID->aid);
170     FREE(objectEntryAID);
171     result=2;
172   }
173   //Destroy object on level HID
174   if (ObjectEntryAID_is_empty(objectEntryHID)) {
175     ObjectEntryHID_delete(&d->objectEntry,objectEntryHID);
176     debug(8,5) ("objectEntry: Host  : %#10.8x deleted\n",objectEntryHID->hid);
177     FREE(objectEntryHID);
178     result=3;
179   }
180   debug(8,10) ("objectEntryDelete: finished\n");
181   return result;
182 }
183
184 /*
185  * objectEntryDeleteAll - Delete all structure objectEntry
186  * @objectEntry: pointer to root structure
187  *
188  */
189 void
190 objectEntryDeleteAll(ORTEDomain *d,ObjectEntry *objectEntry) {
191   ObjectEntryHID *objectEntryHID;
192   ObjectEntryAID *objectEntryAID;
193   ObjectEntryOID *objectEntryOID;
194
195   while((objectEntryHID=ObjectEntryHID_cut_first(objectEntry))) {
196     while((objectEntryAID=ObjectEntryAID_cut_first(objectEntryHID))) {
197       while((objectEntryOID=ObjectEntryOID_cut_first(objectEntryAID))) {
198         eventDetach(d,
199                 objectEntryOID->objectEntryAID,
200                 &objectEntryOID->expirationPurgeTimer,
201                 0);
202         eventDetach(d,
203                 objectEntryOID->objectEntryAID,
204                 &objectEntryOID->sendCallBackDelayTimer,
205                 0);
206         FREE(objectEntryOID->attributes);
207         FREE(objectEntryOID);
208       }
209       FREE(objectEntryAID);
210     }
211     FREE(objectEntryHID);
212   }
213 }
214
215 /*
216  * ObjectEntryDump - Dump a objectEntry structure on stdio
217  * @objectEntry: pointer to root structure
218  *
219  */
220 void
221 objectEntryDump(ObjectEntry *objectEntry) {
222   ObjectEntryHID *objectEntryHID;
223   ObjectEntryAID *objectEntryAID;
224   ObjectEntryOID *objectEntryOID;
225
226   gavl_cust_for_each(ObjectEntryHID,objectEntry,objectEntryHID) {
227     debug(8,5) ("hid:%x\n",objectEntryHID->hid);
228     gavl_cust_for_each(ObjectEntryAID,objectEntryHID,objectEntryAID) {
229       debug(8,5) ("  aid:%x\n",objectEntryAID->aid);
230       gavl_cust_for_each(ObjectEntryOID,objectEntryAID,objectEntryOID) {
231         debug(8,5) ("    oid:%x\n",objectEntryOID->oid,objectEntryOID);
232       }
233     }
234   }
235 }
236