-
Notifications
You must be signed in to change notification settings - Fork 1
/
oscar.c
119 lines (93 loc) · 3.54 KB
/
oscar.c
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
/* Oscar, a hardware abstraction framework for the LeanXcam and IndXcam.
Copyright (C) 2008 Supercomputing Systems AG
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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*! @file
* @brief Oscar framework implementation
*
* Create, destroy and module dependency functionality.
*/
/*!
* \mainpage
* \image html camera-title.png
* \image html scs-logo.png
*
* \section Introduction
* This is the documentation of the Open-Source Camera (OSCAR) software framework.
*/
#include <stdio.h>
#include "oscar.h"
static struct OscModule ** loadedModuels = NULL;
OscFunction(static loadModules, struct OscModule ** deps)
for (struct OscModule ** dep = deps; *dep != NULL; dep += 1) {
OscAssert((*dep)->useCount >= 0);
if ((*dep)->useCount == 0) {
// char * name = (*dep)->name;
// if (name == NULL)
// name = "<noname>";
OscCall(loadModules, (*dep)->dependencies);
// OscMark_m("Loading module %s ...", name);
if ((*dep)->create != NULL)
OscCall((*dep)->create);
}
(*dep)->useCount += 1;
}
OscFunctionEnd()
OscFunction(static unloadModules, struct OscModule ** deps)
for (struct OscModule ** dep = deps; *dep != NULL; dep += 1) {
(*dep)->useCount -= 1;
if ((*dep)->useCount == 0) {
if ((*dep)->destroy != NULL)
OscCall((*dep)->destroy);
OscCall(unloadModules, (*dep)->dependencies);
}
OscAssert((*dep)->useCount >= 0);
}
OscFunctionEnd()
OscFunction(OscCreateFunction, struct OscModule ** modules)
OscAssert_m(loadedModuels == NULL, "The Framework is already loaded!");
// This requires modules point to static data which is done so by the OscCreate Macro. But it may not be a good idea ...
loadedModuels = modules;
OscCall(loadModules, loadedModuels);
OscFunctionCatch()
OscMark_m("Failed to load the Framework.");
OscCall(OscDestroy);
OscFunctionEnd()
OscFunction(OscDestroy)
OscAssert_m(loadedModuels != NULL, "The Framework is not loaded!");
OscCall(unloadModules, loadedModuels);
loadedModuels = NULL;
OscFunctionEnd()
OSC_ERR OscGetVersionNumber(char *hMajor, char *hMinor, char *hPatch)
{
*hMajor = OSC_VERSION_MAJOR;
*hMinor = OSC_VERSION_MINOR;
*hPatch = OSC_VERSION_PATCH;
return SUCCESS;
}
OscFunction(OscGetVersionString, char ** pVersion)
static char buffer[80];
int num;
if (OSC_VERSION_PATCH == 0)
if (OSC_VERSION_RC == 0)
num = snprintf(buffer, sizeof buffer, "v%d.%d", OSC_VERSION_MAJOR, OSC_VERSION_MINOR);
else
num = snprintf(buffer, sizeof buffer, "v%d.%d-RC%d", OSC_VERSION_MAJOR, OSC_VERSION_MINOR, OSC_VERSION_RC);
else
if (OSC_VERSION_RC == 0)
num = snprintf(buffer, sizeof buffer, "v%d.%d-p%d", OSC_VERSION_MAJOR, OSC_VERSION_MINOR, OSC_VERSION_PATCH);
else
num = snprintf(buffer, sizeof buffer, "v%d.%d-p%d-RC%d", OSC_VERSION_MAJOR, OSC_VERSION_MINOR, OSC_VERSION_PATCH, OSC_VERSION_RC);
OscAssert_m(num < sizeof buffer, "No buffer space left.");
*pVersion = buffer;
OscFunctionEnd()