refactoring, stage 1: turned GLiveSupport into a Singleton

This commit is contained in:
fgerlits 2007-08-09 10:44:55 +00:00
parent c7e0c451be
commit 7da892d146
4 changed files with 102 additions and 67 deletions

View file

@ -85,8 +85,15 @@ using namespace LiveSupport::GLiveSupport;
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* The name of the config element for this class * The name of the config element for this class
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
const std::string LiveSupport :: GLiveSupport :: const std::string
GLiveSupport :: configElementNameStr = "gLiveSupport"; LiveSupport :: GLiveSupport :: GLiveSupport :: configElementNameStr
= "gLiveSupport";
/*------------------------------------------------------------------------------
* The singleton instance of GLiveSupport
*----------------------------------------------------------------------------*/
Ptr<LiveSupport::GLiveSupport::GLiveSupport>::Ref
LiveSupport :: GLiveSupport :: GLiveSupport :: singleton;
namespace { namespace {
@ -209,6 +216,21 @@ const std::string serialPortDefaultDevice = "/dev/ttyS0";
/* ============================================================= module code */ /* ============================================================= module code */
/*------------------------------------------------------------------------------
* Return the singleton instance to WidgetFactory
*----------------------------------------------------------------------------*/
Ptr<LiveSupport::GLiveSupport::GLiveSupport>::Ref
LiveSupport :: GLiveSupport ::
GLiveSupport :: getInstance(void) throw ()
{
if (!singleton.get()) {
singleton.reset(new LiveSupport::GLiveSupport::GLiveSupport());
}
return singleton;
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Configure the gLiveSupport object * Configure the gLiveSupport object
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
@ -478,7 +500,7 @@ GLiveSupport :: configSupportedLanguages(const xmlpp::Element & element)
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
bool bool
LiveSupport :: GLiveSupport :: LiveSupport :: GLiveSupport ::
GLiveSupport :: checkConfiguration(void) throw () GLiveSupport :: checkConfiguration(void) throw ()
{ {
// === FATAL ERRORS === // === FATAL ERRORS ===
@ -602,7 +624,7 @@ GLiveSupport :: runDialog(const Glib::ustring & dialogName,
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
LiveSupport :: GLiveSupport :: LiveSupport :: GLiveSupport ::
GLiveSupport :: show(void) throw () GLiveSupport :: show(void) throw ()
{ {
masterPanel.reset(new MasterPanelWindow(shared_from_this(), masterPanel.reset(new MasterPanelWindow(shared_from_this(),
getBundle(), getBundle(),
@ -699,7 +721,7 @@ GLiveSupport :: login(const std::string & login,
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
bool bool
LiveSupport :: GLiveSupport :: LiveSupport :: GLiveSupport ::
GLiveSupport :: logout(void) throw () GLiveSupport :: logout(void) throw ()
{ {
if (!sessionId) { if (!sessionId) {
return false; return false;
@ -733,7 +755,7 @@ GLiveSupport :: logout(void) throw ()
void void
LiveSupport :: GLiveSupport :: LiveSupport :: GLiveSupport ::
GLiveSupport :: storeWindowContents(ContentsStorable * window) GLiveSupport :: storeWindowContents(ContentsStorable * window)
throw () throw ()
{ {
Ptr<const Glib::ustring>::Ref userPreferencesKey Ptr<const Glib::ustring>::Ref userPreferencesKey
= window->getUserPreferencesKey(); = window->getUserPreferencesKey();
@ -759,7 +781,7 @@ GLiveSupport :: storeWindowContents(ContentsStorable * window)
void void
LiveSupport :: GLiveSupport :: LiveSupport :: GLiveSupport ::
GLiveSupport :: loadWindowContents(ContentsStorable * window) GLiveSupport :: loadWindowContents(ContentsStorable * window)
throw () throw ()
{ {
Ptr<const Glib::ustring>::Ref userPreferencesKey Ptr<const Glib::ustring>::Ref userPreferencesKey
= window->getUserPreferencesKey(); = window->getUserPreferencesKey();
@ -1058,7 +1080,7 @@ GLiveSupport :: addToScratchpad(Ptr<Playable>::Ref playable)
void void
LiveSupport :: GLiveSupport :: LiveSupport :: GLiveSupport ::
GLiveSupport :: addToLiveMode(Ptr<Playable>::Ref playable) GLiveSupport :: addToLiveMode(Ptr<Playable>::Ref playable)
throw () throw ()
{ {
masterPanel->updateLiveModeWindow(playable); masterPanel->updateLiveModeWindow(playable);
} }
@ -1070,7 +1092,7 @@ GLiveSupport :: addToLiveMode(Ptr<Playable>::Ref playable)
void void
LiveSupport :: GLiveSupport :: LiveSupport :: GLiveSupport ::
GLiveSupport :: setNowPlaying(Ptr<Playable>::Ref playable) GLiveSupport :: setNowPlaying(Ptr<Playable>::Ref playable)
throw () throw ()
{ {
// test needed: this gets called indirectly from ~MasterPanelWindow // test needed: this gets called indirectly from ~MasterPanelWindow
if (masterPanel) { if (masterPanel) {
@ -1242,7 +1264,7 @@ GLiveSupport :: removeFromSchedule(Ptr<const UniqueId>::Ref scheduleEntryId)
void void
LiveSupport :: GLiveSupport :: LiveSupport :: GLiveSupport ::
GLiveSupport :: preload(Ptr<const Playable>::Ref playable) GLiveSupport :: preload(Ptr<const Playable>::Ref playable)
throw () throw ()
{ {
Ptr<const std::string>::Ref uri = playable->getUri(); Ptr<const std::string>::Ref uri = playable->getUri();
if (uri) { if (uri) {
@ -1366,7 +1388,7 @@ GLiveSupport :: stopOutputAudio(void)
void void
LiveSupport :: GLiveSupport :: LiveSupport :: GLiveSupport ::
GLiveSupport :: onStop(Ptr<const Glib::ustring>::Ref errorMessage) GLiveSupport :: onStop(Ptr<const Glib::ustring>::Ref errorMessage)
throw () throw ()
{ {
outputItemPlayingNow.reset(); outputItemPlayingNow.reset();
try { try {
@ -1497,7 +1519,7 @@ GLiveSupport :: stopCueAudio(void)
void void
LiveSupport :: GLiveSupport :: LiveSupport :: GLiveSupport ::
GLiveSupport :: attachCueAudioListener(AudioPlayerEventListener * listener) GLiveSupport :: attachCueAudioListener(AudioPlayerEventListener * listener)
throw () throw ()
{ {
cuePlayer->attachListener(listener); cuePlayer->attachListener(listener);
} }
@ -1520,7 +1542,7 @@ GLiveSupport :: detachCueAudioListener(AudioPlayerEventListener * listener)
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
Glib::RefPtr<Gdk::Pixbuf> Glib::RefPtr<Gdk::Pixbuf>
LiveSupport :: GLiveSupport :: LiveSupport :: GLiveSupport ::
GLiveSupport :: getStationLogoPixbuf(void) throw() GLiveSupport :: getStationLogoPixbuf(void) throw()
{ {
return stationLogoPixbuf; return stationLogoPixbuf;
} }

View file

@ -155,6 +155,11 @@ class GLiveSupport : public LocalizedConfigurable,
*/ */
static const std::string configElementNameStr; static const std::string configElementNameStr;
/**
* The singleton instance of this object.
*/
static Ptr<GLiveSupport>::Ref singleton;
/** /**
* The authentication client used by the application. * The authentication client used by the application.
*/ */
@ -301,7 +306,7 @@ class GLiveSupport : public LocalizedConfigurable,
* Emit the "edited playlist has been modified" signal. * Emit the "edited playlist has been modified" signal.
*/ */
void void
emitSignalEditedPlaylistModified(void) throw () emitSignalEditedPlaylistModified(void) throw ()
{ {
signalEditedPlaylistModified().emit(); signalEditedPlaylistModified().emit();
} }
@ -357,12 +362,24 @@ class GLiveSupport : public LocalizedConfigurable,
*/ */
bool schedulerAvailable; bool schedulerAvailable;
/**
* Private constructor.
*/
GLiveSupport(void) throw ()
: outputPlayerIsPaused(false),
cuePlayerIsPaused(false)
{
openedAudioClips.reset(new AudioClipMap());
openedPlaylists.reset(new PlaylistMap());
serialStream.reset(new LibSerial::SerialStream());
}
/** /**
* Display a message that the authentication server is not available. * Display a message that the authentication server is not available.
* And offer a chance to edit the options to fix it. * And offer a chance to edit the options to fix it.
*/ */
void void
displayAuthenticationServerMissingMessage(void) throw (); displayAuthenticationServerMissingMessage(void) throw ();
/** /**
* Refresh the playlist in the Live Mode window. * Refresh the playlist in the Live Mode window.
@ -375,7 +392,7 @@ class GLiveSupport : public LocalizedConfigurable,
*/ */
void void
refreshPlaylistInLiveMode(Ptr<Playlist>::Ref playlist) refreshPlaylistInLiveMode(Ptr<Playlist>::Ref playlist)
throw (); throw ();
/** /**
* Replace the placeholders in the RDS settings with the * Replace the placeholders in the RDS settings with the
@ -386,7 +403,7 @@ class GLiveSupport : public LocalizedConfigurable,
*/ */
void void
substituteRdsData(Ptr<Glib::ustring>::Ref rdsString) substituteRdsData(Ptr<Glib::ustring>::Ref rdsString)
throw (); throw ();
/** /**
* Replace a single placeholders in the RDS settings. * Replace a single placeholders in the RDS settings.
@ -444,23 +461,11 @@ class GLiveSupport : public LocalizedConfigurable,
public: public:
/**
* Constructor.
*/
GLiveSupport(void) throw ()
: outputPlayerIsPaused(false),
cuePlayerIsPaused(false)
{
openedAudioClips.reset(new AudioClipMap());
openedPlaylists.reset(new PlaylistMap());
serialStream.reset(new LibSerial::SerialStream());
}
/** /**
* Virtual destructor. * Virtual destructor.
*/ */
virtual virtual
~GLiveSupport(void) throw () ~GLiveSupport(void) throw ()
{ {
if (outputPlayer.get()) { if (outputPlayer.get()) {
outputPlayer->deInitialize(); outputPlayer->deInitialize();
@ -485,11 +490,19 @@ class GLiveSupport : public LocalizedConfigurable,
* @return the name of the expected XML configuration element. * @return the name of the expected XML configuration element.
*/ */
static const std::string static const std::string
getConfigElementName(void) throw () getConfigElementName(void) throw ()
{ {
return configElementNameStr; return configElementNameStr;
} }
/**
* Returns the singleton instance of this object.
*
* @return the singleton instance of this object.
*/
static Ptr<GLiveSupport>::Ref
getInstance() throw ();
/** /**
* Configure the scheduler daemon based on the XML element * Configure the scheduler daemon based on the XML element
* supplied. * supplied.
@ -514,7 +527,7 @@ class GLiveSupport : public LocalizedConfigurable,
* false otherwise * false otherwise
*/ */
bool bool
checkConfiguration(void) throw (); checkConfiguration(void) throw ();
/** /**
* Display a message window. * Display a message window.
@ -524,7 +537,7 @@ class GLiveSupport : public LocalizedConfigurable,
*/ */
void void
displayMessageWindow(const Glib::ustring & message) displayMessageWindow(const Glib::ustring & message)
throw (); throw ();
/** /**
* Run a dialog window with No and Yes buttons. * Run a dialog window with No and Yes buttons.
@ -549,7 +562,7 @@ class GLiveSupport : public LocalizedConfigurable,
* This call will only return after the main window has been closed. * This call will only return after the main window has been closed.
*/ */
void void
show(void) throw (); show(void) throw ();
/** /**
* Change the language of the application. * Change the language of the application.
@ -576,7 +589,7 @@ class GLiveSupport : public LocalizedConfigurable,
*/ */
bool bool
login(const std::string & login, login(const std::string & login,
const std::string & password) throw (); const std::string & password) throw ();
/** /**
* Return the session id for the user. * Return the session id for the user.
@ -588,7 +601,7 @@ class GLiveSupport : public LocalizedConfigurable,
* @see #login * @see #login
*/ */
Ptr<SessionId>::Ref Ptr<SessionId>::Ref
getSessionId(void) const throw () getSessionId(void) const throw ()
{ {
return sessionId; return sessionId;
} }
@ -603,7 +616,7 @@ class GLiveSupport : public LocalizedConfigurable,
* @see #logout * @see #logout
*/ */
bool bool
logout(void) throw (); logout(void) throw ();
/** /**
* Accessor function to the scheduler client held by this object. * Accessor function to the scheduler client held by this object.
@ -611,7 +624,7 @@ class GLiveSupport : public LocalizedConfigurable,
* @return the scheduler client held by this object. * @return the scheduler client held by this object.
*/ */
Ptr<SchedulerClientInterface>::Ref Ptr<SchedulerClientInterface>::Ref
getScheduler(void) throw () getScheduler(void) throw ()
{ {
return scheduler; return scheduler;
} }
@ -622,7 +635,7 @@ class GLiveSupport : public LocalizedConfigurable,
* @return the map of supported languages. * @return the map of supported languages.
*/ */
Ptr<const LanguageMap>::Ref Ptr<const LanguageMap>::Ref
getSupportedLanguages(void) const throw () getSupportedLanguages(void) const throw ()
{ {
return supportedLanguages; return supportedLanguages;
} }
@ -633,7 +646,7 @@ class GLiveSupport : public LocalizedConfigurable,
* @return the metadata type container * @return the metadata type container
*/ */
Ptr<MetadataTypeContainer>::Ref Ptr<MetadataTypeContainer>::Ref
getMetadataTypeContainer(void) const throw () getMetadataTypeContainer(void) const throw ()
{ {
return metadataTypeContainer; return metadataTypeContainer;
} }
@ -675,7 +688,7 @@ class GLiveSupport : public LocalizedConfigurable,
* @exception XmlRpcException on communication problems. * @exception XmlRpcException on communication problems.
*/ */
void void
resetStorage(void) throw (XmlRpcException) resetStorage(void) throw (XmlRpcException)
{ {
storage->reset(); storage->reset();
} }
@ -833,7 +846,7 @@ class GLiveSupport : public LocalizedConfigurable,
* @param playable the audio clip or playlist to be added * @param playable the audio clip or playlist to be added
*/ */
void void
addToLiveMode(Ptr<Playable>::Ref playable) throw (); addToLiveMode(Ptr<Playable>::Ref playable) throw ();
/** /**
* Return the currently edited playlist. * Return the currently edited playlist.
@ -842,7 +855,7 @@ class GLiveSupport : public LocalizedConfigurable,
* if no playlist is edited * if no playlist is edited
*/ */
Ptr<Playlist>::Ref Ptr<Playlist>::Ref
getEditedPlaylist(void) throw () getEditedPlaylist(void) throw ()
{ {
return editedPlaylist; return editedPlaylist;
} }
@ -963,7 +976,7 @@ class GLiveSupport : public LocalizedConfigurable,
*/ */
void void
preload(Ptr<const Playable>::Ref playable) preload(Ptr<const Playable>::Ref playable)
throw (); throw ();
/** /**
* Play a Playable object using the output audio player. * Play a Playable object using the output audio player.
@ -1080,7 +1093,7 @@ class GLiveSupport : public LocalizedConfigurable,
void void
playTestSoundOnCue(Ptr<const Glib::ustring>::Ref oldDevice, playTestSoundOnCue(Ptr<const Glib::ustring>::Ref oldDevice,
Ptr<const Glib::ustring>::Ref newDevice) Ptr<const Glib::ustring>::Ref newDevice)
throw (); throw ();
/** /**
* Search in the local storage. * Search in the local storage.
@ -1105,14 +1118,14 @@ class GLiveSupport : public LocalizedConfigurable,
virtual void virtual void
onStop(Ptr<const Glib::ustring>::Ref errorMessage onStop(Ptr<const Glib::ustring>::Ref errorMessage
= Ptr<const Glib::ustring>::Ref()) = Ptr<const Glib::ustring>::Ref())
throw (); throw ();
/** /**
* Display the playable item on the master panel as "now playing". * Display the playable item on the master panel as "now playing".
*/ */
void void
setNowPlaying(Ptr<Playable>::Ref playable) setNowPlaying(Ptr<Playable>::Ref playable)
throw (); throw ();
/** /**
* Return a pixbuf containing the radio station logo. * Return a pixbuf containing the radio station logo.
@ -1120,7 +1133,7 @@ class GLiveSupport : public LocalizedConfigurable,
* @return a pixbuf containing the station logo image. * @return a pixbuf containing the station logo image.
*/ */
Glib::RefPtr<Gdk::Pixbuf> Glib::RefPtr<Gdk::Pixbuf>
getStationLogoPixbuf() throw (); getStationLogoPixbuf() throw ();
/** /**
* The signal raised when the edited playlist is modified. * The signal raised when the edited playlist is modified.
@ -1128,7 +1141,7 @@ class GLiveSupport : public LocalizedConfigurable,
* @return the signal object (a protected member of this class) * @return the signal object (a protected member of this class)
*/ */
sigc::signal<void> sigc::signal<void>
signalEditedPlaylistModified(void) throw () signalEditedPlaylistModified(void) throw ()
{ {
return signalEditedPlaylistModifiedObject; return signalEditedPlaylistModifiedObject;
} }
@ -1285,7 +1298,7 @@ class GLiveSupport : public LocalizedConfigurable,
*/ */
void void
storeWindowContents(Ptr<ContentsStorable>::Ref window) storeWindowContents(Ptr<ContentsStorable>::Ref window)
throw () throw ()
{ {
storeWindowContents(window.get()); storeWindowContents(window.get());
} }
@ -1297,7 +1310,7 @@ class GLiveSupport : public LocalizedConfigurable,
*/ */
void void
loadWindowContents(Ptr<ContentsStorable>::Ref window) loadWindowContents(Ptr<ContentsStorable>::Ref window)
throw () throw ()
{ {
loadWindowContents(window.get()); loadWindowContents(window.get());
} }
@ -1308,7 +1321,7 @@ class GLiveSupport : public LocalizedConfigurable,
* @param window the window to get the contents of. * @param window the window to get the contents of.
*/ */
void void
storeWindowContents(ContentsStorable * window) throw (); storeWindowContents(ContentsStorable * window) throw ();
/** /**
* Load the contents of a window as a user preference. * Load the contents of a window as a user preference.
@ -1316,13 +1329,13 @@ class GLiveSupport : public LocalizedConfigurable,
* @param window the window to restore the contents of. * @param window the window to restore the contents of.
*/ */
void void
loadWindowContents(ContentsStorable * window) throw (); loadWindowContents(ContentsStorable * window) throw ();
/** /**
* Return whether the storage component is available. * Return whether the storage component is available.
*/ */
bool bool
isStorageAvailable(void) throw() isStorageAvailable(void) throw()
{ {
return storageAvailable; return storageAvailable;
} }
@ -1331,7 +1344,7 @@ class GLiveSupport : public LocalizedConfigurable,
* Return whether the scheduler component is available. * Return whether the scheduler component is available.
*/ */
bool bool
isSchedulerAvailable(void) throw() isSchedulerAvailable(void) throw()
{ {
return schedulerAvailable; return schedulerAvailable;
} }
@ -1340,7 +1353,7 @@ class GLiveSupport : public LocalizedConfigurable,
* Access the StorageClientInterface object. * Access the StorageClientInterface object.
*/ */
Ptr<StorageClientInterface>::Ref Ptr<StorageClientInterface>::Ref
getStorageClient(void) throw() getStorageClient(void) throw()
{ {
return storage; return storage;
} }
@ -1350,19 +1363,19 @@ class GLiveSupport : public LocalizedConfigurable,
* This updates the schedulerAvailable variable accordingly. * This updates the schedulerAvailable variable accordingly.
*/ */
void void
checkSchedulerClient(void) throw(); checkSchedulerClient(void) throw();
/** /**
* Start the scheduler client. * Start the scheduler client.
*/ */
void void
startSchedulerClient(void) throw(); startSchedulerClient(void) throw();
/** /**
* Stop the scheduler client. * Stop the scheduler client.
*/ */
void void
stopSchedulerClient(void) throw(); stopSchedulerClient(void) throw();
/** /**
* Upload a Playable object to the network hub. * Upload a Playable object to the network hub.
@ -1373,7 +1386,7 @@ class GLiveSupport : public LocalizedConfigurable,
* @param playable the audio clip or playlist to be uploaded. * @param playable the audio clip or playlist to be uploaded.
*/ */
void void
uploadToHub(Ptr<Playable>::Ref playable) throw (); uploadToHub(Ptr<Playable>::Ref playable) throw ();
/** /**
* Take a break. * Take a break.
@ -1383,7 +1396,7 @@ class GLiveSupport : public LocalizedConfigurable,
* make sure your window gets redrawn. * make sure your window gets redrawn.
*/ */
void void
runMainLoop(void) throw () runMainLoop(void) throw ()
{ {
while (Gtk::Main::events_pending()) { while (Gtk::Main::events_pending()) {
Gtk::Main::iteration(); Gtk::Main::iteration();
@ -1394,7 +1407,7 @@ class GLiveSupport : public LocalizedConfigurable,
* Preload the Scratchpad window during login. * Preload the Scratchpad window during login.
*/ */
void void
createScratchpadWindow(void) throw (); createScratchpadWindow(void) throw ();
/** /**
* Read the RDS settings, and send them to the serial port. * Read the RDS settings, and send them to the serial port.
@ -1412,7 +1425,7 @@ class GLiveSupport : public LocalizedConfigurable,
* @see substituteRdsData() * @see substituteRdsData()
*/ */
void void
updateRds(void) throw (); updateRds(void) throw ();
/** /**
* Return the directory where the Glade files are. * Return the directory where the Glade files are.
@ -1420,7 +1433,7 @@ class GLiveSupport : public LocalizedConfigurable,
* @return the directory where the Glade files are. * @return the directory where the Glade files are.
*/ */
Glib::ustring Glib::ustring
getGladeDir(void) throw () getGladeDir(void) throw ()
{ {
return gladeDir; return gladeDir;
} }

View file

@ -113,7 +113,7 @@ GLiveSupportTest :: setUp(void) throw (CPPUNIT_NS::Exception)
{ {
Gtk::Main kit(0, 0); Gtk::Main kit(0, 0);
gLiveSupport.reset(new GLiveSupport()); gLiveSupport = GLiveSupport::getInstance();
uid_t uid = getuid(); uid_t uid = getuid();
struct passwd * pwd = getpwuid(uid); struct passwd * pwd = getpwuid(uid);

View file

@ -28,7 +28,7 @@
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
/** @file /** @file
* This file contains the main entry point to the Scheduler daemon. * This file contains the main entry point to the Studio client.
*/ */
/* ============================================================ include files */ /* ============================================================ include files */
@ -155,7 +155,7 @@ int main ( int argc,
} }
Ptr<LiveSupport::GLiveSupport::GLiveSupport>::Ref Ptr<LiveSupport::GLiveSupport::GLiveSupport>::Ref
gLiveSupport(new LiveSupport::GLiveSupport::GLiveSupport()); gLiveSupport = LiveSupport::GLiveSupport::GLiveSupport::getInstance();
try { try {
std::auto_ptr<xmlpp::DomParser> std::auto_ptr<xmlpp::DomParser>