summaryrefslogtreecommitdiff
path: root/Source/DirectFB/src/core/core_parts.c
blob: 1b5f9447bb3b66d407e7017e0783f686720b8206 (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
/*
   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
   (c) Copyright 2000-2004  Convergence (integrated media) GmbH

   All rights reserved.

   Written by Denis Oliver Kropp <dok@directfb.org>,
              Andreas Hundt <andi@fischlustig.de>,
              Sven Neumann <neo@directfb.org>,
              Ville Syrjälä <syrjala@sci.fi> and
              Claudio Ciccani <klan@users.sf.net>.

   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 <fusion/arena.h>
#include <fusion/shmalloc.h>

#include <directfb.h>

#include <core/coredefs.h>
#include <core/coretypes.h>

#include <core/core.h>
#include <core/core_parts.h>

#include <direct/mem.h>
#include <direct/messages.h>


D_DEBUG_DOMAIN( Core_Parts, "Core/Parts", "DirectFB Core Parts" );


DFBResult
dfb_core_part_initialize( CoreDFB  *core,
                          CorePart *core_part )
{
     DFBResult            ret;
     void                *local  = NULL;
     void                *shared = NULL;
     FusionSHMPoolShared *pool;

     pool = dfb_core_shmpool( core );

     if (core_part->initialized) {
          D_BUG( "%s already initialized", core_part->name );
          return DFB_BUG;
     }

     D_DEBUG_AT( Core_Parts, "Going to initialize '%s' core...\n", core_part->name );

     if (core_part->size_local)
          local = D_CALLOC( 1, core_part->size_local );

     if (core_part->size_shared)
          shared = SHCALLOC( pool, 1, core_part->size_shared );

     ret = core_part->Initialize( core, local, shared );
     if (ret) {
          D_ERROR( "DirectFB/Core: Could not initialize '%s' core!\n"
                    "    --> %s\n", core_part->name,
                    DirectFBErrorString( ret ) );

          if (shared)
               SHFREE( pool, shared );

          if (local)
               D_FREE( local );

          return ret;
     }

     if (shared)
          fusion_arena_add_shared_field( dfb_core_arena( core ),
                                         core_part->name, shared );

     core_part->data_local  = local;
     core_part->data_shared = shared;
     core_part->initialized = true;

     return DFB_OK;
}

DFBResult
dfb_core_part_join( CoreDFB  *core,
                    CorePart *core_part )
{
     DFBResult  ret;
     void      *local  = NULL;
     void      *shared = NULL;

     if (core_part->initialized) {
          D_BUG( "%s already joined", core_part->name );
          return DFB_BUG;
     }

     D_DEBUG_AT( Core_Parts, "Going to join '%s' core...\n", core_part->name );

     if (core_part->size_shared &&
         fusion_arena_get_shared_field( dfb_core_arena( core ),
                                        core_part->name, &shared ))
          return DFB_FUSION;

     if (core_part->size_local)
          local = D_CALLOC( 1, core_part->size_local );

     ret = core_part->Join( core, local, shared );
     if (ret) {
          D_ERROR( "DirectFB/Core: Could not join '%s' core!\n"
                    "    --> %s\n", core_part->name,
                    DirectFBErrorString( ret ) );

          if (local)
               D_FREE( local );

          return ret;
     }

     core_part->data_local  = local;
     core_part->data_shared = shared;
     core_part->initialized = true;

     return DFB_OK;
}

DFBResult
dfb_core_part_shutdown( CoreDFB  *core,
                        CorePart *core_part,
                        bool      emergency )
{
     DFBResult            ret;
     FusionSHMPoolShared *pool;

     pool = dfb_core_shmpool( core );

     if (!core_part->initialized)
          return DFB_OK;

     D_DEBUG_AT( Core_Parts, "Going to shutdown '%s' core...\n", core_part->name );

     ret = core_part->Shutdown( core_part->data_local, emergency );
     if (ret)
          D_ERROR( "DirectFB/Core: Could not shutdown '%s' core!\n"
                    "    --> %s\n", core_part->name,
                    DirectFBErrorString( ret ) );

     if (core_part->data_shared)
          SHFREE( pool, core_part->data_shared );

     if (core_part->data_local)
          D_FREE( core_part->data_local );

     core_part->data_local  = NULL;
     core_part->data_shared = NULL;
     core_part->initialized = false;

     return DFB_OK;
}

DFBResult
dfb_core_part_leave( CoreDFB  *core,
                     CorePart *core_part,
                     bool      emergency )
{
     DFBResult ret;

     if (!core_part->initialized)
          return DFB_OK;

     D_DEBUG_AT( Core_Parts, "Going to leave '%s' core...\n", core_part->name );

     ret = core_part->Leave( core_part->data_local, emergency );
     if (ret)
          D_ERROR( "DirectFB/Core: Could not leave '%s' core!\n"
                    "    --> %s\n", core_part->name,
                    DirectFBErrorString( ret ) );

     if (core_part->data_local)
          D_FREE( core_part->data_local );

     core_part->data_local  = NULL;
     core_part->data_shared = NULL;
     core_part->initialized = false;

     return DFB_OK;
}