fixed playlist event

now scheduler correclty plays scheduled events
This commit is contained in:
maroy 2005-01-10 09:36:24 +00:00
parent bd36de8bd4
commit 9a185bb141
11 changed files with 253 additions and 44 deletions

View File

@ -1,8 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE scheduler [ <!DOCTYPE scheduler [
<!ELEMENT scheduler (connectionManagerFactory,storageClientFactory, <!ELEMENT scheduler (user,
scheduleFactory,playLogFactory,audioPlayer,xmlRpcDaemon) > connectionManagerFactory,
authenticationClientFactory,
storageClientFactory,
scheduleFactory,
playLogFactory,
audioPlayer,
xmlRpcDaemon) >
<!ELEMENT connectionManagerFactory (simpleConnectionManager) > <!ELEMENT connectionManagerFactory (simpleConnectionManager) >
@ -11,6 +17,22 @@
<!ATTLIST simpleConnectionManager userName CDATA #REQUIRED > <!ATTLIST simpleConnectionManager userName CDATA #REQUIRED >
<!ATTLIST simpleConnectionManager password CDATA #REQUIRED > <!ATTLIST simpleConnectionManager password CDATA #REQUIRED >
<!ELEMENT authenticationClientFactory (testAuthentication|
webAuthentication)>
<!ELEMENT testAuthentication (user) >
<!ELEMENT user EMPTY >
<!ATTLIST user login CDATA #REQUIRED >
<!ATTLIST user password CDATA #REQUIRED >
<!ELEMENT webAuthentication (location) >
<!ELEMENT location EMPTY >
<!ATTLIST location server CDATA #REQUIRED >
<!ATTLIST location port NMTOKEN #REQUIRED >
<!ATTLIST location path CDATA #REQUIRED >
<!ELEMENT storageClientFactory (testStorage|webStorage) > <!ELEMENT storageClientFactory (testStorage|webStorage) >
<!ELEMENT testStorage (playlist*, audioClip*) > <!ELEMENT testStorage (playlist*, audioClip*) >
@ -19,11 +41,6 @@
<!ELEMENT webStorage (location) > <!ELEMENT webStorage (location) >
<!ATTLIST webStorage tempFiles CDATA #REQUIRED > <!ATTLIST webStorage tempFiles CDATA #REQUIRED >
<!ELEMENT location EMPTY >
<!ATTLIST location server CDATA #REQUIRED >
<!ATTLIST location port NMTOKEN #REQUIRED >
<!ATTLIST location path CDATA #REQUIRED >
<!ELEMENT playlist (playlistElement*) > <!ELEMENT playlist (playlistElement*) >
<!ATTLIST playlist id NMTOKEN #REQUIRED > <!ATTLIST playlist id NMTOKEN #REQUIRED >
<!ATTLIST playlist playlength NMTOKEN #REQUIRED > <!ATTLIST playlist playlength NMTOKEN #REQUIRED >
@ -62,6 +79,8 @@
]> ]>
<scheduler> <scheduler>
<user login="root" password="q" />
<connectionManagerFactory> <connectionManagerFactory>
<simpleConnectionManager dsn = "LiveSupport-test" <simpleConnectionManager dsn = "LiveSupport-test"
userName = "test" userName = "test"
@ -69,6 +88,13 @@
/> />
</connectionManagerFactory> </connectionManagerFactory>
<authenticationClientFactory>
<webAuthentication>
<location server="localhost" port="80"
path="/livesupportStorageServer/xmlrpc/xrLocStor.php" />
</webAuthentication>
</authenticationClientFactory>
<storageClientFactory> <storageClientFactory>
<webStorage tempFiles="file:///tmp/webStorageClient" > <webStorage tempFiles="file:///tmp/webStorageClient" >
<location server="localhost" port="80" <location server="localhost" port="80"

View File

