]> rtime.felk.cvut.cz Git - orte.git/blob - orte/liborte/ORTETypeRegister.c
updated email address - petr@smoliku.cz
[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  *
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 GAVL_CUST_NODE_INT_IMP(ORTEType, TypeEntry, TypeNode, const char *,
35     types, node, typeRegister.typeName, gavl_cmp_str)
36     
37
38 /*****************************************************************************/
39 Boolean
40 ORTETypeRegisterFind(ORTEDomain *d,const char *typeName) {
41   Boolean            result=ORTE_FALSE;
42   
43   if (!d) 
44     return ORTE_FALSE;  //bat handle
45
46   pthread_rwlock_rdlock(&d->typeEntry.lock);    
47   if (ORTEType_find(&d->typeEntry,&typeName)) 
48     result=ORTE_TRUE;
49   pthread_rwlock_unlock(&d->typeEntry.lock);    
50   return result;
51 }
52
53 /*****************************************************************************/
54 int
55 ORTETypeRegisterAdd(ORTEDomain *d,const char *typeName,ORTETypeSerialize ts,
56                     ORTETypeDeserialize ds,ORTETypeGetMaxSize gms,unsigned int ms) {
57   TypeNode           *tn;
58   
59   if (!d) 
60     return ORTE_BAD_HANDLE;       //bat handle
61
62   if (gms) {
63     if (d->domainProp.wireProp.userBytesPerPacket<ms) 
64       return -2;
65   }
66
67   pthread_rwlock_wrlock(&d->typeEntry.lock);    
68   tn=ORTEType_find(&d->typeEntry,&typeName);
69   if (!tn) {
70     tn=(TypeNode*)MALLOC(sizeof(TypeNode));
71     tn->typeRegister.typeName=(char*)MALLOC(strlen(typeName)+1);
72     if (tn->typeRegister.typeName) {
73       memcpy((void*)tn->typeRegister.typeName, 
74              typeName, 
75              strlen(typeName) + 1);
76     }    
77     ORTEType_insert(&d->typeEntry,tn);
78     debug(26,3) ("ORTETypeRegisterAdd: created\n");
79   }
80   tn->typeRegister.serialize=ts;
81   tn->typeRegister.deserialize=ds;
82   tn->typeRegister.getMaxSize=gms;
83   tn->typeRegister.maxSize=ms;
84   pthread_rwlock_unlock(&d->typeEntry.lock);    
85   debug(26,3) ("ORTETypeRegisterAdd: registered type:%s\n",typeName);
86   return ORTE_OK;
87 }
88
89 /*****************************************************************************/
90 int
91 ORTETypeRegisterDestroyAll(ORTEDomain *d) {
92   TypeNode           *tn;
93   
94   if (!d) 
95     return ORTE_BAD_HANDLE;  //bat handle
96
97   pthread_rwlock_wrlock(&d->typeEntry.lock);    
98   while((tn=ORTEType_cut_first(&d->typeEntry))) {
99     FREE((char*)tn->typeRegister.typeName);
100     FREE(tn);
101   }
102   pthread_rwlock_unlock(&d->typeEntry.lock);    
103   return ORTE_OK;
104 }
105
106
107
108
109