diff --git a/livesupport/doc/model/LiveSupport.zuml b/livesupport/doc/model/LiveSupport.zuml index 50913c609..171ab5e76 100644 Binary files a/livesupport/doc/model/LiveSupport.zuml and b/livesupport/doc/model/LiveSupport.zuml differ diff --git a/livesupport/doc/model/Scheduler/Manageschedule_SequenceDiagram.svg b/livesupport/doc/model/Scheduler/Manageschedule_SequenceDiagram.svg index 93518cf85..5db746afc 100644 --- a/livesupport/doc/model/Scheduler/Manageschedule_SequenceDiagram.svg +++ b/livesupport/doc/model/Scheduler/Manageschedule_SequenceDiagram.svg @@ -7,449 +7,447 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - + - - - - + + - - system - + + - + + + + + playlistEditor + + + : - - Scheduler - - - - - - - - - - - - - - playlistEditor - - - - : - - - Playlist editor - + Playlist editor + + + + + + + + + + + + + + system + + + + : + + + + Scheduler + + + + + + + - - - + + + - + - + : - + authenticated - + := - + authenticate - + ( - + authInfo - + ) - - - + + + - + - + : - - schedulEntries + + scheduleEntries - + := - + displaySchedule - + ( - + from - + , - + to - + ) - - - + + + - + - + : - + playlist - + := - + displayPlaylist - + ( - + playlistId - + ) - - - + + + - + - + : - - removeFromSchedule + + isRemoved - - ( + + := - - scheduleEntry + + removeFromSchedule - - , + + ( - - playlist + + scheduleEntry - + ) - - - + + + - + - + : - + reschedule - + ( - + scheduleEntry - + , - - playlist + + newPlaytime - - , - - - newPlaytime - - - ) + + ) - - - + + + - - + + - - : + + : - - scheduleEntries + + scheduleEntries - - := + + := - - displaySchedule + + displaySchedule - - ( + + ( - - from + + from - - , + + , - - to + + to - - ) + + ) diff --git a/livesupport/doc/model/Scheduler/Systembehaviour.svg b/livesupport/doc/model/Scheduler/Systembehaviour.svg index 7a59ce0d5..5f88cb4b9 100644 --- a/livesupport/doc/model/Scheduler/Systembehaviour.svg +++ b/livesupport/doc/model/Scheduler/Systembehaviour.svg @@ -1,7 +1,7 @@ - + @@ -190,492 +190,468 @@ - + - + - + - + - + - - - - - - - - - - - - - + - + - + + + + + + + + + + + + + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -685,13 +661,13 @@ Scheduler - + - + @@ -758,7 +734,7 @@ : - void + UniqueId + @@ -860,496 +836,472 @@ ( - scheduleEntry + scheduleEntryId - + : - - Schedule entry + + UniqueId - - , + + ) - - playlist + + : - - : - - - Playlist - - - ) - - - : - - - void + + boolean - + + + - reschedule + reschedule - ( + ( - scheduleEntry + scheduleEntryId - + + : + + + UniqueId + + + , + + + playtime + + : - - Schedule entry + + TimeStamp - - , + + ) - - playlist + + : - - : - - - Playlist - - - , - - - playtime - - - : - - - TimeStamp - - - ) - - - : - - - void + + void - + + + - displayPlaylists + displayPlaylists - ( + ( - ) + ) - : + : - Playlist + Playlist - + + + - displayPlayLog + displayPlayLog - ( + ( - ) + ) - : + : - Play log + Play log - + + + - generatePlayReport + generatePlayReport - ( + ( - from + from - : + : - TimeStamp + TimeStamp - , + , - to + to - : + : - TimeStamp + TimeStamp - ) + ) - : + : - Play report + Play report - + + + - createPlaylist + createPlaylist - ( + ( - ) + ) - : + : - Playlist + Playlist - + + + - openPlaylistForEditing + openPlaylistForEditing - ( + ( - playlist + playlist - : + : - Playlist + Playlist - ) + ) - : + : - void + void - + + + - addAudioClipToPlaylist + addAudioClipToPlaylist - ( + ( - playlist + playlist - : + : - Playlist + Playlist - , + , - audioClip + audioClip - : + : - , + , - relativeOffset + relativeOffset - : + : - Time + Time - ) + ) - : + : - void + void - + + + - displayAudioClips + displayAudioClips - ( + ( - ) + ) - : + : - + + + - displayAudioClip + displayAudioClip - ( + ( - audioClipId + audioClipId - : + : - ) + ) - : + : - + + + - removeAudioClipFromPlaylist + removeAudioClipFromPlaylist - ( + ( - playlist + playlist - : + : - Playlist + Playlist - , + , - audioClip + audioClip - : + : - ) + ) - : + : - void + void - + + + - updateFadeInOut + updateFadeInOut - ( + ( - playlist + playlist - : + : - Playlist + Playlist - , + , - audioClip + audioClip - : + : - ) + ) - : + : - void + void - + + + - validatePlaylist + validatePlaylist - ( + ( - playlist + playlist - : + : - Playlist + Playlist - ) + ) - : + : - boolean + boolean - + + + - savePlaylist + savePlaylist - ( + ( - playlist + playlist - : + : - Playlist + Playlist - ) + ) - : + : - void + void - + + + - revertEditedPlaylist + revertEditedPlaylist - ( + ( - playlist + playlist - : + : - Playlist + Playlist - ) + ) - : + : - void + void - + + + - start + start - ( + ( - ) + ) - : + : - void + void - + + + - isRunning + isRunning - ( + ( - ) + ) - : + : - boolean + boolean - + + + - stop + stop - ( + ( - ) + ) - : + : - void + void diff --git a/livesupport/doc/model/Scheduler/index.html b/livesupport/doc/model/Scheduler/index.html index 503bf61f3..6979fe90a 100644 --- a/livesupport/doc/model/Scheduler/index.html +++ b/livesupport/doc/model/Scheduler/index.html @@ -14,8 +14,9 @@ Development Loan Fund, under the GNU GPL.
  • Author: $Author: maroy $
  • -
  • Version: $Revision: 1.1 $
  • -
  • Location: $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/doc/model/Scheduler/index.html,v $
  • +
  • Version: $Revision: 1.2 $
  • +
  • Location: $Source: +/home/cvs/livesupport/doc/model/Scheduler/index.html,v $

Scope

This document contains the specification of the LiveSupport Scheduler @@ -42,7 +43,7 @@ playlists on a local audio interface. Specific goals include:

System functions

The main system functions are described below. There are three categories for these functions:
- +
function category
@@ -73,7 +74,7 @@ that it is performed


- +
ref#
@@ -218,7 +219,7 @@ reasons

System attributes

Generic attributes

- +
ref#
@@ -286,7 +287,7 @@ which focuses only on audio aspects of SMIL.

Attributes related to system functions

