interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/libs/vos/vos/remoteproperty.hh

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2001, 2002 Peter Amstutz
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021     Peter Amstutz 
00022     Additions by Reed Hedges marked with initials "rh" and date.
00023 */
00024 #ifndef _REMOTEPROPERTY_HH_
00025 #define _REMOTEPROPERTY_HH_
00026 
00027 #include <vos/vos/property.hh>
00028 
00029 namespace VOS {
00030     class PropertyListener;
00031     class PropertyEvent;
00032 
00033     class VOS_API RemoteProperty : public Property
00034     {
00035     private:
00036         boost::mutex data_mutex;
00037 
00038         std::string cached_data;
00039         std::string cached_datatype;
00040 
00041         uint32_t outgoing_replace_nonce;
00042 
00043         bool doAsyncWrite;
00044 
00045         VUtil::ListenerBase<PropertyListener, PropertyEvent> propertyListeners;
00046 
00047         void updateHandler(Message* m);
00048         void startListeningHandler(Message* m);
00049 
00050     protected:
00051         RemoteProperty(VobjectBase* superobject);
00052 
00053     public:
00054 
00055         static MetaObject* new_RemoteProperty(VobjectBase* superobject, const std::string& type);
00056 
00057         /** Get length (bytes) of decoded data. */
00058         virtual int getLength();
00059 
00060         /** Read decoded data into target, possibly performing decode if necesary
00061          * @see read(std::string, int, int)
00062          */
00063         virtual void read(std::string& target);
00064 
00065         /** Read a substring of decoded data into target, possibly performing decode if necesary
00066          * @param target    Place data in this string
00067          * @param start     Byte offset to start reading
00068          * @param length    Number of bytes to read. If this parameter is -1, read
00069          *                  until the end of the data.
00070          */
00071         virtual void read(std::string& target, int start, int length);
00072 
00073         /** Return decoded data, possibly performing decode if necesary
00074          * @see read(std::string, int int)
00075          */
00076         virtual std::string read();
00077 
00078         /** Return substring of decoded data, possibly performing decode if necesary
00079             @see read(std::string, int int)
00080         */
00081         virtual std::string read(int start, int length);
00082 
00083         /** Write newdata into property value, starting at byte position start */
00084         virtual void write(int start, const std::string& newdata);
00085 
00086         /** Completely change the value and type of data stored in this property.
00087             @param newdata New data.
00088             @param newtype The type of the new datatype. If no type identifier was supplied, the previous one is kept.
00089             NOTE: the initial datatype (set by the constructor) is "?" which is (or should be) an invalid value for
00090             any application.
00091         */
00092         virtual void replace(const std::string& newdata, const std::string& newtype = "?");
00093 
00094         /** Return type of decoded data (usually a MIME type) */
00095         virtual const std::string getDataType();
00096 
00097         /** Add a new property listener to this property. This listener's methods
00098          * will be called when the property is modified.
00099          * @see PropertyListener
00100          * @param pl    The new property listener. If it is also a RefCounted
00101          * object, references will be acquired correctly.
00102          * @param refresh If given, determines whether the new property
00103          *   listener will be immediately notified of the current property
00104          *   value (before this method returns).
00105          */
00106         virtual void addPropertyListener(PropertyListener* pl, bool refresh = true);
00107 
00108         /** Remove the property listener 'pl' from this property.
00109          * @param pl    Listener to remove. If it is also a RefCounted object,
00110          * references will be released correctly.
00111          */
00112         virtual void removePropertyListener(PropertyListener* pl);
00113 
00114         /** Asynchronous replace means calls to "replace" will be
00115             assumed successful and immediately committed locally,
00116             without waiting for response from the remote site.
00117          */
00118         virtual void enableAsyncReplace(bool b);
00119 
00120         /** Return MetaObject type, "property" */
00121         virtual const std::string getVOSType();
00122     };
00123 }
00124 
00125 #endif