@ -1,8 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE scheduler [ <!DOCTYPE scheduler [
<!ELEMENT scheduler (connectionManagerFactory,storageClientFactory, <!ELEMENT scheduler (user,
scheduleFactory,playLogFactory,audioPlayer,xmlRpcDaemon) > connectionManagerFactory,
authenticationClientFactory,
storageClientFactory,
scheduleFactory,
playLogFactory,
audioPlayer,
xmlRpcDaemon) >
<!ELEMENT connectionManagerFactory (simpleConnectionManager) > <!ELEMENT connectionManagerFactory (simpleConnectionManager) >
@ -11,6 +17,22 @@
<!ATTLIST simpleConnectionManager userName CDATA #REQUIRED > <!ATTLIST simpleConnectionManager userName CDATA #REQUIRED >
<!ATTLIST simpleConnectionManager password CDATA #REQUIRED > <!ATTLIST simpleConnectionManager password CDATA #REQUIRED >
<!ELEMENT authenticationClientFactory (testAuthentication|
webAuthentication)>
<!ELEMENT testAuthentication (user) >
<!ELEMENT user EMPTY >
<!ATTLIST user login CDATA #REQUIRED >
<!ATTLIST user password CDATA #REQUIRED >
<!ELEMENT webAuthentication (location) >
<!ELEMENT location EMPTY >
<!ATTLIST location server CDATA #REQUIRED >
<!ATTLIST location port NMTOKEN #REQUIRED >
<!ATTLIST location path CDATA #REQUIRED >
<!ELEMENT storageClientFactory (testStorage) > <!ELEMENT storageClientFactory (testStorage) >
<!ELEMENT testStorage (playlist*, audioClip*) > <!ELEMENT testStorage (playlist*, audioClip*) >
@ -54,6 +76,8 @@
]> ]>
<scheduler> <scheduler>
<user login="root" password="q" />
<connectionManagerFactory> <connectionManagerFactory>
<simpleConnectionManager dsn = "LiveSupport-test" <simpleConnectionManager dsn = "LiveSupport-test"
userName = "test" userName = "test"
@ -61,6 +85,12 @@
/> />
</connectionManagerFactory> </connectionManagerFactory>
<authenticationClientFactory>
<testAuthentication>
<user login="root" password="q" />
</testAuthentication>
</authenticationClientFactory>
<storageClientFactory> <storageClientFactory>
<testStorage tempFiles="file:///tmp/tempPlaylist"> <testStorage tempFiles="file:///tmp/tempPlaylist">
<playlist id="0000000000000001" playlength="01:30:00.000"> <playlist id="0000000000000001" playlength="01:30:00.000">

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.5 $ Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEvent.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEvent.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -46,6 +46,7 @@
#include "PlaylistEvent.h" #include "PlaylistEvent.h"
using namespace boost;
using namespace LiveSupport::Core; using namespace LiveSupport::Core;
using namespace LiveSupport::Scheduler; using namespace LiveSupport::Scheduler;
@ -65,15 +66,19 @@ using namespace LiveSupport::Scheduler;
* Constructor. * Constructor.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
PlaylistEvent :: PlaylistEvent( PlaylistEvent :: PlaylistEvent(
Ptr<SessionId>::Ref sessionId,
Ptr<AudioPlayerInterface>::Ref audioPlayer, Ptr<AudioPlayerInterface>::Ref audioPlayer,
Ptr<StorageClientInterface>::Ref storage, Ptr<StorageClientInterface>::Ref storage,
Ptr<ScheduleEntry>::Ref scheduleEntry) Ptr<ScheduleEntry>::Ref scheduleEntry)
throw () throw ()
{ {
this->sessionId = sessionId;
this->audioPlayer = audioPlayer; this->audioPlayer = audioPlayer;
this->storage = storage; this->storage = storage;
this->scheduleEntry = scheduleEntry; this->scheduleEntry = scheduleEntry;
this->sessionId.reset(new SessionId("dummy session ID"));
// this init time is a wild guess, say 5 seconds should be enough
initTime.reset(new posix_time::time_duration(0, 0, 5, 0));
} }

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.5 $ Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEvent.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEvent.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -40,6 +40,7 @@
#include "configure.h" #include "configure.h"
#endif #endif
#include "LiveSupport/Core/SessionId.h"
#include "LiveSupport/Core/ScheduleEntry.h" #include "LiveSupport/Core/ScheduleEntry.h"
#include "LiveSupport/Storage/StorageClientInterface.h" #include "LiveSupport/Storage/StorageClientInterface.h"
#include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h" #include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h"
@ -69,7 +70,7 @@ using namespace LiveSupport::Storage;
* A scheduled event for playing a playlist. * A scheduled event for playing a playlist.
* *
* @author $Author: maroy $ * @author $Author: maroy $
* @version $Revision: 1.5 $ * @version $Revision: 1.6 $
*/ */
class PlaylistEvent : public virtual ScheduledEventInterface class PlaylistEvent : public virtual ScheduledEventInterface
{ {
@ -109,13 +110,15 @@ class PlaylistEvent : public virtual ScheduledEventInterface
/** /**
* Constructor. * Constructor.
* *
* @param sessionId the session id used to access the storage.
* @param audioPlayer the audio player to play the playlist with. * @param audioPlayer the audio player to play the playlist with.
* @param storage the storage containing the playlist to play, * @param storage the storage containing the playlist to play,
* and all the related audio clips. * and all the related audio clips.
* @param scheduleEntry the schedule entry this event is * @param scheduleEntry the schedule entry this event is
* playing. * playing.
*/ */
PlaylistEvent(Ptr<AudioPlayerInterface>::Ref audioPlayer, PlaylistEvent(Ptr<SessionId>::Ref sessionId,
Ptr<AudioPlayerInterface>::Ref audioPlayer,
Ptr<StorageClientInterface>::Ref storage, Ptr<StorageClientInterface>::Ref storage,
Ptr<ScheduleEntry>::Ref scheduleEntry) Ptr<ScheduleEntry>::Ref scheduleEntry)
throw (); throw ();

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.1 $ Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventContainer.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventContainer.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -63,11 +63,13 @@ using namespace LiveSupport::Scheduler;
* Constructor. * Constructor.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
PlaylistEventContainer :: PlaylistEventContainer( PlaylistEventContainer :: PlaylistEventContainer(
Ptr<SessionId>::Ref sessionId,
Ptr<StorageClientInterface>::Ref storage, Ptr<StorageClientInterface>::Ref storage,
Ptr<ScheduleInterface>::Ref schedule, Ptr<ScheduleInterface>::Ref schedule,
Ptr<AudioPlayerInterface>::Ref audioPlayer) Ptr<AudioPlayerInterface>::Ref audioPlayer)
throw () throw ()
{ {
this->sessionId = sessionId;
this->storage = storage; this->storage = storage;
this->schedule = schedule; this->schedule = schedule;
this->audioPlayer = audioPlayer; this->audioPlayer = audioPlayer;
@ -84,7 +86,7 @@ PlaylistEventContainer :: getNextEvent(Ptr<ptime>::Ref when) throw ()
Ptr<PlaylistEvent>::Ref event; Ptr<PlaylistEvent>::Ref event;
if (entry.get()) { if (entry.get()) {
event.reset(new PlaylistEvent(audioPlayer, storage, entry)); event.reset(new PlaylistEvent(sessionId, audioPlayer, storage, entry));
} }
return event; return event;

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.2 $ Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventContainer.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventContainer.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -40,6 +40,7 @@
#include "configure.h" #include "configure.h"
#endif #endif
#include "LiveSupport/Core/SessionId.h"
#include "LiveSupport/Storage/StorageClientInterface.h" #include "LiveSupport/Storage/StorageClientInterface.h"
#include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h" #include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h"
#include "LiveSupport/EventScheduler/EventContainerInterface.h" #include "LiveSupport/EventScheduler/EventContainerInterface.h"
@ -70,12 +71,18 @@ using namespace LiveSupport::Storage;
/** /**
* An event container holding the scheduled playlists. * An event container holding the scheduled playlists.
* *
* @author $Author: fgerlits $ * @author $Author: maroy $
* @version $Revision: 1.2 $ * @version $Revision: 1.3 $
*/ */
class PlaylistEventContainer : public virtual EventContainerInterface class PlaylistEventContainer : public virtual EventContainerInterface
{ {
private: private:
/**
* The session id, passed on to PlaylistEvents, to access
* resources from the storage.
*/
Ptr<SessionId>::Ref sessionId;
/** /**
* The storage containing the playlists to play. * The storage containing the playlists to play.
*/ */
@ -96,12 +103,15 @@ class PlaylistEventContainer : public virtual EventContainerInterface
/** /**
* Constructor. * Constructor.
* *
* @param sessionId the session id that will be accepted by
* calls to storage
* @param storage the storage containing the playlist and related * @param storage the storage containing the playlist and related
* audio clips * audio clips
* @param schedule the schedule to get the events from. * @param schedule the schedule to get the events from.
* @param audioPlayer the audio player to play the playlists with. * @param audioPlayer the audio player to play the playlists with.
*/ */
PlaylistEventContainer(Ptr<StorageClientInterface>::Ref storage, PlaylistEventContainer(Ptr<SessionId>::Ref sessionId,
Ptr<StorageClientInterface>::Ref storage,
Ptr<ScheduleInterface>::Ref schedule, Ptr<ScheduleInterface>::Ref schedule,
Ptr<AudioPlayerInterface>::Ref audioPlayer) Ptr<AudioPlayerInterface>::Ref audioPlayer)
throw (); throw ();

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.3 $ Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventContainerTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventContainerTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -198,7 +198,10 @@ PlaylistEventContainerTest :: simpleTest(void)
throw (CPPUNIT_NS::Exception) throw (CPPUNIT_NS::Exception)
{ {
Ptr<PlaylistEventContainer>::Ref container; Ptr<PlaylistEventContainer>::Ref container;
container.reset(new PlaylistEventContainer(storage, schedule, audioPlayer)); container.reset(new PlaylistEventContainer(sessionId,
storage,
schedule,
audioPlayer));
// see that there are no events scheduled // see that there are no events scheduled
Ptr<ScheduledEventInterface>::Ref scheduledEvent; Ptr<ScheduledEventInterface>::Ref scheduledEvent;
@ -215,7 +218,10 @@ PlaylistEventContainerTest :: scheduleTest(void)
throw (CPPUNIT_NS::Exception) throw (CPPUNIT_NS::Exception)
{ {
Ptr<PlaylistEventContainer>::Ref container; Ptr<PlaylistEventContainer>::Ref container;
container.reset(new PlaylistEventContainer(storage, schedule, audioPlayer)); container.reset(new PlaylistEventContainer(sessionId,
storage,
schedule,
audioPlayer));
// schedule playlist 1 at 10 seconds from now // schedule playlist 1 at 10 seconds from now
Ptr<UniqueId>::Ref playlistId(new UniqueId(1)); Ptr<UniqueId>::Ref playlistId(new UniqueId(1));

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.2 $ Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -43,6 +43,7 @@
#include <string> #include <string>
#include "LiveSupport/Core/TimeConversion.h" #include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Authentication/AuthenticationClientFactory.h"
#include "LiveSupport/Storage/StorageClientFactory.h" #include "LiveSupport/Storage/StorageClientFactory.h"
#include "LiveSupport/PlaylistExecutor/AudioPlayerFactory.h" #include "LiveSupport/PlaylistExecutor/AudioPlayerFactory.h"
@ -53,6 +54,7 @@
using namespace boost::posix_time; using namespace boost::posix_time;
using namespace LiveSupport::Core; using namespace LiveSupport::Core;
using namespace LiveSupport::Authentication;
using namespace LiveSupport::Storage; using namespace LiveSupport::Storage;
using namespace LiveSupport::PlaylistExecutor; using namespace LiveSupport::PlaylistExecutor;
using namespace LiveSupport::Scheduler; using namespace LiveSupport::Scheduler;
@ -69,6 +71,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION(PlaylistEventTest);
*/ */
static const std::string audioPlayerConfigFileName = "etc/audioPlayer.xml"; static const std::string audioPlayerConfigFileName = "etc/audioPlayer.xml";
/**
* The name of the configuration file for the authentication client factory.
*/
static const std::string authenticationClientConfigFileName =
"etc/authenticationClient.xml";
/** /**
* The name of the configuration file for the storage client * The name of the configuration file for the storage client
*/ */
@ -104,6 +112,14 @@ PlaylistEventTest :: setUp(void) throw ()
storage = scf->getStorageClient(); storage = scf->getStorageClient();
// get an authentication client
Ptr<AuthenticationClientFactory>::Ref acf;
acf = AuthenticationClientFactory::getInstance();
parser.reset(new xmlpp::DomParser(authenticationClientConfigFileName,
true));
acf->configure(*(parser->get_document()->get_root_node()));
authentication = acf->getAuthenticationClient();
} catch (std::invalid_argument &e) { } catch (std::invalid_argument &e) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
CPPUNIT_FAIL("semantic error in configuration file"); CPPUNIT_FAIL("semantic error in configuration file");
@ -115,6 +131,10 @@ PlaylistEventTest :: setUp(void) throw ()
audioPlayer->initialize(); audioPlayer->initialize();
duration.reset(new time_duration(seconds(30))); duration.reset(new time_duration(seconds(30)));
if (!(sessionId = authentication->login("root", "q"))) {
CPPUNIT_FAIL("could not log in to authentication server");
}
} }
@ -129,6 +149,10 @@ PlaylistEventTest :: tearDown(void) throw ()
duration.reset(); duration.reset();
storage.reset(); storage.reset();
audioPlayer.reset(); audioPlayer.reset();
authentication->logout(sessionId);
sessionId.reset();
authentication.reset();
} }
@ -150,7 +174,8 @@ PlaylistEventTest :: createTestEvent(void) throw ()
startTime, startTime,
endTime)); endTime));
Ptr<PlaylistEvent>::Ref playlistEvent(new PlaylistEvent(audioPlayer, Ptr<PlaylistEvent>::Ref playlistEvent(new PlaylistEvent(sessionId,
audioPlayer,
storage, storage,
scheduleEntry)); scheduleEntry));

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.2 $ Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventTest.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PlaylistEventTest.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -42,6 +42,7 @@
#include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/HelperMacros.h>
#include "LiveSupport/Authentication/AuthenticationClientInterface.h"
#include "LiveSupport/Storage/StorageClientInterface.h" #include "LiveSupport/Storage/StorageClientInterface.h"
#include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h" #include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h"
@ -53,6 +54,7 @@ using namespace boost::posix_time;
using namespace LiveSupport; using namespace LiveSupport;
using namespace LiveSupport::Core; using namespace LiveSupport::Core;
using namespace LiveSupport::Authentication;
using namespace LiveSupport::PlaylistExecutor; using namespace LiveSupport::PlaylistExecutor;
/* ================================================================ constants */ /* ================================================================ constants */
@ -66,8 +68,8 @@ using namespace LiveSupport::PlaylistExecutor;
/** /**
* Unit test for the PlaylistEvent class * Unit test for the PlaylistEvent class
* *
* @author $Author: fgerlits $ * @author $Author: maroy $
* @version $Revision: 1.2 $ * @version $Revision: 1.3 $
* @see PlaylistEvent * @see PlaylistEvent
*/ */
class PlaylistEventTest : public CPPUNIT_NS::TestFixture class PlaylistEventTest : public CPPUNIT_NS::TestFixture
@ -94,6 +96,16 @@ class PlaylistEventTest : public CPPUNIT_NS::TestFixture
*/ */
Ptr<time_duration>::Ref duration; Ptr<time_duration>::Ref duration;
/**
* An authentication client.
*/
Ptr<AuthenticationClientInterface>::Ref authentication;
/**
* A session ID from the authentication client login() method.
*/
Ptr<SessionId>::Ref sessionId;
/** /**
* Create a playlist event for testing purposes. * Create a playlist event for testing purposes.
*/ */

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.14 $ Version : $Revision: 1.15 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemon.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemon.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -54,6 +54,7 @@
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Db/ConnectionManagerFactory.h" #include "LiveSupport/Db/ConnectionManagerFactory.h"
#include "LiveSupport/Authentication/AuthenticationClientFactory.h"
#include "LiveSupport/Storage/StorageClientFactory.h" #include "LiveSupport/Storage/StorageClientFactory.h"
#include "LiveSupport/PlaylistExecutor/AudioPlayerFactory.h" #include "LiveSupport/PlaylistExecutor/AudioPlayerFactory.h"
#include "ScheduleFactory.h" #include "ScheduleFactory.h"
@ -89,6 +90,20 @@ static const std::string confElement = "scheduler";
*/ */
static const std::string xmlRpcDaemonConfElement = "xmlRpcDaemon"; static const std::string xmlRpcDaemonConfElement = "xmlRpcDaemon";
/**
* The name of the config child element for the login and password
*/
static const std::string userConfigElementName = "user";
/**
* The name of the config element attribute for the login
*/
static const std::string userLoginAttrName = "login";
/**
* The name of the config element attribute for the password
*/
static const std::string userPasswordAttrName = "password";
/* =============================================== local function prototypes */ /* =============================================== local function prototypes */
@ -154,7 +169,27 @@ SchedulerDaemon :: configure(const xmlpp::Element & element)
throw std::invalid_argument(eMsg); throw std::invalid_argument(eMsg);
} }
xmlpp::Node::NodeList nodes; xmlpp::Node::NodeList nodes;
const xmlpp::Element * elem;
const xmlpp::Attribute * attribute;
// read in the user data
std::string login;
std::string password;
nodes = element.get_children(userConfigElementName);
if (nodes.size() < 1) {
throw std::invalid_argument("no user element");
}
elem = dynamic_cast<const xmlpp::Element*> (*nodes.begin());
if (!(attribute = elem->get_attribute(userLoginAttrName))) {
throw std::invalid_argument("missing login attribute");
}
login = attribute->get_value();
if (!(attribute = elem->get_attribute(userPasswordAttrName))) {
throw std::invalid_argument("missing password attribute");
}
password = attribute->get_value();
// configure the ConnectionManagerFactory // configure the ConnectionManagerFactory
nodes = nodes =
@ -166,6 +201,16 @@ SchedulerDaemon :: configure(const xmlpp::Element & element)
= ConnectionManagerFactory::getInstance(); = ConnectionManagerFactory::getInstance();
cmf->configure( *((const xmlpp::Element*) *(nodes.begin())) ); cmf->configure( *((const xmlpp::Element*) *(nodes.begin())) );
// configure the AuthenticationClientFactory
nodes =
element.get_children(AuthenticationClientFactory::getConfigElementName());
if (nodes.size() < 1) {
throw std::invalid_argument("no authenticationClientFactory element");
}
Ptr<AuthenticationClientFactory>::Ref acf
= AuthenticationClientFactory::getInstance();
acf->configure( *((const xmlpp::Element*) *(nodes.begin())) );
// configure the StorageClientFactory // configure the StorageClientFactory
nodes = element.get_children(StorageClientFactory::getConfigElementName()); nodes = element.get_children(StorageClientFactory::getConfigElementName());
if (nodes.size() < 1) { if (nodes.size() < 1) {
@ -207,11 +252,20 @@ SchedulerDaemon :: configure(const xmlpp::Element & element)
// do some initialization, using the configured objects // do some initialization, using the configured objects
authentication = acf->getAuthenticationClient();
try {
sessionId = authentication->login(login, password);
} catch (AuthenticationException &e) {
// TODO: mark error
std::cerr << "authentication problem: " << e.what() << std::endl;
}
audioPlayer = apf->getAudioPlayer(); audioPlayer = apf->getAudioPlayer();
Ptr<PlaylistEventContainer>::Ref eventContainer; Ptr<PlaylistEventContainer>::Ref eventContainer;
Ptr<time_duration>::Ref granularity; Ptr<time_duration>::Ref granularity;
eventContainer.reset(new PlaylistEventContainer(scf->getStorageClient(), eventContainer.reset(new PlaylistEventContainer(sessionId,
scf->getStorageClient(),
sf->getSchedule(), sf->getSchedule(),
audioPlayer)); audioPlayer));
// TODO: read granularity from config file // TODO: read granularity from config file
@ -223,6 +277,17 @@ SchedulerDaemon :: configure(const xmlpp::Element & element)
} }
/*------------------------------------------------------------------------------
* Destructor.
*----------------------------------------------------------------------------*/
SchedulerDaemon :: ~SchedulerDaemon(void) throw ()
{
if (authentication.get() && sessionId.get()) {
authentication->logout(sessionId);
}
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Register our XML-RPC methods * Register our XML-RPC methods
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/

View File

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $ Author : $Author: maroy $
Version : $Revision: 1.12 $ Version : $Revision: 1.13 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemon.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemon.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -60,6 +60,8 @@
#include "LiveSupport/Core/Ptr.h" #include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Installable.h" #include "LiveSupport/Core/Installable.h"
#include "LiveSupport/Core/Configurable.h" #include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/SessionId.h"
#include "LiveSupport/Authentication/AuthenticationClientInterface.h"
#include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h" #include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h"
#include "LiveSupport/EventScheduler/EventScheduler.h" #include "LiveSupport/EventScheduler/EventScheduler.h"
#include "AddAudioClipToPlaylistMethod.h" #include "AddAudioClipToPlaylistMethod.h"
@ -90,6 +92,7 @@ namespace Scheduler {
using namespace LiveSupport; using namespace LiveSupport;
using namespace LiveSupport::Core; using namespace LiveSupport::Core;
using namespace LiveSupport::Authentication;
using namespace LiveSupport::PlaylistExecutor; using namespace LiveSupport::PlaylistExecutor;
/* ================================================================ constants */ /* ================================================================ constants */
@ -112,9 +115,13 @@ using namespace LiveSupport::PlaylistExecutor;
* *
* <pre><code> * <pre><code>
* &lt;scheduler&gt; * &lt;scheduler&gt;
* &lt;user login="userid" password="pwd" /&gt;
* &lt;connectionManagerFactory&gt; * &lt;connectionManagerFactory&gt;
* ... * ...
* &lt;/connectionManagerFactory&gt; * &lt;/connectionManagerFactory&gt;
* &lt;authenticationClientFactory&gt;
* ...
* &lt;/authenticationClientFactory&gt;
* &lt;storageClientFactory&gt; * &lt;storageClientFactory&gt;
* ... * ...
* &lt;/storageClientFactory&gt; * &lt;/storageClientFactory&gt;
@ -130,20 +137,30 @@ using namespace LiveSupport::PlaylistExecutor;
* &lt;/scheduler&gt; * &lt;/scheduler&gt;
* </code></pre> * </code></pre>
* *
* The user element holds creditentials for accessing the storage,
* configured below.
*
* For details on the included elements, see the corresponding documentation * For details on the included elements, see the corresponding documentation
* for XmlRpcDaemon, StorageClientFactory, ConnectionManagerFactory * for XmlRpcDaemon, StorageClientFactory, ConnectionManagerFactory
* and ScheduleFactory. * ScheduleFactory and AuthenticationClientFactory.
* *
* The DTD for the above element is the following: * The DTD for the above element is the following:
* *
* <pre><code> * <pre><code>
* &lt;!ELEMENT scheduler (connectionManagerFactory,storageClientFactory, * &lt;!ELEMENT scheduler (user,
* scheduleFactory,playLogFactory,xmlRpcDaemon) &gt; * connectionManagerFactory,
* authenticationClientFactory,
* storageClientFactory,
* scheduleFactory,
* playLogFactory,
* audioPlayer,
* xmlRpcDaemon) &gt;
* </code></pre> * </code></pre>
* *
* @author $Author: fgerlits $ * @author $Author: maroy $
* @version $Revision: 1.12 $ * @version $Revision: 1.13 $
* @see ConnectionManagerFactory * @see ConnectionManagerFactory
* @see AuthenticationClientFactory
* @see StorageClientFactory * @see StorageClientFactory
* @see ScheduleFactory * @see ScheduleFactory
* @see XmlRpcDaemon * @see XmlRpcDaemon
@ -159,6 +176,16 @@ class SchedulerDaemon : public Installable,
*/ */
static Ptr<SchedulerDaemon>::Ref schedulerDaemon; static Ptr<SchedulerDaemon>::Ref schedulerDaemon;
/**
* The authentication client.
*/
Ptr<AuthenticationClientInterface>::Ref authentication;
/**
* The session id for the scheduler user.
*/
Ptr<SessionId>::Ref sessionId;
/** /**
* The event scheduler. * The event scheduler.
*/ */
@ -301,9 +328,7 @@ class SchedulerDaemon : public Installable,
* Virtual destructor. * Virtual destructor.
*/ */
virtual virtual
~SchedulerDaemon(void) throw () ~SchedulerDaemon(void) throw ();
{
}
/** /**
* Return a pointer to the singleton instance of SchedulerDaemon. * Return a pointer to the singleton instance of SchedulerDaemon.