- +
ref#
@@ -385,9 +386,9 @@ This section lists generic (essential) uses cases, that do not contain architecture-specific considerations.

+ data="EssentialUseCases.svg" height="800" width="700">

UC-1 Upload playlist

- +
@@ -420,7 +421,7 @@ architecture-specific considerations.
ref#

Typical course of events

- +
actor action
@@ -499,7 +500,7 @@ notified and the use case ends.

UC-2 Manage schedule

- +

Typical course of events

-
ref#
@@ -544,7 +545,7 @@ decides to, he might remove or re-schedule some of these playlists.
+
actor action
@@ -655,7 +656,7 @@ again

UC-3 Manage playlists

- +

Typical course of events

-
ref#
@@ -698,7 +699,7 @@ playlists. If he decides so, he might delete some of these playlists.
+
actor action
@@ -781,7 +782,7 @@ user is notified, and the list of playlists is displayed to the user.

UC-4 Retrieve remote files

- +
@@ -830,7 +831,7 @@ Note that this use case is somewhat reversed, as it is initiated by the system (not an actor), and the main tasks are done by an external actor (the Media archive).

Typical course of events

-
ref#
+
actor action
@@ -958,7 +959,7 @@ audio clip. the system is notified and the use case ends.

UC-5 Review play log

- +
@@ -995,7 +996,7 @@ reasons.
ref#

Typical course of events

- +
actor action
@@ -1074,7 +1075,7 @@ authenticated. the user is notified and the use case ends.

UC-6 Create playlist

- +
@@ -1116,7 +1117,7 @@ on the system.
ref#

Typical course of events

- +
actor action
@@ -1196,7 +1197,7 @@ authenticated. the user is notified and the use case ends.

UC-7 Edit playlist

- +
@@ -1237,7 +1238,7 @@ professionals to edit the playlsits on the system.
ref#

Typical course of events

- +
actor action
@@ -1391,7 +1392,7 @@ shown.

UC-8 Start/stop scheduler

- +
@@ -1432,7 +1433,7 @@ deamon with the same script.
ref#

Typical course of events

- +
actor action
@@ -1500,11 +1501,11 @@ The following figure displays the semantic concepts identified for the Scheduler daemon, and the main associations between the concepts.

+ data="Concepts.svg" height="1000" width="950">

Concepts


- +
concept
@@ -1643,7 +1644,7 @@ stopping the scheduler daemon.

Associations


- +
source
@@ -1898,43 +1899,43 @@ is discussed in this section.
System diagrams are presented for each use case below.

UC-1 Upload playlists

+ data="Uploadplaylists_SequenceDiagram.svg" height="200" width="550">

UC-2 Manage schedule

+ data="Manageschedule_SequenceDiagram.svg" height="350" width="650">

UC-3 Manage playlists

+ data="Manageplaylists_SequenceDiagram.svg" height="300" width="650">

UC-4 Retrieve remote files

+ data="Retrieveremotefiles_SequenceDiagram.svg" height="300" width="750">

UC-5 Review play log

+ data="Reviewplaylog_SequenceDiagram.svg" height="250" width="650">

UC-6 Create playlist

+ data="Createplaylist_SequenceDiagram.svg" height="250" width="650">

UC-7 Edit playlist
+ data="Editplaylist_SequenceDiagram.svg" height="500" width="800">

UC-8 Start/stop scheduler

+ data="Startstopscheduler_SequenceDiagram.svg" height="200" width="600">

System objects

The following figures shows the system objects and their functions, as derived from the system sequence diagrams.
+ data="Systembehaviour.svg" height="450" width="550">

Contracts

For all operations exposed in the system sequence diagrams, the following contracts are defined.
@@ -1942,7 +1943,7 @@ following contracts are defined.
See Authentication : authenticate

Contract for Scheduler : uploadPlaylist

- +
@@ -1990,7 +1991,8 @@ an error
- @@ -2051,7 +2053,7 @@ supplied schedule
Name
@@ -1950,7 +1951,7 @@ See Authentication : authenticate
uploadPlaylist
(playlist : Playlist,
playtime: Schedule)
-: void
+: UniqueId
Output
none
+
the unique id of the +ScheduleEntry created with this upload

Contract for Scheduler : displaySchedule

- +
Name
@@ -2125,7 +2127,7 @@ the specified time period.

Contract for Scheduler : displayPlaylist

- +
Name
@@ -2198,7 +2200,7 @@ for the specified playlistId, indicate as an error.

Contract for Scheduler : deletePlaylist

- +
Name
@@ -2298,15 +2300,14 @@ error.

Contract for Scheduler : removeFromSchedule

- +
@@ -2337,15 +2338,16 @@ playlist from a schedule entry
- - @@ -2370,6 +2372,15 @@ is removed.
+ + + + + @@ -2383,16 +2394,15 @@ is removed.

Contract for Scheduler : reschedule

-
Name
removeFromSchedule
-(scheduleEntry : Schedule entry,
-playlist : Playlist)
-: void
+(scheduleEntryId : UniqueId)
+: bool
Exceptions
If the specified -scheduleEntry does not exist, indicate as an error.
-If the specified playlist does not exist, indicate as an error.
+
If no ScheduleEntry by +the specified +scheduleEntryId exist, indicate as an error.
Output
none
+
true if the specified +entry was removed, false if it did not exist.
association broken

+
The ScheduleEntry specified by the +scheduleEntryId is deleted
+
instance deletion
+

