00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "vos/vos.hh"
00033 #include "property/property.hh"
00034 #include "sound.hh"
00035
00036
00037
00038 Sound::Sound(MetaObject* s) : MetaObject(s) {
00039
00040 }
00041
00042 LocalSound::LocalSound(MetaObject* s) : Sound(s), MetaObject(s) {
00043 }
00044
00045
00046
00047 void LocalSound::initialize() {
00048 setSound(NULL, 0, "?");
00049 }
00050
00051
00052 RemoteSound::RemoteSound(MetaObject* s) : Sound(s), MetaObject(s) {
00053 addUpdateHandler<RemoteSound>("sound:play", this, &RemoteSound::handlePlay);
00054 addUpdateHandler<RemoteSound>("sound:stop", this, &RemoteSound::handleStop);
00055 addUpdateHandler<RemoteSound>("sound:pause", this, &RemoteSound::handlePause);
00056 addUpdateHandler<RemoteSound>("sound:resume", this, &RemoteSound::handleResume);
00057 }
00058
00059
00060
00061
00062
00063 const string Sound::getType() {
00064 return string("sound:sound");
00065 }
00066
00067
00068 void Sound::registerExtenders() {
00069 LocalSite::addLocalObjectExtension(typeid(LocalSound).name(), &LocalSound::new_LocalSound);
00070 LocalSite::addLocalObjectExtension(typeid(Sound).name(), &LocalSound::new_LocalSound);
00071 LocalSite::addLocalObjectExtension("sound:sound", &LocalSound::new_LocalSound);
00072 RemoteSite::addRemoteObjectExtension(typeid(RemoteSound).name(), &RemoteSound::new_RemoteSound);
00073 RemoteSite::addRemoteObjectExtension(typeid(Sound).name(), &RemoteSound::new_RemoteSound);
00074 RemoteSite::addRemoteObjectExtension("sound:sound", &RemoteSound::new_RemoteSound);
00075
00076 }
00077
00078
00079
00080
00081 void* Sound::getSound() {
00082 string s;
00083 rREF(Vobject&, v, findObject("sound:sound"), s = meta_cast<Property&>(v).read() );
00084 return (void*)s.data();
00085 }
00086
00087 string Sound::getSoundDatatype() {
00088 string s;
00089 rREF(Vobject&, v, findObject("sound:sound"), s = meta_cast<Property&>(v).getDataType() );
00090 return s;
00091 }
00092
00093 unsigned int Sound::getSoundLength() {
00094 unsigned int len;
00095 rREF(Vobject&, v, findObject("sound:sound"), len = meta_cast<Property&>(v).getLength() );
00096 return len;
00097 }
00098
00099 void Sound::setSound(void* data, unsigned int len, const string& datatype) {
00100
00101 string s( (char*)data, len);
00102 Property::setProperty(*this, "sound:sound", s, datatype, &NoPropertyAccessControl::static_);
00103 }
00104
00105 bool Sound::getLoop() {
00106 string s;
00107 try {
00108 rREF(Vobject&, v, findObject("sound:loop"), s = meta_cast<Property&>(v).read(); );
00109 } catch(NoSuchObjectError) {
00110 return false;
00111 }
00112 return (s == "yes");
00113 }
00114
00115
00116 void Sound::setLoop(const bool value) {
00117
00118 string s;
00119 if(value)
00120 s = "yes";
00121 else
00122 s = "no";
00123 Property::setProperty(*this, "sound:loop", s, "text/x-yes-no", &NoPropertyAccessControl::static_);
00124 }
00125
00126 bool Sound::getImmediate() {
00127 string s;
00128 try {
00129 rREF(Vobject&, v, findObject("sound:immediate"), s = meta_cast<Property&>(v).read(); );
00130 } catch(NoSuchObjectError) {
00131 return false;
00132 }
00133 return (s == "yes");
00134 }
00135
00136 void Sound::setImmediate(const bool value) {
00137
00138 string s;
00139 if(value)
00140 s = "yes";
00141 else
00142 s = "no";
00143 Property::setProperty(*this, "sound:immediate", s, "text/x-yes-no", &NoPropertyAccessControl::static_);
00144 }
00145
00146
00147
00148 void LocalSound::sendMessage(Message* m) {
00149
00150
00151 Sound::sendMessage(m);
00152 }
00153
00154
00155
00156
00157
00158
00159 void RemoteSound::sendUpdateMessage(Message* m) {
00160
00161 Sound::sendUpdateMessage(m);
00162 }
00163
00164
00165
00166 void LocalSound::play() {
00167 pREF(Message*, m, new Message(),
00168 m->setType("update");
00169 m->setFrom(getURL().getString());
00170 m->setTo(getSite().getURL().getString());
00171 m->setMethod("sound:play");
00172 getSite().sendMessage(m);
00173 );
00174 }
00175
00176 void LocalSound::stop() {
00177 pREF(Message*, m, new Message(),
00178 m->setType("update");
00179 m->setFrom(getURL().getString());
00180 m->setTo(getSite().getURL().getString());
00181 m->setMethod("sound:stop");
00182 getSite().sendMessage(m);
00183 );
00184 }
00185
00186 void LocalSound::pause() {
00187 pREF(Message*, m, new Message(),
00188 m->setType("update");
00189 m->setFrom(getURL().getString());
00190 m->setTo(getSite().getURL().getString());
00191 m->setMethod("sound:pause");
00192 getSite().sendMessage(m);
00193 );
00194 }
00195
00196 void LocalSound::resume() {
00197 pREF(Message*, m, new Message(),
00198 m->setType("update");
00199 m->setFrom(getURL().getString());
00200 m->setTo(getSite().getURL().getString());
00201 m->setMethod("sound:resume");
00202 getSite().sendMessage(m);
00203 );
00204 }
00205
00206
00207
00208
00209
00210
00211 void RemoteSound::handlePlay(Message* m) {
00212
00213
00214
00215 m->release();
00216 }
00217
00218
00219 void RemoteSound::handleStop(Message* m) {
00220
00221
00222
00223 m->release();
00224 }
00225
00226
00227 void RemoteSound::handlePause(Message* m) {
00228
00229
00230
00231 m->release();
00232 }
00233
00234
00235 void RemoteSound::handleResume(Message* m) {
00236
00237
00238
00239 m->release();
00240 }
00241
00242
00243
00244
00245
00246
00247
00248 MetaObject* LocalSound::new_LocalSound(MetaObject* s, const string& type) {
00249 LocalSound* o = new LocalSound(s);
00250 o->initialize();
00251 return o;
00252 }
00253
00254 MetaObject* RemoteSound::new_RemoteSound(MetaObject* s, const string& type) {
00255 return new RemoteSound(s);
00256 }
00257