source: trunk/src/core/RpLibraryCInterface.cc @ 1040

Last change on this file since 1040 was 1018, checked in by gah, 16 years ago

Massive changes: New directory/file layout

File size: 6.0 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: C Rappture Library Source
4 *
5 * ======================================================================
6 *  AUTHOR:  Derrick Kearney, Purdue University
7 *  Copyright (c) 2004-2007  Purdue Research Foundation
8 *
9 *  See the file "license.terms" for information on usage and
10 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * ======================================================================
12 */
13
14#include "RpLibrary.h"
15#include "RpLibraryCInterface.h"
16#include "RpBufferCHelper.h"
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22RpLibrary*
23rpLibrary (const char* path)
24{
25    if (path == NULL) {
26        return (new RpLibrary());
27    }
28
29    return (new RpLibrary(path));
30}
31
32int
33rpFreeLibrary (RpLibrary** lib)
34{
35    int retVal = 1;
36
37    if (lib && (*lib)) {
38        delete (*lib);
39        (*lib) = NULL;
40        retVal =  0;
41    }
42
43    return retVal;
44}
45
46RpLibrary*
47rpElement (RpLibrary* lib, const char* path)
48{
49    return (lib->element(path));
50}
51
52RpLibrary*
53rpElementAsObject (RpLibrary* lib, const char* path)
54{
55    return rpElement(lib,path);
56}
57
58
59int
60rpElementAsType (RpLibrary* lib, const char* path, const char** retCStr)
61{
62    int retVal = 1;
63    static std::string retStr = "";
64    RpLibrary* retLib = lib->element(path);
65
66    if (retLib) {
67        retStr = retLib->nodeType();
68        // check to see if retStr is empty
69        retVal = 0;
70    }
71
72    *retCStr = retStr.c_str();
73
74    return retVal;
75}
76
77int
78rpElementAsComp (RpLibrary* lib, const char* path, const char** retCStr)
79{
80    int retVal = 1;
81    static std::string retStr = "";
82    RpLibrary* retLib = lib->element(path);
83
84    if (retLib) {
85        retStr = retLib->nodeComp();
86        // check to see if retStr is empty
87        retVal = 0;
88    }
89
90    *retCStr = retStr.c_str();
91    return retVal;
92}
93
94int
95rpElementAsId (RpLibrary* lib, const char* path, const char** retCStr)
96{
97    int retVal = 1;
98    static std::string retStr = "";
99    RpLibrary* retLib = lib->element(path);
100
101    if (retLib) {
102        retStr = retLib->nodeId();
103        // check to see if retStr is empty
104        retVal = 0;
105    }
106
107    *retCStr = retStr.c_str();
108    return retVal;
109}
110
111RpLibrary*
112rpChildren (RpLibrary* lib, const char* path, RpLibrary* childEle )
113{
114    return ( lib->children(path,childEle) );
115}
116
117RpLibrary*
118rpChildrenByType( RpLibrary* lib,
119                const char* path,
120                RpLibrary* childEle,
121                const char* type )
122{
123    return ( lib->children(path,childEle,type) );
124}
125
126int
127rpGet (RpLibrary* lib, const char* path, const char** retCStr)
128{
129    return rpGetString(lib,path,retCStr);
130}
131
132int
133rpGetString (RpLibrary* lib, const char* path, const char** retCStr)
134{
135    int retVal = 0;
136    static std::string retStr = "";
137
138    retStr = lib->getString(path);
139
140    *retCStr = retStr.c_str();
141    return retVal;
142}
143
144int
145rpGetDouble (RpLibrary* lib, const char* path, double* retDVal)
146{
147    int retVal = 0;
148    *retDVal = lib->getDouble(path);
149    return retVal;
150}
151
152int
153rpGetData (RpLibrary* lib, const char* path, RapptureBuffer* retBuf)
154{
155    Rappture::Buffer rpbuf;
156    int retVal = 0;
157
158    if (retBuf == NULL) {
159        return -1;
160    }
161
162    rpbuf = lib->getData(path);
163    RpBufferToCBuffer(&rpbuf, retBuf);
164    return retVal;
165}
166
167int
168rpPut ( RpLibrary* lib,
169        const char* path,
170        const char* value,
171        const char* id,
172        unsigned int append )
173{
174    int retVal = 0;
175    lib->put(path,value,id,append);
176    return retVal;
177}
178
179int
180rpPutString (   RpLibrary* lib,
181                const char* path,
182                const char* value,
183                unsigned int append )
184{
185    int retVal = 0;
186    lib->put(path,value,"",append);
187    return retVal;
188}
189
190int
191rpPutDouble (   RpLibrary* lib,
192                const char* path,
193                double value,
194                unsigned int append )
195{
196    int retVal = 0;
197    lib->put(path,value,"",append);
198    return retVal;
199}
200
201int rpPutData ( RpLibrary* lib,
202                const char* path,
203                const char* bytes,
204                int nBytes,
205                unsigned int append )
206{
207    int retVal = 0;
208    lib->putData(path,bytes,nBytes,append);
209    return retVal;
210}
211
212int rpPutFile ( RpLibrary* lib,
213                const char* path,
214                const char* fileName,
215                unsigned int binary,
216                unsigned int append  )
217{
218    int retVal = 0;
219    lib->putFile(path,fileName,binary,append);
220    return retVal;
221}
222
223int
224rpXml (RpLibrary* lib, const char** retCStr)
225{
226    int retVal = 1;
227    static std::string retStr = "";
228
229    if (lib != NULL) {
230        retStr = "";
231        retStr = lib->xml();
232
233        // string should never be empty after lib->xml fxn call
234        // lib->xml returns xml header at the very least.
235        if ( !retStr.empty() ) {
236            retVal = 0;
237        }
238    }
239
240    *retCStr = retStr.c_str();
241    return retVal;
242}
243
244int
245rpNodeComp (RpLibrary* node, const char** retCStr)
246{
247    int retVal = 1;
248    static std::string retStr = "";
249
250    if (node != NULL) {
251        retStr = "";
252        retStr = node->nodeComp();
253        if ( !retStr.empty() ) {
254            retVal = 0;
255        }
256        *retCStr = retStr.c_str();
257    }
258
259    return retVal;
260}
261
262int
263rpNodeType (RpLibrary* node, const char** retCStr)
264{
265    int retVal = 1;
266    static std::string retStr = "";
267
268    if (node != NULL) {
269        retStr = "";
270        retStr = node->nodeType();
271        if ( !retStr.empty() ) {
272            retVal = 0;
273        }
274        *retCStr = retStr.c_str();
275    }
276
277    return retVal;
278}
279
280int
281rpNodeId (RpLibrary* node, const char** retCStr)
282{
283    int retVal = 0;
284    static std::string retStr = "";
285
286    if (node != NULL) {
287        retStr = "";
288        retStr = node->nodeId();
289        if ( !retStr.empty() ) {
290            retVal = 0;
291        }
292        *retCStr = retStr.c_str();
293    }
294
295    return retVal;
296}
297
298int
299rpResult (RpLibrary* lib)
300{
301    int retVal = 0;
302    // signal the processing is complete
303    lib->put("tool.version.rappture.language", "c");
304    lib->result();
305    return retVal;
306}
307
308#ifdef __cplusplus
309}
310#endif
Note: See TracBrowser for help on using the repository browser.