Flattenable.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_FLATTENABLE_H
00014 #define _SUPPORT_FLATTENABLE_H
00015 
00022 #include <support/SupportDefs.h>
00023 #include <support/Value.h>
00024 
00025 #if _SUPPORTS_NAMESPACE
00026 namespace palmos {
00027 namespace support {
00028 #endif
00029 
00034 enum {
00035     // Request a flattened form that may contain references to
00036     // active objects.
00037     B_FLATTEN_FORM_ACTIVE = 0,
00038 
00039     // Request a flattened form that can be written to persistent
00040     // storage.
00041     B_FLATTEN_FORM_PERSISTENT = 1
00042 };
00043 
00044 class SFlattenable
00045 {
00046 public: 
00047     virtual             ~SFlattenable() { };
00048     virtual ssize_t     FlattenedSize() const;
00049     virtual status_t    Flatten(void *buffer, ssize_t size) const;
00050     virtual status_t    Unflatten(type_code c, const void *buf, ssize_t size);
00051 
00052             // Convert this object into a SValue.
00053     virtual SValue      AsValue(int32_t form = B_FLATTEN_FORM_ACTIVE) const = 0;
00054 
00055             // Assign this object from a SValue previously created by
00056             // the above function.
00057     virtual status_t    SetFromValue(const SValue& value) = 0;
00058 
00059     virtual ssize_t     ParcelSize(int32_t form = B_FLATTEN_FORM_ACTIVE) const;
00060 
00061             // Flatten the object into a raw parcel.  This will keep
00062             // track of the number of bytes written, but NOT the type
00063             // code (it is up to the caller to store the type code
00064             // separately).
00065     virtual ssize_t     WriteParcel(SParcel& target, int32_t form = B_FLATTEN_FORM_ACTIVE) const;
00066 
00067             // Unflatten the object from a raw parcel.  If it can't
00068             // accept the given type code, it must fail without reading
00069             // anything from the parcel.
00070     virtual ssize_t     ReadParcel(type_code type, SParcel& source, ssize_t size);
00071 
00072 
00073     virtual bool        IsFixedSize() const = 0;
00074     virtual type_code   TypeCode() const = 0;
00075     virtual bool        AllowsTypeCode(type_code code) const;
00076 };
00077 
00078 /*-------------------------------------------------------------*/
00079 /*-------------------------------------------------------------*/
00080 
00083 #if _SUPPORTS_NAMESPACE
00084 } } // namespace palmos::support
00085 #endif
00086 
00087 #endif /* _SUPPORT_FLATTENABLE_H */