Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SoundPlay.cc

Go to the documentation of this file.
00001 #include "SoundPlay.h"
00002 #include "Simulator.h"
00003 #include "SharedGlobals.h"
00004 #include "Main.h"
00005 #include "IPC/MessageReceiver.h"
00006 #include "IPC/RegionRegistry.h"
00007 #include "Events/EventRouter.h"
00008 #include "SimConfig.h"
00009 
00010 SoundPlayThread * SoundPlay::player;
00011 
00012 SoundPlay::SoundPlay()
00013   : Process(getID(),getClassName()),
00014     requests(ipc_setup->registerRegion(getSoundPlayID(),sizeof(sim::SoundPlayQueue_t))),
00015     events(ipc_setup->registerRegion(Main::getEventsID(),sizeof(sim::EventQueue_t))),
00016     statusRequest(ipc_setup->registerRegion(Simulator::getStatusRequestID(),sizeof(sim::StatusRequest_t))),
00017     soundmanager(ipc_setup->registerRegion(getSoundManagerID(),sizeof(SoundManager))),
00018     soundProf(ipc_setup->registerRegion(getSoundProfilerID(),sizeof(soundProfiler_t))),
00019     etrans(NULL), sndrecv(NULL), statusrecv(NULL)
00020 {
00021   new (&(*requests)) sim::SoundPlayQueue_t;
00022   new (&(*soundmanager)) SoundManager;
00023   new (&(*soundProfiler)) soundProfiler_t;
00024   sndman=&(*soundmanager);
00025   ::soundProfiler=&(*soundProf);
00026 }
00027 
00028 SoundPlay::~SoundPlay() {
00029   delete etrans;
00030   etrans=NULL;
00031   MotionManager::setTranslator(NULL);
00032 }
00033 
00034 void SoundPlay::DoStart() {
00035   Process::DoStart();
00036   //These are constructed by other processes, so need to wait
00037   //until the construction runlevel is complete before we access them
00038   if(!sim::config.multiprocess) {
00039     // don't use our own etrans here, because erouter will delete it for us, don't want a double-delete in our destructor...
00040     EventTranslator * forwardTrans = new IPCEventTranslator(*events);
00041     forwardTrans->setTrapEventValue(true);
00042     erouter->setForwardingAgent(getID(),forwardTrans);
00043   } else {
00044     etrans=new IPCEventTranslator(*events);
00045     MotionManager::setTranslator(etrans); //although SoundPlay shouldn't use any motions...
00046 
00047     // Set up Event Translator to trap and send events to main process
00048     //send everything over except erouter events
00049     for(unsigned int i=0; i<EventBase::numEGIDs; i++)
00050       if(i!=EventBase::erouterEGID)
00051         erouter->addTrapper(etrans,static_cast<EventBase::EventGeneratorID_t>(i));
00052   }
00053   
00054   player = new SoundPlayThread;
00055   player->start();
00056   sndrecv=new MessageReceiver(*requests,gotSnd);
00057   statusrecv=new MessageReceiver(*statusRequest,statusReport);
00058 }
00059 
00060 void SoundPlay::DoStop() {
00061   sndrecv->finish();
00062   statusrecv->finish();
00063   
00064   delete sndrecv;
00065   sndrecv=NULL;
00066   delete statusrecv;
00067   statusrecv=NULL;
00068   delete player;
00069   player=NULL;
00070   
00071   sndman->stopPlay();
00072   if(sim::config.multiprocess) {
00073     erouter->removeTrapper(etrans);
00074     delete etrans;
00075     etrans=NULL;
00076   }
00077   Process::DoStop();
00078 }
00079 
00080 
00081 /*! @file
00082  * @brief 
00083  * @author ejt (Creator)
00084  *
00085  * $Author: ejt $
00086  * $Name: tekkotsu-4_0 $
00087  * $Revision: 1.2 $
00088  * $State: Exp $
00089  * $Date: 2007/11/10 22:58:13 $
00090  */
00091 

Tekkotsu Hardware Abstraction Layer 4.0
Generated Thu Nov 22 01:00:53 2007 by Doxygen 1.5.4