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

vos/metaobjects/sound/sound.cc

Go to the documentation of this file.
00001 /* $Id: sound.cc,v 1.8 2002/10/09 15:27:27 reed Exp $ */
00002 
00003 /*  Copyright (C) 2002 Reed Hedges
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00018 
00019 
00020     This file was generated by otd2cpp.pl, a script for ADR by Reed Hedges <reed@zerohour.net>.
00021    I can make no garuntee that this code will work, or even that it even is safe to run.
00022    Use it at your own risk.
00023 */
00024 
00025 
00026 /** @file sound.cc Code: a MetaObject for Sound object types.
00027 
00028     @TODO what is the correct way to send an update message?
00029 
00030 */
00031 
00032 #include "vos/vos.hh"
00033 #include "property/property.hh"
00034 #include "sound.hh"
00035 
00036 /* Constructors */
00037 
00038 Sound::Sound(MetaObject* s) : MetaObject(s) {
00039 
00040 }
00041 
00042 LocalSound::LocalSound(MetaObject* s) : Sound(s), MetaObject(s) {
00043 }
00044 
00045 
00046 /* Initialize required subobjects: */
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 /* Return type string ("sound") */
00062 
00063 const string Sound::getType() {
00064     return string("sound:sound");
00065 }
00066 
00067 /* Register extenders with libvos MetaFactory */
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 /* Get and set Subproperties and other Subobjects */
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     //TODO: you might want to use different access control on the property
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     //TODO: you might want to use different access control on the property
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     //TODO: you might want to use different access control on the property
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 /* Process local object messages */
00148 void LocalSound::sendMessage(Message* m) {
00149 
00150     /* Let superclass have message */
00151     Sound::sendMessage(m);
00152 }
00153 
00154 
00155 
00156 
00157 
00158 /* Process remote update messages */
00159 void RemoteSound::sendUpdateMessage(Message* m) {
00160     /* let superclass have message... */
00161     Sound::sendUpdateMessage(m);
00162 }
00163 
00164 /* Local Actuators: send messages to remote objects */
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 /* Message Handlers:  */
00207 
00208     /* TODO you might wantto override some of these methods in LocalSound  and RemoteSound */
00209 
00210 /** Handle remote-update message sound:play (When this message is recieved by a remote object, the sound should be played from the beginning. If the sound is already playing, it may be stopped or played simultaneously, as capabilities of the system permit. When recieved by a local object (from a remote object), the message may be relayed to all remote objects (?).) */
00211 void RemoteSound::handlePlay(Message* m) {
00212 
00213     //TODO: add code here
00214 
00215     m->release();   // decrease refcount before returning.
00216 }
00217 
00218 /** Handle remote-update message sound:stop (All playback of this sound should be immediately stopped. However, if "loop" is "yes", the sound should be re-played from the beginning.  When recieved by a local object (from a remote object), the message may be relayed to all remote objects (?).) */
00219 void RemoteSound::handleStop(Message* m) {
00220 
00221     // TODO
00222 
00223     m->release();   // decrease refcount before returning.
00224 }
00225 
00226 /** Handle remote-update message sound:pause (When recieved by a remote object,  it sould enter a "paused" state, in which all playback is stopped, but current position is saved.When recieved by a local object (from a remote object), the message may be relayed to all remote objects (?).) */
00227 void RemoteSound::handlePause(Message* m) {
00228 
00229     // TODO
00230 
00231     m->release();   // decrease refcount before returning.
00232 }
00233 
00234 /** Handle remote-update message sound:resume (If recieved by a remote object in "paused" state, it should resume playing. If not in paused state, do nothing.When recieved by a local object (from a remote object), the message may be relayed to all remote objects (?).) */
00235 void RemoteSound::handleResume(Message* m) {
00236 
00237     // TODO
00238 
00239     m->release();   // decrease refcount before returning.
00240 }
00241 
00242 /* Remote Actuators: */
00243 
00244 
00245 /* Generators for factory */
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 

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