1 |
693 |
jeremybenn |
extern "C" {
|
2 |
|
|
typedef struct _IO_FILE FILE;
|
3 |
|
|
extern struct _IO_FILE *stderr;
|
4 |
|
|
extern int fprintf (FILE *__restrict __stream, __const char *__restrict __format, ...);
|
5 |
|
|
}
|
6 |
|
|
enum {
|
7 |
|
|
kPOVMSObjectClassID = 'OCLA', kPOVMSMessageClassID = 'MCLA', kPOVMSMessageIdentID = 'MIDE', kPOVMSSourceAddressID = 'MSRC', kPOVMSDestinationAddressID = 'MDST', kPOVMSMessageTimeoutID = 'TOUT', kPOVMSMessageErrorID = 'MERR' };
|
8 |
|
|
typedef void * POVMSContext;
|
9 |
|
|
typedef struct POVMSData POVMSObject, *POVMSObjectPtr;
|
10 |
|
|
typedef struct POVMSData POVMSAttribute, *POVMSAttributePtr;
|
11 |
|
|
struct POVMSData {
|
12 |
|
|
union {
|
13 |
|
|
struct POVMSNode *root;
|
14 |
|
|
};
|
15 |
|
|
};
|
16 |
|
|
struct POVMSNode {
|
17 |
|
|
struct POVMSNode *next;
|
18 |
|
|
unsigned int key;
|
19 |
|
|
struct POVMSData data;
|
20 |
|
|
};
|
21 |
|
|
int POVMSObject_New (POVMSObjectPtr object, unsigned int objclass);
|
22 |
|
|
int POVMSObject_Set (POVMSObjectPtr object, POVMSAttributePtr attr, unsigned int key);
|
23 |
|
|
int POVMSAttr_Copy (POVMSAttributePtr sourceattr, POVMSAttributePtr destattr);
|
24 |
|
|
int POVMSUtil_GetType (POVMSObjectPtr object, unsigned int key, unsigned int *typevalue);
|
25 |
|
|
namespace pov_base {
|
26 |
|
|
enum {
|
27 |
|
|
kNoError = 0, kNoErr = kNoError, kParamErr = -1, kMemFullErr = -2, kOutOfMemoryErr = kMemFullErr, kInvalidDataSizeErr = -3, kCannotHandleDataErr = -4, kNullPointerErr = -5, kChecksumErr = -6, kParseErr = -7, kCannotOpenFileErr = -8, kInvalidDestAddrErr = -9, kCannotConnectErr = -10, kDisconnectedErr = -11, kHostDisconnectedErr = -12, kNetworkDataErr = -13, kNetworkConnectionErr = -14, kObjectAccessErr = -15, kVersionErr = -16, kFileDataErr = -17, kAuthorisationErr = -18, kDataTypeErr = -19, kTimeoutErr = -20, kInvalidContextErr = -21 };
|
28 |
|
|
}
|
29 |
|
|
using namespace pov_base;
|
30 |
|
|
struct POVMSContextData {
|
31 |
|
|
};
|
32 |
|
|
int POVMS_AssertFunction (int cond, const char *str, const char *filename, int line);
|
33 |
|
|
int POVMS_OpenContext(POVMSContext *contextrefptr) {
|
34 |
|
|
POVMSContextData *context = __null;
|
35 |
|
|
if(contextrefptr == __null) return kParamErr;
|
36 |
|
|
if(POVMS_AssertFunction(context != __null, "POVMS_Open_Context failed, out of memory", "povms.cpp", 283) == false) return kMemFullErr;
|
37 |
|
|
return kNoErr;
|
38 |
|
|
}
|
39 |
|
|
int POVMS_AssertFunction(int cond, const char *str, const char *filename, int line) {
|
40 |
|
|
if(cond == false) {
|
41 |
|
|
fprintf(stderr, "POVMS_ASSERT failed in %s line %d: %s\n", filename, (int)line, str);
|
42 |
|
|
}
|
43 |
|
|
}
|
44 |
|
|
int POVMSObject_Copy(POVMSObjectPtr sourceobject, POVMSObjectPtr destobject) {
|
45 |
|
|
POVMSNode *cur = __null;
|
46 |
|
|
POVMSAttribute attr;
|
47 |
|
|
unsigned int t;
|
48 |
|
|
int ret = kNoErr;
|
49 |
|
|
if(sourceobject == destobject) return kParamErr;
|
50 |
|
|
if(POVMSUtil_GetType(sourceobject, kPOVMSObjectClassID, &t) != kNoErr) return kObjectAccessErr;
|
51 |
|
|
if(POVMSObject_New(destobject, t) != kNoErr) return kObjectAccessErr;
|
52 |
|
|
for(cur = sourceobject->root;
|
53 |
|
|
cur != __null;
|
54 |
|
|
cur = cur->next) {
|
55 |
|
|
if(POVMS_AssertFunction(POVMSAttr_Copy(&(cur->data), &attr) == kNoErr, "POVMSObject_Copy failed, out of memory", "povms.cpp", 2028) == false) {
|
56 |
|
|
}
|
57 |
|
|
if(POVMS_AssertFunction(POVMSObject_Set(destobject, &attr, cur->key) == kNoErr, "POVMSObject_Copy failed, out of memory", "povms.cpp", 2034) == false) {
|
58 |
|
|
}
|
59 |
|
|
}
|
60 |
|
|
return ret;
|
61 |
|
|
}
|
62 |
|
|
int POVMSObject_Merge(POVMSObjectPtr sourceobject, POVMSObjectPtr destobject) {
|
63 |
|
|
POVMSNode *cur = __null;
|
64 |
|
|
POVMSAttribute attr;
|
65 |
|
|
unsigned int t1, t2;
|
66 |
|
|
int ret = kNoErr;
|
67 |
|
|
if(destobject == __null) return kParamErr;
|
68 |
|
|
if(POVMSUtil_GetType(sourceobject, kPOVMSObjectClassID, &t1) != kNoErr) return kObjectAccessErr;
|
69 |
|
|
if(POVMSUtil_GetType(sourceobject, kPOVMSObjectClassID, &t2) != kNoErr) return kObjectAccessErr;
|
70 |
|
|
for(cur = sourceobject->root;
|
71 |
|
|
cur != __null;
|
72 |
|
|
cur = cur->next) {
|
73 |
|
|
if(POVMS_AssertFunction(POVMSObject_Set(destobject, &attr, cur->key) == kNoErr, "POVMSObject_Merge failed, out of memory", "povms.cpp", 2090) == false) {
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
return ret;
|
77 |
|
|
}
|