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/vos/vos.hh>
00030
00031
00032 #include "miscdefs.hh"
00033
00034 namespace VOS {
00035
00036 #define VOS_TALK_NO_VOICE "#f"
00037 #define VOS_TALK_VOICE_DATATYPE "application/x-festival"
00038
00039 class TalkMessage;
00040 class TalkListener;
00041
00042
00043
00044
00045
00046
00047
00048
00049 class MISC_API Talkative : public MetaObject
00050 {
00051 protected:
00052 virtual void do_say(TalkMessage& msg) = 0;
00053 virtual void do_resend(Talkative* resendTo, TalkMessage& m) = 0;
00054 public:
00055
00056
00057
00058
00059 static const unsigned short UNSPECIFIED;
00060 static const unsigned short PUBLIC;
00061 static const unsigned short PRIVATE;
00062 static const unsigned short AUTO;
00063 static const unsigned short FROM_APP;
00064 static const unsigned short SYSTEM;
00065 static const unsigned short EMOTE;
00066
00067
00068
00069 public:
00070
00071 Talkative(VobjectBase* superobject);
00072
00073
00074 const std::string getVOSType();
00075
00076
00077
00078
00079 std::string getVoice();
00080
00081
00082
00083
00084
00085
00086 void setVoice(const std::string& value);
00087
00088
00089
00090
00091
00092
00093 virtual void say(TalkMessage& msg);
00094
00095
00096 void say(const std::string& text, Talkative& sender,
00097 const unsigned short scope, const int priority = 0,
00098 uint32_t replynonce = 0,
00099 uint32_t thisnonce = 0);
00100
00101
00102
00103 void say(const std::string& text, Talkative& sender, uint32_t in_reply_to = 0) {
00104 say(text, sender, UNSPECIFIED, 0, in_reply_to);
00105 }
00106
00107
00108 virtual VUtil::vRef<Vobject> getRelayListeners();
00109
00110 virtual void addRelay(Talkative* t);
00111 virtual void removeRelay(Talkative* t);
00112
00113
00114
00115
00116
00117
00118
00119 virtual void sayToAllMembers(Vobject* target, TalkMessage& msg);
00120
00121
00122
00123
00124
00125 virtual void resend(Talkative* resendTo, TalkMessage& msg);
00126
00127
00128 void resend(Talkative* resendTo,
00129 const std::string& text,
00130 const unsigned short scope, const int priority = 0,
00131 uint32_t replynonce = 0,
00132 uint32_t thisnonce = 0);
00133
00134
00135
00136 void resend(Talkative* resendTo, const std::string& text,
00137 uint32_t in_reply_to = 0)
00138 {
00139 resend(resendTo, text, UNSPECIFIED, 0, in_reply_to);
00140 }
00141 };
00142
00143
00144
00145
00146
00147
00148 class MISC_API TalkListener {
00149 public:
00150 virtual ~TalkListener() { }
00151
00152
00153 virtual void notifyTalkMessage(TalkMessage& m) = 0;
00154 };
00155
00156
00157
00158
00159 class MISC_API TalkMessage : public VUtil::RefCounted {
00160 private:
00161 std::string text;
00162 std::vector< VUtil::vRef<Talkative> > relay_path;
00163
00164 VUtil::vRef<Talkative> origin;
00165 VUtil::vRef<Talkative> last_sender;
00166
00167 unsigned short scope;
00168 int priority;
00169 time_t time;
00170 uint32_t reply_nonce;
00171 uint32_t this_nonce;
00172
00173 VUtil::vRef<Message> vosmessage;
00174 public:
00175
00176 TalkMessage(Talkative& se, std::string t = "",
00177 unsigned short sc = Talkative::UNSPECIFIED,
00178 int pr = 0, time_t tm = -1,
00179 uint32_t rn = 0,
00180 uint32_t tn = 0);
00181 TalkMessage(Message* m);
00182
00183 VUtil::vRef<Talkative> getReceiver() { return relay_path.back(); }
00184 VUtil::vRef<Talkative> getLastSender() { return last_sender; }
00185 VUtil::vRef<Talkative> getOrigin() { return origin; }
00186 const std::vector< VUtil::vRef<Talkative> >& getRelayPath()
00187 { return relay_path; }
00188
00189 void addHop(Talkative* t);
00190
00191 const std::string& getText() { return text; }
00192 unsigned short getScope() { return scope; }
00193 int getPriority() { return priority; }
00194 time_t getTime() { return time; }
00195 uint32_t getReplyNonce() { return reply_nonce; }
00196 uint32_t getNonce() { return this_nonce; }
00197 VUtil::vRef<Message> getVOSMessage();
00198
00199 virtual void deliverTo(TalkListener* tl)
00200 {
00201 tl->notifyTalkMessage(*this);
00202 }
00203 };
00204
00205
00206
00207
00208
00209
00210
00211 class MISC_API LocalTalkative : public Talkative {
00212
00213 private:
00214 VUtil::ListenerBase<TalkListener, TalkMessage> listeners;
00215
00216
00217 VUtil::vRef<Talkative> replyto;
00218
00219
00220 virtual void handleSay(Message* m);
00221 virtual void handleResend(Message* m);
00222
00223 protected:
00224
00225
00226
00227
00228
00229
00230
00231
00232 virtual void do_say(TalkMessage& msg);
00233
00234 virtual void do_resend(Talkative* sendTo, TalkMessage& m);
00235
00236 public:
00237
00238 LocalTalkative(VobjectBase* superobject);
00239
00240 ~LocalTalkative();
00241
00242 static MetaObject* new_LocalTalkative(VobjectBase* superobject, const std::string& type);
00243
00244
00245
00246
00247
00248 virtual void addTalkListener(TalkListener* l);
00249
00250
00251
00252
00253
00254 virtual void removeTalkListener(TalkListener* l);
00255 };
00256
00257
00258
00259
00260
00261
00262 class MISC_API RemoteTalkative : public virtual Talkative
00263 {
00264 protected:
00265
00266
00267
00268
00269 virtual void do_say(TalkMessage& msg);
00270
00271 virtual void do_resend(Talkative* sendTo, TalkMessage& m);
00272
00273 public:
00274
00275 RemoteTalkative(VobjectBase* superobject);
00276
00277 static MetaObject* new_RemoteTalkative(VobjectBase* superobject,
00278 const std::string& type);
00279 };
00280
00281
00282 class MISC_API TalkativeAccessControl
00283 {
00284 public:
00285 virtual ~TalkativeAccessControl() { }
00286
00287
00288 virtual const std::string getPolicyName() = 0;
00289
00290 virtual bool checkSendPermission(Vobject* requester,
00291 Vobject* parent,
00292 TalkMessage& msg,
00293 std::string& errmessage) = 0;
00294 virtual bool checkResendPermission(Vobject* requester,
00295 Vobject* parent,
00296 TalkMessage& msg,
00297 std::string& errmessage) = 0;
00298
00299 };
00300
00301 class MISC_API AcceptAllTalkativeAC : public TalkativeAccessControl
00302 {
00303 public:
00304 static AcceptAllTalkativeAC static_;
00305
00306 virtual ~AcceptAllTalkativeAC() { }
00307
00308
00309 virtual const std::string getPolicyName()
00310 { return "talkative:accept-all"; }
00311
00312 virtual bool checkSendPermission(Vobject* requester,
00313 Vobject* parent,
00314 TalkMessage& msg,
00315 std::string& errmessage)
00316 { return true; }
00317
00318 virtual bool checkResendPermission(Vobject* requester,
00319 Vobject* parent,
00320 TalkMessage& msg,
00321 std::string& errmessage)
00322 { return true; }
00323 };
00324
00325 class MISC_API SendOnlyTalkativeAC : public TalkativeAccessControl
00326 {
00327 public:
00328 static SendOnlyTalkativeAC static_;
00329
00330 virtual ~SendOnlyTalkativeAC() { }
00331
00332
00333 virtual const std::string getPolicyName()
00334 { return "talkative:send-only"; }
00335
00336 virtual bool checkSendPermission(Vobject* requester,
00337 Vobject* parent,
00338 TalkMessage& msg,
00339 std::string& errmessage)
00340 { return true; }
00341
00342 virtual bool checkResendPermission(Vobject* requester,
00343 Vobject* parent,
00344 TalkMessage& msg,
00345 std::string& errmessage)
00346 { return false; }
00347 };
00348
00349 class MISC_API DenyAllTalkativeAC : public TalkativeAccessControl
00350 {
00351 public:
00352 static DenyAllTalkativeAC static_;
00353
00354 virtual ~DenyAllTalkativeAC() { }
00355
00356
00357 virtual const std::string getPolicyName()
00358 { return "talkative:deny-all"; }
00359
00360 virtual bool checkSendPermission(Vobject* requester,
00361 Vobject* parent,
00362 TalkMessage& msg,
00363 std::string& errmessage)
00364 { return false; }
00365
00366 virtual bool checkResendPermission(Vobject* requester,
00367 Vobject* parent,
00368 TalkMessage& msg,
00369 std::string& errmessage)
00370 { return false; }
00371 };
00372
00373 }
00374
00375 #ifndef MISC_EXPORTS
00376 IMPORT_METAOBJECT_FACTORIES(Talkative)
00377 #endif
00378
00379 #endif // #ifdef _TALKATIVE_HH_
00380