Skip to content

Commit

Permalink
Merge pull request #176 from Montellese/jsonrpc_notifications
Browse files Browse the repository at this point in the history
jsonrpc: Refactoring and renaming of notifications
  • Loading branch information
Montellese committed Jun 8, 2011
2 parents c8609ff + 1eb3c40 commit 28743c1
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 62 deletions.
26 changes: 12 additions & 14 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3311,7 +3311,7 @@ void CApplication::Stop(int exitCode)
{
try
{
CAnnouncementManager::Announce(System, "xbmc", "ApplicationStop");
CAnnouncementManager::Announce(System, "xbmc", "OnQuit");

// cancel any jobs from the jobmanager
CJobManager::GetInstance().CancelJobs();
Expand Down Expand Up @@ -3908,7 +3908,7 @@ void CApplication::OnPlayBackEnded()
getApplicationMessenger().HttpApi("broadcastlevel; OnPlayBackEnded;1");
#endif

CAnnouncementManager::Announce(Player, "xbmc", "PlaybackEnded");
CAnnouncementManager::Announce(Player, "xbmc", "OnStop");

if (IsPlayingAudio())
{
Expand Down Expand Up @@ -3937,7 +3937,9 @@ void CApplication::OnPlayBackStarted()
getApplicationMessenger().HttpApi("broadcastlevel; OnPlayBackStarted;1");
#endif

CAnnouncementManager::Announce(Player, "xbmc", "PlaybackStarted", m_itemCurrentFile);
CVariant param;
param["speed"] = 1;
CAnnouncementManager::Announce(Player, "xbmc", "OnPlay", m_itemCurrentFile, param);

CGUIMessage msg(GUI_MSG_PLAYBACK_STARTED, 0, 0);
g_windowManager.SendThreadMessage(msg);
Expand All @@ -3957,8 +3959,6 @@ void CApplication::OnQueueNextItem()
getApplicationMessenger().HttpApi("broadcastlevel; OnQueueNextItem;1");
#endif

CAnnouncementManager::Announce(Player, "xbmc", "QueueNextItem");

if(IsPlayingAudio())
{
CLastfmScrobbler::GetInstance()->SubmitQueue();
Expand Down Expand Up @@ -3986,7 +3986,7 @@ void CApplication::OnPlayBackStopped()
getApplicationMessenger().HttpApi("broadcastlevel; OnPlayBackStopped;1");
#endif

CAnnouncementManager::Announce(Player, "xbmc", "PlaybackStopped", m_itemCurrentFile);
CAnnouncementManager::Announce(Player, "xbmc", "OnStop", m_itemCurrentFile);

CLastfmScrobbler::GetInstance()->SubmitQueue();
CLibrefmScrobbler::GetInstance()->SubmitQueue();
Expand All @@ -4007,7 +4007,7 @@ void CApplication::OnPlayBackPaused()
getApplicationMessenger().HttpApi("broadcastlevel; OnPlayBackPaused;1");
#endif

CAnnouncementManager::Announce(Player, "xbmc", "PlaybackPaused", m_itemCurrentFile);
CAnnouncementManager::Announce(Player, "xbmc", "OnPause", m_itemCurrentFile);
}

void CApplication::OnPlayBackResumed()
Expand All @@ -4022,7 +4022,9 @@ void CApplication::OnPlayBackResumed()
getApplicationMessenger().HttpApi("broadcastlevel; OnPlayBackResumed;1");
#endif

CAnnouncementManager::Announce(Player, "xbmc", "PlaybackResumed", m_itemCurrentFile);
CVariant param;
param["speed"] = 1;
CAnnouncementManager::Announce(Player, "xbmc", "OnPlay", m_itemCurrentFile, param);
}

void CApplication::OnPlayBackSpeedChanged(int iSpeed)
Expand All @@ -4043,7 +4045,7 @@ void CApplication::OnPlayBackSpeedChanged(int iSpeed)

CVariant param;
param["speed"] = iSpeed;
CAnnouncementManager::Announce(Player, "xbmc", "PlaybackSpeedChanged", m_itemCurrentFile, param);
CAnnouncementManager::Announce(Player, "xbmc", "OnPlay", m_itemCurrentFile, param);
}

void CApplication::OnPlayBackSeek(int iTime, int seekOffset)
Expand All @@ -4065,7 +4067,7 @@ void CApplication::OnPlayBackSeek(int iTime, int seekOffset)
CVariant param;
param["time"] = iTime;
param["seekoffset"] = seekOffset;
CAnnouncementManager::Announce(Player, "xbmc", "PlaybackSeek", param);
CAnnouncementManager::Announce(Player, "xbmc", "OnSeek", param);
g_infoManager.SetDisplayAfterSeek(2500, seekOffset/1000);
}

