Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/metaobjects/misc/talkative.hh

Go to the documentation of this file.
00001 /* $Id: talkative.hh,v 1.30 2003/07/24 05:25:49 tetron Exp $ */
00002 
00003 
00004 /* This file was generated by otd2cpp.pl, a script for ADR by Reed Hedges <reed@zerohour.net>.
00005 
00006     Copyright (C) 2002 Reed Hedges <reed@interreality.org>
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Lesser General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public
00019     License along with this library; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00021 
00022 */
00023 
00024 #ifndef _TALKATIVE_HH_
00025 #define _TALKATIVE_HH_
00026 
00027 #include <time.h>
00028 
00029 #include <vos/corelibs/vos/vos.hh>
00030 #include <vos/metaobjects/property/property.hh>
00031 
00032 
00033 #if defined(_WIN32) && defined(_MSC_VER)
00034 # ifdef MISC_EXPORTS
00035 #  define MISC_API __declspec(dllexport)
00036 # else
00037 #  define MISC_API __declspec(dllimport)
00038 # endif
00039 #else
00040 # define MISC_API
00041 #endif
00042 
00043 #define VOS_TALK_NO_VOICE "#f"
00044 #define VOS_TALK_VOICE_DATATYPE "application/x-festival"
00045 
00046 class TalkMessage;
00047 
00048 /** MetaObject implementing Talkative Object Type.
00049     This object type facilitates verbal intercommunication in the form of text which may be synthesized as human speech (if possible).
00050 */
00051 
00052 
00053 class MISC_API Talkative : public virtual MetaObject
00054 {
00055 private:
00056     PropertyAccessControl *defaultPropertyAC;
00057 
00058 public:
00059 
00060     /** @name Message scope codes */
00061     //@{
00062 
00063     static const unsigned short UNSPECIFIED;
00064     static const unsigned short PUBLIC;
00065     static const unsigned short PRIVATE;
00066     static const unsigned short AUTO;
00067     static const unsigned short FROM_APP;   ///<Same as SYSTEM
00068     static const unsigned short SYSTEM; ///<Same as FROM_APP
00069 
00070     //@}
00071 
00072 public:
00073 
00074     /** Constructor */
00075     Talkative(MetaObject* superobject);
00076 
00077     /** Initialize default property AC (For local Talkative objects only) to &NoPropertyAccessControl::static_ */
00078     void initialize();
00079 
00080     /** Initialize default property AC (For local Talkative objects only) to given policy */
00081     void initialize(PropertyAccessControl* ac);
00082 
00083     /** Initialize default property AC (For local Talkative objects only) to given policy */
00084     inline void setPropertyAccessControl(PropertyAccessControl* ac) {
00085         initialize(ac);
00086     }
00087 
00088 
00089     /** Return type string ("talkative") */
00090     const std::string getType();
00091 
00092     /** Register Extenders */
00093     static void registerExtenders();
00094 
00095 
00096     /** @name Access Subobjects (if any)  */
00097     //@{
00098 
00099     /** Get the value of voice property. */
00100     std::string get_voice();
00101 
00102     /** Get the datatype of voice property. */
00103     std::string get_voice_datatype();
00104 
00105     /** Set voice property.
00106         @param value The new value
00107         @param datatype The new datatype: if omitted, then the existing datatype will be preserved.
00108         @param ac    Access control policy for the voice property (Ignored by Remote Talkative objects)
00109      */
00110     void set_voice(const std::string& value, const std::string& datatype = "?", PropertyAccessControl* ac = NULL);
00111 
00112     //@}
00113 
00114 
00115     /** @name Actuators. User-functions that correspond to message actions. */
00116 //@{
00117 
00118     /** Send a talk message to this object. This message contains text to be spoken or displayed. The "voice" property should be used, to select a voice if applicable.
00119         @see Talkative::TalkMessage
00120     */
00121 
00122     virtual void do_say(TalkMessage& msg) = 0;
00123 
00124     /** Contructs a TalkMessage and calls do_say(TalkMessage&)
00125     @deprecated
00126     */
00127     void do_say(const std::string& text, Talkative& sender,
00128                 const unsigned short scope, const int priority = 0,
00129                 const std::string& replynonce = "",
00130                 const std::string& thisnonce = "");
00131 
00132     /** calls do_say(text, sender, UNSPECIFIED, 0, "")
00133         @deprecated
00134     */
00135     void do_say(const std::string& text, Talkative& sender, const std::string& in_reply_to = "") {
00136         do_say(text, sender, UNSPECIFIED, 0, in_reply_to);
00137     }
00138 
00139     //@}
00140 
00141 };
00142 
00143 /** Structure defining a talk message */
00144 class MISC_API TalkMessage {
00145 public:
00146     std::string text;
00147     Talkative& sender;
00148     unsigned short scope;   ///<See scope codes below. Combine multiple codes with |.
00149     int priority;
00150     time_t time;  ///< Time message was sent (seconds since midnight, Jan 1 1970, UTC., except -1 means no time available.)
00151     std::string reply_nonce;  ///< If not empty (""), this is the nonce (message ID) of a previous message to which this one is a reply.
00152     std::string this_nonce;   ///< If not empty (""), this is the nonce (message ID) of this talk message. Combine with URL of sender to form a unique ID.
00153 
00154     TalkMessage(Talkative& se, std::string t = "",
00155         unsigned short sc = Talkative::UNSPECIFIED,
00156         int pr = 0,
00157         time_t tm = -1, std::string rn = "", std::string tn = "" ) :
00158         text(t), sender(se), scope(sc), priority(pr), time(tm),
00159         reply_nonce(rn), this_nonce(tn)
00160         {   }
00161 
00162 };
00163 
00164 /** Interface for message listeners.
00165     @see addTalkListener.
00166 */
00167 class MISC_API TalkListener {
00168 public:
00169     /** Override this method to handle talk messages. */
00170     virtual void notifyTalkMessage(TalkMessage& m) = 0;
00171 };
00172 
00173 /** Local version of Talkative. */
00174 
00175 class MISC_API LocalTalkative : public virtual Talkative {
00176 
00177 private:
00178     typedef vector<TalkListener*> ListenerList;
00179     ListenerList listeners;
00180 
00181     /* Which object sent us the last message? (or NULL for none) */
00182     Talkative* replyto;
00183 
00184     /* What was the nonce of the last message? */
00185     std::string replynonce;
00186 
00187 public:
00188 
00189     /* Constructor */
00190     LocalTalkative(MetaObject* superobject);
00191 
00192     /* Destructor */
00193     ~LocalTalkative();
00194 
00195     /* Static generator, for factory. */
00196     static MetaObject* new_LocalTalkative(MetaObject* superobject, const std::string& type);
00197 
00198 
00199     /** Register a new TalkListener.
00200         @param l The listener object. If l is also a RefCounted object, a
00201         referece will be acquired.
00202     */
00203     void addTalkListener(TalkListener* l);
00204 
00205     /** Remove a TalkListener
00206         @param l The listener object. If l is also a RefCounted object, the
00207         referece will be released.
00208     */
00209     void removeTalkListener(TalkListener* l);
00210 
00211     /** Send a message from this object, to whatever object sent this object
00212     * the last message with scope "PRIVATE"
00213         @throws NoSuchObjectError if there is no object to reply to.
00214     */
00215     void reply_to_last(const std::string& text, const int priority = 0 );
00216 
00217 
00218     /** Send a message from this object to all children of 'parent' that are
00219     * talkative with scope "PUBLIC" */
00220     void say_to_all(const std::string& text, Vobject& parent, const int priority = 0, const std::string& replynonce = "" );
00221 
00222 
00223     /** Send a message to this object.
00224         If there are no TalkListener%s registered, then the message will
00225         simply be LOG%ged.  Otherwise, each of the listeners will be passed the
00226         message (in the order in which they were registered).
00227         It is also possible to override this method to do something else
00228         entirely.
00229     */
00230     void do_say(TalkMessage& msg);
00231 
00232 protected:
00233 
00234     /* Handle message say (This message contains text to be spoken or displayed. If spoken (synthesized), then the "voice" property should be used, if possible, to select a voice. ) */
00235     virtual void handle_say(Message* m);
00236 
00237 };
00238 
00239 
00240 /** Remote version of Talkative. */
00241 
00242 class MISC_API RemoteTalkative : public virtual Talkative
00243 {
00244 
00245 public:
00246 
00247     /* Constructor */
00248     RemoteTalkative(MetaObject* superobject);
00249 
00250     /* Static generator, for factory. */
00251     static MetaObject* new_RemoteTalkative(MetaObject* superobject, const std::string& type);
00252 
00253     /** Send a say messsage to the local object.
00254         If the "time" field of msg is -1, then it will be filled in with the
00255         current time.
00256     */
00257     virtual void do_say(TalkMessage& msg);
00258 
00259 
00260 };
00261 
00262 
00263 #endif // #ifdef _TALKATIVE_HH_
00264 

Generated on Tue Aug 12 03:55:45 2003 for Interreality Project - VOS by doxygen 1.3.2