2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: c_api_common.cc /main/5 1996/07/18 16:01:11 drk $ */
25 #include "dstr/void_ptr_array.h"
26 #include "storage/page_storage.h"
27 #include "api/info_lib.h"
30 #include "schema/store_desc.h"
31 #include "dynhash/data_t.h"
32 #include "index/index.h"
33 #include "object/compressed_pstring.h"
34 #include "object/pstring.h"
36 #include "oliasdb/DtMmdb.h"
37 #include "oliasdb/olias_funcs.h"
38 #include "oliasdb/c_api_common.h"
39 #include "oliasdb/graphic_hd.h"
41 #include "exception_init.h"
43 void_ptr_array* infolib_array = 0;
44 void_ptr_array* bookcase_array = 0;
45 OLIAS_DB *mmdb_ptr = 0;
47 DtMmdbHandle* DtMmdbGroundId;
49 void initialize_MMDB()
51 initialize_exception();
55 cin_ptr = new fstream(0);
56 cout_ptr = new fstream(1);
57 cerr_ptr = new fstream(2);
59 g_memory_pool_ptr = new memory_pool;
61 page_storage::f_global_pcache_ptr = new page_cache_global_part;
63 ostring::input_buf = new char[LBUFSIZ];
65 data_t::larson_convertor_ptr = new atoi_larson;
66 data_t::pearson_convertor_ptr = new atoi_pearson(SHRT_MAX, 256);
68 ground_ptr = new oid_t(c_code_t(0), i_code_t(0));
70 //root::io_info_buffer_ptr = new struct persis_t;
72 pstring::v_io_buf_ptr = new buffer(LBUFSIZ);
73 graphic_smart_ptr::local_graphic_buffer_ptr = new buffer(LBUFSIZ);
75 compressed_pstring::working_buffer_ptr = new buffer(LBUFSIZ);
76 compressed_pstring::v_cp_io_buf_ptr = new buffer(LBUFSIZ);
78 store_desc::v_unixf_pool_ptr =
79 new lru(ACTIVE_UNIXF_SZ, INACTIVE_UNIXF_SZ, false);
81 c_index::v_static_key_ptr = new key_type(LBUFSIZ);
83 infolib_array = new void_ptr_array(10);
84 bookcase_array = new void_ptr_array(10);
89 delete c_index::v_static_key_ptr;
91 delete store_desc::v_unixf_pool_ptr;
93 delete compressed_pstring::working_buffer_ptr;
94 delete compressed_pstring::v_cp_io_buf_ptr;
96 delete pstring::v_io_buf_ptr;
97 delete graphic_smart_ptr::local_graphic_buffer_ptr;
99 //delete root::io_info_buffer_ptr;
103 delete data_t::larson_convertor_ptr;
104 delete data_t::pearson_convertor_ptr;
106 delete ostring::input_buf;
108 delete page_storage::f_global_pcache_ptr;
110 delete g_memory_pool_ptr;
116 delete infolib_array;
117 delete bookcase_array;
123 ///////////////////////////////////////////////////////////////
139 void* operator new( size_t sz ) throw(std::bad_alloc)
141 void* p = (void*)malloc(sz);
142 //printf("a::operator new called(). sz= %d, allo=%x\n", sz, p);
146 void operator delete( void* p ) throw()
148 //printf("a::operator free called(). alloc= %x\n", p);
155 void* centerline_new(int n, char*, int)
157 return :: operator new(n);
163 info_lib* getInfoLib(int infolib_descriptor)
165 if ( 0 <= infolib_descriptor && infolib_array &&
166 infolib_descriptor < infolib_array -> no_elmts()
169 return (info_lib*)(*infolib_array)[infolib_descriptor];
175 info_base* getBookCase(int bookcase_descriptor)
177 if ( 0 <= bookcase_descriptor && bookcase_array &&
178 bookcase_descriptor < bookcase_array -> no_elmts()
180 return (info_base*)(*bookcase_array)[bookcase_descriptor];
185 oid_t* getPrimiaryOid(DtMmdbInfoRequest* x)
187 if ( x == 0 ) return 0;
189 if ( x -> primary_oid == 0 ) return 0;
191 return (oid_t*)(x -> primary_oid -> oid_ptr);
194 oid_t* getSecondaryOid(DtMmdbInfoRequest* x)
196 if ( x == 0 ) return 0;
198 if ( x -> secondary_oid == 0 ) return 0;
200 return (oid_t*)(x -> secondary_oid -> oid_ptr);
203 int getSeqNum(DtMmdbInfoRequest* x)
205 if ( x == 0 ) return -1;
206 return x -> sequence_num;
209 const char* getLocator(DtMmdbInfoRequest* x)
211 if ( x == 0 ) return 0;
213 return x -> locator_ptr;
216 DtMmdbHandle* newDtMmdbHandle(const oid_t& x)
218 oid_t* y = new oid_t(x);
219 DtMmdbHandle *z = (DtMmdbHandle*)malloc(sizeof(DtMmdbHandle));
220 z -> oid_ptr = (void*)y;
224 DtMmdbGraphicInfo* newDtMmdbGraphicInfo()
226 DtMmdbGraphicInfo *z =
227 (DtMmdbGraphicInfo*)malloc(sizeof(DtMmdbGraphicInfo));
231 void DtMmdbFreeHandle(DtMmdbHandle* x)
234 // delete x -> oid_ptr;
239 void DtMmdbFreeHandleList(DtMmdbHandle** list)
244 DtMmdbFreeHandle(list[i]);
251 #ifdef REGRESSION_TEST
252 extern int auto_test(int argc, char** argv, OLIAS_DB& db);
256 int auto_test_c_api(int argc, char** argv)
260 #ifdef REGRESSION_TEST
262 return auto_test(argc, argv, db);
268 mcatch (mmdbException &,e)
270 cerr << "Exception msg: " << e << "\n";
279 DtMmdbInfoRequest* newDtMmdbInfoRequestWithLoc(int bc_id, char* loc)
281 DtMmdbInfoRequest* x =
282 (DtMmdbInfoRequest*) malloc(sizeof(DtMmdbInfoRequest));
285 x -> bookcase_descriptor = bc_id ;
286 x -> primary_oid = 0;
287 x -> secondary_oid = 0;
288 x -> locator_ptr = loc;
292 DtMmdbInfoRequest* newDtMmdbInfoRequestWithPrimaryOid(int bc_id, char* oid_str)
294 DtMmdbInfoRequest* x =
295 (DtMmdbInfoRequest*) malloc(sizeof(DtMmdbInfoRequest));
298 x -> bookcase_descriptor = bc_id ;
299 x -> locator_ptr = 0;
300 x -> primary_oid = newDtMmdbHandle(oid_t(oid_str, true, false));
301 x -> secondary_oid = 0;
305 DtMmdbInfoRequest* newDtMmdbInfoRequestWithSecondaryOid(int bc_id, char* oid_str)
307 DtMmdbInfoRequest* x =
308 (DtMmdbInfoRequest*) malloc(sizeof(DtMmdbInfoRequest));
311 x -> bookcase_descriptor = bc_id ;
312 x -> locator_ptr = 0;
313 x -> primary_oid = 0;
314 x -> secondary_oid = newDtMmdbHandle(oid_t(oid_str, true, false));
318 DtMmdbInfoRequest* newDtMmdbInfoRequestWithSeqnum(int bc_id, char* str)
320 DtMmdbInfoRequest* x =
321 (DtMmdbInfoRequest*) malloc(sizeof(DtMmdbInfoRequest));
324 x -> bookcase_descriptor = bc_id ;
325 x -> locator_ptr = 0;
326 x -> primary_oid = 0;
327 x -> secondary_oid = 0;
328 x -> sequence_num = atoi(str);
332 char* DtMmdbHandleToString(DtMmdbHandle* x)
334 static char buf[100];
336 oid_t *z = (oid_t*)(x -> oid_ptr);
337 snprintf(buf, sizeof(buf), "%d.%d", z -> ccode(), (int)z -> icode());
344 void DtMmdbFreeInfoRequest(DtMmdbInfoRequest* x)
347 DtMmdbFreeHandle(x-> primary_oid);
348 DtMmdbFreeHandle(x-> secondary_oid);