Expand All @@ -4084,10 +4086,6 @@ void CApplication::OnPlayBackSeekChapter(int iChapter)
getApplicationMessenger().HttpApi(tmp);
}
#endif

CVariant param;
param["chapter"] = iChapter;
CAnnouncementManager::Announce(Player, "xbmc", "PlaybackSeekChapter", param);
}

bool CApplication::IsPlaying() const
Expand Down
17 changes: 11 additions & 6 deletions xbmc/interfaces/AnnouncementManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void CAnnouncementManager::Announce(EAnnouncementFlag flag, const char *sender,
void CAnnouncementManager::Announce(EAnnouncementFlag flag, const char *sender, const char *message, CFileItemPtr item)
{
CVariant data;
Announce(flag, sender, message, data);
Announce(flag, sender, message, item, data);
}

void CAnnouncementManager::Announce(EAnnouncementFlag flag, const char *sender, const char *message, CFileItemPtr item, CVariant &data)
Expand All @@ -83,19 +83,24 @@ void CAnnouncementManager::Announce(EAnnouncementFlag flag, const char *sender,
if (item->HasVideoInfoTag())
{
CVideoDatabase::VideoContentTypeToString((VIDEODB_CONTENT_TYPE)item->GetVideoContentType(), type);

id = item->GetVideoInfoTag()->m_iDbId;
}
else if (item->HasMusicInfoTag())
{
type = "music";
if (item->IsAlbum())
type = "album";
else
type = "song";

id = item->GetMusicInfoTag()->GetDatabaseId();
}
else
type = "unknown";

object["type"] = type;
if (id > 0)
{
type += "id";
object[type] = id;
}
object["id"] = id;

Announce(flag, sender, message, object);
}
162 changes: 161 additions & 1 deletion xbmc/interfaces/json-rpc/ServiceDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -2065,5 +2065,165 @@ namespace JSONRPC
"}";

const char* const JSON_NOTIFICATION_DESCRIPTION =
"{ }";
"{"
"\"Player.OnPlay\": {"
"\"type\": \"notification\","
"\"description\": \"Playback of a media item has been started or the playback speed has changed.\","
"\"params\": ["
"{ \"name\": \"sender\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"data\", \"type\": \"object\", \"required\": true,"
"\"properties\": {"
"\"speed\": { \"type\": \"integer\", \"required\": true },"
"\"type\": { \"type\": \"string\", \"id\": \"Notifications.Player.Type\", \"enum\": [ \"unknown\", \"movie\", \"episode\", \"musicvideo\", \"song\" ], \"required\": true },"
"\"id\": { \"$ref\": \"Library.Id\" }"
"}"
"}"
"],"
"\"returns\": null"
"},"
"\"Player.OnPause\": {"
"\"type\": \"notification\","
"\"description\": \"Playback of a media item has been paused.\","
"\"params\": ["
"{ \"name\": \"sender\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"data\", \"type\": \"object\", \"required\": true,"
"\"properties\": {"
"\"type\": { \"$ref\": \"Notifications.Player.Type\", \"required\": true },"
"\"id\": { \"$ref\": \"Library.Id\" }"
"}"
"}"
"],"
"\"returns\": null"
"},"
"\"Player.OnStop\": {"
"\"type\": \"notification\","
"\"description\": \"Playback of a media item has been stopped.\","
"\"params\": ["
"{ \"name\": \"sender\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"data\", \"type\": \"object\", \"required\": true,"
"\"properties\": {"
"\"type\": { \"$ref\": \"Notifications.Player.Type\" },"
"\"id\": { \"$ref\": \"Library.Id\" }"
"}"
"}"
"],"
"\"returns\": null"
"},"
"\"Player.OnSeek\": {"
"\"type\": \"notification\","
"\"description\": \"The playback position has been changed.\","
"\"params\": ["
"{ \"name\": \"sender\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"data\", \"type\": \"object\", \"required\": true,"
"\"properties\": {"
"\"time\": { \"type\": \"integer\", \"required\": true },"
"\"seekoffset\": { \"type\": \"integer\", \"required\": true }"
"}"
"}"
"],"
"\"returns\": null"
"},"
"\"AudioLibrary.OnUpdate\": {"
"\"type\": \"notification\","
"\"description\": \"An audio item has been updated.\","
"\"params\": ["
"{ \"name\": \"sender\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"data\", \"type\": \"object\", \"required\": true,"
"\"properties\": {"
"\"id\": { \"$ref\": \"Library.Id\", \"required\": true },"
"\"type\": { \"type\": \"string\", \"id\": \"Notifications.Library.Audio.Type\", \"enum\": [ \"song\" ], \"required\": true }"
"}"
"}"
"],"
"\"returns\": null"
"},"
"\"AudioLibrary.OnRemove\": {"
"\"type\": \"notification\","
"\"description\": \"An audio item has been removed.\","
"\"params\": ["
"{ \"name\": \"sender\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"data\", \"type\": \"object\", \"required\": true,"
"\"properties\": {"
"\"id\": { \"$ref\": \"Library.Id\", \"required\": true },"
"\"type\": { \"$ref\": \"Notifications.Library.Audio.Type\", \"required\": true }"
"}"
"}"
"],"
"\"returns\": null"
"},"
"\"VideoLibrary.OnUpdate\": {"
"\"type\": \"notification\","
"\"description\": \"A video item has been updated.\","
"\"params\": ["
"{ \"name\": \"sender\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"data\", \"type\": \"object\", \"required\": true,"
"\"properties\": {"
"\"id\": { \"$ref\": \"Library.Id\", \"required\": true },"
"\"type\": { \"type\": \"string\", \"id\": \"Notifications.Library.Video.Type\", \"enum\": [ \"movie\", \"tvshow\", \"episode\", \"musicvideo\" ], \"required\": true },"
"\"playcount\": { \"type\": \"integer\", \"minimum\": 0, \"default\": -1 }"
"}"
"}"
"],"
"\"returns\": null"
"},"
"\"VideoLibrary.OnRemove\": {"
"\"type\": \"notification\","
"\"description\": \"A video item has been removed.\","
"\"params\": ["
"{ \"name\": \"sender\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"data\", \"type\": \"object\", \"required\": true,"
"\"properties\": {"
"\"id\": { \"$ref\": \"Library.Id\", \"required\": true },"
"\"type\": { \"$ref\": \"Notifications.Library.Video.Type\", \"required\": true }"
"}"
"}"
"],"
"\"returns\": null"
"},"
"\"System.OnQuit\": {"
"\"type\": \"notification\","
"\"description\": \"XBMC will be closed.\","
"\"params\": ["
"{ \"name\": \"sender\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"data\", \"type\": \"null\", \"required\": true }"
"],"
"\"returns\": null"
"},"
"\"System.OnRestart\": {"
"\"type\": \"notification\","
"\"description\": \"The system will be restarted.\","
"\"params\": ["
"{ \"name\": \"sender\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"data\", \"type\": \"null\", \"required\": true }"
"],"
"\"returns\": null"
"},"
"\"System.OnSleep\": {"
"\"type\": \"notification\","
"\"description\": \"The system will be suspended.\","
"\"params\": ["
"{ \"name\": \"sender\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"data\", \"type\": \"null\", \"required\": true }"
"],"
"\"returns\": null"
"},"
"\"System.OnWake\": {"
"\"type\": \"notification\","
"\"description\": \"The system woke up from suspension.\","
"\"params\": ["
"{ \"name\": \"sender\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"data\", \"type\": \"null\", \"required\": true }"
"],"
"\"returns\": null"
"},"
"\"System.OnLowBattery\": {"
"\"type\": \"notification\","
"\"description\": \"The system is on low battery.\","
"\"params\": ["
"{ \"name\": \"sender\", \"type\": \"string\", \"required\": true },"
"{ \"name\": \"data\", \"type\": \"null\", \"required\": true }"
"],"
"\"returns\": null"
"}"
"}";
}
12 changes: 6 additions & 6 deletions xbmc/music/MusicDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4756,15 +4756,15 @@ int CMusicDatabase::GetVariousArtistsAlbumsCount()
void CMusicDatabase::AnnounceRemove(std::string content, int id)
{
CVariant data;
data["content"] = content;
data[content + "id"] = id;
ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "RemoveAudio", data);
data["type"] = content;
data["id"] = id;
ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnRemove", data);
}

void CMusicDatabase::AnnounceUpdate(std::string content, int id)
{
CVariant data;
data["content"] = content;
data[content + "id"] = id;
ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "UpdateAudio", data);
data["type"] = content;
data["id"] = id;
ANNOUNCEMENT::CAnnouncementManager::Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnUpdate", data);
}
35 changes: 9 additions & 26 deletions xbmc/powermanagement/PowerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,41 +129,24 @@ void CPowerManager::SetDefaults()

bool CPowerManager::Powerdown()
{

bool success = CanPowerdown() ? m_instance->Powerdown() : false;
if (success)
CAnnouncementManager::Announce(System, "xbmc", "Shutdown");

return success;
return CanPowerdown() ? m_instance->Powerdown() : false;
}

bool CPowerManager::Suspend()
{
bool success = false;
if (CanSuspend())
success = m_instance->Suspend();

if (success)
CAnnouncementManager::Announce(System, "xbmc", "Suspend");

return success;
return CanSuspend() ? m_instance->Suspend() : false;
}

bool CPowerManager::Hibernate()
{
bool success = false;
if (CanHibernate())
success = m_instance->Hibernate();

if (success)
CAnnouncementManager::Announce(System, "xbmc", "Hibernate");

return success;
return CanHibernate() ? m_instance->Hibernate() : false;
}
bool CPowerManager::Reboot()
{
bool success = CanReboot() ? m_instance->Reboot() : false;

if (success)
CAnnouncementManager::Announce(System, "xbmc", "Reboot");
CAnnouncementManager::Announce(System, "xbmc", "OnRestart");

return success;
}
Expand Down Expand Up @@ -192,7 +175,7 @@ void CPowerManager::ProcessEvents()

void CPowerManager::OnSleep()
{
CAnnouncementManager::Announce(System, "xbmc", "Sleep");
CAnnouncementManager::Announce(System, "xbmc", "OnSleep");
CLog::Log(LOGNOTICE, "%s: Running sleep jobs", __FUNCTION__);

#ifdef HAS_LCD
Expand Down Expand Up @@ -250,7 +233,7 @@ void CPowerManager::OnWake()
g_application.UpdateLibraries();
g_weatherManager.Refresh();

CAnnouncementManager::Announce(System, "xbmc", "Wake");
CAnnouncementManager::Announce(System, "xbmc", "OnWake");
}

void CPowerManager::OnLowBattery()
Expand All @@ -259,5 +242,5 @@ void CPowerManager::OnLowBattery()

g_application.m_guiDialogKaiToast.QueueNotification(CGUIDialogKaiToast::Warning, g_localizeStrings.Get(13050), "");

CAnnouncementManager::Announce(System, "xbmc", "LowBattery");
CAnnouncementManager::Announce(System, "xbmc", "OnLowBattery");
}
Loading

0 comments on commit 28743c1

Please sign in to comment.