Imported Upstream version 1.0beta3
[platform/upstream/syncevolution.git] / src / synthesis / src / sysync_SDK / Sources / blobs.h
1 /*
2  *  File:    blobs.h
3  *
4  *  Author:  Beat Forster (bfo@synthesis.ch)
5  *
6  *
7  *  DBApi database adapter
8  *  BLOB (Binary Large Object) access
9  *
10  *  Copyright (c) 2005-2009 by Synthesis AG (www.synthesis.ch)
11  *
12  *
13  *  E X A M P L E    C O D E
14  *
15  */
16
17 #ifndef BLOBS_H
18 #define BLOBS_H
19
20 #include "sync_dbapidef.h" // get some definitions
21 #ifdef PLATFORM_FILE
22   #include "platform_file.h"
23 #endif
24
25 #include <string>
26
27 namespace sysync {
28
29
30
31 /* NOTE: A BLOB object can be used for different BLOBs,
32  *       but only for one BLOB simultaneously.
33  *       If a new BLOB will be opened, the old one will
34  *       be closed automatically, if still opened.
35  *       read/write with <aFirst> = true  will open a new one
36  *         "    "     "      "    = false will ignore <aBlobName>
37  */
38 class TBlob {
39   public:
40     TBlob();
41    ~TBlob();
42
43     void     Init( void* aCB, cAppCharP aDBName, string aBlobPath,
44                                                  string aContextName,
45                                                  string sDevKey,
46                                                  string sUsrKey );
47
48     string   BlobName  ( cItemID  aID, cAppCharP aBlobID );
49
50     size_t   BlobSize  (  string  aBlobName ); // allowed also for open BLOBs
51
52     TSyError ReadBlob  (  string  aBlobName,
53                       appPointer *blkPtr, memSize *blkSize, memSize *totSize,
54                             bool  aFirst,    bool *aLast );
55     TSyError ReadBlob  ( cItemID  aID,  cAppCharP  aBlobID,
56                       appPointer *blkPtr, memSize *blkSize, memSize *totSize,
57                             bool  aFirst,    bool *aLast );
58
59     TSyError WriteBlob (  string  aBlobName,
60                       appPointer  blkPtr, memSize  blkSize, memSize  totSize,
61                             bool  aFirst,    bool  aLast );
62     TSyError WriteBlob ( cItemID  aID,  cAppCharP  aBlobID,
63                       appPointer  blkPtr, memSize  blkSize, memSize  totSize,
64                             bool  aFirst,    bool  aLast );
65
66     TSyError DeleteBlob(  string  aBlobName );
67     TSyError DeleteBlob( cItemID  aID, cAppCharP  aBlobID );
68
69     #ifdef PLATFORM_FILE
70       TSyError GetAttr ( string  aBlobName, TAttr  &aAttr, bool &isFolder ); // get BLOB's file attributes
71       TSyError SetAttr                    ( TAttr   aAttr );                 // set  "      "      "
72
73       TSyError GetDates( string  aBlobName, TDates &aDate );                 // get BLOB's file dates
74       TSyError SetDates( string  aBlobName, TDates  aDate );                 // set  "      "      "
75     #endif
76
77     string getDBName() const { return fDBName; }
78     string getBlobPath() const { return fBlobPath; }
79     string getContextName() const { return fContextName; }
80     string getDevKey() const { return fDevKey; }
81     string getUsrKey() const { return fUsrKey; }
82
83   private:
84     void*  fCB;       // callback structure, for debug logs
85     string fDBName;   // database name,      for debug logs
86
87     string fBlobPath; // params for creating BLOB's name
88     string fContextName;
89     string fDevKey;
90     string fUsrKey;
91
92     FILE*   fFile;     // assigned file
93     bool    fOpened;   // Is it currently opened ?
94     memSize fCurPos;   // current position
95     memSize fSize;     // BLOB's size
96
97     string fName;     // BLOB's file name
98
99     #ifdef PLATFORM_FILE
100       TAttr  fAttr;   // BLOB's file attributes
101       bool   fAttrActive;
102
103       TDates fDate;   // BLOB's file dates
104       bool   fDateActive;
105     #endif
106
107     TSyError  OpenBlob( const char* mode );
108     TSyError CloseBlob();
109 }; // TBlob
110
111
112 } /* namespace */
113 #endif /* BLOBS_H */
114 /* eof */