summaryrefslogtreecommitdiff
path: root/Source/FusionDale/src/coma/icoma.c
blob: 8295b14057991f12836d47161e438bddd774e5c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
   (c) Copyright 2007  directfb.org

   All rights reserved.

   Written by Denis Oliver Kropp <dok@directfb.org>.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#include <config.h>

#include <unistd.h>

#include <fusiondale.h>

#include <direct/interface.h>

#include <fusion/shmalloc.h>

#include <coma/coma.h>
#include <coma/component.h>

#include <coma/icomacomponent.h>

#include "icoma.h"



static void
IComa_Destruct( IComa *thiz )
{
     IComa_data *data = (IComa_data*)thiz->priv;

     coma_exit( data->coma, false );

     DIRECT_DEALLOCATE_INTERFACE( thiz );
}

static DirectResult
IComa_AddRef( IComa *thiz )
{
     DIRECT_INTERFACE_GET_DATA (IComa);

     data->ref++;

     return DR_OK;
}

static DirectResult
IComa_Release( IComa *thiz )
{
     DIRECT_INTERFACE_GET_DATA (IComa)

     if (--data->ref == 0)
          IComa_Destruct( thiz );

     return DR_OK;
}

static DirectResult
IComa_CreateComponent( IComa           *thiz,
                       const char      *name,
                       ComaMethodFunc   func,
                       int              num_notifications,
                       void            *ctx,
                       IComaComponent **ret_interface )
{
     DirectResult    ret;
     ComaComponent  *component;
     IComaComponent *interface;

     DIRECT_INTERFACE_GET_DATA(IComa)

     /* Check arguments */
     if (!ret_interface)
          return DR_INVARG;

     /* Create a new component. */
     ret = coma_create_component( data->coma, name, func, num_notifications, ctx, &component );
     if (ret)
          return ret;

     DIRECT_ALLOCATE_INTERFACE( interface, IComaComponent );

     ret = IComaComponent_Construct( interface, data->coma, component, num_notifications );

     coma_component_unref( component );

     if (ret == DR_OK)
          *ret_interface = interface;

     return ret;
}

static DirectResult
IComa_GetComponent( IComa           *thiz,
                    const char      *name,
                    unsigned int     timeout,
                    IComaComponent **ret_interface )
{
     DirectResult    ret;
     ComaComponent  *component;
     IComaComponent *interface;

     DIRECT_INTERFACE_GET_DATA(IComa)

     /* Check arguments */
     if (!ret_interface)
          return DR_INVARG;

     /* Get the component. */
     ret = coma_get_component( data->coma, name, timeout, &component );
     if (ret)
          return ret;

     DIRECT_ALLOCATE_INTERFACE( interface, IComaComponent );

     ret = IComaComponent_Construct( interface, data->coma, component, component->num_notifications );

     coma_component_unref( component );

     if (ret == DR_OK)
          *ret_interface = interface;

     return DR_OK;
}

static DirectResult
IComa_Allocate( IComa         *thiz,
                unsigned int   bytes,
                void         **ret_ptr )
{
     DIRECT_INTERFACE_GET_DATA(IComa)

     if (!bytes || !ret_ptr)
          return DR_INVARG;

     return coma_allocate( data->coma, bytes, ret_ptr );
}

static DirectResult
IComa_Deallocate( IComa *thiz,
                  void  *ptr )
{
     DIRECT_INTERFACE_GET_DATA(IComa)

     if (!ptr)
          return DR_INVARG;

     return coma_deallocate( data->coma, ptr );
}

static DirectResult
IComa_GetLocal( IComa         *thiz,
                unsigned int   bytes,
                void         **ret_ptr )
{
     DIRECT_INTERFACE_GET_DATA(IComa)

     if (!bytes || !ret_ptr)
          return DR_INVARG;

     return coma_get_local( data->coma, bytes, ret_ptr );
}

static DirectResult
IComa_FreeLocal( IComa *thiz )
{
     DIRECT_INTERFACE_GET_DATA(IComa)

     return coma_free_local( data->coma );
}

DirectResult
IComa_Construct( IComa *thiz, Coma *coma )
{
     /* Allocate interface data. */
     DIRECT_ALLOCATE_INTERFACE_DATA( thiz, IComa );

     /* Initialize interface data. */
     data->ref  = 1;
     data->coma = coma;

     /* Assign interface pointers. */
     thiz->AddRef          = IComa_AddRef;
     thiz->Release         = IComa_Release;
     thiz->CreateComponent = IComa_CreateComponent;
     thiz->GetComponent    = IComa_GetComponent;
     thiz->Allocate        = IComa_Allocate;
     thiz->Deallocate      = IComa_Deallocate;
     thiz->GetLocal        = IComa_GetLocal;
     thiz->FreeLocal       = IComa_FreeLocal;

     return DR_OK;
}