oc.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /* Copyright 2009, UCAR/Unidata and OPeNDAP, Inc.
  2. See the COPYRIGHT dap for more information. */
  3. /*
  4. Draft OC External Interface
  5. Created: 4/4/2009
  6. Last Revised: 4/14/2009
  7. */
  8. #ifndef OC_H
  9. #define OC_H
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. /* if defined, use magic numbers for consistency]) */
  13. #define OC_FASTCONSISTENCY
  14. /* OC_MAX_DIMS should be greater or equal to max allowed by dap or netcdf*/
  15. #define OC_MAX_DIMS 1024
  16. /* Specifies the OCtype.*/
  17. /* Primitives = Duplicate of the NODE_Byte..Node_URL union nc_type*/
  18. typedef unsigned long OCtype;
  19. /* Note: use #define rather than enum so we can extend if needed
  20. more easily */
  21. /* Primitives*/
  22. /* OC_Ubyte, OC_Char, OC_Int64 and OC_UInt64 are defined for future extension*/
  23. #define OC_NAT ((OCtype)0)
  24. #define OC_Char ((OCtype)1)
  25. #define OC_Byte ((OCtype)2)
  26. #define OC_UByte ((OCtype)3)
  27. #define OC_Int16 ((OCtype)4)
  28. #define OC_UInt16 ((OCtype)5)
  29. #define OC_Int32 ((OCtype)6)
  30. #define OC_UInt32 ((OCtype)7)
  31. #define OC_Int64 ((OCtype)8)
  32. #define OC_UInt64 ((OCtype)9)
  33. #define OC_Float32 ((OCtype)10)
  34. #define OC_Float64 ((OCtype)11)
  35. #define OC_String ((OCtype)12)
  36. #define OC_URL ((OCtype)13)
  37. /* Non-primitives*/
  38. #define OC_Dataset ((OCtype)100)
  39. #define OC_Sequence ((OCtype)101)
  40. #define OC_Grid ((OCtype)102)
  41. #define OC_Structure ((OCtype)103)
  42. #define OC_Dimension ((OCtype)104)
  43. #define OC_Attribute ((OCtype)105)
  44. #define OC_Attributeset ((OCtype)106)
  45. #define OC_Primitive ((OCtype)107)
  46. #define OC_Group ((OCtype)108)
  47. #define OC_Type ((OCtype)109)
  48. /* Define a set of error
  49. positive are system errors
  50. (needs work)
  51. */
  52. typedef int OCerror;
  53. #define OC_NOERR (0)
  54. #define OC_EBADID (-1)
  55. #define OC_ECHAR (-2)
  56. #define OC_EDIMSIZE (-3)
  57. #define OC_EEDGE (-4)
  58. #define OC_EINVAL (-5)
  59. #define OC_EINVALCOORDS (-6)
  60. #define OC_ENOMEM (-7)
  61. #define OC_ENOTVAR (-8)
  62. #define OC_EPERM (-9)
  63. #define OC_ESTRIDE (-10)
  64. #define OC_EDAP (-11)
  65. #define OC_EXDR (-12)
  66. #define OC_ECURL (-13)
  67. #define OC_EBADURL (-14)
  68. #define OC_EBADVAR (-15)
  69. #define OC_EOPEN (-16)
  70. #define OC_EIO (-17)
  71. #define OC_ENODATA (-18)
  72. #define OC_EDAPSVC (-19)
  73. #define OC_ENAMEINUSE (-20)
  74. #define OC_EDAS (-21)
  75. #define OC_EDDS (-22)
  76. #define OC_EDATADDS (-23)
  77. #define OC_ERCFILE (-24)
  78. #define OC_ENOFILE (-25)
  79. /* Define the classes of DAP DXD objects */
  80. typedef int OCdxd;
  81. #define OCDDS 0
  82. #define OCDAS 1
  83. #define OCDATADDS 2
  84. #define OCDATA OCDATADDS
  85. /* Define flags */
  86. typedef int OCflags;
  87. #define OCONDISK 1
  88. typedef enum OCmode {
  89. OCNULLMODE = 0,
  90. OCFIELDMODE = 1,
  91. OCSEQUENCEMODE = 2,
  92. OCARRAYMODE = 3,
  93. OCPRIMITIVEMODE = 4,
  94. OCEMPTYMODE = 0x8000000 /* internal use only */
  95. } OCmode;
  96. /* Define an unsigned alternative to off(64)_t*/
  97. typedef unsigned long long ocoffset_t;
  98. /* Define a wrapper for dimension sizes */
  99. typedef size_t ocindex_t;
  100. /* Define the effective API */
  101. #ifndef OCINTERNAL_H
  102. /* The OCobject type references a component of a DAS or DDS
  103. (e.g. Sequence, Grid, Dataset, etc). These objects
  104. are nested, so most objects reference a container object
  105. and subnode objects.
  106. */
  107. #ifdef OC_FASTCONSISTENCY
  108. /* Use unsigned int * so we can dereference to get magic number */
  109. typedef unsigned int* OCobject;
  110. #define OCNULL NULL
  111. #else
  112. typedef unsigned long OCobject;
  113. #define OCNULL ((OCobject)0)
  114. #endif
  115. /* These are the two critical types*/
  116. /* Think of OClink as analogous to the C stdio FILE structure;
  117. it "holds" all the other state info about
  118. a connection to the server, the url request, and the DAS/DDS/DATADDSinfo.
  119. */
  120. /* Renamed from OCconnection because of confusion about term "connection"
  121. 3/24/2010 by dmh
  122. */
  123. typedef OCobject OClink;
  124. /* Keep old name for back compatibility */
  125. typedef OClink OCconnection; /*Deprecated*/
  126. /* Tag kind of log entry*/
  127. #define OCLOGNOTE 0
  128. #define OCLOGWARN 1
  129. #define OCLOGERR 2
  130. #define OCLOGDBG 3
  131. /**************************************************/
  132. #ifdef __cplusplus
  133. extern "C" {
  134. #endif
  135. extern int oc_dumpnode(OClink conn, OCobject root0);
  136. /**************************************************/
  137. /* Link management */
  138. extern OCerror oc_open(const char* url, OClink*);
  139. extern OCerror oc_close(OClink);
  140. /**************************************************/
  141. /* Root management */
  142. /* Fetch and parse a given class of DXD the server specified
  143. at open time, and using a specified set of constraints
  144. and flags.
  145. Return the root node of the parsed tree of objects.
  146. */
  147. extern OCerror oc_fetchf(OClink,
  148. const char* constraints,
  149. OCdxd,
  150. OCflags,
  151. OCobject* rootp);
  152. /*
  153. Equivalent to oc_fetchf with zero flag parameter
  154. */
  155. extern OCerror oc_fetch(OClink,
  156. const char* constraints,
  157. OCdxd,
  158. OCobject* rootp);
  159. /* Release/reclaim the tree of objects associated with a given root */
  160. extern OCerror oc_root_free(OClink, OCobject root);
  161. /* Return the # of OCobjects associated with a tree with specified root */
  162. extern unsigned int oc_inq_nobjects(OClink, OCobject root);
  163. /* Return all the OCobjects associated with a tree with specified root */
  164. extern OCobject* oc_inq_objects(OClink, OCobject root);
  165. /* Return the text of the DDS or DAS as received from the server */
  166. extern const char* oc_inq_text(OClink, OCobject root);
  167. /**************************************************/
  168. /* Object Management */
  169. /* Any of the pointers may be NULL in the following procedure call;
  170. If the object is of type Dataset, then return # of global attributes
  171. If the object is of type Attribute, then return the # of values in nattrp.
  172. The caller must free the resulting name string.
  173. */
  174. extern OCerror oc_inq_object(OClink, OCobject,
  175. char** namep,
  176. OCtype* typep,
  177. OCtype* primitivetypep, /* if objecttype == OC_Primitive */
  178. OCobject* parentp,
  179. unsigned int* rankp,
  180. unsigned int* nsubnodesp,
  181. unsigned int* nattrp);
  182. /* Also define some more individual accessors */
  183. extern OCerror oc_inq_name(OClink,OCobject,char**);
  184. extern OCerror oc_inq_class(OClink,OCobject,OCtype*);
  185. extern OCerror oc_inq_type(OClink,OCobject,OCtype*); /*alias for oc_inq_class*/
  186. extern OCerror oc_inq_primtype(OClink,OCobject,OCtype*);
  187. extern OCerror oc_inq_nsubnodes(OClink,OCobject,unsigned int*);
  188. extern OCerror oc_inq_rank(OClink,OCobject,unsigned int*);
  189. extern OCerror oc_inq_nattr(OClink,OCobject,unsigned int*);
  190. extern OCerror oc_inq_root(OClink,OCobject,OCobject*);
  191. extern OCerror oc_inq_container(OClink,OCobject,OCobject*);
  192. /* Return the subnode objects, if any, associated with a given object.
  193. Caller must free the returned subnodes memory.
  194. */
  195. extern OCerror oc_inq_subnodes(OClink,OCobject,OCobject** subnodes);
  196. /* Return the i'th subnode object, if any, associated with a given object */
  197. /* If there is none such, then return OC_EINVAL */
  198. extern OCerror oc_inq_ith(OClink,OCobject, unsigned int, OCobject*);
  199. /* Return the dimension objects, if any, associated with a given object */
  200. /* Caller must free returned vector for dimids */
  201. /* If there are no dimensions (i.e. rank == 0), then return NULL */
  202. extern OCerror oc_inq_dimset(OClink,OCobject, OCobject** dimids);
  203. /* Return the i'th dim object, if any, associated with a given object */
  204. /* If there is no such dim, then return OC_EINVAL */
  205. extern OCerror oc_inq_ithdim(OClink,OCobject, unsigned int, OCobject*);
  206. /* Return the size and name associated with a given dimension object
  207. as defined in the DDS
  208. */
  209. extern OCerror oc_inq_dim(OClink,OCobject,ocindex_t*,char**);
  210. /* Attribute Management */
  211. /* Added: 11/2/2009 DMH:
  212. Provide access to DDS node attributes
  213. in the form of the original underlying
  214. DAS string.
  215. One specifies the DDS root to get the global attributes.
  216. Caller must free returned strings.
  217. */
  218. extern OCerror oc_inq_attrstrings(OClink,OCobject, unsigned int i,
  219. char** name, OCtype* octype,
  220. unsigned int* nvalues,char*** stringvalues);
  221. /* Obtain the attributes associated with a given DDS OCobject.
  222. One specifies the DDS root to get the global attributes
  223. This code takes the DAS strings and does a default
  224. conversion to binary values.
  225. */
  226. extern OCerror oc_inq_attr(OClink,OCobject, unsigned int i,
  227. char** name,OCtype* octype,
  228. unsigned int* nvalues,void** values);
  229. /* Convenience function to simplify reclaiming the allocated attribute
  230. value memory
  231. */
  232. extern void oc_attr_reclaim(OCtype, unsigned int nvalues, void* values);
  233. /* Access ith value string of a DAS object.
  234. OCtype of the object is assumed to be OC_Attribute.
  235. Note that this is different than the above inq_attr
  236. and inq_attrstrings, which work on DDS
  237. objects. Note also that the return value is always a string.
  238. Caller must free returned string.
  239. */
  240. extern OCerror oc_inq_dasattr_nvalues(OClink, OCobject,
  241. unsigned int* nvaluesp);
  242. extern OCerror oc_inq_dasattr(OClink,OCobject, unsigned int,
  243. OCtype* primtypep, char** valuep);
  244. /**************************************************/
  245. /* Data management */
  246. /*
  247. These procedures allow for the location and extraction
  248. of data from the data packet part of a DATADDS.
  249. See ocuserman.html for detailed description.
  250. */
  251. typedef OCobject OCdata;
  252. /* Obtain the OCdata object that references the
  253. whole data from a DATADDS fetch request specified
  254. by the root object. This does not access the server.
  255. */
  256. extern OCerror oc_data_root(OClink, OCobject root, OCdata);
  257. /* Create an empty OCdata object */
  258. extern OCdata oc_data_new(OClink);
  259. /* Reclaim a no longer needed OCdata object */
  260. extern OCerror oc_data_free(OClink, OCdata);
  261. /* Given an OCdata object, set the nested subnode OCdata object
  262. to refer to the data associated with the i'th element of
  263. the parent data object. NOTE: if the i'th element is not
  264. present then this function will return OC_ENODATA.
  265. See the user's manual for details on mapping multi-
  266. dimensional arrays to single indices.
  267. */
  268. extern OCerror oc_data_ith(OClink,
  269. OCdata parentdata,
  270. ocindex_t index,
  271. OCdata subdata);
  272. /* Return the actual data values associated with the specified OCdata.
  273. The OCdata is assumed to be referencing either a scalar
  274. primitive value or a (1d) array of primitive values.
  275. If scalar, then index must be 0 and count must be 1.
  276. */
  277. extern OCerror oc_data_get(OClink,OCdata,
  278. void* memory, size_t memsize,
  279. ocindex_t index, ocindex_t count);
  280. /* Return the OCdata's current index */
  281. extern OCerror oc_data_index(OClink,OCdata, ocindex_t*);
  282. /* Return the mode associated the specified OCdata object */
  283. extern OCerror oc_data_mode(OClink,OCdata, OCmode*);
  284. /* Return the OCobject associated the specified OCdata object */
  285. extern OCerror oc_data_object(OClink,OCdata, OCobject*);
  286. /* Compute the the count associated with the specified OCdata
  287. instance. Note: this is potentially computationally costly
  288. when computing # records.
  289. */
  290. extern OCerror oc_data_count(OClink, OCdata, ocindex_t*);
  291. /**************************************************/
  292. /* Misc. OCtype-related functions */
  293. /* Return size of the given type (Primitive only) */
  294. extern size_t oc_typesize(OCtype);
  295. /* Return a canonical printable string describing a given type:
  296. e.g. Byte, Int16, etc.
  297. */
  298. extern const char* oc_typetostring(OCtype);
  299. /* Given a value of a primitive OC type, provide a canonical
  300. string representing that value
  301. */
  302. extern OCerror oc_typeprint(OCtype, char* buf, size_t bufsize, void* value);
  303. /**************************************************/
  304. /* Logging */
  305. extern void oc_loginit(void);
  306. extern void oc_setlogging(int onoff); /* 1=>start logging 0=>stop */
  307. extern void oc_logopen(const char* logfilename);
  308. extern void oc_logclose(void);
  309. extern void oc_logtext(int tag, const char* text);
  310. extern void oc_log(int tag, const char* fmt, ...);
  311. /**************************************************/
  312. /* Miscellaneous */
  313. /* Convert an OCerror to a human readable string */
  314. extern const char* oc_errstring(int err);
  315. /* Get client parameters from the URL
  316. DO NOT free the result
  317. */
  318. extern const char* oc_clientparam_get(OClink, const char* param);
  319. extern OCerror oc_clientparam_delete(OClink, const char* param);
  320. extern OCerror oc_clientparam_insert(OClink, const char* param, const char* value);
  321. extern OCerror oc_clientparam_replace(OClink, const char* param, const char* value);
  322. /**************************************************/
  323. /* Merging operations */
  324. /* Merge a specified DAS into a specified DDS or DATADDS */
  325. extern OCerror oc_attach_das(OClink, OCobject dasroot, OCobject ddsroot);
  326. /**************************************************/
  327. /* Debugging */
  328. extern OCerror oc_dd(OClink,OCobject,int level);
  329. extern OCerror oc_ddnode(OClink,OCobject);
  330. /* When a server error is detected, then it is possible
  331. to get the server error info using this procedure */
  332. extern OCerror oc_svcerrordata(OClink link, char** codep,
  333. char** msgp, long* httpp);
  334. /**************************************************/
  335. /* Experimental */
  336. /* New 10/31/2009: return raw information about a datadds
  337. */
  338. extern OCerror oc_raw_xdrsize(OClink, OCobject, size_t*);
  339. /* Resend a url as a head request to check the Last-Modified time */
  340. extern OCerror oc_update_lastmodified_data(OClink);
  341. /* Get last known modification time; -1 => data unknown */
  342. extern long oc_get_lastmodified_data(OClink);
  343. extern OCerror oc_ping(const char* url);
  344. /**************************************************/
  345. #endif /*OCINTERNAL_H*/
  346. #ifdef __cplusplus
  347. }
  348. #endif
  349. #endif /*OC_H*/