ByteStream.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Palmsource, Inc.
00003  * 
00004  * This software is licensed as described in the file LICENSE, which
00005  * you should have received as part of this distribution. The terms
00006  * are also available at http://www.openbinder.org/license.html.
00007  * 
00008  * This software consists of voluntary contributions made by many
00009  * individuals. For the exact contribution history, see the revision
00010  * history and logs, available at http://www.openbinder.org
00011  */
00012 
00013 #ifndef _SUPPORT_BYTESTREAM_H
00014 #define _SUPPORT_BYTESTREAM_H
00015 
00025 #include <support/SupportDefs.h>
00026 #include <support/IByteStream.h>
00027 #include <support/IStorage.h>
00028 
00029 #include <sys/uio.h>
00030 
00031 #if _SUPPORTS_NAMESPACE
00032 namespace palmos {
00033 namespace support {
00034 #endif
00035 
00036 /*---------------------------------------------------------------------*/
00037 /*------- Local Streams -----------------------------------------------*/
00038 
00039 // These must be here (instead of in IByteStream.h) because many low-level
00040 // parts of the system want to know about the byte stream interfaces, but
00041 // BBinder (which the local implementation depends on) must itself know about
00042 // those low-level pieces.  Circular dependencies are bad!
00043 
00044 /*-----------------------------------------------------------------*/
00045 
00046 class BnByteInput : public BnInterface<IByteInput>
00047 {
00048 public:
00049         virtual status_t        Link(const sptr<IBinder>& to, const SValue &bindings, uint32_t flags = 0);
00050         virtual status_t        Unlink(const wptr<IBinder>& from, const SValue &bindings, uint32_t flags = 0);
00051         virtual status_t        Effect(const SValue &in, const SValue &inBindings, const SValue &outBindings, SValue *out);
00052         virtual status_t        Transact(uint32_t code, SParcel& data, SParcel* reply = NULL, uint32_t flags = 0);
00053         
00054 protected:
00055         inline                  BnByteInput() : BnInterface<IByteInput>() { }
00056         inline                  BnByteInput(const SContext& c) : BnInterface<IByteInput>(c) { }
00057         inline virtual          ~BnByteInput() { }
00058         
00059         virtual status_t        HandleEffect(const SValue &in, const SValue &inBindings, const SValue &outBindings, SValue *out);
00060     
00061 private:
00062                                 BnByteInput(const BnByteInput& o);  // no implementation
00063         BnByteInput&            operator=(const BnByteInput& o);    // no implementation
00064 };
00065 
00066 /*-----------------------------------------------------------------*/
00067 
00068 class BnByteOutput : public BnInterface<IByteOutput>
00069 {
00070 public:
00071         virtual status_t        Link(const sptr<IBinder>& to, const SValue &bindings, uint32_t flags = 0);
00072         virtual status_t        Unlink(const wptr<IBinder>& from, const SValue &bindings, uint32_t flags = 0);
00073         virtual status_t        Effect(const SValue &in, const SValue &inBindings, const SValue &outBindings, SValue *out);
00074         virtual status_t        Transact(uint32_t code, SParcel& data, SParcel* reply = NULL, uint32_t flags = 0);
00075         
00076 protected:
00077         inline                  BnByteOutput() : BnInterface<IByteOutput>() { }
00078         inline                  BnByteOutput(const SContext& c) : BnInterface<IByteOutput>(c) { }
00079         inline virtual          ~BnByteOutput() { }
00080         
00081         virtual status_t        HandleEffect(const SValue &in, const SValue &inBindings, const SValue &outBindings, SValue *out);
00082     
00083 private:
00084                                 BnByteOutput(const BnByteOutput& o);    // no implementation
00085         BnByteOutput&           operator=(const BnByteOutput& o);       // no implementation
00086 };
00087 
00088 /*-----------------------------------------------------------------*/
00089 
00090 class BnByteSeekable : public BnInterface<IByteSeekable>
00091 {
00092 public:
00093         virtual status_t        Link(const sptr<IBinder>& to, const SValue &bindings, uint32_t flags = 0);
00094         virtual status_t        Unlink(const wptr<IBinder>& from, const SValue &bindings, uint32_t flags = 0);
00095         virtual status_t        Effect(const SValue &in, const SValue &inBindings, const SValue &outBindings, SValue *out);
00096         virtual status_t        Transact(uint32_t code, SParcel& data, SParcel* reply = NULL, uint32_t flags = 0);
00097         
00098 protected:
00099         inline                  BnByteSeekable() : BnInterface<IByteSeekable>() { }
00100         inline                  BnByteSeekable(const SContext& c) : BnInterface<IByteSeekable>(c) { }
00101         inline virtual          ~BnByteSeekable() { }
00102         
00103         virtual status_t        HandleEffect(const SValue &in, const SValue &inBindings, const SValue &outBindings, SValue *out);
00104     
00105 private:
00106                                 BnByteSeekable(const BnByteSeekable& o);    // no implementation
00107         BnByteSeekable&         operator=(const BnByteSeekable& o);         // no implementation
00108 };
00109 
00114 /*---------------------------------------------------------------------*/
00115 /*------- BByteStream Class -------------------------------------------*/
00116 
00118 
00120 class BByteStream : public BnByteInput, public BnByteOutput, public BnByteSeekable
00121 {
00122 public:
00123 
00124                             BByteStream(const sptr<IStorage>& store);
00125     
00126     virtual SValue          Inspect(const sptr<IBinder>& caller, const SValue &which, uint32_t flags = 0);
00127     
00128     virtual ssize_t         ReadV(const struct iovec *vector, ssize_t count, uint32_t flags = 0);
00129     virtual ssize_t         WriteV(const struct iovec *vector, ssize_t count, uint32_t flags = 0);
00130     virtual status_t        Sync();
00131     
00132     virtual off_t           Seek(off_t position, uint32_t seek_mode);
00133     virtual off_t           Position() const;
00134 
00135 protected:
00136                             BByteStream(IStorage *This);
00137 
00138     virtual                 ~BByteStream();
00139 
00140 private:
00141                             BByteStream(const BByteStream&);
00142 
00143             off_t           m_pos;
00144             IStorage *      m_store;
00145 };
00146 
00148 
00150 class BReadOnlyStream : public BnByteInput, public BnByteSeekable
00151 {
00152 public:
00153 
00154                             BReadOnlyStream(const sptr<IStorage>& store);
00155     
00156     virtual SValue          Inspect(const sptr<IBinder>& caller, const SValue &which, uint32_t flags = 0);
00157     
00158     virtual ssize_t         ReadV(const struct iovec *vector, ssize_t count, uint32_t flags = 0);
00159     
00160     virtual off_t           Seek(off_t position, uint32_t seek_mode);
00161     virtual off_t           Position() const;
00162 
00163 protected:
00164                             BReadOnlyStream(IStorage *This);
00165 
00166     virtual                 ~BReadOnlyStream();
00167 
00168 private:
00169                             BReadOnlyStream(const BByteStream&);
00170 
00171             off_t           m_pos;
00172             IStorage *      m_store;
00173 };
00174 
00176 
00178 class BWriteOnlyStream : public BnByteOutput, public BnByteSeekable
00179 {
00180 public:
00181 
00182                             BWriteOnlyStream(const sptr<IStorage>& store);
00183     
00184     virtual SValue          Inspect(const sptr<IBinder>& caller, const SValue &which, uint32_t flags = 0);
00185     
00186     virtual ssize_t         WriteV(const struct iovec *vector, ssize_t count, uint32_t flags = 0);
00187     virtual status_t        Sync();
00188     
00189     virtual off_t           Seek(off_t position, uint32_t seek_mode);
00190     virtual off_t           Position() const;
00191 
00192 protected:
00193                             BWriteOnlyStream(IStorage *This);
00194 
00195     virtual                 ~BWriteOnlyStream();
00196 
00197 private:
00198                             BWriteOnlyStream(const BByteStream&);
00199 
00200             off_t           m_pos;
00201             IStorage *      m_store;
00202 };
00203 
00204 /*-------------------------------------------------------------*/
00205 
00208 #if _SUPPORTS_NAMESPACE
00209 } } // namespace palmos::support
00210 #endif
00211 
00212 #endif /* _SUPPORT_BYTESTREAM_H */