00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _SUPPORT_ISTORAGE_INTERFACE_H
00014 #define _SUPPORT_ISTORAGE_INTERFACE_H
00015
00021 #include <support/SupportDefs.h>
00022 #include <support/IInterface.h>
00023 #include <support/Binder.h>
00024 #include <sys/uio.h>
00025
00026 #if _SUPPORTS_NAMESPACE
00027 namespace palmos {
00028 namespace support {
00029 #endif
00030
00035
00036
00037
00039 enum {
00040 B_WRITE_AT_TRANSACTION = 'WRAT',
00041 B_READ_AT_TRANSACTION = 'RDAT'
00042 };
00043
00045
00046 struct read_at_transaction
00047 {
00048 off_t position;
00049 size_t size;
00050 };
00051
00054
00057 struct write_at_transaction
00058 {
00059 off_t position;
00060 };
00061
00063 class IStorage : public IInterface
00064 {
00065 public:
00066
00067 B_DECLARE_META_INTERFACE(Storage)
00068
00069
00070 virtual off_t Size() const = 0;
00072 virtual status_t SetSize(off_t size) = 0;
00073
00075
00077 virtual ssize_t ReadAtV(off_t position, const struct iovec *vector, ssize_t count) = 0;
00078
00080 ssize_t ReadAt(off_t position, void* buffer, size_t size);
00081
00083
00085 virtual ssize_t WriteAtV(off_t position, const struct iovec *vector, ssize_t count) = 0;
00086
00088 ssize_t WriteAt(off_t position, const void* buffer, size_t size);
00089
00091
00093 virtual status_t Sync() = 0;
00094 };
00095
00096
00097
00100 class BnStorage : public BnInterface<IStorage>
00101 {
00102 public:
00103 virtual status_t Transact(uint32_t code, SParcel& data, SParcel* reply = NULL, uint32_t flags = 0);
00104
00105 protected:
00106 inline BnStorage() : BnInterface<IStorage>() { }
00107 inline BnStorage(const SContext& c) : BnInterface<IStorage>(c) { }
00108 inline virtual ~BnStorage() { }
00109
00110 virtual status_t HandleEffect(const SValue &in, const SValue &inBindings, const SValue &outBindings, SValue *out);
00111
00112 private:
00113 BnStorage(const BnStorage& o);
00114 BnStorage& operator=(const BnStorage& o);
00115 };
00116
00117
00118
00119
00120 inline ssize_t IStorage::ReadAt(off_t position, void *buffer, size_t size)
00121 {
00122 iovec v;
00123 v.iov_base = buffer;
00124 v.iov_len = size;
00125 return ReadAtV(position, &v,1);
00126 }
00127
00128 inline ssize_t IStorage::WriteAt(off_t position, const void *buffer, size_t size)
00129 {
00130 iovec v;
00131 v.iov_base = const_cast<void*>(buffer);
00132 v.iov_len = size;
00133 return WriteAtV(position, &v,1);
00134 }
00135
00136
00137
00138 #if _SUPPORTS_NAMESPACE
00139 } }
00140 #endif
00141
00142 #endif // _SUPPORT_ISTORAGE_INTERFACE_H