kpilot

pilotSerialDatabase.h

Go to the documentation of this file.
00001 #ifndef _KPILOT_PILOTSERIALDATABASE_H
00002 #define _KPILOT_PILOTSERIALDATABASE_H
00003 /* KPilot
00004 **
00005 ** Copyright (C) 1998-2001 by Dan Pilone
00006 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00007 ** Copyright (C) 2006 Adriaan de Groot <groot@kde.org>
00008 **
00009 ** See the .cc file for an explanation of what this file is for.
00010 */
00011 
00012 /*
00013 ** This program is free software; you can redistribute it and/or modify
00014 ** it under the terms of the GNU Lesser General Public License as published by
00015 ** the Free Software Foundation; either version 2.1 of the License, or
00016 ** (at your option) any later version.
00017 **
00018 ** This program is distributed in the hope that it will be useful,
00019 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00021 ** GNU Lesser General Public License for more details.
00022 **
00023 ** You should have received a copy of the GNU Lesser General Public License
00024 ** along with this program in a file called COPYING; if not, write to
00025 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00026 ** MA 02110-1301, USA.
00027 */
00028 
00029 /*
00030 ** Bug reports and questions can be sent to kde-pim@kde.org
00031 */
00032 
00033 
00034 #include "pilotDatabase.h"
00035 #include "pilotRecord.h"
00036 
00042 class KPilotDeviceLink;
00043 
00048 class KDE_EXPORT PilotSerialDatabase : public PilotDatabase
00049 {
00050 friend class KPilotDeviceLink;
00051 protected:
00052     PilotSerialDatabase( KPilotDeviceLink *l, const QString &dbName );
00053     PilotSerialDatabase( KPilotDeviceLink *l, const DBInfo *info );
00054 
00055 public:
00056     virtual ~PilotSerialDatabase();
00057 
00059     virtual int readAppBlock(unsigned char* buffer, int maxLen);
00061     virtual int writeAppBlock(unsigned char* buffer, int len);
00063     virtual unsigned int recordCount() const;
00065      virtual QValueList<recordid_t> idList();
00067     virtual PilotRecord* readRecordById(recordid_t id);
00069     virtual PilotRecord* readRecordByIndex(int index);
00071     virtual PilotRecord* readNextRecInCategory(int category);
00077     virtual PilotRecord* readNextModifiedRec(int *ind=NULL);
00078 
00083     virtual recordid_t writeRecord(PilotRecord* newRecordb);
00084 
00090     virtual int deleteRecord(recordid_t id, bool all=false);
00092     virtual int resetSyncFlags();
00094     virtual int resetDBIndex();
00096     virtual int cleanup();
00097 
00098     virtual QString dbPathName() const;
00099 
00104     virtual int deleteDatabase();
00105 
00111     virtual bool createDatabase(long creator=0,
00112         long type=0, int cardno=0, int flags=0, int version=0);
00113     QString getDBName() { return fDBName; }
00114 
00115 
00116     virtual DBType dbType() const;
00117 
00118 protected:
00119     virtual void openDatabase();
00120     virtual void closeDatabase();
00124     int getDBHandle() const
00125     {
00126         return fDBHandle;
00127     }
00128 
00129 
00130 private:
00131     void setDBHandle(int handle) { fDBHandle = handle; }
00132 
00133     QString     fDBName;
00134     int         fDBHandle;
00135     int         fDBSocket;
00136     // Pilot-link 0.12 allocates buffers as needed and resizes them.
00137     // Start with a buffer that is _probably_ big enough for most
00138     // PIM records, but much smaller than the 64k that we use otherwise.
00139     // Might want to add algorithm for trying to optimize the initial
00140     // allocation for a given database.
00141     static const int InitialBufferSize = 2048;
00142 };
00143 
00144 #endif