00001 /** 00002 * @file sync/SyncBase.h 00003 * 00004 * Part of CCNx Sync. 00005 * 00006 * Copyright (C) 2011 Palo Alto Research Center, Inc. 00007 * 00008 * This library is free software; you can redistribute it and/or modify it 00009 * under the terms of the GNU Lesser General Public License version 2.1 00010 * as published by the Free Software Foundation. 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. You should have received 00015 * a copy of the GNU Lesser General Public License along with this library; 00016 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, 00017 * Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 00020 00021 #ifndef CCN_SyncBase 00022 #define CCN_SyncBase 00023 00024 #include <sys/types.h> 00025 #include <stdint.h> 00026 #include <ccnr/ccnr_private.h> 00027 00028 // Incomplete types for opaque structures. 00029 struct ccn_schedule; 00030 struct ccn; 00031 struct SyncPrivate; 00032 00033 // A SyncBase is the common data for a Sync Agent. Each Sync Agent supports a 00034 // list of collections. 00035 00036 struct SyncBaseStruct { 00037 struct SyncErrStruct *errList; // private data for Sync 00038 struct SyncPrivate *priv; // opaque data for Repo (from Repo) 00039 void *client_handle; // the ccnr/ccns handle to use (from Repo or Sync client) 00040 struct ccn *ccn; // the ccn handle to use (from Repo) 00041 struct ccn_schedule *sched; // the scheduler to use (from Repo) 00042 int debug; // higher gives more output, 0 gives none 00043 unsigned lastRootId; // last root id assigned (0 is not used) 00044 ccnr_hwm highWater; // high water mark for accession numbers 00045 }; 00046 00047 // Error support 00048 00049 enum SyncErrCode { 00050 SyncErrCode_none = 0, // no error 00051 SyncErrCode_bug = 1, // internal bug 00052 SyncErrCode_caller = 2 // caller error (bad args, wrong state, ...) 00053 }; 00054 00055 struct SyncErrStruct { 00056 struct SyncErrStruct *next; 00057 enum SyncErrCode code; 00058 char * file; 00059 int line; 00060 }; 00061 00062 // add a new error record 00063 // this routine should be called from the SET_SYNC_ERR macro 00064 void SyncSetErrInner(struct SyncBaseStruct *base, 00065 enum SyncErrCode code, 00066 char * file, int line); 00067 00068 // clear all the existing error records 00069 void SyncClearErr(struct SyncBaseStruct *base); 00070 00071 // Basic object support 00072 00073 // allocate and initialize a new sync base 00074 struct SyncBaseStruct * 00075 SyncNewBase(struct ccnr_handle *ccnr, 00076 struct ccn *ccn, 00077 struct ccn_schedule *sched); 00078 00079 // initialize a sync base 00080 void 00081 SyncInit(struct SyncBaseStruct *bp); 00082 00083 // free up the resources for the sync base 00084 // called by Repo when shutting down 00085 // (no callbacks possible at this point) 00086 void 00087 SyncFreeBase(struct SyncBaseStruct **bp); 00088 00089 // Enumeration support 00090 // called by Repo 00091 // name = NULL indicates end of enumeration 00092 // returns -1 to terminate, 0 to continue 00093 int 00094 SyncNotifyContent(struct SyncBaseStruct *base, 00095 int enumeration, 00096 ccnr_accession item, 00097 struct ccn_charbuf *name); 00098 00099 // shutdown a sync base 00100 void 00101 SyncShutdown(struct SyncBaseStruct *bp); 00102 00103 #endif