+
@@ -2423,9 +2433,9 @@ playlist is scheduled to play.
- @@ -2433,7 +2443,7 @@ an error.
- @@ -2470,7 +2480,7 @@ to the supplied playtime.
Name
reschedule
-(scheduleEntry : Schedule entry,
-playlist : Playlist,
+(scheduleEntryId : UniqueId,
playtime : TimeStamp)
-: void
+: bool
Exceptions
If the specified -scheduleEntry does not exist, indicate as an error.
-If the specified playlist does not exist, indicate as an error.
+
If no ScheduleEntry by +the specified +scheduleEntryId exist, indicate as an error.
If the new playtime conflicts with other schedule entries, indicate as an error.
Output
none
+
false on errors

Contract for Scheduler : displayPlaylists

- +
Name
@@ -2543,7 +2553,7 @@ in the Playlist store.

Contract for Scheduler : displayPlayLog

- +
Name
@@ -2617,7 +2627,7 @@ contained in the Play log.

Contract for Scheduler : generatePlayReport

- +
Name
@@ -2692,7 +2702,7 @@ Audio clips played in the specified time period.

Contract for Scheduler : createPlaylist

- +
Name
@@ -2790,7 +2800,7 @@ for the playlist

Contract for Scheduler : openPlaylistForEditing

- +
Name
@@ -2886,7 +2896,7 @@ for the playlist

Contract for Scheduler : addAudioClipToPlaylist

- +
Name
@@ -2974,7 +2984,7 @@ the playlist with the audio clip, with the specified relativeOffset

Contract for Scheduler : displayAudioClips

- +
Name
@@ -3049,7 +3059,7 @@ the Scheduler

Contract for Scheduler : displayAudioClip

- +
Name
@@ -3125,7 +3135,7 @@ by the audioClipId

Contract for Scheduler : removeAudioClipFromPlaylist

- +
Name
@@ -3212,7 +3222,7 @@ with the Playlist is removed, with the related FadeInfo instances

Contract for Scheduler : updateFadeInFadeOut

- +
Name
@@ -3298,7 +3308,7 @@ audio clip in the playlist are updated

Contract for Scheduler : validatePlaylist

- +
Name
@@ -3373,7 +3383,7 @@ for being complete (not containing silence) and other sanity criteria.

Contract for Scheduler : savePlaylist

- +
Name
@@ -3466,7 +3476,7 @@ been used for reverting is deleted (see revertEditedPlaylist)

Contract for Scheduler : revertEditedPlaylist

- +
Name
@@ -3561,7 +3571,7 @@ for the playlist

Contract for Scheduler : start

- +
Name
@@ -3654,7 +3664,7 @@ deamon to run

Contract for Scheduler : isRunning

- +
Name
@@ -3730,7 +3740,7 @@ running, false otherwise

Contract for Scheduler : stop

- +
Name
@@ -3814,7 +3824,7 @@ currently running

Contract for Media archive : authenticate

TODO: move to Media archive spec
- +
Name
@@ -3887,7 +3897,7 @@ authentication is recognized, false otherwise

Contract for Media archive : retrieveAudioClip

TODO: move to Media archive spec
- +
Name
@@ -3977,7 +3987,7 @@ contents of the retrieved audio clip

Contract for Local storage : authenticate

TODO: move to Local storage spec
- +
Name
@@ -4050,7 +4060,7 @@ authentication is recognized, false otherwise

Contract for Local storage : existsAudioClip

TODO: move to Local storage spec
- +
Name
@@ -4123,7 +4133,7 @@ with the provided id exists, false otherwise

Contract for Local storage : storeAudioClip

TODO: move to Local storage spec
- +
Name
diff --git a/livesupport/products/scheduler/etc/Makefile.in b/livesupport/products/scheduler/etc/Makefile.in index 31e5a8980..e9f5ef903 100644 --- a/livesupport/products/scheduler/etc/Makefile.in +++ b/livesupport/products/scheduler/etc/Makefile.in @@ -21,7 +21,7 @@ # # # Author : $Author: maroy $ -# Version : $Revision: 1.4 $ +# Version : $Revision: 1.5 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/etc/Makefile.in,v $ # # @configure_input@ @@ -112,6 +112,7 @@ SCHEDULER_OBJS = ${TMP_DIR}/SignalDispatcher.o \ ${TMP_DIR}/UploadPlaylistMethod.o \ ${TMP_DIR}/DisplayScheduleMethod.o \ ${TMP_DIR}/DisplayPlaylistMethod.o \ + ${TMP_DIR}/RemoveFromScheduleMethod.o \ ${TMP_DIR}/ScheduleFactory.o \ ${TMP_DIR}/PostgresqlSchedule.o @@ -126,9 +127,11 @@ TEST_RUNNER_OBJS = ${SCHEDULER_OBJS} \ ${TMP_DIR}/SchedulerDaemonUploadTest.o \ ${TMP_DIR}/SchedulerDaemonDisplayScheduleTest.o \ ${TMP_DIR}/SchedulerDaemonDisplayPlaylistTest.o \ + ${TMP_DIR}/SchedulerDaemonRemoveFromScheduleTest.o \ ${TMP_DIR}/UploadPlaylistMethodTest.o \ ${TMP_DIR}/DisplayScheduleMethodTest.o \ ${TMP_DIR}/DisplayPlaylistMethodTest.o \ + ${TMP_DIR}/RemoveFromScheduleMethodTest.o \ ${TMP_DIR}/PostgresqlScheduleTest.o \ ${TMP_DIR}/TestRunner.o TEST_RUNNER_LIBS = ${SCHEDULER_EXE_LIBS} -lcppunit -ldl diff --git a/livesupport/products/scheduler/src/PostgresqlSchedule.cxx b/livesupport/products/scheduler/src/PostgresqlSchedule.cxx index 684988679..81e30584d 100644 --- a/livesupport/products/scheduler/src/PostgresqlSchedule.cxx +++ b/livesupport/products/scheduler/src/PostgresqlSchedule.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlSchedule.cxx,v $ ------------------------------------------------------------------------------*/ @@ -109,6 +109,21 @@ const std::string PostgresqlSchedule::getScheduleEntriesStmt = "(? <= starts) AND (starts < ?) " "ORDER BY starts"; +/*------------------------------------------------------------------------------ + * The SQL statement for querying if a schedule entry exists. + * Expects a single argument, the id of the schedule to check. + * Returns 1 if the entry exists, 0 otherwise. + *----------------------------------------------------------------------------*/ +const std::string PostgresqlSchedule::scheduleEntryExistsStmt = + "SELECT COUNT(*) FROM schedule WHERE id = ?"; + +/*------------------------------------------------------------------------------ + * The SQL statement for removing a schedule. + * Expects a single argument, the id of the schedule to remove. + *----------------------------------------------------------------------------*/ +const std::string PostgresqlSchedule::removeFromScheduleStmt = + "DELETE FROM schedule WHERE id = ?"; + /* =============================================== local function prototypes */ @@ -219,7 +234,7 @@ PostgresqlSchedule :: isTimeframeAvailable( /*------------------------------------------------------------------------------ * Schedule a playlist *----------------------------------------------------------------------------*/ -void +Ptr::Ref PostgresqlSchedule :: schedulePlaylist( Ptr::Ref playlist, Ptr::Ref playtime) @@ -227,11 +242,11 @@ PostgresqlSchedule :: schedulePlaylist( { Ptr::Ref conn; bool result = false; + Ptr::Ref id; try { conn = cm->getConnection(); Ptr::Ref timestamp; - Ptr::Ref id; Ptr::Ref ends; Ptr::Ref pstmt(conn->prepareStatement( schedulePlaylistStmt)); @@ -260,6 +275,8 @@ PostgresqlSchedule :: schedulePlaylist( if (!result) { throw std::invalid_argument("couldn't insert into database"); } + + return id; } @@ -316,3 +333,68 @@ PostgresqlSchedule :: getScheduleEntries( return result; } + +/*------------------------------------------------------------------------------ + * Tell if a schedule entry exists. + *----------------------------------------------------------------------------*/ +bool +PostgresqlSchedule :: scheduleEntryExists( + Ptr::Ref entryId) + throw () +{ + Ptr::Ref conn; + bool result = false; + + try { + conn = cm->getConnection(); + Ptr::Ref pstmt(conn->prepareStatement( + scheduleEntryExistsStmt)); + pstmt->setInt(1, entryId->getId()); + + Ptr::Ref rs(pstmt->executeQuery()); + result = (rs->next()) ? (rs->getInt(1) == 1) : false; + + cm->returnConnection(conn); + } catch (std::exception &e) { + if (conn) { + cm->returnConnection(conn); + } + throw std::invalid_argument(e.what()); + } + + return result; +} + + +/*------------------------------------------------------------------------------ + * Remove a schedule entry from a schedule + *----------------------------------------------------------------------------*/ +void +PostgresqlSchedule :: removeFromSchedule( + Ptr::Ref entryId) + throw (std::invalid_argument) +{ + Ptr::Ref conn; + bool result = false; + + try { + conn = cm->getConnection(); + Ptr::Ref pstmt(conn->prepareStatement( + removeFromScheduleStmt)); + pstmt->setInt(1, entryId->getId()); + + result = pstmt->executeUpdate() == 1; + + cm->returnConnection(conn); + } catch (std::exception &e) { + if (conn) { + cm->returnConnection(conn); + } + throw std::invalid_argument(e.what()); + } + + if (!result) { + throw std::invalid_argument("specified schedule entry does not exist"); + } +} + diff --git a/livesupport/products/scheduler/src/PostgresqlSchedule.h b/livesupport/products/scheduler/src/PostgresqlSchedule.h index 579c9e7df..d1add56cb 100644 --- a/livesupport/products/scheduler/src/PostgresqlSchedule.h +++ b/livesupport/products/scheduler/src/PostgresqlSchedule.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlSchedule.h,v $ ------------------------------------------------------------------------------*/ @@ -81,7 +81,7 @@ using namespace LiveSupport::Core; * * * @author $Author: maroy $ - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ class PostgresqlSchedule : public Configurable, public ScheduleInterface @@ -117,6 +117,16 @@ class PostgresqlSchedule : public Configurable, */ static const std::string getScheduleEntriesStmt; + /** + * The SQL statement for telling if a schedule entry exists. + */ + static const std::string scheduleEntryExistsStmt; + + /** + * The SQL statement for removing a schedule entry. + */ + static const std::string removeFromScheduleStmt; + /** * The database connection manager to use for connecting the * database. @@ -216,10 +226,11 @@ class PostgresqlSchedule : public Configurable, * * @param playlist the playlist to schedule. * @param playtime the time to schedule the playlist for. + * @return the id of the newly created playlist. * @exception std::invalid_argument if the there is something * already scheduled for the duration of the playlist. */ - virtual void + virtual Ptr::Ref schedulePlaylist(Ptr::Ref playlist, Ptr::Ref playtime) throw (std::invalid_argument); @@ -237,6 +248,28 @@ class PostgresqlSchedule : public Configurable, getScheduleEntries(Ptr::Ref fromTime, Ptr::Ref toTime) throw (); + + /** + * Tell if a schedule entry exists by the give name. + * + * @param entryId the id of the schedule entry to check for. + * @return true if the schedule entry exists in the Schedule, + * false otherwise. + */ + virtual bool + scheduleEntryExists(Ptr::Ref entryId) + throw (); + + /** + * Remove a schedule entry from the schedule. + * + * @param entryId the id of the schedule to remove. + * @exception std::invalid_argument if no schedule with the specified + * id exists. + */ + virtual void + removeFromSchedule(Ptr::Ref entryId) + throw (std::invalid_argument); }; diff --git a/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx b/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx index dc637f589..8df364bdf 100644 --- a/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx +++ b/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlScheduleTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -299,3 +299,97 @@ PostgresqlScheduleTest :: getScheduleEntriesTest(void) } +/*------------------------------------------------------------------------------ + * See if scheduleEntryExists() returns correct results + *----------------------------------------------------------------------------*/ +void +PostgresqlScheduleTest :: scheduleEntryExistsTest(void) + throw (CPPUNIT_NS::Exception) +{ + // create a 1 hour long playlist + Ptr::Ref playlistId = UniqueId::generateId(); + Ptr::Ref playlength(new time_duration(1, 0, 0)); + Ptr::Ref playlist(new Playlist(playlistId, playlength)); + + Ptr::Ref from; + Ptr::Ref to; + + Ptr::Ref entryId1; + Ptr::Ref entryId2; + + // at the very first, check for a nonexistent entry + entryId1.reset(new UniqueId(9999)); + CPPUNIT_ASSERT(!schedule->scheduleEntryExists(entryId1)); + + try { + // schedule our playlist for 2004-07-23, 10 o'clock + from.reset(new ptime(time_from_string("2004-07-23 10:00:00"))); + entryId1 = schedule->schedulePlaylist(playlist, from); + + // schedule our playlist for 2004-07-23, 12 o'clock + from.reset(new ptime(time_from_string("2004-07-23 12:00:00"))); + entryId2 = schedule->schedulePlaylist(playlist, from); + + // now let's check if our entries exist + CPPUNIT_ASSERT(schedule->scheduleEntryExists(entryId1)); + CPPUNIT_ASSERT(schedule->scheduleEntryExists(entryId2)); + + } catch (std::invalid_argument &e) { + CPPUNIT_FAIL(e.what()); + } +} + + +/*------------------------------------------------------------------------------ + * See if removeFromSchedule() really removes + *----------------------------------------------------------------------------*/ +void +PostgresqlScheduleTest :: removeFromScheduleTest(void) + throw (CPPUNIT_NS::Exception) +{ + // create a 1 hour long playlist + Ptr::Ref playlistId = UniqueId::generateId(); + Ptr::Ref playlength(new time_duration(1, 0, 0)); + Ptr::Ref playlist(new Playlist(playlistId, playlength)); + + Ptr::Ref from; + Ptr::Ref to; + + Ptr::Ref entryId1; + Ptr::Ref entryId2; + + // at the very first, try to remove something not scheduled + bool gotException = false; + try { + entryId1.reset(new UniqueId(9999)); + schedule->removeFromSchedule(entryId1); + } catch (std::invalid_argument &e) { + gotException = true; + } + CPPUNIT_ASSERT(gotException); + + try { + // schedule our playlist for 2004-07-23, 10 o'clock + from.reset(new ptime(time_from_string("2004-07-23 10:00:00"))); + entryId1 = schedule->schedulePlaylist(playlist, from); + + // schedule our playlist for 2004-07-23, 12 o'clock + from.reset(new ptime(time_from_string("2004-07-23 12:00:00"))); + entryId2 = schedule->schedulePlaylist(playlist, from); + + // now let's remove one of them, and see that it's not there anymore + CPPUNIT_ASSERT(schedule->scheduleEntryExists(entryId1)); + schedule->removeFromSchedule(entryId1); + CPPUNIT_ASSERT(!schedule->scheduleEntryExists(entryId1)); + + // now let's remove the other, and see that it's not there anymore + CPPUNIT_ASSERT(schedule->scheduleEntryExists(entryId2)); + schedule->removeFromSchedule(entryId2); + CPPUNIT_ASSERT(!schedule->scheduleEntryExists(entryId2)); + + } catch (std::invalid_argument &e) { + CPPUNIT_FAIL(e.what()); + } +} + + diff --git a/livesupport/products/scheduler/src/PostgresqlScheduleTest.h b/livesupport/products/scheduler/src/PostgresqlScheduleTest.h index a2401e2d2..8ff216409 100644 --- a/livesupport/products/scheduler/src/PostgresqlScheduleTest.h +++ b/livesupport/products/scheduler/src/PostgresqlScheduleTest.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/PostgresqlScheduleTest.h,v $ ------------------------------------------------------------------------------*/ @@ -64,7 +64,7 @@ using namespace LiveSupport::Core; * Unit test for the PostgresqlSchedule class. * * @author $Author: maroy $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * @see PostgresqlSchedule */ class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture @@ -74,6 +74,8 @@ class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(simpleScheduleTest); CPPUNIT_TEST(scheduleAndQueryTest); CPPUNIT_TEST(getScheduleEntriesTest); + CPPUNIT_TEST(scheduleEntryExistsTest); + CPPUNIT_TEST(removeFromScheduleTest); CPPUNIT_TEST_SUITE_END(); private: @@ -123,6 +125,22 @@ class PostgresqlScheduleTest : public CPPUNIT_NS::TestFixture void getScheduleEntriesTest(void) throw (CPPUNIT_NS::Exception); + /** + * Schedule some playlists, then check if they exist. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + scheduleEntryExistsTest(void) throw (CPPUNIT_NS::Exception); + + /** + * Schedule some playlists, then remove them. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + removeFromScheduleTest(void) throw (CPPUNIT_NS::Exception); + public: /** diff --git a/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx b/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx new file mode 100644 index 000000000..e87e6a7c6 --- /dev/null +++ b/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx @@ -0,0 +1,141 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: maroy $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethod.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#ifdef HAVE_TIME_H +#include +#else +#error need time.h +#endif + + +#include + +#include "ScheduleInterface.h" +#include "ScheduleFactory.h" +#include "RemoveFromScheduleMethod.h" + + +using namespace LiveSupport; +using namespace LiveSupport::Core; + +using namespace LiveSupport::Scheduler; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * The name of this XML-RPC method. + *----------------------------------------------------------------------------*/ +const std::string RemoveFromScheduleMethod::methodName = "removeFromSchedule"; + +/*------------------------------------------------------------------------------ + * The name of the playlist id member in the XML-RPC parameter + * structure. + *----------------------------------------------------------------------------*/ +const std::string RemoveFromScheduleMethod::scheduleEntryIdName = + "scheduleEntryId"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Construct the method and register it right away. + *----------------------------------------------------------------------------*/ +RemoveFromScheduleMethod :: RemoveFromScheduleMethod ( + Ptr::Ref xmlRpcServer) throw() + : XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get()) +{ +} + + +/*------------------------------------------------------------------------------ + * Extract the UniqueId from an XML-RPC function call parameter + *----------------------------------------------------------------------------*/ +Ptr::Ref +RemoveFromScheduleMethod :: extractScheduleEntryId( + XmlRpc::XmlRpcValue & xmlRpcValue) + throw (std::invalid_argument) +{ + if (!xmlRpcValue.hasMember(scheduleEntryIdName)) { + throw std::invalid_argument("no playlist id in parameter structure"); + } + + Ptr::Ref id(new UniqueId((int) xmlRpcValue[scheduleEntryIdName])); + return id; +} + + +/*------------------------------------------------------------------------------ + * Execute the remove from schedule XML-RPC function call. + *----------------------------------------------------------------------------*/ +void +RemoveFromScheduleMethod :: execute(XmlRpc::XmlRpcValue & parameters, + XmlRpc::XmlRpcValue & returnValue) + throw () +{ + try { + if (!parameters.valid()) { + // TODO: mark error + returnValue = XmlRpc::XmlRpcValue(false); + return; + } + + Ptr::Ref entryId = extractScheduleEntryId(parameters[0]); + + Ptr::Ref sf = ScheduleFactory::getInstance(); + Ptr::Ref schedule = sf->getSchedule(); + + if (!schedule->scheduleEntryExists(entryId)) { + // TODO: mark error; + returnValue = XmlRpc::XmlRpcValue(false); + return; + } + + schedule->removeFromSchedule(entryId); + + } catch (std::invalid_argument &e) { + // TODO: mark error + returnValue = XmlRpc::XmlRpcValue(false); + return; + } + + returnValue = XmlRpc::XmlRpcValue(true); +} + diff --git a/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h b/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h new file mode 100644 index 000000000..81b80ed41 --- /dev/null +++ b/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h @@ -0,0 +1,148 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: maroy $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethod.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef RemoveFromScheduleMethod_h +#define RemoveFromScheduleMethod_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include +#include +#include +#include +#include + +#include "LiveSupport/Core/Ptr.h" +#include "LiveSupport/Core/UniqueId.h" + + +namespace LiveSupport { +namespace Scheduler { + +using namespace LiveSupport; +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * An XML-RPC method object to remove a scheduled entry. + * + * The name of the method when called through XML-RPC is "removeFromSchedule". + * The expected parameter is an XML-RPC structure, with the following + * members: + *
    + *
  • scheduleEntryId - int - the id of the scheduled entry to remove
  • + *
+ * + * @author $Author: maroy $ + * @version $Revision: 1.1 $ + */ +class RemoveFromScheduleMethod : public XmlRpc::XmlRpcServerMethod +{ + private: + /** + * The name of this method, as it will be registered into the + * XML-RPC server. + */ + static const std::string methodName; + + /** + * The name of the entry id member in the XML-RPC parameter + * structure. + */ + static const std::string scheduleEntryIdName; + + /** + * Extract the schedule entry id from the XML-RPC parameters. + * + * @param xmlRpcValue the XML-RPC parameter to extract from. + * @return a UniqueId that was found in the XML-RPC parameter. + * @exception std::invalid_argument if there was no UniqueId + * in xmlRpcValue + */ + Ptr::Ref + extractScheduleEntryId(XmlRpc::XmlRpcValue & xmlRpcValue) + throw (std::invalid_argument); + + + public: + /** + * A default constructor, for testing purposes. + */ + RemoveFromScheduleMethod(void) throw () + : XmlRpc::XmlRpcServerMethod(methodName) + { + } + + /** + * Constuctor that registers the method with the server right away. + * + * @param xmlRpcServer the XML-RPC server to register with. + */ + RemoveFromScheduleMethod( + Ptr::Ref xmlRpcServer) + throw (); + + /** + * Execute the remove from schedule command on the Scheduler daemon. + * + * @param parameters XML-RPC function call parameters + * @param returnValue the return value of the call (out parameter) + */ + void + execute( XmlRpc::XmlRpcValue & parameters, + XmlRpc::XmlRpcValue & returnValue) throw (); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Scheduler +} // namespace LiveSupport + +#endif // RemoveFromScheduleMethod_h + diff --git a/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx b/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx new file mode 100644 index 000000000..6fec577db --- /dev/null +++ b/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx @@ -0,0 +1,185 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: maroy $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#if HAVE_UNISTD_H +#include +#else +#error "Need unistd.h" +#endif + + +#include +#include +#include + +#include "ScheduleFactory.h" +#include "UploadPlaylistMethod.h" +#include "RemoveFromScheduleMethod.h" +#include "RemoveFromScheduleMethodTest.h" + + +using namespace LiveSupport::Scheduler; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +CPPUNIT_TEST_SUITE_REGISTRATION(RemoveFromScheduleMethodTest); + +/** + * The name of the configuration file for the schedule factory. + */ +const std::string RemoveFromScheduleMethodTest::scheduleConfig = + "etc/scheduleFactory.xml"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Configure a Configurable with an XML file. + *----------------------------------------------------------------------------*/ +void +RemoveFromScheduleMethodTest :: configure( + Ptr::Ref configurable, + const std::string fileName) + throw (std::invalid_argument, + xmlpp::exception) +{ + Ptr::Ref parser(new xmlpp::DomParser(fileName, true)); + const xmlpp::Document * document = parser->get_document(); + const xmlpp::Element * root = document->get_root_node(); + + configurable->configure(*root); +} + + +/*------------------------------------------------------------------------------ + * Set up the test environment + *----------------------------------------------------------------------------*/ +void +RemoveFromScheduleMethodTest :: setUp(void) throw () +{ + try { + Ptr::Ref sf = ScheduleFactory::getInstance(); + configure(sf, scheduleConfig); + + schedule = sf->getSchedule(); + schedule->install(); + } catch (std::invalid_argument &e) { + CPPUNIT_FAIL("semantic error in configuration file"); + } catch (xmlpp::exception &e) { + CPPUNIT_FAIL("error parsing configuration file"); + } catch (std::exception &e) { + CPPUNIT_FAIL(e.what()); + } +} + + +/*------------------------------------------------------------------------------ + * Clean up the test environment + *----------------------------------------------------------------------------*/ +void +RemoveFromScheduleMethodTest :: tearDown(void) throw () +{ + schedule->uninstall(); +} + + +/*------------------------------------------------------------------------------ + * Just a very simple smoke test + *----------------------------------------------------------------------------*/ +void +RemoveFromScheduleMethodTest :: firstTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::Ref uploadMethod( + new UploadPlaylistMethod()); + Ptr::Ref removeMethod( + new RemoveFromScheduleMethod()); + XmlRpc::XmlRpcValue rootParameter; + XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue result; + struct tm time; + Ptr::Ref entryId; + + // first schedule (upload) a playlist) + parameters["playlistId"] = 1; + time.tm_year = 2001; + time.tm_mon = 11; + time.tm_mday = 12; + time.tm_hour = 10; + time.tm_min = 0; + time.tm_sec = 0; + parameters["playtime"] = &time; + rootParameter[0] = parameters; + + uploadMethod->execute(rootParameter, result); + entryId.reset(new UniqueId((int) result)); + + parameters.clear(); + result.clear(); + parameters["scheduleEntryId"] = (int) entryId->getId(); + rootParameter[0] = parameters; + + removeMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(result); +} + + +/*------------------------------------------------------------------------------ + * A test to try to remove a not-scheduled entry + *----------------------------------------------------------------------------*/ +void +RemoveFromScheduleMethodTest :: negativeTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::Ref removeMethod( + new RemoveFromScheduleMethod()); + XmlRpc::XmlRpcValue rootParameter; + XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue result; + Ptr::Ref entryId(new UniqueId(9999)); + + parameters["scheduleEntryId"] = (int) entryId->getId(); + rootParameter[0] = parameters; + + removeMethod->execute(rootParameter, result); + CPPUNIT_ASSERT(!result); +} + diff --git a/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.h b/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.h new file mode 100644 index 000000000..e56668c54 --- /dev/null +++ b/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.h @@ -0,0 +1,143 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: maroy $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RemoveFromScheduleMethodTest.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef RemoveFromScheduleMethodTest_h +#define RemoveFromScheduleMethodTest_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include + + +namespace LiveSupport { +namespace Scheduler { + +using namespace LiveSupport; +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * Unit test for the RemoveFromScheduleMethod class. + * + * @author $Author: maroy $ + * @version $Revision: 1.1 $ + * @see RemoveFromScheduleMethod + */ +class RemoveFromScheduleMethodTest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(RemoveFromScheduleMethodTest); + CPPUNIT_TEST(firstTest); + CPPUNIT_TEST(negativeTest); + CPPUNIT_TEST_SUITE_END(); + + /** + * The name of the configuration file for the schedule factory. + */ + static const std::string scheduleConfig; + + /** + * The schedule used during the test. + */ + Ptr::Ref schedule; + + /** + * Configure a configurable with an XML file. + * + * @param configurable configure this + * @param fileName the name of the XML file to configure with. + * @exception std::invalid_argument on configuration errors. + * @exception xmlpp::exception on XML parsing errors. + */ + void + configure(Ptr::Ref configurable, + std::string fileName) + throw (std::invalid_argument, + xmlpp::exception); + + + protected: + + /** + * A simple test. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + firstTest(void) throw (CPPUNIT_NS::Exception); + + /** + * A simple test for trying to remove a non-existent entry. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + negativeTest(void) throw (CPPUNIT_NS::Exception); + + public: + + /** + * Set up the environment for the test case. + */ + void + setUp(void) throw (); + + /** + * Clean up the environment after the test case. + */ + void + tearDown(void) throw (); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Scheduler +} // namespace LiveSupport + +#endif // RemoveFromScheduleMethodTest_h + diff --git a/livesupport/products/scheduler/src/ScheduleInterface.h b/livesupport/products/scheduler/src/ScheduleInterface.h index a9af21ad3..cc8b08be2 100644 --- a/livesupport/products/scheduler/src/ScheduleInterface.h +++ b/livesupport/products/scheduler/src/ScheduleInterface.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/ScheduleInterface.h,v $ ------------------------------------------------------------------------------*/ @@ -70,7 +70,7 @@ using namespace LiveSupport::Core; * The generic interface for the component scheduling events. * * @author $Author: maroy $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ class ScheduleInterface : virtual public Installable { @@ -92,10 +92,11 @@ class ScheduleInterface : virtual public Installable * * @param playlist the playlist to schedule. * @param playtime the time to schedule the playlist for. + * @return the id of the newly created playlist. * @exception std::invalid_argument if the there is something * already scheduled for the duration of the playlist. */ - virtual void + virtual Ptr::Ref schedulePlaylist(Ptr::Ref playlist, Ptr::Ref playtime) throw (std::invalid_argument) @@ -115,6 +116,30 @@ class ScheduleInterface : virtual public Installable Ptr::Ref toTime) throw () = 0; + + /** + * Tell if a schedule entry exists by the give name. + * + * @param entryId the id of the schedule entry to check for. + * @return true if the schedule entry exists in the Schedule, + * false otherwise. + */ + virtual bool + scheduleEntryExists(Ptr::Ref entryId) + throw () + = 0; + + /** + * Remove a schedule entry from the schedule. + * + * @param entryId the id of the schedule to remove. + * @exception std::invalid_argument if no schedule with the specified + * id exists. + */ + virtual void + removeFromSchedule(Ptr::Ref entryId) + throw (std::invalid_argument) + = 0; }; diff --git a/livesupport/products/scheduler/src/SchedulerDaemon.cxx b/livesupport/products/scheduler/src/SchedulerDaemon.cxx index c6cd96cc7..636e35f19 100644 --- a/livesupport/products/scheduler/src/SchedulerDaemon.cxx +++ b/livesupport/products/scheduler/src/SchedulerDaemon.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemon.cxx,v $ ------------------------------------------------------------------------------*/ @@ -165,6 +165,7 @@ SchedulerDaemon :: registerXmlRpcFunctions( xmlRpcServer->addMethod(uploadPlaylistMethod.get()); xmlRpcServer->addMethod(displayScheduleMethod.get()); xmlRpcServer->addMethod(displayPlaylistMethod.get()); + xmlRpcServer->addMethod(removeFromScheduleMethod.get()); } diff --git a/livesupport/products/scheduler/src/SchedulerDaemon.h b/livesupport/products/scheduler/src/SchedulerDaemon.h index 87f2b83d5..dcfec9c7f 100644 --- a/livesupport/products/scheduler/src/SchedulerDaemon.h +++ b/livesupport/products/scheduler/src/SchedulerDaemon.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.4 $ + Version : $Revision: 1.5 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemon.h,v $ ------------------------------------------------------------------------------*/ @@ -63,6 +63,7 @@ #include "UploadPlaylistMethod.h" #include "DisplayScheduleMethod.h" #include "DisplayPlaylistMethod.h" +#include "RemoveFromScheduleMethod.h" #include "XmlRpcDaemon.h" @@ -118,7 +119,7 @@ using namespace LiveSupport::Core; * * * @author $Author: maroy $ - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * @see ConnectionManagerFactory * @see StorageClientFactory * @see ScheduleFactory @@ -150,6 +151,11 @@ class SchedulerDaemon : public Installable, */ Ptr::Ref displayPlaylistMethod; + /** + * The RemoveFromScheduleMethod the daemon is providing. + */ + Ptr::Ref removeFromScheduleMethod; + /** * Default constructor. */ @@ -159,6 +165,7 @@ class SchedulerDaemon : public Installable, uploadPlaylistMethod.reset(new UploadPlaylistMethod()); displayScheduleMethod.reset(new DisplayScheduleMethod()); displayPlaylistMethod.reset(new DisplayPlaylistMethod()); + removeFromScheduleMethod.reset(new RemoveFromScheduleMethod()); } protected: diff --git a/livesupport/products/scheduler/src/SchedulerDaemonRemoveFromScheduleTest.cxx b/livesupport/products/scheduler/src/SchedulerDaemonRemoveFromScheduleTest.cxx new file mode 100644 index 000000000..390889cff --- /dev/null +++ b/livesupport/products/scheduler/src/SchedulerDaemonRemoveFromScheduleTest.cxx @@ -0,0 +1,168 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: maroy $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/SchedulerDaemonRemoveFromScheduleTest.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#if HAVE_UNISTD_H +#include +#else +#error "Need unistd.h" +#endif + + +#include +#include +#include + +#include "SchedulerDaemon.h" +#include "SchedulerDaemonRemoveFromScheduleTest.h" + + +using namespace XmlRpc; +using namespace LiveSupport::Scheduler; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +CPPUNIT_TEST_SUITE_REGISTRATION(SchedulerDaemonRemoveFromScheduleTest); + +/** + * The name of the configuration file for the scheduler daemon. + */ +static const std::string configFileName = "etc/scheduler.xml"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Set up the test environment + *----------------------------------------------------------------------------*/ +void +SchedulerDaemonRemoveFromScheduleTest :: setUp(void) throw () +{ + Ptr::Ref daemon = SchedulerDaemon::getInstance(); + + if (!daemon->isConfigured()) { + try { + std::auto_ptr + parser(new xmlpp::DomParser(configFileName, true)); + const xmlpp::Document * document = parser->get_document(); + daemon->configure(*(document->get_root_node())); + } catch (std::invalid_argument &e) { + std::cerr << e.what() << std::endl; + CPPUNIT_FAIL("semantic error in configuration file"); + } catch (xmlpp::exception &e) { + std::cerr << e.what() << std::endl; + CPPUNIT_FAIL("error parsing configuration file"); + } + } + + daemon->install(); +// daemon->start(); +// sleep(5); +} + + +/*------------------------------------------------------------------------------ + * Clean up the test environment + *----------------------------------------------------------------------------*/ +void +SchedulerDaemonRemoveFromScheduleTest :: tearDown(void) throw () +{ + Ptr::Ref daemon = SchedulerDaemon::getInstance(); + +// daemon->stop(); + daemon->uninstall(); +} + + +/*------------------------------------------------------------------------------ + * A simple smoke test. + *----------------------------------------------------------------------------*/ +void +SchedulerDaemonRemoveFromScheduleTest :: simpleTest(void) + throw (CPPUNIT_NS::Exception) +{ + XmlRpcValue parameters; + XmlRpcValue result; + struct tm time; + + XmlRpcClient xmlRpcClient("localhost", 3344, "/RPC2", false); + + // first schedule a playlist, so that there is something to remove + parameters["playlistId"] = 1; + time.tm_year = 2001; + time.tm_mon = 11; + time.tm_mday = 12; + time.tm_hour = 10; + time.tm_min = 0; + time.tm_sec = 0; + parameters["playtime"] = &time; + + xmlRpcClient.execute("uploadPlaylist", parameters, result); + CPPUNIT_ASSERT(result.valid()); + + Ptr::Ref entryId(new UniqueId((int) result)); + + parameters["scheduleEntryId"] = (int) entryId->getId(); + + xmlRpcClient.execute("removeFromSchedule", parameters, result); + CPPUNIT_ASSERT(result.valid()); + CPPUNIT_ASSERT(((bool)result) == true); +} + + +/*------------------------------------------------------------------------------ + * A simple negative test. + *----------------------------------------------------------------------------*/ +void +SchedulerDaemonRemoveFromScheduleTest :: negativeTest(void) + throw (CPPUNIT_NS::Exception) +{ + XmlRpcValue parameters; + XmlRpcValue result; + + XmlRpcClient xmlRpcClient("localhost", 3344, "/RPC2", false); + + parameters["scheduleEntryId"] = 9999; + + xmlRpcClient.execute("removeFromSchedule", parameters, result); + CPPUNIT_ASSERT(result.valid()); + CPPUNIT_ASSERT(((bool)result) == false); +} + diff --git a/livesupport/products/scheduler/src/SchedulerDaemonRemoveFromScheduleTest.h b/livesupport/products/scheduler/src/SchedulerDaemonRemoveFromScheduleTest.h new file mode 100644 index 000000000..0b5218192 --- /dev/null +++ b/livesupport/products/scheduler/src/SchedulerDaemonRemoveFromScheduleTest.h @@ -0,0 +1,117 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: maroy $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/SchedulerDaemonRemoveFromScheduleTest.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef SchedulerDaemonRemoveFromScheduleTest_h +#define SchedulerDaemonRemoveFromScheduleTest_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include + + +namespace LiveSupport { +namespace Scheduler { + +using namespace LiveSupport; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * Unit test to test the removeFromSchedule XML-RPC call. + * + * @author $Author: maroy $ + * @version $Revision: 1.1 $ + * @see SchedulerDaemon + */ +class SchedulerDaemonRemoveFromScheduleTest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(SchedulerDaemonRemoveFromScheduleTest); + CPPUNIT_TEST(simpleTest); + CPPUNIT_TEST(negativeTest); + CPPUNIT_TEST_SUITE_END(); + + protected: + + /** + * Simple smoke test. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + simpleTest(void) throw (CPPUNIT_NS::Exception); + + /** + * Simple negative test. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + negativeTest(void) throw (CPPUNIT_NS::Exception); + + public: + + /** + * Set up the environment for the test case. + */ + void + setUp(void) throw (); + + /** + * Clean up the environment after the test case. + */ + void + tearDown(void) throw (); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Scheduler +} // namespace LiveSupport + +#endif // SchedulerDaemonRemoveFromScheduleTest_h + diff --git a/livesupport/products/scheduler/src/SchedulerDaemonUploadTest.cxx b/livesupport/products/scheduler/src/SchedulerDaemonUploadTest.cxx index 50aa9cb36..1087086b9 100644 --- a/livesupport/products/scheduler/src/SchedulerDaemonUploadTest.cxx +++ b/livesupport/products/scheduler/src/SchedulerDaemonUploadTest.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/Attic/SchedulerDaemonUploadTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -135,6 +135,6 @@ SchedulerDaemonUploadTest :: simpleTest(void) parameters["playtime"] = &time; xmlRpcClient.execute("uploadPlaylist", parameters, result); - CPPUNIT_ASSERT(result); + CPPUNIT_ASSERT(result.valid()); } diff --git a/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx b/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx index 14c0ba240..5f50bfa13 100644 --- a/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx +++ b/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/UploadPlaylistMethod.cxx,v $ ------------------------------------------------------------------------------*/ @@ -135,11 +135,11 @@ UploadPlaylistMethod :: extractPlayschedule( /*------------------------------------------------------------------------------ - * Execute the stop XML-RPC function call. + * Execute the upload playlist method XML-RPC function call. *----------------------------------------------------------------------------*/ void -UploadPlaylistMethod :: execute( XmlRpc::XmlRpcValue & parameters, - XmlRpc::XmlRpcValue & returnValue) +UploadPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters, + XmlRpc::XmlRpcValue & returnValue) throw () { try { @@ -151,6 +151,7 @@ UploadPlaylistMethod :: execute( XmlRpc::XmlRpcValue & parameters, Ptr::Ref id = extractPlaylistId(parameters[0]); Ptr::Ref playschedule = extractPlayschedule(parameters[0]); + Ptr::Ref scheduleEntryId; Ptr::Ref scf; Ptr::Ref storage; @@ -177,15 +178,14 @@ UploadPlaylistMethod :: execute( XmlRpc::XmlRpcValue & parameters, return; } - schedule->schedulePlaylist(playlist, playschedule); + scheduleEntryId = schedule->schedulePlaylist(playlist, playschedule); + + returnValue = XmlRpc::XmlRpcValue((int) scheduleEntryId->getId()); } catch (std::invalid_argument &e) { // TODO: mark error returnValue = XmlRpc::XmlRpcValue(false); return; } - - // TODO - returnValue = XmlRpc::XmlRpcValue(true); } diff --git a/livesupport/products/scheduler/src/UploadPlaylistMethod.h b/livesupport/products/scheduler/src/UploadPlaylistMethod.h index ab2cdf94b..e831277b9 100644 --- a/livesupport/products/scheduler/src/UploadPlaylistMethod.h +++ b/livesupport/products/scheduler/src/UploadPlaylistMethod.h @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/UploadPlaylistMethod.h,v $ ------------------------------------------------------------------------------*/ @@ -76,9 +76,11 @@ using namespace LiveSupport::Core; *
  • playtime - the time when the playlist should be scheduled, * an ISO 8601 DateTime field
  • * + * The return value is an int, the id of the schedule entry created + * by uploading, or a boolean false, if there were errors. * * @author $Author: maroy $ - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ */ class UploadPlaylistMethod : public XmlRpc::XmlRpcServerMethod { diff --git a/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx b/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx index b501c38fe..45abf175f 100644 --- a/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx +++ b/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx @@ -22,7 +22,7 @@ Author : $Author: maroy $ - Version : $Revision: 1.3 $ + Version : $Revision: 1.4 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/UploadPlaylistMethodTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -169,7 +169,7 @@ UploadPlaylistMethodTest :: firstTest(void) rootParameter[0] = parameters; method->execute(rootParameter, result); - CPPUNIT_ASSERT(result); + CPPUNIT_ASSERT(result.valid()); } @@ -198,7 +198,7 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void) rootParameter[0] = parameters; method->execute(rootParameter, result); - CPPUNIT_ASSERT(result); + CPPUNIT_ASSERT(result.valid()); // try to load the same one, but in an overlapping time region // (we know that playlist with id 1 in 1 hour long) @@ -227,7 +227,7 @@ UploadPlaylistMethodTest :: overlappingPlaylists(void) rootParameter[0] = parameters; method->execute(rootParameter, result); - CPPUNIT_ASSERT(result); + CPPUNIT_ASSERT(result.valid()); // try to load the same one, this time overlapping both previos instnaces parameters["playlistId"] = 1;