/home/tetron/hack/vos/apps/tutorials/vostut7hello.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "vostut7hello.hh"
00011
00012 using namespace VUtil;
00013 using namespace VOS;
00014
00015
00016
00017 Hello::Hello(VobjectBase* superobject)
00018 : MetaObject(superobject)
00019 {
00020 }
00021
00022
00023
00024 const std::string Hello::getVOSType()
00025 {
00026 return "tutorial:hello";
00027 }
00028
00029
00030
00031
00032
00033
00034
00035
00036 RemoteHello::RemoteHello(VobjectBase* superobject)
00037 : Hello(superobject)
00038 { }
00039
00040
00041
00042
00043 std::string RemoteHello::hello(const std::string& s)
00044 {
00045
00046 std::string ret;
00047
00048
00049
00050
00051
00052
00053
00054 vRef<Message> m(new Message(this, "tutorial:hello", true), false);
00055
00056 m->appendField("word", s);
00057
00058
00059
00060
00061
00062 vRef<Message> n = ProcessMessage::sendMsgAndWaitForReply(this, m);
00063
00064 try {
00065
00066
00067 ret = n->getField("word")->value;
00068
00069 } catch(NoSuchFieldError) {
00070
00071
00072
00073
00074 ret = "***site did not return a word field***";
00075 }
00076
00077
00078 return ret;
00079 }
00080
00081
00082
00083
00084
00085
00086 MetaObject* RemoteHello::new_RemoteHello(VobjectBase* superobject, const std::string& type)
00087 {
00088 return new RemoteHello(superobject);
00089 }
00090
00091
00092
00093
00094
00095
00096
00097 LocalHello::LocalHello(VobjectBase* superobject)
00098 : Hello(superobject)
00099 {
00100
00101 static bool init = true;
00102 if(init) {
00103 init = false;
00104
00105
00106
00107
00108
00109
00110
00111 VobjectBase::addMessageHandler("tutorial:hello", &LocalHello::handleHello);
00112 }
00113 }
00114
00115
00116
00117
00118
00119 std::string LocalHello::hello(const std::string& s)
00120 {
00121 return ("Hello there! You said \"" + s + "\"");
00122 }
00123
00124
00125
00126
00127
00128
00129
00130 void LocalHello::handleHello(Message* m)
00131 {
00132
00133
00134
00135 vRef<Message> reply(new Message(this, m, "tutorial:hello-reply"), false);
00136
00137 try {
00138
00139
00140 std::string s = hello(m->getField("word")->value);
00141
00142
00143
00144
00145 reply->appendField("word", s);
00146
00147 } catch(NoSuchFieldError) {
00148
00149
00150 reply->appendField("error", "need a field \"word\"");
00151
00152 }
00153
00154 try {
00155
00156
00157
00158 vRef<Vobject> v = findObject(m->getFrom());
00159
00160 v->sendMessage(reply);
00161
00162 } catch(NoSuchSiteError) {
00163 } catch(NoSuchObjectError) {
00164 } catch(AccessControlError) {
00165 } catch(RemoteError) {
00166 } catch(BadURLError) {
00167 }
00168 }
00169
00170
00171
00172
00173
00174
00175 MetaObject* LocalHello::new_LocalHello(VobjectBase* superobject, const std::string& type)
00176 {
00177 return new LocalHello(superobject);
00178 }
00179
00180
00181
00182
00183
00184
00185
00186 BEGIN_REGISTER_METAOBJECT_FACTORIES(Hello)
00187
00188
00189
00190
00191
00192
00193
00194
00195 Site::addLocalMetaObjectFactory(typeid(Hello).name(), &LocalHello::new_LocalHello);
00196 Site::addLocalMetaObjectFactory(typeid(LocalHello).name(), &LocalHello::new_LocalHello);
00197 Site::addLocalMetaObjectFactory("tutorial:hello", &LocalHello::new_LocalHello);
00198
00199
00200
00201
00202
00203
00204 Site::addRemoteMetaObjectFactory(typeid(Hello).name(), "tutorial:hello", &RemoteHello::new_RemoteHello);
00205 Site::addRemoteMetaObjectFactory(typeid(RemoteHello).name(), "tutorial:hello", &RemoteHello::new_RemoteHello);
00206 Site::addRemoteMetaObjectFactory("tutorial:hello", "tutorial:hello", &RemoteHello::new_RemoteHello);
00207 END_REGISTER_METAOBJECT_FACTORIES(Hello)
00208