svvitch
digital signage player
|
00001 #include "Container.h" 00002 00003 00004 Container::Container(Renderer& renderer): Content(renderer, 0), _initialized(true) { 00005 } 00006 00007 Container::‾Container() { 00008 initialize(); 00009 } 00010 00011 void Container::initialize() { 00012 _initialized = true; 00013 vector<ContentPtr> list; 00014 { 00015 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00016 list.swap(_list); 00017 } 00018 int count = 0; 00019 for (vector<ContentPtr>::iterator it = list.begin(); it != list.end(); it++) SAFE_DELETE(*it);count++; 00020 // _log.information(Poco::format("Container::initialize() %d", count)); 00021 } 00022 00023 void Container::add(ContentPtr c) { 00024 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00025 _list.push_back(c); 00026 c->set("itemNo", _list.size()); 00027 _initialized = false; 00028 } 00029 00030 ContentPtr Container::get(int i) { 00031 if (_initialized) return NULL; 00032 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00033 if (!_initialized) { 00034 try { 00035 return _list.at(i); 00036 } catch (std::out_of_range& ex) { 00037 } 00038 } 00039 return NULL; 00040 } 00041 00042 int Container::size() { 00043 return _list.size(); 00044 } 00045 00046 ContentPtr Container::operator[](int i) { 00047 if (_initialized) return NULL; 00048 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00049 return get(i); 00050 } 00051 00052 const string Container::opened() { 00053 if (_initialized) return ""; 00054 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00055 string mediaID; 00056 for (vector<ContentPtr>::const_iterator it = _list.begin(); it != _list.end(); it++) { 00057 string id = (*it)->opened(); 00058 if (id.empty()) return ""; 00059 if (mediaID.empty()) mediaID = id; 00060 } 00061 return mediaID; 00062 } 00063 00064 void Container::play() { 00065 // Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00066 for (vector<ContentPtr>::iterator it = _list.begin(); it != _list.end(); it++) (*it)->play(); 00067 } 00068 00069 void Container::pause() { 00070 // Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00071 for (vector<ContentPtr>::iterator it = _list.begin(); it != _list.end(); it++) (*it)->pause(); 00072 } 00073 00074 void Container::stop() { 00075 // Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00076 for (vector<ContentPtr>::iterator it = _list.begin(); it != _list.end(); it++) (*it)->stop(); 00077 } 00078 00079 bool Container::useFastStop() { 00080 // Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00081 bool useFastStop = false; 00082 for (vector<ContentPtr>::iterator it = _list.begin(); it != _list.end(); it++) useFastStop |= (*it)->useFastStop(); 00083 return useFastStop; 00084 } 00085 00086 void Container::rewind() { 00087 // Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00088 for (vector<ContentPtr>::iterator it = _list.begin(); it != _list.end(); it++) (*it)->rewind(); 00089 } 00090 00091 const bool Container::finished() { 00092 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00093 bool finished = true; 00094 for (vector<ContentPtr>::iterator it = _list.begin(); it != _list.end(); it++) { 00095 finished &= (*it)->finished(); 00096 } 00097 return finished; 00098 } 00099 00100 void Container::notifyKey(const int keycode, const bool shift, const bool ctrl) { 00101 if (!_initialized) { 00102 for (vector<ContentPtr>::iterator it = _list.begin(); it != _list.end(); it++) (*it)->notifyKey(keycode, shift, ctrl); 00103 } 00104 } 00105 00106 void Container::process(const DWORD& frame) { 00107 if (!_initialized) { 00108 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00109 for (vector<ContentPtr>::iterator it = _list.begin(); it != _list.end(); it++) (*it)->process(frame); 00110 } 00111 } 00112 00113 void Container::draw(const DWORD& frame) { 00114 if (!_initialized) { 00115 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00116 for (vector<ContentPtr>::iterator it = _list.begin(); it != _list.end(); it++) (*it)->draw(frame); 00117 } 00118 } 00119 00120 void Container::preview(const DWORD& frame) { 00121 if (!_initialized) { 00122 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00123 for (vector<ContentPtr>::iterator it = _list.begin(); it != _list.end(); it++) (*it)->preview(frame); 00124 } 00125 } 00126 00127 const int Container::current() { 00128 if (!_initialized) { 00129 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00130 if (!_list.empty()) { 00131 return _list.at(0)->current(); 00132 } 00133 } 00134 return 0; 00135 } 00136 00137 const int Container::duration() { 00138 if (!_initialized) { 00139 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00140 if (!_list.empty()) { 00141 return _list.at(0)->duration(); 00142 } 00143 } 00144 return 0; 00145 } 00146 00147 void Container::setProperty(const string& key, const string& value) { 00148 Poco::ScopedLock<Poco::FastMutex> lock(_lock); 00149 for (vector<ContentPtr>::iterator it = _list.begin(); it != _list.end(); it++) (*it)->set(key, value); 00150 }