cbarry.h

Go to the documentation of this file.
00001 /**
00002  * \file        cbarry.h
00003  *              Main header file for Barry C API - incomplete
00004  */
00005 
00006 /*
00007     Copyright (C) 2007-2012, Net Direct Inc. (http://www.netdirect.ca/)
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018     See the GNU General Public License in the COPYING file at the
00019     root directory of this project for more details.
00020 */
00021 
00022 #ifndef __BARRY_CBARRY_H__
00023 #define __BARRY_CBARRY_H__
00024 
00025 /*
00026  * Supporting C headers
00027  */
00028 #include "dll.h"
00029 #include <stdint.h>
00030 #include <time.h>
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 
00036 /*
00037  * Barry C API
00038  *
00039  * All functions that can fail will either return a handle, which can
00040  * be compared to NULL, or return int, which will == -1 on error.
00041  *
00042  * Functions that return a "count" can also fail, but rarely (such as
00043  * if you pass in a bad handle).
00044  */
00045 
00046 /* Handle types */
00047 typedef void* probe_handle_t;
00048 typedef void* con_handle_t;
00049 typedef void* state_table_handle_t;
00050 typedef void* record_handle_t;
00051 typedef void (*process_record_callback_t)(int record_type,
00052         record_handle_t filled_record);
00053 typedef void (*fill_record_callback_t)(int record_type,
00054         record_handle_t empty_record);
00055 
00056 /* Record type codes */
00057 #define BARRY_RECORD_CONTACT            1
00058 #define BARRY_RECORD_MESSAGE            2
00059 #define BARRY_RECORD_CALENDAR           3
00060 #define BARRY_RECORD_SERVICEBOOK        4
00061 
00062 /* Record field type codes */
00063 #define BARRY_FIELDTYPE_NUMBER          1       /* uint32_t */
00064 #define BARRY_FIELDTYPE_STRING          2       /* null terminated or raw str */
00065 #define BARRY_FIELDTYPE_TIME            3       /* time_t */
00066 
00067 #define IS_NUMBER(fieldcode)    (((fieldcode & 0xff0000) == 0x010000)
00068 #define IS_STRING(fieldcode)    (((fieldcode & 0xff0000) == 0x020000)
00069 #define IS_TIME(fieldcode)      (((fieldcode & 0xff0000) == 0x030000)
00070 
00071 /* Contact record field codes */
00072 #define BARRY_CONTACT_RECORDID          0x010101        /* uint32_t */
00073 #define BARRY_CONTACT_EMAIL             0x020102        /* strings below... */
00074 #define BARRY_CONTACT_PHONE             0x020103
00075 #define BARRY_CONTACT_FAX               0x020104
00076 #define BARRY_CONTACT_WORKPHONE         0x020105
00077 #define BARRY_CONTACT_HOMEPHONE         0x020106
00078 #define BARRY_CONTACT_MOBILEPHONE       0x020107
00079 #define BARRY_CONTACT_PAGER             0x020108
00080 #define BARRY_CONTACT_PIN               0x020109
00081 #define BARRY_CONTACT_FIRSTNAME         0x02010a
00082 #define BARRY_CONTACT_LASTNAME          0x02010b
00083 #define BARRY_CONTACT_COMPANY           0x02010c
00084 #define BARRY_CONTACT_DEFAULTCOMMMETHOD 0x02010d
00085 #define BARRY_CONTACT_ADDRESS1          0x02010e
00086 #define BARRY_CONTACT_ADDRESS2          0x02010f
00087 #define BARRY_CONTACT_ADDRESS3          0x020110
00088 #define BARRY_CONTACT_CITY              0x020111
00089 #define BARRY_CONTACT_PROVINCE          0x020112
00090 #define BARRY_CONTACT_POSTALCODE        0x020113
00091 #define BARRY_CONTACT_COUNTRY           0x020114
00092 #define BARRY_CONTACT_TITLE             0x020115
00093 #define BARRY_CONTACT_PUBLICKEY         0x020116
00094 #define BARRY_CONTACT_NOTES             0x020117
00095 
00096 /* Message record field codes */
00097 #define BARRY_MESSAGE_FROM_NAME         0x020201        /* all strings */
00098 #define BARRY_MESSAGE_FROM_EMAIL        0x020202
00099 #define BARRY_MESSAGE_TO_NAME           0x020203
00100 #define BARRY_MESSAGE_TO_EMAIL          0x020204
00101 #define BARRY_MESSAGE_CC_NAME           0x020205
00102 #define BARRY_MESSAGE_CC_EMAIL          0x020206
00103 #define BARRY_MESSAGE_SUBJECT           0x020207
00104 #define BARRY_MESSAGE_BODY              0x020208        /* string or raw */
00105 
00106 /* Calendar record field codes */
00107 #define BARRY_CALENDAR_ALLDAYEVENT      0x010301        /* true/false number */
00108 #define BARRY_CALENDAR_SUBJECT          0x020302        /* strings... */
00109 #define BARRY_CALENDAR_NOTES            0x020303
00110 #define BARRY_CALENDAR_LOCATION         0x020304
00111 #define BARRY_CALENDAR_NOTIFICATIONTIME 0x030305        /* time_t... */
00112 #define BARRY_CALENDAR_STARTTIME        0x030306
00113 #define BARRY_CALENDAR_ENDTIME          0x030307
00114 #define BARRY_CALENDAR_INTERVAL         0x010308        /* number */
00115 #define BARRY_CALENDAR_RECURRINGENDTIME 0x030309        /* time_t */
00116 #define BARRY_CALENDAR_PERPETUAL        0x01030a        /* true/false number */
00117 #define BARRY_CALENDAR_TIMEZONE         0x01030b        /* numeric code */
00118 
00119 /* Service Book record field codes */
00120 #define BARRY_SERVICEBOOK_RECORDID      0x010401        /* number */
00121 #define BARRY_SERVICEBOOK_NAME          0x020402        /* strings... */
00122 #define BARRY_SERVICEBOOK_HIDDENNAME    0x020403
00123 #define BARRY_SERVICEBOOK_DESCRIPTION   0x020404
00124 #define BARRY_SERVICEBOOK_DSID          0x020405
00125 #define BARRY_SERVICEBOOK_BESDOMAIN     0x020406
00126 #define BARRY_SERVICEBOOK_UNIQUEID      0x020407
00127 #define BARRY_SERVICEBOOK_CONTENTID     0x020408
00128 #define BARRY_SERVICEBOOK_CONFIG_FORMAT 0x010409        /* number */
00129 
00130 /* Initialization */
00131 BXEXPORT void barry_init(int data_dump_mode);
00132 BXEXPORT const char *barry_version(int *major, int *minor);
00133 
00134 /* Error string retrieval */
00135 BXEXPORT const char *barry_get_last_error();
00136 
00137 /* Probe API */
00138 BXEXPORT probe_handle_t barry_probe(void);
00139 BXEXPORT void barry_probe_close(probe_handle_t handle);
00140 BXEXPORT int barry_probe_count(probe_handle_t handle);
00141 BXEXPORT int barry_probe_find_active(probe_handle_t handle, uint32_t pin);
00142 BXEXPORT void barry_probe_result(probe_handle_t handle, int index,
00143         struct ProbeResult *result);
00144 
00145 /* Controller API */
00146 BXEXPORT con_handle_t barry_con_open(struct ProbeResult *result);
00147 BXEXPORT void barry_con_close(con_handle_t handle);
00148 BXEXPORT int barry_con_mode(con_handle_t handle, int mode);
00149 BXEXPORT int barry_con_get_dbid(con_handle_t handle, const char *dbname);
00150 BXEXPORT int barry_con_get_db_count(con_handle_t handle);
00151 BXEXPORT int barry_con_get_db_info(con_handle_t handle, int index,
00152         unsigned int *number, unsigned int *record_count,
00153         char *name, int name_buf_size);
00154 BXEXPORT int barry_con_add_record(con_handle_t handle, unsigned int dbid,
00155         record_handle_t rec);
00156 BXEXPORT int barry_con_get_record(con_handle_t handle, unsigned int dbid,
00157         unsigned int state_table_index, record_handle_t *rec);
00158 BXEXPORT int barry_con_set_record(con_handle_t handle, unsigned int dbid,
00159         unsigned int state_table_index, record_handle_t rec);
00160 BXEXPORT int barry_con_clear_dirty(con_handle_t handle, unsigned int dbid,
00161         unsigned int state_table_index);
00162 BXEXPORT int barry_con_delete_record(con_handle_t handle, unsigned int dbid,
00163         unsigned int state_table_index);
00164 BXEXPORT int barry_con_load_database(con_handle_t handle, unsigned int dbid,
00165         process_record_callback_t callback);
00166 BXEXPORT int barry_con_save_database(con_handle_t handle, unsigned int dbid,
00167         fill_record_callback_t callback);
00168 
00169 /* State table API */
00170 BXEXPORT state_table_handle_t barry_get_state_table(con_handle_t handle,
00171         unsigned int dbid);
00172 BXEXPORT void barry_free_state_table(state_table_handle_t handle);
00173 BXEXPORT int barry_make_new_record_id(state_table_handle_t handle);
00174 BXEXPORT int barry_get_state_count(state_handle_t handle);
00175 BXEXPORT int barry_get_state(state_table_handle_t handle, unsigned int index,
00176         uint32_t *record_id, int *dirty_flag);
00177         /* note: not every index from 0 to "state_count" is guaranteed to
00178            exist... check the return value */
00179 BXEXPORT int barry_get_state_by_record_id(state_table_handle_t handle, unsigned int rec,
00180         unsigned int *index, int *dirty_flag);
00181 
00182 /* Record API */
00183 BXEXPORT record_handle_t barry_create_record(int record_type);
00184 BXEXPORT void barry_free_record(record_handle_t handle);
00185 BXEXPORT uint32_t barry_rec_get_num(record_handle_t handle, int field_type);
00186 BXEXPORT int barry_rec_set_num(record_handle_t handle, int field_type, uint32_t val);
00187 BXEXPORT const char *barry_rec_get_str(record_handle_t handle, int field_type);
00188 BXEXPORT int barry_rec_set_str(record_handle_t handle, int field_type, const char *str);
00189 BXEXPORT const char *barry_rec_get_raw(record_handle_t handle, int field_type,
00190         int *raw_size);
00191 BXEXPORT int barry_rec_set_raw(record_handle_t handle, int field_type,
00192         const char *buf, int size);
00193 BXEXPORT time_t barry_rec_get_time(record_handle_t handle, int field_type);
00194 BXEXPORT int barry_rec_set_time(record_handle_t handle, int field_type, time_t t);
00195 
00196 /* Calendar record special API */
00197 BXEXPORT int barry_calendar_set_daily(record_handle_t handle);
00198 BXEXPORT int barry_calendar_set_monthly_by_date(record_handle_t handle,
00199         int day_of_month);
00200 BXEXPORT int barry_calendar_set_monthly_by_day(record_handle_t handle,
00201         int day_of_week, int week_of_month);
00202 BXEXPORT int barry_calendar_set_yearly_by_date(record_handle_t handle,
00203         int day_of_month, int month_of_year);
00204 BXEXPORT int barry_calendar_set_yearly_by_day(record_handle_t handle,
00205         int day_of_week, int week_of_month, int month_of_year);
00206 BXEXPORT int barry_calendar_set_weekly(record_handle_t handle, int weekday_bits);
00207 BXEXPORT int barry_calendar_get_fixme_need_read_access_to_this
00208 
00209 /* Time zone API */
00210 BXEXPORT const TimeZone* barry_get_time_zone_table();
00211 BXEXPORT const TimeZone* barry_get_time_zone(uint16_t code);
00212 BXEXPORT uint16_t barry_get_time_zone_code(signed short hour_offset,
00213         signed short min_offset);       /* returns TIME_ZONE_CODE_ERR on error*/
00214 
00215 #ifdef __cplusplus
00216 }
00217 #endif
00218 
00219 #endif
00220