/* ----------------------------------------------------------------------------
 * Raima Database Manager
 *
 * Copyright (c) 2001-2008 Birdstep Technology Inc.,  All rights reserved.
 *
 * Use of this software, whether in source code format, or in executable,
 * binary object code form, is governed by the Birdstep LICENSE which
 * is fully described in the LICENSE.TXT file, included within this
 * distribution of files.
 * ----------------------------------------------------------------------------
 */
#if !defined(__PROTO_H)
#define __PROTO_H

#if defined(__cplusplus)
extern "C" {
#endif

/* From dberr.c */
RDM_EXPORT int32_t EXTERNAL_FCN dberr_msg(char *, uint32_t, const DB_TASK *);

RDM_EXPORT int32_t EXTERNAL_FCN _dberr(int32_t, const char *, int32_t, DB_TASK *); /*lint -esym(534,_dberr) */
#define dberr(n)   _dberr(n, __FILE__, __LINE__, db->task)
#define dbierr(n)  _dberr(n, __FILE__, __LINE__, dbi->db->task)
#define taskerr(n) _dberr(n, __FILE__, __LINE__, task)

/* From connect.c */
RDM_EXPORT int32_t EXTERNAL_FCN sortcmp(const SET_ENTRY *, const char *, const char *, const DB_ENTRY *);
/* From dio.c: */
RDM_EXPORT int32_t EXTERNAL_FCN dio_open(FILE_NO, uint8_t, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_close(FILE_NO, const DB_INSTANCE *);
int32_t EXTERNAL_FCN dio_clear_db(const DB_ENTRY *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_clear(const DB_TASK *);

RDM_EXPORT int32_t EXTERNAL_FCN dio_blobget(FILE_NO, F_ADDR, int32_t, char **, PGHNDL *, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_flush(DB_TASK *);
int32_t EXTERNAL_FCN dio_flush_precommit(DB_TASK *);
int32_t EXTERNAL_FCN dio_flush_commit(DB_TASK *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_keyget(FILE_NO, F_ADDR, int32_t, char **, PGHNDL *, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_read(const DB_ADDR *, char **, int32_t, PGHNDL *, const DB_ENTRY *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_write(PGHNDL); /*lint -esym(534,dio_write) */
RDM_EXPORT int32_t EXTERNAL_FCN dio_release(PGHNDL); /*lint -esym(534,dio_release) */
RDM_EXPORT int32_t EXTERNAL_FCN dio_read_slot(FILE_NO, F_ADDR, int32_t, char **, PGHNDL *, const DB_INSTANCE *);
RDM_EXPORT void   *EXTERNAL_FCN dio_pgBuffer(PGHNDL);

RDM_EXPORT int32_t         EXTERNAL_FCN dio_pzalloc(FILE_NO, F_ADDR *, int16_t *, const RECORD_ENTRY *, const DB_INSTANCE *);
RDM_EXPORT int32_t         EXTERNAL_FCN dio_pzdel(FILE_NO, F_ADDR, F_ADDR, const RECORD_ENTRY *, const DB_INSTANCE *);
#if defined(NOT_USED)
int32_t         EXTERNAL_FCN dio_pzgetcircnext(FILE_NO, F_ADDR *, const DB_INSTANCE *);
#endif
RDM_EXPORT PSP_FILE_OFFSET EXTERNAL_FCN dio_filesize(FILE_NO, const DB_INSTANCE *);
RDM_EXPORT int32_t         EXTERNAL_FCN dio_truncate(FILE_NO, PSP_FILE_OFFSET, const DB_INSTANCE *);

/* From keyfcns.c: */
#define KEY_FORWARD  (1)
#define KEY_REVERSE (-1)
RDM_EXPORT int32_t EXTERNAL_FCN key_open(const DB_TASK *);
RDM_EXPORT void    EXTERNAL_FCN key_close(const DB_ENTRY *);
RDM_EXPORT int32_t EXTERNAL_FCN key_init(uint32_t, const FIELD_ENTRY **, const DB_ENTRY *);
RDM_EXPORT void    EXTERNAL_FCN key_reset(FILE_NO, const DB_ENTRY *);
RDM_EXPORT int32_t EXTERNAL_FCN key_locate(const FIELD_ENTRY *, const void *, const DB_ADDR *, DB_ADDR *, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN key_scan(KEY_INST_INFO *, int32_t);
RDM_EXPORT int32_t EXTERNAL_FCN key_boundary(KEY_INST_INFO *, int32_t);
RDM_EXPORT int32_t EXTERNAL_FCN key_insert(const FIELD_ENTRY *, const char *, const DB_ADDR *, const KEY_INFO *, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN key_bldcom(const FIELD_ENTRY *, const char *, RDM_DATA_FORMAT, char *, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN key_bldgrp(const FIELD_ENTRY *, const char *, RDM_DATA_FORMAT, char *, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN hash_insert(const FIELD_ENTRY *, const char *, const DB_ADDR *, const HASH_INFO *, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN hash_locate(const FIELD_ENTRY *, const void *, DB_ADDR *, const DB_INSTANCE *);
RDM_EXPORT void EXTERNAL_FCN    get_hash_prev(F_ADDR *, const KEY_NODE *, const FILE_ENTRY *, const DB_ENTRY *);
RDM_EXPORT void EXTERNAL_FCN    get_hash_next(F_ADDR *, const KEY_NODE *, const FILE_ENTRY *, const DB_ENTRY *);

/* From libfcns.c: */
RDM_EXPORT int32_t EXTERNAL_FCN fldcmp(const FIELD_ENTRY *, const FIELD_DATA *, const FIELD_DATA *, const DB_ENTRY *);
RDM_EXPORT int32_t EXTERNAL_FCN check_dbfiles_w_locks(const DB_ENTRY *);
RDM_EXPORT int32_t EXTERNAL_FCN check_transaction_type(TRANS_TYPE, DB_TASK *);
RDM_EXPORT int32_t EXTERNAL_FCN DBAcmp(const DB_ADDR *, const DB_ADDR *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_pzgetdchain(FILE_NO, F_ADDR *, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_pzgetnext(FILE_NO, F_ADDR *, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_pzgetdbkey(FILE_NO, uint8_t cryptkey[CRYPTPWLEN], const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_pzgetfilekey(FILE_NO, uint8_t cryptkey[CRYPTPWLEN], const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_pzgettotal(uint16_t, F_ADDR *, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_pzsetdchain(FILE_NO, F_ADDR, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_pzsetnext(FILE_NO, F_ADDR, const DB_INSTANCE *);
int32_t EXTERNAL_FCN dio_pzsetdbtkey(FILE_NO, const uint8_t cryptkey[CRYPTPWLEN], const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_pzsetfilekey(FILE_NO, const uint8_t cryptkey[CRYPTPWLEN], const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN dio_pzsetdbkey(FILE_NO, const uint8_t cryptkey[CRYPTPWLEN], const DB_INSTANCE *dbi);
RDM_EXPORT int32_t EXTERNAL_FCN dio_pzsettotal(uint16_t, F_ADDR, const DB_INSTANCE *);
void EXTERNAL_FCN MemPtr4ToUnoMemPtr(const MEM_PTR4 *, MEM_PTR *, uint16_t);
void EXTERNAL_FCN MemPtr8ToUnoMemPtr(const MEM_PTR8 *, MEM_PTR *, uint16_t);
void EXTERNAL_FCN UnoMemPtrToMemPtr4(const MEM_PTR *, MEM_PTR4 *);
void EXTERNAL_FCN UnoMemPtrToMemPtr8(const MEM_PTR *, MEM_PTR8 *);
void EXTERNAL_FCN SetPtr4ToUnoSetPtr(const SET_PTR4 *, SET_PTR *, uint16_t);
void EXTERNAL_FCN SetPtr8ToUnoSetPtr(const SET_PTR8 *, SET_PTR *, uint16_t);
void EXTERNAL_FCN UnoSetPtrToSetPtr4(const SET_PTR *, SET_PTR4 *);
void EXTERNAL_FCN UnoSetPtrToSetPtr8(const SET_PTR *, SET_PTR8 *);
RDM_EXPORT void EXTERNAL_FCN DbAddr48ToDbAddr(const void *, DB_ADDR *, uint16_t, const DB_ENTRY *);
RDM_EXPORT void EXTERNAL_FCN DbAddr4ToDbAddr(const DB_ADDR4 *, DB_ADDR *, uint16_t);
RDM_EXPORT void EXTERNAL_FCN DbAddr8ToDbAddr(const DB_ADDR8 *, DB_ADDR *, uint16_t);

RDM_EXPORT void EXTERNAL_FCN DbAddrToDbAddr48(const DB_ADDR *, void *, const DB_ENTRY *);
RDM_EXPORT void EXTERNAL_FCN DbAddrToDbAddr4(const DB_ADDR *, DB_ADDR4 *);
RDM_EXPORT void EXTERNAL_FCN DbAddrToDbAddr8(const DB_ADDR *, DB_ADDR8 *);

RDM_EXPORT void EXTERNAL_FCN get_uno_set_ptr(SET_PTR *, const void *, uint16_t, const DB_ENTRY *);
void EXTERNAL_FCN get_uno_set_ptr4(SET_PTR *, const SET_PTR4 *, uint16_t);
void EXTERNAL_FCN get_uno_set_ptr8(SET_PTR *, const SET_PTR8 *, uint16_t);

RDM_EXPORT void EXTERNAL_FCN put_uno_set_ptr(void *, const SET_PTR *, const DB_ENTRY *);

RDM_EXPORT void EXTERNAL_FCN get_uno_mem_ptr(MEM_PTR *, const void *, uint16_t, const DB_ENTRY *);
void EXTERNAL_FCN get_uno_mem_ptr4(MEM_PTR *, const void *, uint16_t);
void EXTERNAL_FCN get_uno_mem_ptr8(MEM_PTR *, const void *, uint16_t);

RDM_EXPORT void EXTERNAL_FCN put_uno_mem_ptr(void *, const MEM_PTR *, const DB_ENTRY *);

RDM_EXPORT void EXTERNAL_FCN get_key_slot_ptr(KEY_SLOT_PTR *, const char *, const DB_ENTRY *);

RDM_EXPORT void EXTERNAL_FCN get_vaddr(V_ADDR *, const void *, const SCHEMA_ENTRY *);
void EXTERNAL_FCN put_vaddr(void *, V_ADDR, const DB_ENTRY *);

RDM_EXPORT void EXTERNAL_FCN get_faddr(F_ADDR *, const void *, const DB_ENTRY *);
RDM_EXPORT void EXTERNAL_FCN put_faddr(void *, F_ADDR, const DB_ENTRY *);

RDM_EXPORT int32_t EXTERNAL_FCN nfld_check(int32_t, const FIELD_ENTRY **, const DB_ENTRY *);
RDM_EXPORT int32_t EXTERNAL_FCN nkey_check(int32_t, const FIELD_ENTRY **, const DB_ENTRY *);
int32_t EXTERNAL_FCN nhash_check(int32_t, const FIELD_ENTRY **, const DB_ENTRY *);
RDM_EXPORT int32_t EXTERNAL_FCN nset_check(int32_t, const SET_ENTRY **, const DB_ENTRY *);
int32_t EXTERNAL_FCN nhashorkey_check( int32_t, const FIELD_ENTRY **, const DB_ENTRY *);
RDM_EXPORT int32_t EXTERNAL_FCN nrec_check(int32_t, const RECORD_ENTRY **, const DB_ENTRY *);
RDM_EXPORT const KEY_ENTRY *EXTERNAL_FCN get_next_key_field(const FIELD_ENTRY *, const KEY_ENTRY *, const SCHEMA_ENTRY *);
RDM_EXPORT int32_t EXTERNAL_FCN check_dba( const DB_ADDR  *dba, const DB_ENTRY *db);
int32_t EXTERNAL_FCN check_dbaEx( const DB_ADDR  *dba, F_ADDR *last_recno, const DB_ENTRY *db);

RDM_EXPORT const FIELD_ENTRY  *EXTERNAL_FCN get_fd_by_name(const RECORD_ENTRY *, const char *);
RDM_EXPORT const FILE_ENTRY   *EXTERNAL_FCN get_ft_by_name(const DB_ENTRY *, const char *);
RDM_EXPORT const RECORD_ENTRY *EXTERNAL_FCN get_rt_by_name(const DB_ENTRY *, const char *);
RDM_EXPORT const RECORD_ENTRY *EXTERNAL_FCN get_rt_by_dba(const DB_ENTRY *, const DB_ADDR *);
RDM_EXPORT const SET_ENTRY    *EXTERNAL_FCN get_st_by_name(const DB_ENTRY *, const char *);
RDM_EXPORT uint16_t            EXTERNAL_FCN get_null_offset(const RECORD_ENTRY *);
RDM_EXPORT const FIELD_ENTRY  *EXTERNAL_FCN get_key_fd_by_name(const RECORD_ENTRY *, const char *);
RDM_EXPORT uint32_t            EXTERNAL_FCN count_valid_records(const RDM_RAWSTAT *, uint32_t);
RDM_EXPORT int32_t             EXTERNAL_FCN get_field_constant(const FIELD_ENTRY *fd);

/* From opens.c: */
PSP_FH  EXTERNAL_FCN open_b(const char *, uint32_t, uint16_t, DB_TASK *);
void    EXTERNAL_FCN commit_file(PSP_FH, const DB_TASK *);

/* From recfcns.c: */
RDM_EXPORT int32_t EXTERNAL_FCN r_gfld(const FIELD_ENTRY *, const char *, char *, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN r_gvarfld(const FIELD_ENTRY *, const char *, char *, const DB_INSTANCE *);
RDM_EXPORT int32_t EXTERNAL_FCN r_tstoptkey(const FIELD_ENTRY *, const char *, const DB_INSTANCE *);

/* From pathfcns.c */
int32_t EXTERNAL_FCN con_dbd(char *, const char *, char *, DB_TASK *);
int32_t EXTERNAL_FCN con_dbf(char *, const char *, const char *, char *, DB_TASK *);
char   *EXTERNAL_FCN get_element(const char *, int32_t);

/* From rdmreplication.c: */
void EXTERNAL_FCN get_final_replog_name(char *, DB_ULONG, const DB_TASK *);

/* From enter.c */
RDM_EXPORT int32_t EXTERNAL_FCN db_enter(const char *, int32_t, DB_TASK *, DB_ENTRY **);
RDM_EXPORT int32_t EXTERNAL_FCN db_exit(int32_t, DB_TASK *);
RDM_EXPORT int32_t EXTERNAL_FCN dh_enter(const char *, const DB_ENTRY *);
RDM_EXPORT int32_t EXTERNAL_FCN dh_exit(int32_t, const DB_ENTRY *);

/* Functions called by utils */
RDM_EXPORT int32_t EXTERNAL_FCN db_initfile(uint16_t, FILE_NO, const DB_ENTRY *);

#if defined(__cplusplus)
}
#endif

#endif  /* __PROTO_H */

