/** @file AimlQBotBundle.cpp * @author Alessandro Polo * @version $Id: AimlQBotBundle.cpp 71 2009-03-19 09:48:52Z alex $ * @brief * File containing methods for the wosh::AimlQBotBundle class. * The header for this class can be found in AimlQBotBundle.h, check that file * for class description. ****************************************************************************/ /* Copyright (c) 2009, WOSH - Wide Open Smart Home * by Alessandro Polo - OpenSmartHome.com * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the OpenSmartHome.com WOSH nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ****************************************************************************/ #include "AimlQBotBundle.h" #include "AimlQBot.h" #include #include #include #include using namespace std; namespace wosh { namespace services { ////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS AimlQBotBundle::AimlQBotBundle() : BundleGeneric() { BundleGeneric::setName( _AimlQBotBundle_NAME ); BundleGeneric::setType( "wosh.Service.AimlQBot" ); Properties.setProperty( _Bundle_KEY_Version, _AimlQBotBundle_VERSION ); Interfaces.add( ServiceInterface::getInterfaceName() ); Interfaces.add( AimlQBotInterface::getInterfaceName() ); Log.log( Logger::VERBOSE, " Configuring AimlQBot worker.." ); botWorker = new AimlQBot(); botWorker->setBusConnector( &BusCore ); botWorker->setLogger( &Log ); botWorker->setThreadListener(this); botWorker->setOwnerObject(this); Log.log( Logger::VERBOSE, " Setting default properties and permissions.." ); Log.log( Logger::VERBOSE, " Registering methods.." ); setBundleState(Bundle::CREATED, false); } AimlQBotBundle::~AimlQBotBundle() { Log.log( Logger::INFO, " Destroying.." ); if ( isBundleRunning() ) { Log.log( Logger::WARNING, "~AimlQBotBundle() : Destroying while RUNNING! Trying to stop.." ); bundleStop(); } delete this->botWorker; this->botWorker = NULL; Log.log( Logger::VERBOSE, ":~ModemDslBundle() : Destroyed." ); } //////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////// BUNDLE CONTROL WRESULT AimlQBotBundle::bundleStart() { if ( !BundleGeneric::bundleValidate_StartStop(Bundle::STARTING) ) return WRET_ERR_WRONG_STATE; WRESULT ret = BundleGeneric::start_SynchThread( this->botWorker ); // BUNDLE-STATE (STARTED) will be updated async by WORKER, through call: thread_event() return ret; } WRESULT AimlQBotBundle::bundleStop() { if ( !BundleGeneric::bundleValidate_StartStop(Bundle::STOPPING) ) return WRET_ERR_WRONG_STATE; WRESULT ret = BundleGeneric::stop_SynchThread( this->botWorker ); // BUNDLE-STATE (STOPPED) will be updated async by WORKER, through call: thread_event() return ret; } ////////////////////////////////////////////////////////////////////////////////////////////// BUNDLE CONTROL ////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// PROCESS BUS MESSAGES void AimlQBotBundle::processMessage( const Message& message ) { BundleGeneric::processMessage( message ); } //////////////////////////////////////////////////////////////////////////////////////// PROCESS BUS MESSAGES ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////// PROPERTY EVENT WRESULT AimlQBotBundle::applyingProperty( const string& key, const Data& value ) { if ( key == "" ) { } else // maybe its a base-class Property (as name, debug-level, ..) return BundleGeneric::applyingProperty(key, value); return WRET_OK; } ////////////////////////////////////////////////////////////////////////////////////////////// PROPERTY EVENT ////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// THREAD EVENTS void AimlQBotBundle::thread_event( Thread* thread, Thread::THREAD_STATE event ) { long id = 0; if ( thread != NULL ) id = thread->getThreadID(); Log.log( Logger::VERBOSE, ":thread_event(%i) : %s", id, Thread::getThreadStateAsString(event).c_str() ); switch(event) { case Thread::RUNNING: { setBundleState( Bundle::STARTED ); // register PROTOCOL to SessionServer (if exists) break; } case Thread::STOPPED: { setBundleState( Bundle::STOPPED ); // UNregister PROTOCOL to SessionServer (if exists) break; } default: break; } } /////////////////////////////////////////////////////////////////////////////////////////////// THREAD EVENTS ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////// METHODS ///////////////////////////////////////////////////////////////////////////////////////////////////// METHODS ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// }; // namespace services }; // namespace wosh