00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00049
00050
00051
00052
00053 class MISC_API Talkative : public virtual MetaObject
00054 {
00055 private:
00056 PropertyAccessControl *defaultPropertyAC;
00057
00058 public:
00059
00060
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;
00068 static const unsigned short SYSTEM;
00069
00070
00071
00072 public:
00073
00074
00075 Talkative(MetaObject* superobject);
00076
00077
00078 void initialize();
00079
00080
00081 void initialize(PropertyAccessControl* ac);
00082
00083
00084 inline void setPropertyAccessControl(PropertyAccessControl* ac) {
00085 initialize(ac);
00086 }
00087
00088
00089
00090 const std::string getType();
00091
00092
00093 static void registerExtenders();
00094
00095
00096
00097
00098
00099
00100 std::string get_voice();
00101
00102
00103 std::string get_voice_datatype();
00104
00105
00106
00107
00108
00109
00110 void set_voice(const std::string& value, const std::string& datatype = "?", PropertyAccessControl* ac = NULL);
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 virtual void do_say(TalkMessage& msg) = 0;
00123
00124
00125
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
00133
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
00144 class MISC_API TalkMessage {
00145 public:
00146 std::string text;
00147 Talkative& sender;
00148 unsigned short scope;
00149 int priority;
00150 time_t time;
00151 std::string reply_nonce;
00152 std::string this_nonce;
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
00165
00166
00167 class MISC_API TalkListener {
00168 public:
00169
00170 virtual void notifyTalkMessage(TalkMessage& m) = 0;
00171 };
00172
00173
00174
00175 class MISC_API LocalTalkative : public virtual Talkative {
00176
00177 private:
00178 typedef vector<TalkListener*> ListenerList;
00179 ListenerList listeners;
00180
00181
00182 Talkative* replyto;
00183
00184
00185 std::string replynonce;
00186
00187 public:
00188
00189
00190 LocalTalkative(MetaObject* superobject);
00191
00192
00193 ~LocalTalkative();
00194
00195
00196 static MetaObject* new_LocalTalkative(MetaObject* superobject, const std::string& type);
00197
00198
00199
00200
00201
00202
00203 void addTalkListener(TalkListener* l);
00204
00205
00206
00207
00208
00209 void removeTalkListener(TalkListener* l);
00210
00211
00212
00213
00214
00215 void reply_to_last(const std::string& text, const int priority = 0 );
00216
00217
00218
00219
00220 void say_to_all(const std::string& text, Vobject& parent, const int priority = 0, const std::string& replynonce = "" );
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 void do_say(TalkMessage& msg);
00231
00232 protected:
00233
00234
00235 virtual void handle_say(Message* m);
00236
00237 };
00238
00239
00240
00241
00242 class MISC_API RemoteTalkative : public virtual Talkative
00243 {
00244
00245 public:
00246
00247
00248 RemoteTalkative(MetaObject* superobject);
00249
00250
00251 static MetaObject* new_RemoteTalkative(MetaObject* superobject, const std::string& type);
00252
00253
00254
00255
00256
00257 virtual void do_say(TalkMessage& msg);
00258
00259
00260 };
00261
00262
00263 #endif // #ifdef _TALKATIVE_HH_
00264