Message.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_MESSAGE_H
00014 #define _SUPPORT_MESSAGE_H
00015 
00021 #include <support/SupportDefs.h>
00022 #include <support/ITextStream.h>
00023 #include <support/Value.h>
00024 
00025 #if _SUPPORTS_NAMESPACE
00026 namespace palmos {
00027 namespace support {
00028 #endif
00029 
00034 class SMessageList;
00035 
00036 /*-------------------------------------------------------------*/
00037 
00039 class SMessage
00040 {
00041 public:
00042 
00043                         SMessage();
00044                         SMessage(uint32_t what);
00045                         SMessage(uint32_t what, int32_t priority);
00046                         SMessage(const SMessage &);
00047                         SMessage(const SValue &);
00048                         ~SMessage();
00049 
00050         SMessage&       operator=(const SMessage &);
00051 
00052 inline  uint32_t        What() const;
00053 inline  void            SetWhat(uint32_t val);
00054         
00055 inline  nsecs_t         When() const;
00056 inline  void            SetWhen(nsecs_t val);
00057         
00058 inline  int32_t         Priority() const;
00059 inline  void            SetPriority(int32_t val);
00060         
00061 inline  const SValue&   Data() const;
00062 inline  SValue&         Data();
00063 inline  void            SetData(const SValue& data);
00064         
00065         // Convenience functions.  These are the same as calling
00066         // the corresponding function on Data().
00067 inline  void            Join(const SValue& from, uint32_t flags = 0);
00068 inline  void            JoinItem(const SValue& key, const SValue& value, uint32_t flags=0);
00069 inline  const SValue&   ValueFor(const SValue& key) const;
00070 inline  const SValue&   ValueFor(const char* key) const;
00071 inline  const SValue&   operator[](const SValue& key) const     { return ValueFor(key); }
00072 inline  const SValue&   operator[](const char* key) const       { return ValueFor(key); }
00073         
00074         SValue          AsValue() const;
00075 inline                  operator SValue() const         { return AsValue(); }
00076 
00077         status_t        PrintToStream(const sptr<ITextOutput>& io, uint32_t flags = 0) const;
00078 
00079 private:
00080 
00081 friend  class           SMessageList;
00082 
00083         uint32_t        m_what;
00084         nsecs_t         m_when;
00085         int32_t         m_priority;
00086         SValue          m_data;
00087         
00088         SMessage *      m_next;
00089         SMessage *      m_prev;
00090 };
00091 
00092 _IMPEXP_SUPPORT const sptr<ITextOutput>& operator<<(const sptr<ITextOutput>& io, const SMessage& message);
00093 
00096 /*----------------------------------------------------------------*/
00097 /*----- inline definitions ---------------------------------------*/
00098 
00099 inline uint32_t SMessage::What() const
00100 {
00101     return m_what;
00102 }
00103 
00104 inline void SMessage::SetWhat(uint32_t val)
00105 {
00106     m_what = val;
00107 }
00108 
00109 inline nsecs_t SMessage::When() const
00110 {
00111     return m_when;
00112 }
00113 
00114 inline void SMessage::SetWhen(nsecs_t val)
00115 {
00116     m_when = val;
00117 }
00118 
00119 inline int32_t SMessage::Priority() const
00120 {
00121     return m_priority;
00122 }
00123 
00124 inline void SMessage::SetPriority(int32_t val)
00125 {
00126     m_priority = val;
00127 }
00128 
00129 inline const SValue& SMessage::Data() const
00130 {
00131     return m_data;
00132 }
00133 
00134 inline SValue& SMessage::Data()
00135 {
00136     return m_data;
00137 }
00138 
00139 inline void SMessage::SetData(const SValue& data)
00140 {
00141     m_data = data;
00142 }
00143 
00144 inline void SMessage::Join(const SValue& from, uint32_t flags)
00145 {
00146     m_data.Join(from, flags);
00147 }
00148 
00149 inline void SMessage::JoinItem(const SValue& key, const SValue& value, uint32_t flags)
00150 {
00151     m_data.JoinItem(key, value, flags);
00152 }
00153 
00154 inline const SValue& SMessage::ValueFor(const SValue& key) const
00155 {
00156     return m_data.ValueFor(key);
00157 }
00158 
00159 inline const SValue& SMessage::ValueFor(const char* key) const
00160 {
00161     return m_data.ValueFor(key);
00162 }
00163 
00164 /*-------------------------------------------------------------*/
00165 
00166 #if _SUPPORTS_NAMESPACE
00167 } } // namespace palmos::support
00168 #endif
00169 
00170 #endif /* _MESSAGE_H */