]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/ORTETypeRegister.c
e12ac06080676220c64a5b61a747625b27870738
[orte.git] / orte / liborte / ORTETypeRegister.c
1 /*
2  *  $Id: ORTETypeRegister.c,v 0.0.0.1   2003/08/21 
3  *
4  *  DEBUG:  section 26                  Type register
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 GAVL_CUST_NODE_INT_IMP(ORTEType, TypeEntry, TypeNode, char *,
25     types, node, typeRegister.typeName, gavl_cmp_str)
26
27
28 /*****************************************************************************/
29 Boolean
30 ORTETypeRegisterFind(ORTEDomain *d,char *typeName) {
31   Boolean            result=ORTE_FALSE;
32   
33   if (!d) return ORTE_FALSE;  //bat handle
34   pthread_rwlock_rdlock(&d->typeEntry.lock);    
35   if (ORTEType_find(&d->typeEntry,&typeName)) 
36     result=ORTE_TRUE;
37   pthread_rwlock_unlock(&d->typeEntry.lock);    
38   return result;
39 }
40
41 /*****************************************************************************/
42 int
43 ORTETypeRegisterAdd(ORTEDomain *d,char *typeName,ORTETypeSerialize ts,
44                     ORTETypeDeserialize ds,unsigned int gms) {
45   TypeNode           *tn;
46   
47   if (!d) return -1;       //bat handle
48   if (gms>d->domainProp.wireProp.userMaxSerDeserSize) return -2;
49   pthread_rwlock_wrlock(&d->typeEntry.lock);    
50   tn=ORTEType_find(&d->typeEntry,&typeName);
51   if (!tn) {
52     tn=(TypeNode*)MALLOC(sizeof(TypeNode));
53     tn->typeRegister.typeName=strdup(typeName);
54     ORTEType_insert(&d->typeEntry,tn);
55   }
56   tn->typeRegister.serialize=ts;
57   tn->typeRegister.deserialize=ds;
58   tn->typeRegister.getMaxSize=gms;
59   pthread_rwlock_unlock(&d->typeEntry.lock);    
60   debug(26,3) ("ORTETypeRegisterAdd: registered type:%s\n",typeName);
61   return 0;
62 }
63
64 /*****************************************************************************/
65 int
66 ORTETypeRegisterDestroyAll(ORTEDomain *d) {
67   TypeNode           *tn;
68   
69   if (!d) return -1;       //bat handle
70   pthread_rwlock_wrlock(&d->typeEntry.lock);    
71   while((tn=ORTEType_cut_first(&d->typeEntry))) {
72     FREE(tn);
73   }
74   pthread_rwlock_unlock(&d->typeEntry.lock);    
75   return 0;
76 }
77
78
79
80
81