1 /******************************************************************************* 2 * povms.h 3 * 4 * This module contains all defines, typedefs, and prototypes for povms.cpp. 5 * 6 * --------------------------------------------------------------------------- 7 * Persistence of Vision Ray Tracer ('POV-Ray') version 3.7. 8 * Copyright 1991-2013 Persistence of Vision Raytracer Pty. Ltd. 9 * 10 * POV-Ray is free software: you can redistribute it and/or modify 11 * it under the terms of the GNU Affero General Public License as 12 * published by the Free Software Foundation, either version 3 of the 13 * License, or (at your option) any later version. 14 * 15 * POV-Ray is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Affero General Public License for more details. 19 * 20 * You should have received a copy of the GNU Affero General Public License 21 * along with this program. If not, see <http://www.gnu.org/licenses/>. 22 * --------------------------------------------------------------------------- 23 * POV-Ray is based on the popular DKB raytracer version 2.12. 24 * DKBTrace was originally written by David K. Buck. 25 * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins. 26 * --------------------------------------------------------------------------- 27 * $File: //depot/public/povray/3.x/source/base/povms.h $ 28 * $Revision: #1 $ 29 * $Change: 6069 $ 30 * $DateTime: 2013/11/06 11:59:40 $ 31 * $Author: chrisc $ 32 *******************************************************************************/ 33 34 #ifndef POVMS_H 35 #define POVMS_H 36 37 #ifndef POVMS_NO_DUMP_SUPPORT 38 #include <stdio.h> 39 #endif 40 41 /***************************************************************************** 42 * Global preprocessor defines 43 ******************************************************************************/ 44 45 /* Note: This low level fatal error text output function is required. 46 It defaults to printf if you do not overload it in config.h! */ 47 #ifndef POVMS_ASSERT_OUTPUT 48 #define POVMS_ASSERT_OUTPUT(s,f,l) fprintf(stderr, "POVMS_ASSERT failed in %s line %d: %s\n", f, (int)l, s) 49 #endif 50 51 #ifndef POVMS_LOG_OUTPUT 52 #define POVMS_LOG_OUTPUT(s) 53 #endif 54 55 /* Note: POVMSType needs to be 32 bit! (unsigned), it will be composed 56 of four characters, i.e. 'MyTp', 'any ', '4Mac', etc. */ 57 #ifndef POVMSType 58 #define POVMSType unsigned int 59 #endif 60 61 #ifndef POVMSInt 62 #define POVMSInt int 63 #endif 64 65 #ifndef POVMSLong 66 #define POVMSLong long long 67 68 #define SetPOVMSLong(v,h,l) *v = (((((POVMSLong)(h)) & 0x00000000ffffffff) << 32) | (((POVMSLong)(l)) & 0x00000000ffffffff)) 69 #define GetPOVMSLong(h,l,v) *h = ((v) >> 32) & 0x00000000ffffffff; *l = (v) & 0x00000000ffffffff 70 71 #define POVMSLongToCDouble(x) double(x) 72 #endif 73 74 #ifndef POVMSFloat 75 #define POVMSFloat float 76 #endif 77 78 #ifndef POVMSBool 79 #define POVMSBool int 80 #endif 81 82 #ifndef POVMSUCS2 83 #define POVMSUCS2 unsigned short 84 #endif 85 86 #ifndef POVMSStream 87 #define POVMSStream unsigned char 88 #endif 89 90 #ifndef POVMS_NO_ORDERED_STREAM_DATA 91 #ifndef POVMSIEEEFloat 92 #define POVMSIEEEFloat float 93 94 #define POVMSFloatToPOVMSIEEEFloat(p, f) f = p 95 #define POVMSIEEEFloatToPOVMSFloat(f, p) p = f 96 97 #define HexToPOVMSIEEEFloat(h, f) *((int *)(&f)) = h 98 #endif 99 #else 100 // POVMSIEEEFloat does not have to be an IEEE 754 float 101 // if POVMS_NO_ORDERED_STREAM_DATA is off. It only 102 // has to be 32 bit in size! 103 #ifndef POVMSIEEEFloat 104 #define POVMSIEEEFloat POVMSFloat 105 106 #define POVMSFloatToPOVMSIEEEFloat(p, f) f = p 107 #define POVMSIEEEFloatToPOVMSFloat(f, p) p = f 108 #endif 109 #endif 110 111 /* Note: POVMSAddress needs work with the default copy constructor. 112 Adjust it to fit you message addressing needs! */ 113 114 #ifndef POVMSAddress 115 #define POVMSAddress void * 116 #define POVMSInvalidAddress NULL 117 #endif 118 119 /* Note: Use POVMS_EXPORT if you need a special export keyword 120 in order to use the POVMS functions as part of a library. */ 121 #ifndef POVMS_EXPORT 122 #define POVMS_EXPORT 123 #endif 124 125 #ifndef POVMS_CDECL 126 #define POVMS_CDECL 127 #endif 128 129 #undef POVMS_VERSION 130 #define POVMS_VERSION 2 131 132 133 /***************************************************************************** 134 * Global typedefs 135 ******************************************************************************/ 136 137 /* Note: All only upper case types are reserved for internal use. */ 138 enum 139 { 140 kPOVMSObjectClassID = 'OCLA', 141 kPOVMSMessageClassID = 'MCLA', 142 kPOVMSMessageIdentID = 'MIDE', 143 kPOVMSSourceAddressID = 'MSRC', 144 kPOVMSDestinationAddressID = 'MDST', 145 kPOVMSMessageTimeoutID = 'TOUT', 146 kPOVMSMessageErrorID = 'MERR', 147 kPOVMSMessageSequenceID = 'MSEQ', 148 kPOVMSResultSequenceID = 'RSEQ' 149 }; 150 151 enum 152 { 153 kPOVMSType_Object = 'OBJE', 154 kPOVMSType_LockedObject = 'LOCK', 155 kPOVMSType_ResultObject = 'RESU', 156 kPOVMSType_Address = 'ADDR', 157 kPOVMSType_Null = 'NULL', 158 kPOVMSType_WildCard = '****', 159 kPOVMSType_CString = 'CSTR', 160 kPOVMSType_UCS2String = 'U2ST', 161 kPOVMSType_Int = 'INT4', 162 kPOVMSType_Long = 'INT8', 163 kPOVMSType_Float = 'FLT4', 164 kPOVMSType_Double = 'FLT8', 165 kPOVMSType_Bool = 'BOOL', 166 kPOVMSType_Type = 'TYPE', 167 kPOVMSType_List = 'LIST', 168 kPOVMSType_VectorInt = 'VIN4', 169 kPOVMSType_VectorLong = 'VIN8', 170 kPOVMSType_VectorFloat = 'VFL4', 171 kPOVMSType_VectorType = 'VTYP', 172 }; 173 174 typedef void * POVMSContext; 175 176 typedef struct POVMSData POVMSObject; 177 typedef struct POVMSData POVMSAttribute; 178 typedef struct POVMSData POVMSAttributeList; 179 180 typedef POVMSObject *POVMSObjectPtr; 181 typedef POVMSAttribute *POVMSAttributePtr; 182 typedef POVMSAttributeList *POVMSAttributeListPtr; 183 184 typedef struct POVMSNode POVMSNode; 185 186 struct POVMSData 187 { 188 POVMSType type; 189 int size; 190 union 191 { 192 void *ptr; 193 struct POVMSData *items; 194 struct POVMSNode *root; 195 }; 196 }; 197 198 struct POVMSNode 199 { 200 struct POVMSNode *last; 201 struct POVMSNode *next; 202 POVMSType key; 203 struct POVMSData data; 204 }; 205 206 enum 207 { 208 kPOVMSSendMode_Invalid = 0, 209 kPOVMSSendMode_NoReply = 1, 210 kPOVMSSendMode_WaitReply = 2, 211 kPOVMSSendMode_WantReceipt = 3 212 }; 213 214 215 /***************************************************************************** 216 * Global variables 217 ******************************************************************************/ 218 219 220 /***************************************************************************** 221 * Global functions 222 ******************************************************************************/ 223 224 // POVMS context functions 225 POVMS_EXPORT int POVMS_CDECL POVMS_OpenContext (POVMSContext *contextrefptr); 226 POVMS_EXPORT int POVMS_CDECL POVMS_CloseContext (POVMSContext contextref); 227 POVMS_EXPORT int POVMS_CDECL POVMS_GetContextAddress(POVMSContext contextref, POVMSAddress *addrptr); 228 229 // Message receive handler functions 230 POVMS_EXPORT int POVMS_CDECL POVMS_InstallReceiver (POVMSContext contextref, int (*hfunc)(POVMSObjectPtr, POVMSObjectPtr, int, void *), POVMSType hclass, POVMSType hid, void *hpd); 231 POVMS_EXPORT int POVMS_CDECL POVMS_RemoveReceiver (POVMSContext contextref, POVMSType hclass, POVMSType hid); 232 233 // Message receive functions 234 POVMS_EXPORT int POVMS_CDECL POVMS_ProcessMessages (POVMSContext contextref, POVMSBool blocking, POVMSBool yielding); 235 POVMS_EXPORT int POVMS_CDECL POVMS_Receive (POVMSContext contextref, POVMSObjectPtr msg, POVMSObjectPtr result, int mode); 236 237 // Message send functions 238 POVMS_EXPORT int POVMS_CDECL POVMS_Send (POVMSContext contextref, POVMSObjectPtr msg, POVMSObjectPtr result, int mode); 239 240 // Message data functions 241 POVMS_EXPORT int POVMS_CDECL POVMSMsg_SetupMessage (POVMSObjectPtr object, POVMSType msgclass, POVMSType msgid); 242 POVMS_EXPORT int POVMS_CDECL POVMSMsg_GetMessageClass (POVMSObjectPtr object, POVMSType *msgclass); 243 POVMS_EXPORT int POVMS_CDECL POVMSMsg_SetMessageClass (POVMSObjectPtr object, POVMSType msgclass); 244 POVMS_EXPORT int POVMS_CDECL POVMSMsg_GetMessageIdentifier (POVMSObjectPtr object, POVMSType *msgid); 245 POVMS_EXPORT int POVMS_CDECL POVMSMsg_SetMessageIdentifier (POVMSObjectPtr object, POVMSType msgid); 246 POVMS_EXPORT int POVMS_CDECL POVMSMsg_GetSourceAddress (POVMSObjectPtr object, POVMSAddress *value); 247 POVMS_EXPORT int POVMS_CDECL POVMSMsg_SetSourceAddress (POVMSObjectPtr object, POVMSAddress value); 248 POVMS_EXPORT int POVMS_CDECL POVMSMsg_GetDestinationAddress (POVMSObjectPtr object, POVMSAddress *value); 249 POVMS_EXPORT int POVMS_CDECL POVMSMsg_SetDestinationAddress (POVMSObjectPtr object, POVMSAddress value); 250 251 // Object functions 252 POVMS_EXPORT int POVMS_CDECL POVMSObject_New (POVMSObjectPtr object, POVMSType objclass); 253 POVMS_EXPORT int POVMS_CDECL POVMSObject_Delete (POVMSObjectPtr object); 254 POVMS_EXPORT int POVMS_CDECL POVMSObject_Copy (POVMSObjectPtr sourceobject, POVMSObjectPtr destobject); 255 POVMS_EXPORT int POVMS_CDECL POVMSObject_Merge (POVMSObjectPtr sourceobject, POVMSObjectPtr destobject); 256 POVMS_EXPORT int POVMS_CDECL POVMSObject_Get (POVMSObjectPtr object, POVMSAttributePtr attr, POVMSType key); 257 POVMS_EXPORT int POVMS_CDECL POVMSObject_Set (POVMSObjectPtr object, POVMSAttributePtr attr, POVMSType key); 258 POVMS_EXPORT int POVMS_CDECL POVMSObject_Remove (POVMSObjectPtr object, POVMSType key); 259 POVMS_EXPORT int POVMS_CDECL POVMSObject_Exist (POVMSObjectPtr object, POVMSType key); 260 POVMS_EXPORT int POVMS_CDECL POVMSObject_Count (POVMSObjectPtr object, int *cnt); 261 POVMS_EXPORT int POVMS_CDECL POVMSObject_GetClass (POVMSObjectPtr object, POVMSType *objclass); 262 263 #ifndef POVMS_NO_DUMP_SUPPORT 264 // Object debug functions 265 POVMS_EXPORT int POVMS_CDECL POVMSObject_Dump (FILE *file, POVMSObjectPtr object); 266 POVMS_EXPORT int POVMS_CDECL POVMSObject_DumpAttr (FILE *file, POVMSAttributePtr attr); 267 #endif 268 269 // Object streaming functions 270 POVMS_EXPORT int POVMS_CDECL POVMSObjectStream_Size (POVMSObjectPtr object, int *streamsize); 271 POVMS_EXPORT int POVMS_CDECL POVMSObjectStream_Read (POVMSObjectPtr object, POVMSStream *stream, int *maxstreamsize); 272 POVMS_EXPORT int POVMS_CDECL POVMSObjectStream_Write(POVMSObjectPtr object, POVMSStream *stream, int *maxstreamsize); 273 274 // Attribute functions 275 POVMS_EXPORT int POVMS_CDECL POVMSAttr_New (POVMSAttributePtr attr); 276 POVMS_EXPORT int POVMS_CDECL POVMSAttr_Delete (POVMSAttributePtr attr); 277 POVMS_EXPORT int POVMS_CDECL POVMSAttr_Copy (POVMSAttributePtr sourceattr, POVMSAttributePtr destattr); 278 POVMS_EXPORT int POVMS_CDECL POVMSAttr_Get (POVMSAttributePtr attr, POVMSType type, void *data, int *maxdatasize); 279 POVMS_EXPORT int POVMS_CDECL POVMSAttr_Set (POVMSAttributePtr attr, POVMSType type, const void *data, int datasize); 280 POVMS_EXPORT int POVMS_CDECL POVMSAttr_Size (POVMSAttributePtr attr, int *size); 281 POVMS_EXPORT int POVMS_CDECL POVMSAttr_Type (POVMSAttributePtr attr, POVMSType *type); 282 283 // Attribute list functions 284 POVMS_EXPORT int POVMS_CDECL POVMSAttrList_New (POVMSAttributeListPtr attr); 285 POVMS_EXPORT int POVMS_CDECL POVMSAttrList_Delete (POVMSAttributeListPtr attr); 286 POVMS_EXPORT int POVMS_CDECL POVMSAttrList_Copy (POVMSAttributeListPtr sourcelist, POVMSAttributeListPtr destlist); 287 POVMS_EXPORT int POVMS_CDECL POVMSAttrList_Append (POVMSAttributeListPtr attr, POVMSAttributePtr item); 288 POVMS_EXPORT int POVMS_CDECL POVMSAttrList_AppendN (POVMSAttributeListPtr attr, int cnt, POVMSAttributePtr item); 289 POVMS_EXPORT int POVMS_CDECL POVMSAttrList_Remove (POVMSAttributeListPtr attr); 290 POVMS_EXPORT int POVMS_CDECL POVMSAttrList_GetNth (POVMSAttributeListPtr attr, int index, POVMSAttributePtr item); 291 POVMS_EXPORT int POVMS_CDECL POVMSAttrList_SetNth (POVMSAttributeListPtr attr, int index, POVMSAttributePtr item); 292 POVMS_EXPORT int POVMS_CDECL POVMSAttrList_RemoveNth(POVMSAttributeListPtr attr, int index); 293 POVMS_EXPORT int POVMS_CDECL POVMSAttrList_Clear (POVMSAttributeListPtr attr); 294 POVMS_EXPORT int POVMS_CDECL POVMSAttrList_Count (POVMSAttributeListPtr attr, int *cnt); 295 296 // Utility functions 297 POVMS_EXPORT int POVMS_CDECL POVMSUtil_SetString (POVMSObjectPtr object, POVMSType key, const char *str); // Note: Strings may not contain \0 characters codes! 298 POVMS_EXPORT int POVMS_CDECL POVMSUtil_SetUCS2String(POVMSObjectPtr object, POVMSType key, const POVMSUCS2 *str); // Note: Strings may not contain \0 characters codes! 299 POVMS_EXPORT int POVMS_CDECL POVMSUtil_SetInt (POVMSObjectPtr object, POVMSType key, POVMSInt value); 300 POVMS_EXPORT int POVMS_CDECL POVMSUtil_SetLong (POVMSObjectPtr object, POVMSType key, POVMSLong value); 301 POVMS_EXPORT int POVMS_CDECL POVMSUtil_SetFloat (POVMSObjectPtr object, POVMSType key, POVMSFloat value); 302 POVMS_EXPORT int POVMS_CDECL POVMSUtil_SetBool (POVMSObjectPtr object, POVMSType key, POVMSBool boolvalue); 303 POVMS_EXPORT int POVMS_CDECL POVMSUtil_SetType (POVMSObjectPtr object, POVMSType key, POVMSType typevalue); 304 POVMS_EXPORT int POVMS_CDECL POVMSUtil_GetStringLength(POVMSObjectPtr object, POVMSType key, int *len); // Note: Includes trailing \0 character code! 305 POVMS_EXPORT int POVMS_CDECL POVMSUtil_GetString (POVMSObjectPtr object, POVMSType key, char *str, int *maxlen); 306 POVMS_EXPORT int POVMS_CDECL POVMSUtil_GetUCS2StringLength(POVMSObjectPtr object, POVMSType key, int *len); // Note: Includes trailing \0 character code! 307 POVMS_EXPORT int POVMS_CDECL POVMSUtil_GetUCS2String(POVMSObjectPtr object, POVMSType key, POVMSUCS2 *str, int *maxlen); 308 POVMS_EXPORT int POVMS_CDECL POVMSUtil_GetInt (POVMSObjectPtr object, POVMSType key, POVMSInt *value); 309 POVMS_EXPORT int POVMS_CDECL POVMSUtil_GetLong (POVMSObjectPtr object, POVMSType key, POVMSLong *value); 310 POVMS_EXPORT int POVMS_CDECL POVMSUtil_GetFloat (POVMSObjectPtr object, POVMSType key, POVMSFloat *value); 311 POVMS_EXPORT int POVMS_CDECL POVMSUtil_GetBool (POVMSObjectPtr object, POVMSType key, POVMSBool *boolvalue); 312 POVMS_EXPORT int POVMS_CDECL POVMSUtil_GetType (POVMSObjectPtr object, POVMSType key, POVMSType *typevalue); 313 POVMS_EXPORT int POVMS_CDECL POVMSUtil_TempAlloc (void **ptr, int datasize); 314 POVMS_EXPORT int POVMS_CDECL POVMSUtil_TempFree (void *ptr); 315 316 // Memory debug functions 317 #ifdef _DEBUG_POVMS_TRACE_MEMORY_ 318 POVMS_EXPORT int POVMS_TraceDump (); 319 #endif 320 321 #endif /* POVMS_H */ 322 323 #ifdef POVMSCPP_H 324 #define POVMS_EXPORT_STREAM_FUNCTIONS 325 #endif 326 327 // Stream functions only available to the C++ interface 328 #ifdef POVMS_EXPORT_STREAM_FUNCTIONS 329 330 // Stream reading functions 331 POVMS_EXPORT int POVMS_CDECL POVMSStream_ReadString (char *data, POVMSStream *stream, int datasize, int *maxstreamsize); 332 POVMS_EXPORT int POVMS_CDECL POVMSStream_ReadUCS2String (POVMSUCS2 *data, POVMSStream *stream, int datasize, int *maxstreamsize); 333 POVMS_EXPORT int POVMS_CDECL POVMSStream_ReadInt (POVMSInt *data, POVMSStream *stream, int *maxstreamsize); 334 POVMS_EXPORT int POVMS_CDECL POVMSStream_ReadLong (POVMSLong *data, POVMSStream *stream, int *maxstreamsize); 335 POVMS_EXPORT int POVMS_CDECL POVMSStream_ReadFloat (POVMSFloat *data, POVMSStream *stream, int *maxstreamsize); 336 POVMS_EXPORT int POVMS_CDECL POVMSStream_ReadType (POVMSType *data, POVMSStream *stream, int *maxstreamsize); 337 POVMS_EXPORT int POVMS_CDECL POVMSStream_Read (struct POVMSData *data, POVMSStream *stream, int *maxstreamsize); 338 339 // Stream writing functions 340 POVMS_EXPORT int POVMS_CDECL POVMSStream_WriteString (const char *data, POVMSStream *stream, int *maxstreamsize); 341 POVMS_EXPORT int POVMS_CDECL POVMSStream_WriteUCS2String (const POVMSUCS2 *data, POVMSStream *stream, int *maxstreamsize); 342 POVMS_EXPORT int POVMS_CDECL POVMSStream_WriteInt (POVMSInt data, POVMSStream *stream, int *maxstreamsize); 343 POVMS_EXPORT int POVMS_CDECL POVMSStream_WriteLong (POVMSLong data, POVMSStream *stream, int *maxstreamsize); 344 POVMS_EXPORT int POVMS_CDECL POVMSStream_WriteFloat (POVMSFloat data, POVMSStream *stream, int *maxstreamsize); 345 POVMS_EXPORT int POVMS_CDECL POVMSStream_WriteType (POVMSType data, POVMSStream *stream, int *maxstreamsize); 346 POVMS_EXPORT int POVMS_CDECL POVMSStream_Write (struct POVMSData *data, POVMSStream *stream, int *maxstreamsize); 347 348 // Stream utility functions 349 POVMS_EXPORT int POVMS_CDECL POVMSStream_Size (struct POVMSData *data); 350 POVMS_EXPORT int POVMS_CDECL POVMSStream_CheckMessageHeader (POVMSStream *stream, int streamsize, int *totalsize); 351 352 #endif 353