From b6ebbd4df6a6a588692bd0e5e1bbd1d920aad3e1 Mon Sep 17 00:00:00 2001 From: Dieter Hametner Date: Wed, 17 Jan 2007 01:15:59 +0000 Subject: - Moved cRecordings locking infrastructure to RecordingsManager. - Take care to have at any time maximum one instance of RecordingsManager alive. This is done with a combination of boost::shared_ptr and boost::weak_ptr. See LiveRecordingsManager() function. - RecordingsTree now uses RecordingsManager to calculate a MD5 Hash for each 'real' cRecording item. - The MD5 Hash is used in the Ajax-Request to start play back of a recording. (Server side needs implementation of this.) - Id's are also used in the DOM for the identification of the tooltips. - New code dependency on openssl libraries (for md5 function). - Changed style (not yet complete) to have 'action' items also in the recording description popup. --- Makefile | 4 ++-- css/styles.css | 27 +++++++++++++++++++++++++-- pages/pageelems.ecpp | 4 ++-- pages/recordings.ecpp | 29 ++++++++++++++++------------- recordings.cpp | 49 +++++++++++++++++++++++++++++++++++++++++-------- recordings.h | 36 +++++++++++++++++++++++++++++++++--- 6 files changed, 119 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index ff35b5a..310be38 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # # Makefile for a Video Disk Recorder plugin # -# $Id: Makefile,v 1.27 2007/01/13 18:37:21 lordjaxom Exp $ +# $Id: Makefile,v 1.28 2007/01/17 01:15:59 tadi Exp $ # The official name of this plugin. # This name will be used in the '-P...' option of VDR to load the plugin. @@ -52,7 +52,7 @@ INCLUDES += -I$(VDRDIR)/include -Ihttpd DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"' export DEFINES -LIBS += httpd/libhttpd.a +LIBS += -lssl httpd/libhttpd.a SUBDIRS = httpd pages css images javascript diff --git a/css/styles.css b/css/styles.css index cad5ef2..571effe 100644 --- a/css/styles.css +++ b/css/styles.css @@ -402,14 +402,37 @@ div.domTTrecordings { border: none; } -.domTTrecordings div.re_longdescr { +.domTTrecordings div.re_description { } .domTTrecordings div.re_content { - border: 1px solid black; + padding: 0; + margin: 0; + + border-right: 1px solid #000000; + border-bottom: 1px solid #000000; background: white; } +.domTTrecordings div.re_content div.re_tools { + float: left; + width: 26px; + margin: 0; + padding: 0; + + text-align: center; + vertical-align: top; + border-right: 1px solid #C0C1DA; +} + +.domTTrecordings div.re_content div div { + margin-left: 50px; +} + +.domTTrecordings div.re_content div.re_tools a img { + margin-top: 5px; +} + .domTTrecordings div.boxheader div div a { } diff --git a/pages/pageelems.ecpp b/pages/pageelems.ecpp index 326a8b8..79d5d51 100644 --- a/pages/pageelems.ecpp +++ b/pages/pageelems.ecpp @@ -44,7 +44,7 @@ component; tChannelID channelid; tEventID eventid; - border="0"/> + /> <%def ajax_js> @@ -57,5 +57,5 @@ component; string image; string alt = ""; - <$ alt $> + <$ alt $> diff --git a/pages/recordings.ecpp b/pages/recordings.ecpp index 2defee4..6139d1f 100644 --- a/pages/recordings.ecpp +++ b/pages/recordings.ecpp @@ -11,9 +11,7 @@ using namespace vdrlive; <%args> <%request scope="page"> -RecordingsTree recordingsTree; -const std::string lPref("long_"); -const std::string sPref("short_"); +RecordingsTree recordingsTree(LiveRecordingsManager()); <%include>page_init.eh <%cpp> @@ -115,9 +113,9 @@ for (iter = recordingsTree.begin(path); iter != end; ++iter) {
<$ day $>
<$ FormatDateTime(tr("%b %d %y"), recItem->StartTime()) $>
<$ FormatDateTime(tr("%I:%M %p"), recItem->StartTime()) $>
-
<& tooltip.display domId=(lPref + recItem->Id()) &>><$ recItem->Name() $>
+
<& tooltip.display domId=(recItem->Id()) &>><$ recItem->Name() $>
- <& pageelems.play_recording recordingid=(recItem->Recording()->FileName()) image="play.png" alt="" &> + <& pageelems.play_recording recordingid=(recItem->Id()) image="play.png" alt="" &>
@@ -160,16 +158,21 @@ for (iter = recordingsTree.begin(path); iter != end; ++iter) { std::string shortDescr; if (info->ShortText()) shortDescr = info->ShortText(); std::string longDescr; if (info->Description()) longDescr = info->Description(); }> -
-
-
<$ recItem->Name() $><& tooltip.close domId=(lPref + recItem->Id()) &>
+
+
+
<$ recItem->Name() $><& tooltip.close domId=(recItem->Id()) &>
-
<$ (start) $>
-
<$ (title) $>
-
<$ (shortDescr) $>
-
- <$ (longDescr) $> +
+ <& pageelems.play_recording recordingid=(recItem->Id()) image="play.png" alt="" &> +
+
+
<$ (start) $>
+
<$ (title) $>
+
<$ (shortDescr) $>
+
+ <$ (longDescr) $> +
diff --git a/recordings.cpp b/recordings.cpp index f8c09d6..5d82a68 100644 --- a/recordings.cpp +++ b/recordings.cpp @@ -1,17 +1,37 @@ -#include +#include +#include #include +#include +#include +#include #include "tools.h" #include "recordings.h" namespace vdrlive { - RecordingsTree::RecordingsTree() : - m_maxLevel(0), - m_root(new RecordingsItemDir()), + RecordingsManager::RecordingsManager() : m_recordingsLock(&Recordings) + { + } + string RecordingsManager::Md5Hash(const cRecording* recording) const + { + unsigned char md5[MD5_DIGEST_LENGTH]; + const char* fileName = recording->FileName(); + MD5(reinterpret_cast(fileName), strlen(fileName), md5); + + ostringstream hashStr; + hashStr << hex; + for (size_t i = 0; i < MD5_DIGEST_LENGTH; i++) + hashStr << (0 + md5[i]); + return hashStr.str(); + } + + RecordingsTree::RecordingsTree(RecordingsManagerPtr recMan) : + m_maxLevel(0), + m_root(new RecordingsItemDir()), + m_recManPtr(recMan) { - int recCount = 0; // esyslog("DH: ****** RecordingsTree::RecordingsTree() ********"); for ( cRecording* recording = Recordings.First(); recording != 0; recording = Recordings.Next( recording ) ) { if (m_maxLevel < recording->HierarchyLevels()) { @@ -48,9 +68,7 @@ namespace vdrlive { } else { string recName(name.substr(index, name.length() - index)); - string recId("recId_"); - recId += lexical_cast(++recCount); - RecordingsItemPtr recPtr (new RecordingsItemRec(recId, recName, recording)); + RecordingsItemPtr recPtr (new RecordingsItemRec(m_recManPtr->Md5Hash(recording), recName, recording)); dir->m_entries.insert(pair< string, RecordingsItemPtr > (recName, recPtr)); // esyslog("DH: added rec: '%s'", recName.c_str()); } @@ -157,4 +175,19 @@ namespace vdrlive { return m_recording->start; } + RecordingsManagerPtr LiveRecordingsManager() + { + static weak_ptr livingRecMan; + + RecordingsManagerPtr r = livingRecMan.lock(); + if (r) { + return r; + } + else { + RecordingsManagerPtr n(new RecordingsManager); + livingRecMan = n; + return n; + } + } + } // namespace vdrlive diff --git a/recordings.h b/recordings.h index a8ea907..bf016a4 100644 --- a/recordings.h +++ b/recordings.h @@ -12,6 +12,27 @@ namespace vdrlive { using namespace boost; using namespace std; + class RecordingsManager; + typedef shared_ptr RecordingsManagerPtr; + + class RecordingsManager + { + friend RecordingsManagerPtr LiveRecordingsManager(); + + public: + /** + * generates a Md5 hash from a cRecording entry. It can be used + * to reidentify a recording. + */ + string Md5Hash(const cRecording* recording) const; + + private: + RecordingsManager(); + + cThreadLock m_recordingsLock; + }; + + class RecordingsTree { public: @@ -54,7 +75,7 @@ namespace vdrlive { virtual time_t StartTime() const { return 0; } virtual bool IsDir() const { return true; } - virtual const string Id() const { return ""; } + virtual const string Id() const { string e; return e; } private: int m_level; @@ -79,7 +100,7 @@ namespace vdrlive { string m_id; }; - RecordingsTree(); + RecordingsTree(RecordingsManagerPtr recManPtr); virtual ~RecordingsTree(); @@ -91,11 +112,20 @@ namespace vdrlive { private: int m_maxLevel; RecordingsItemPtr m_root; - cThreadLock m_recordingsLock; + RecordingsManagerPtr m_recManPtr; Map::iterator findDir(RecordingsItemPtr& dir, const string& dirname); }; + /** + * return singleton instance of RecordingsManager as a shared Pointer. + * This ensures that after last use of the RecordingsManager it is + * deleted. After deletion of the original RecordingsManager a repeated + * call to this function creates a new RecordingsManager which is again + * kept alive as long references to it exist. + */ + RecordingsManagerPtr LiveRecordingsManager(); + } // namespace vdrlive #endif // VDR_LIVE_RECORDINGS_H -- cgit v1.2.3