📄 stservicemanager.cxx
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. 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. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY 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. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * */static const char* const STServiceManager_cxx_Version = "$Id: STServiceManager.cxx,v 1.1 2001/10/26 21:47:52 icahoon Exp $";#include "global.h"#include "STServiceManager.hxx"#include "Service.hxx"#include "ControlEvent.hxx"#include "VLog.hxx"using namespace Vocal;using Vocal::Services::Event;using Vocal::Services::Service;using Vocal::Services::ServiceManager;using Vocal::Services::STServiceManager;using Vocal::Services::ControlEvent;using Vocal::Signals::SignalAction;using Vocal::Behavioral::EventObserver;using Vocal::Logging::VLog;STServiceManager::STServiceManager( SignalAction * signalAction) : ServiceManager(signalAction), myService(0), myObserver(0){ const string fn("STServiceManager::STServiceManager"); VLog log(fn); VDEBUG(log) << fn << ": this = " << this << VDEBUG_END(log);}STServiceManager::~STServiceManager(){ const string fn("STServiceManager::~STServiceManager"); VLog log(fn); VDEBUG(log) << fn << ": this = " << this << VDEBUG_END(log);}void STServiceManager::manage(Service & service){ const string fn("STServiceManager::manage"); VLog log(fn); assert( myService == 0 ); myService = &service; myService->setSignalAction(mySignalAction); myObserver = new STSMObserver(*myService); VINFO(log) << fn << ": Managing service: " << myService->name() << VINFO_END(log);}void STServiceManager::unmanage(){ const string fn("STServiceManager::unmanage"); VLog log(fn); assert( myService != 0 ); VINFO(log) << fn << ": Unmanaging service: " << myService->name() << VINFO_END(log); delete myObserver; myObserver = 0; myService->setSignalAction(0); myService = 0;}ReturnCode STServiceManager::start(){ const string fn("STServiceManager::start"); VLog log(fn); assert( myService != 0 ); VINFO(log) << fn << ": Service starting: " << myService->name() << VINFO_END(log); ControlEvent * ctrlEvent = new ControlEvent(ControlEvent::START, myService->getFifo()); Sptr<Event> startEvent = ctrlEvent; myService->getFifo().add(startEvent); return ( SUCCESS );}ReturnCode STServiceManager::run(){ const string fn("STServiceManager::run"); VLog log(fn); assert( myService != 0 ); VINFO(log) << fn << ": Service running: " << myService->name() << VINFO_END(log); return ( myService->run() );}void STServiceManager::stop(){ // Tear down will be taken care of in run.}void STServiceManager::shutdown(){ // Tear down will be taken care of in run.}STServiceManager::STSMObserver::STSMObserver( Service & service) : EventObserver< Sptr<Event> >(service.getEventSubject()), myService(service){ myService.subscribe(*this);} STServiceManager::STSMObserver::~STSMObserver(){ myService.unsubscribe(*this);} bool STServiceManager::STSMObserver::interestedIn(const Sptr<Event> & event){ Sptr<ControlEvent> ctrlEvent; ctrlEvent.dynamicCast(event); return ( ctrlEvent != 0 );}void STServiceManager::STSMObserver::onEvent(Sptr<Event> event){ const string fn("STServiceManager::STSMObserver::onEvent"); VLog log(fn); Sptr<ControlEvent> ctrlEvent; ctrlEvent.dynamicCast(event); if ( ctrlEvent == 0 ) { return; } switch ( ctrlEvent->getType() ) { case ControlEvent::START_RESPONSE: { ReturnCode rc = ctrlEvent->getReturnCode(); VINFO(log) << fn << ": Service started: " << myService.name() << ", rc = " << ctrlEvent->getReturnCode() << VINFO_END(log); if ( rc != SUCCESS ) { ControlEvent * ctrlEvent = new ControlEvent(ControlEvent::SHUTDOWN, myService.getFifo()); ctrlEvent->setReturnCode(rc); Sptr<Event> shutdownEvent = ctrlEvent; myService.getFifo().add(shutdownEvent); } break; } case ControlEvent::STOP_RESPONSE: case ControlEvent::SHUTDOWN_RESPONSE: { ReturnCode rc = ctrlEvent->getReturnCode(); VINFO(log) << fn << ": Service shutting down: " << myService.name() << ", rc = " << rc << VINFO_END(log); ControlEvent * ctrlEvent = new ControlEvent(ControlEvent::SHUTDOWN, myService.getFifo()); ctrlEvent->setReturnCode(rc); Sptr<Event> shutdownEvent = ctrlEvent; myService.getFifo().add(shutdownEvent); break; } default: { VWARN(log) << fn << ": Unknown control event: " << *ctrlEvent << VWARN_END(log); break; } }}ostream & STServiceManager::STSMObserver::writeTo(ostream & out) const{ return ( out << "STSMObserver" );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -