summaryrefslogtreecommitdiff
path: root/p2pvr/daemon/recordings.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2014-03-13 19:42:07 +0000
committerrandomdan <randomdan@localhost>2014-03-13 19:42:07 +0000
commitab1eee942e75874739ce5f0b4ba289aac5cc3faf (patch)
tree6e43828794fe0c0c5c9921ec1911695b67357c50 /p2pvr/daemon/recordings.cpp
parentExpose more of the interface (diff)
downloadp2pvr-ab1eee942e75874739ce5f0b4ba289aac5cc3faf.tar.bz2
p2pvr-ab1eee942e75874739ce5f0b4ba289aac5cc3faf.tar.xz
p2pvr-ab1eee942e75874739ce5f0b4ba289aac5cc3faf.zip
Restructure into more sensibly arranged libs
Diffstat (limited to 'p2pvr/daemon/recordings.cpp')
-rw-r--r--p2pvr/daemon/recordings.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/p2pvr/daemon/recordings.cpp b/p2pvr/daemon/recordings.cpp
new file mode 100644
index 0000000..bad8032
--- /dev/null
+++ b/p2pvr/daemon/recordings.cpp
@@ -0,0 +1,82 @@
+#include <pch.hpp>
+#include "recordings.h"
+#include "resources.h"
+#include <Ice/Ice.h>
+#include <logger.h>
+#include "sqlContainerCreator.h"
+
+ResourceString(Recording_Insert, daemon_sql_Recordings_insert_sql);
+ResourceString(Recording_InsertNewId, daemon_sql_Recordings_insertNewId_sql);
+ResourceString(Recording_Delete, daemon_sql_Recordings_delete_sql);
+ResourceString(Recording_GetStorage, daemon_sql_Recordings_getStorage_sql);
+ResourceString(Recording_GetAll, daemon_sql_Recordings_getAll_sql);
+
+template<>
+void
+CreateColumns<P2PVR::RecordingPtr>(const ColumnCreator & cc)
+{
+ cc("recordingid", true);
+ cc("storageaddress", false);
+ cc("guid", false);
+ cc("scheduleid", false);
+ cc("title", false);
+ cc("subtitle", false);
+ cc("description", false);
+ cc("starttime", false);
+ cc("duration", false);
+}
+
+template<>
+void
+UnbindColumns(RowState & rs, const P2PVR::RecordingPtr & r)
+{
+ rs.fields[0] >> r->RecordingId;
+ rs.fields[1] >> r->StorageAddress;
+ rs.fields[2] >> r->Guid;
+ rs.fields[3] >> r->ScheduleId;
+ rs.fields[4] >> r->Title;
+ rs.fields[5] >> r->Subtitle;
+ rs.fields[6] >> r->Description;
+ rs.fields[7] >> r->StartTime;
+ rs.fields[8] >> r->Duration;
+}
+
+int
+Recordings::NewRecording(const P2PVR::RecordingPtr & r, const Ice::Current &)
+{
+ Logger()->messagebf(LOG_INFO, "%s: Creating new recording %s at %s", __PRETTY_FUNCTION__, r->Guid, r->StorageAddress);
+ TxHelper tx(this);
+ auto insert = Modify(Recording_Insert,
+ r->StorageAddress, r->Guid, r->ScheduleId, r->Title, r->Subtitle, r->Description, r->StartTime, r->Duration);
+ insert.second->execute();
+ r->RecordingId = SelectScalar<int>(Recording_InsertNewId);
+ Logger()->messagebf(LOG_INFO, "%s: Created recording Id: %d", __PRETTY_FUNCTION__, r->RecordingId);
+ return r->RecordingId;
+}
+
+void
+Recordings::DeleteRecording(int id, const Ice::Current & ice)
+{
+ Logger()->messagebf(LOG_INFO, "%s: Deleting recording Id: %d", __PRETTY_FUNCTION__, id);
+ auto ic = ice.adapter->getCommunicator();
+ TxHelper tx(this);
+ auto recordingStorages = Select(Recording_GetStorage, id);
+ while (recordingStorages.second->fetch()) {
+ std::string addr = recordingStorages.second / "storageaddress";
+ std::string guid = recordingStorages.second / "guid";
+ auto storage = P2PVR::StoragePrx::checkedCast(ic->stringToProxy(addr));
+ storage->Delete(guid);
+ Logger()->messagebf(LOG_DEBUG, "%s: Delete %s from StorageAddress %s", __PRETTY_FUNCTION__, guid, addr);
+ }
+ Modify(Recording_Delete, id).second->execute();
+}
+
+P2PVR::RecordingList
+Recordings::GetRecordings(const Ice::Current &)
+{
+ P2PVR::RecordingList rtn;
+ SqlContainerCreator<P2PVR::RecordingList, P2PVR::Recording> cc(rtn);
+ cc.populate(Select(Recording_GetAll).second);
+ return rtn;
+}
+