diff options
author | Dieter Hametner <dh (plus) vdr (at) gekrumbel (dot) de> | 2007-01-17 01:15:59 +0000 |
---|---|---|
committer | Dieter Hametner <dh (plus) vdr (at) gekrumbel (dot) de> | 2007-01-17 01:15:59 +0000 |
commit | b6ebbd4df6a6a588692bd0e5e1bbd1d920aad3e1 (patch) | |
tree | 2c29c286acbd2fab9d520b9858c1da012b191e82 /recordings.cpp | |
parent | 14601674821ef51d93bff42759ac44d334946045 (diff) | |
download | vdr-plugin-live-b6ebbd4df6a6a588692bd0e5e1bbd1d920aad3e1.tar.gz vdr-plugin-live-b6ebbd4df6a6a588692bd0e5e1bbd1d920aad3e1.tar.bz2 |
- 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.
Diffstat (limited to 'recordings.cpp')
-rw-r--r-- | recordings.cpp | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/recordings.cpp b/recordings.cpp index f8c09d6..5d82a68 100644 --- a/recordings.cpp +++ b/recordings.cpp @@ -1,17 +1,37 @@ -#include <string> +#include <cstring> +#include <openssl/md5.h> #include <boost/shared_ptr.hpp> +#include <boost/weak_ptr.hpp> +#include <string> +#include <sstream> #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<const unsigned char*>(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<string, int>(++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<RecordingsManager> livingRecMan; + + RecordingsManagerPtr r = livingRecMan.lock(); + if (r) { + return r; + } + else { + RecordingsManagerPtr n(new RecordingsManager); + livingRecMan = n; + return n; + } + } + } // namespace vdrlive |