\r
#include <time.h>\r
\r
-#define DBG_LEVEL 3\r
+#define DBG_LEVEL 1\r
#include "Raym/Log.h"\r
\r
#include "b25/arib_std_b25.h"\r
\r
RaymUnlock(this);\r
\r
-#ifdef OBJC_MEMORY_CHECK\r
- DebugLog0("global_objc_count_ = %d", Raym::global_objc_count_);\r
+#ifdef RAYM_MEMORY_CHECK\r
+ DebugLog0("global_raym_count_ = %d", Raym::global_raym_count_);\r
#endif\r
DebugLog2("Controller::systemWillSuspend() end");\r
}\r
#pragma mark ------- プロパティ取得 -------\r
#endif\r
\r
+/*\r
+ *\r
+ */\r
bool Controller::isTunerInitialized(int tuner)\r
{\r
DebugLog2("Controller::isTunerInitialized()");\r
\r
bool result = false;\r
\r
+ RaymLock(this);\r
+\r
if ((0 <= tuner) && (tuner < _tuner_count))\r
{\r
- RaymLock(this);\r
-\r
Dictionary *tunersInfo = _props->dictionaryForKey(KEY_TUNERS);\r
if (tunersInfo != NULL)\r
{\r
result = tunerInfo->boolForKey(KEY_INITIALIZED);\r
}\r
}\r
-\r
- RaymUnlock(this);\r
}\r
\r
+ RaymUnlock(this);\r
+\r
return result;\r
}\r
\r
+/*\r
+ *\r
+ */\r
bool Controller::isTunerEnabled(int tuner)\r
{\r
DebugLog2("Controller::isTunerEnabled()");\r
\r
bool result = false;\r
\r
+ RaymLock(this);\r
+\r
if ((0 <= tuner) && (tuner < _tuner_count))\r
{\r
- // lock\r
- EnterCriticalSection(&_cs);\r
-\r
Dictionary *tunersInfo = _props->dictionaryForKey(KEY_TUNERS);\r
if (tunersInfo != NULL)\r
{\r
result = tunerInfo->boolForKey(KEY_ENABLED);\r
}\r
}\r
-\r
- // unlock\r
- LeaveCriticalSection(&_cs);\r
}\r
\r
+ RaymUnlock(this);\r
+\r
return result;\r
}\r
\r
+/*\r
+ *\r
+ */\r
bool Controller::isChannelEnabled(int tuner, int channel)\r
{\r
DebugLog2("Controller::isChannelEnabled()");\r
\r
bool result = false;\r
\r
+ RaymLock(this);\r
+\r
if ((0 <= tuner) && (tuner < _tuner_count) && (0 <= channel) && (channel <= Tuner::MAX_CHANNELS_ISDB_T))\r
{\r
- // lock\r
- EnterCriticalSection(&_cs);\r
-\r
Dictionary *tunersInfo = _props->dictionaryForKey(KEY_TUNERS);\r
if (tunersInfo != NULL)\r
{\r
}\r
}\r
}\r
-\r
- // unlock\r
- LeaveCriticalSection(&_cs);\r
}\r
\r
+ RaymUnlock(this);\r
+\r
return result;\r
}\r
\r
{\r
DebugLog2("Controller::scanChannel(%d)", tuner);\r
\r
+ RaymLock(this);\r
if ((tuner < 0) || (_tuner_count <= tuner))\r
{\r
+ RaymUnlock(this);\r
DebugLog3("Invalid tuner: %d", tuner);\r
return;\r
}\r
\r
+ DebugLog0("");\r
DebugLog0("start channel scan of \"%s\".", _tuners[tuner]->name());\r
\r
- // lock\r
- EnterCriticalSection(&_cs);\r
-\r
// 設定ファイルから全チューナ情報取得\r
Dictionary *tunersInfo = _props->dictionaryForKey(KEY_TUNERS);\r
if (tunersInfo == NULL)\r
tunerInfo->setBool(false, KEY_INITIALIZED);\r
\r
// unlock\r
- LeaveCriticalSection(&_cs);\r
+ RaymUnlock(this);\r
\r
// 全チャンネル情報を作成\r
Dictionary *channels = Dictionary::dictionaryWithCapacity(0);\r
// チャンネルIDを設定\r
channelInfo->setString(channelID, KEY_CHANNEL_ID);\r
\r
- // lock\r
- EnterCriticalSection(&_cs);\r
+ RaymLock(this);\r
\r
// チャンネル設定\r
if (_tuners[tuner]->setChannel(ch))\r
DebugLog0(" CH %s: NG", chkey);\r
}\r
\r
- // unlock\r
- LeaveCriticalSection(&_cs);\r
+ RaymUnlock(this);\r
}\r
\r
- // lock\r
- EnterCriticalSection(&_cs);\r
+ RaymLock(this);\r
\r
// チューナを初期化済みに更新\r
tunerInfo->setBool(true, KEY_INITIALIZED);\r
// 設定ファイルを更新\r
_props->writeToFile(_props_path, true);\r
\r
- // unlock\r
- LeaveCriticalSection(&_cs);\r
+ RaymUnlock(this);\r
}\r
\r
+/*\r
+ *\r
+ */\r
int Controller::getChannel(int tuner)\r
{\r
DebugLog2("Controller::getChannel()");\r
\r
int channel = -1;\r
\r
+ RaymLock(this);\r
+\r
if ((0 <= tuner) && (tuner < _tuner_count))\r
{\r
- // lock\r
- EnterCriticalSection(&_cs);\r
-\r
Dictionary *tunersInfo = _status->dictionaryForKey(KEY_TUNERS);\r
if (tunersInfo != NULL)\r
{\r
channel = tunerInfo->integerForKey(KEY_CHANNEL);\r
}\r
}\r
-\r
- // unlock\r
- LeaveCriticalSection(&_cs);\r
}\r
\r
+ RaymUnlock(this);\r
+\r
return channel;\r
}\r
\r
+/*\r
+ *\r
+ */\r
bool Controller::setChannel(int tuner, int channel)\r
{\r
DebugLog2("Controller::setChannel()");\r
\r
bool result = false;\r
\r
+ RaymLock(this);\r
+\r
if ((0 <= tuner) && (tuner < _tuner_count))\r
{\r
- // lock\r
- EnterCriticalSection(&_cs);\r
-\r
if (!_tuners[tuner]->isLocked())\r
{\r
Dictionary *tunersInfo = _status->dictionaryForKey(KEY_TUNERS);\r
\r
result = true;\r
}\r
- else\r
- {\r
- DebugLog0("set channel failed. %d, %d", tuner, channel);\r
- }\r
}\r
}\r
-\r
- // unlock\r
- LeaveCriticalSection(&_cs);\r
}\r
\r
+ RaymUnlock(this);\r
+\r
return result;\r
}\r
\r
{\r
// 初期化成功\r
DebugLog2("tuner initialize success.");\r
-#if 0\r
- // EPG収集用タイマ起動(ISDB-S)\r
- _timer_epg_s = NSTimer::alloc()->initWithTimeInterval(DEF_COLLECT_EPG_DELAY, this, (void *)CMD_COLLECT_EPG_ISDB_S, true);\r
- if (_timer_epg_s != NULL)\r
- {\r
- _timer_epg_s->fire();\r
- }\r
-\r
- // EPG収集用タイマ起動(ISDB-T)\r
- _timer_epg_t = NSTimer::alloc()->initWithTimeInterval(DEF_COLLECT_EPG_DELAY, this, (void *)CMD_COLLECT_EPG_ISDB_T, true);\r
- if (_timer_epg_t != NULL)\r
- {\r
- _timer_epg_t->fire();\r
- }\r
-#endif\r
}\r
else\r
{\r
suspend();\r
}\r
break;\r
-\r
- case CMD_PERIODIC: // 周期処理\r
- periodic();\r
- break;\r
-\r
- case CMD_PERIODIC_2: // 周期処理2\r
- periodic_2();\r
- break;\r
-\r
- case CMD_COLLECT_EPG_ISDB_S: // EPG収集(ISDB-S)\r
- // 番組情報収集(ISDB-S)\r
- if (collectEPGs(Tuner::ISDB_S))\r
- {\r
- // 終了(繰り返し無し)\r
- _timer_epg_s->setRepeats(false);\r
- }\r
- else\r
- {\r
- // リトライ\r
- _timer_epg_s->setTimeInterval(DEF_COLLECT_EPG_RETRY);\r
- }\r
- break;\r
-\r
- case CMD_COLLECT_EPG_ISDB_T: // 番組情報収集(ISDB-T)\r
- if (collectEPGs(Tuner::ISDB_T))\r
- {\r
- // 終了(繰り返し無し)\r
- _timer_epg_t->setRepeats(false);\r
- }\r
- else\r
- {\r
- // リトライ\r
- _timer_epg_t->setTimeInterval(DEF_COLLECT_EPG_RETRY);\r
- }\r
- break;\r
#endif\r
}\r
}\r
}\r
}\r
\r
- // UDPポートマッピング\r
- DebugLog0(" UDP Port Mapping :");\r
- DebugLog0(" tuner, ch -> port");\r
+ DebugLog0("");\r
+ DebugLog0("UDP Port Mapping");\r
+ DebugLog0(" Tuner, CH -> Port");\r
int udpport = _props->integerForKey(KEY_BEGIN_UDP_PORT);\r
for (int tuner = 0; tuner < _tuner_count; ++tuner)\r
{\r
{\r
if (isChannelEnabled(tuner, ch))\r
{\r
- DebugLog0(" %5d,%3d -> %5d", tuner, ch, udpport);\r
+ DebugLog0(" %5d,%3d -> %5d", tuner, ch, udpport);\r
_streaming->mapping(tuner, ch, udpport++);\r
}\r
}\r
}\r
\r
+ _reservation->systemResumed();\r
+\r
RaymLock(this);\r
_initialized = true;\r
RaymUnlock(this);\r
DebugLog0("iPTd ver %s (rev.%d)", VERSION, REVISION);\r
DebugLog0("initialize...");\r
\r
+ HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());\r
+ if (hProcess != NULL)\r
+ {\r
+ if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS) == FALSE)\r
+ {\r
+ DebugLog0("SetPriorityClass failed.");\r
+ }\r
+ CloseHandle(hProcess);\r
+ }\r
+\r
int result = 0;\r
\r
// 初期化\r
_system_path = String::stringWithFormat("%s", GetExecutePath());\r
if (_system_path == NULL)\r
{\r
- DebugLog0("error: GetExecutePath()\n");\r
+ DebugLog0("error: GetExecutePath()");\r
result = -1;\r
break;\r
}\r
_system_path = _system_path->stringByReplacingOccurrencesOfString("iPTd.exe", "");\r
_system_path->retain();\r
- DebugLog2("_system_path: %s\n", _system_path->cString());\r
+ DebugLog1("system path: %s", _system_path->cString());\r
\r
// プロパティファイルのパス設定\r
_props_path = String::alloc()->initWithFormat("%s%s.iptd.plist", _system_path->cString(), _plist_prefix);\r
if (_props_path == NULL)\r
{\r
- DebugLog0("error: set property file path.\n");\r
+ DebugLog0("error: set property file path.");\r
result = -1;\r
break;\r
}\r
_props = Dictionary::alloc()->initWithContentsOfFile(_props_path);\r
if (_props == NULL)\r
{\r
- DebugLog1("because \"%s\" is not exists, created.\n", _props_path->cString());\r
+ DebugLog1("property file: %s (created)", _props_path->cString());\r
_props = Dictionary::alloc()->initWithCapacity(0);\r
}\r
else\r
{\r
- DebugLog1("property file: \"%s\"\n", _props_path->cString());\r
+ DebugLog1("property file: %s", _props_path->cString());\r
}\r
\r
// ステータスファイルのパス設定\r
_status_path = String::alloc()->initWithFormat("%s%s.iptd.status.plist", _system_path->cString(), _plist_prefix);\r
if (_status_path == NULL)\r
{\r
- DebugLog0("error: set status file path.\n");\r
+ DebugLog0("error: set status file path.");\r
result = -1;\r
break;\r
}\r
_status = Dictionary::alloc()->initWithContentsOfFile(_status_path);\r
if (_status == NULL)\r
{\r
- DebugLog1("because \"%s\" is not exists, created.\n", _status_path->cString());\r
+ DebugLog1("status file: %s (created)", _status_path->cString());\r
_status = Dictionary::alloc()->initWithCapacity(0);\r
}\r
else\r
{\r
- DebugLog1("status file: \"%s\"\n", _status_path->cString());\r
+ DebugLog1("status file: %s", _status_path->cString());\r
}\r
\r
// システム名\r
result = -1;\r
break;\r
}\r
- _props->setString(String::alloc()->initWithFormat("%s\\Videos", public_dir), KEY_STORE_PATH);\r
+ _props->setString(String::stringWithFormat("%s\\Videos", public_dir), KEY_STORE_PATH);\r
\r
// 更新フラグ\r
updated = true;\r
break;\r
}\r
\r
- //\r
- _streaming = Streaming::alloc()->initWithController(this);\r
- if (_streaming == NULL)\r
- {\r
- result = -1;\r
- break;\r
- }\r
-\r
// httpdのルートパス\r
String *rootPath = _system_path->stringByAppendingPathComponent("html");\r
isDir = false;\r
*/\r
}\r
\r
- //\r
- _httpd = HTTPD::alloc()->initWithController(this, _props->integerForKey(KEY_HTTP_PORT), rootPath);\r
- if (_httpd == NULL)\r
- {\r
- result = -1;\r
- break;\r
- }\r
-\r
-\r
// プロパティファイルを保存\r
if (updated)\r
{\r
}\r
}\r
\r
+\r
+ //\r
+ _streaming = Streaming::alloc()->initWithController(this);\r
+ if (_streaming == NULL)\r
+ {\r
+ result = -1;\r
+ break;\r
+ }\r
+\r
+ //\r
+ _httpd = HTTPD::alloc()->initWithController(this, _props->integerForKey(KEY_HTTP_PORT), rootPath);\r
+ if (_httpd == NULL)\r
+ {\r
+ result = -1;\r
+ break;\r
+ }\r
+\r
if (!_httpd->start())\r
{\r
DebugLog0("Can't start httpd.");\r
break;\r
}\r
\r
-\r
// 再開タイマ起動\r
_timer_restart = Timer::alloc()->initWithTimeInterval(1.0, this, (void *)CMD_RESTART, false);\r
_timer_restart->fire();\r
Reservation::Reservation()\r
{\r
_controller = NULL;\r
- _tuner_count = -1;\r
_tuners = NULL;\r
_reservations_path = NULL;\r
_reservations = NULL;\r
Reservation *Reservation::initWithController(Controller *controller)\r
{\r
_controller = controller;\r
- _tuner_count = controller->_tuner_count;\r
_tuners = controller->_tuners;\r
\r
_reservations_path = String::alloc()->initWithFormat("%s%s.iptd.reservations.plist", _controller->_system_path->cString(), Controller::_plist_prefix);\r
_reservations = Dictionary::alloc()->initWithContentsOfFile(_reservations_path);\r
if (_reservations == NULL)\r
{\r
- DebugLog1("because \"%s\" is not exists, created.", _reservations_path->cString());\r
+ DebugLog1("reservations file: %s (created)", _reservations_path->cString());\r
_reservations = Dictionary::alloc()->initWithCapacity(0);\r
if (_reservations == NULL)\r
{\r
}\r
else\r
{\r
- DebugLog1("reservations file: \"%s\"", _reservations_path->cString());\r
+ DebugLog1("reservations file: %s", _reservations_path->cString());\r
\r
_reservation_seq_id = _reservations->integerForKey(KEY_EPG_LAST_RESV_ID);\r
}\r
_epgs = Dictionary::alloc()->initWithContentsOfFile(_epgs_path);\r
if (_epgs == NULL)\r
{\r
- DebugLog1("because \"%s\" is not exists, created.", _epgs_path->cString());\r
+ DebugLog1("epgs file: %s (created)", _epgs_path->cString());\r
_epgs = Dictionary::alloc()->initWithCapacity(0);\r
if (_epgs == NULL)\r
{\r
}\r
else\r
{\r
- DebugLog1("epgs file: \"%s\"", _epgs_path->cString());\r
+ DebugLog1("epgs file: %s", _epgs_path->cString());\r
\r
// 過去の番組データは削除\r
removePastEPGs();\r
\r
time_t now = time(NULL);\r
\r
- for (int tuner = 0; tuner < _tuner_count; ++tuner)\r
+ for (int tuner = 0; tuner < _controller->_tuner_count; ++tuner)\r
{\r
Array *array = _reservations->arrayForKey(_tuners[tuner]->name());\r
if ((array == NULL) || (array->count() == 0))\r
\r
void Reservation::systemResumed()\r
{\r
+ DebugLog2("%s", __FUNCTION__);\r
+\r
RaymLock(_controller);\r
\r
_cancel_epg_collect = false;\r
// lock\r
RaymLock(_controller);\r
\r
- while ((0 <= tuner) && (tuner < _tuner_count) && (in_epg != NULL))\r
+ while ((0 <= tuner) && (tuner < _controller->_tuner_count) && (in_epg != NULL))\r
{\r
Dictionary *epg = Dictionary::dictionaryWithDictionary(in_epg);\r
if (epg == NULL)\r
RaymLock(_controller);\r
\r
//\r
- if ((0 <= tuner) && (tuner < _tuner_count))\r
+ if ((0 <= tuner) && (tuner < _controller->_tuner_count))\r
{\r
Array *array = _reservations->arrayForKey(_tuners[tuner]->name());\r
if (array != NULL)\r
//\r
else if ((tuner < 0) && (0 <= reserve_id) && (reserve_id < 1000000))\r
{\r
- for (int i = 0; i < _tuner_count; ++i)\r
+ for (int i = 0; i < _controller->_tuner_count; ++i)\r
{\r
Array *array = _reservations->arrayForKey(_tuners[i]->name());\r
if (array != NULL)\r
}\r
\r
// 録画予約をチェック\r
- for (int tuner = 0; tuner < _tuner_count; ++tuner)\r
+ for (int tuner = 0; tuner < _controller->_tuner_count; ++tuner)\r
{\r
Array *array = _reservations->arrayForKey(_tuners[tuner]->name());\r
if ((array == NULL) || (array->count() == 0))\r
// 既にロックされた状態でコールされる前提\r
bool locked = false;\r
RaymLock(_controller);\r
- if ((0 <= tuner) && (tuner < _tuner_count))\r
+ if ((0 <= tuner) && (tuner < _controller->_tuner_count))\r
{\r
locked = _tuners[tuner]->isLocked();\r
}\r
int tuner = 0;\r
bool locked = false;\r
RaymLock(_controller);\r
- for (int i = _tuner_count - 1; i >= 0; --i)\r
+ for (int i = _controller->_tuner_count - 1; i >= 0; --i)\r
{\r
if (_controller->isTunerEnabled(i))\r
{\r
// ロック確認\r
if (!locked)\r
{\r
- DebugLog0("Controller::collectEPGs(%s) end(Can't locled).", type == Tuner::ISDB_S ? "ISDB-S" : "ISDB-T");\r
+ DebugLog0("Controller::collectEPGs(%s) end(Can't locked).", type == Tuner::ISDB_S ? "ISDB-S" : "ISDB-T");\r
// ロックできない場合は収集しない\r
return false;\r
}\r
bool need_update = false;\r
\r
#ifdef RAYM_MEMORY_CHECK\r
- DebugLog0("global_objc_count_ = %d", Raym::global_raym_count_);\r
+// DebugLog0("global_objc_count_ = %d", Raym::global_raym_count_);\r
#endif\r
\r
// lock\r
// 現在時刻取得\r
time_t now = time(NULL);\r
\r
- DebugLog2("periodic: %d", now);\r
+// DebugLog2("periodic: %d", now);\r
\r
//\r
- for (int tuner = 0; tuner < _tuner_count; ++tuner)\r
+ for (int tuner = 0; tuner < _controller->_tuner_count; ++tuner)\r
{\r
Array *array = _reservations->arrayForKey(_tuners[tuner]->name());\r
if ((array == NULL) || (array->count() == 0))\r
_reservations->writeToFile(_reservations_path, true);\r
}\r
\r
-#if 0\r
// EPG収集時刻を取得\r
- NSString *collect_str = _props->stringForKey(KEY_COLLECT_EPG_TIME);\r
+ String *collect_str = _controller->_props->stringForKey(KEY_COLLECT_EPG_TIME);\r
if (collect_str != NULL)\r
{\r
// 秒に変換\r
time_t collect_time = 0;\r
- getTimeWithString(collect_str, &collect_time);\r
+ Controller::getTimeWithString(collect_str, &collect_time);\r
\r
// 現在時刻と比較\r
if ((collect_time <= now) && (now < collect_time + 1))\r
{\r
// EPG収集用タイマ起動(ISDB-S)\r
RELEASE(_timer_epg_s);\r
- _timer_epg_s = NSTimer::alloc()->initWithTimeInterval(DEF_COLLECT_EPG_DELAY, this, (void *)CMD_COLLECT_EPG_ISDB_S, true);\r
+ _timer_epg_s = Timer::alloc()->initWithTimeInterval(DEF_COLLECT_EPG_DELAY, this, (void *)CMD_COLLECT_EPG_ISDB_S, true);\r
if (_timer_epg_s != NULL)\r
{\r
_timer_epg_s->fire();\r
{\r
// EPG収集用タイマ起動(ISDB-T)\r
RELEASE(_timer_epg_t);\r
- _timer_epg_t = NSTimer::alloc()->initWithTimeInterval(DEF_COLLECT_EPG_DELAY, this, (void *)CMD_COLLECT_EPG_ISDB_T, true);\r
+ _timer_epg_t = Timer::alloc()->initWithTimeInterval(DEF_COLLECT_EPG_DELAY, this, (void *)CMD_COLLECT_EPG_ISDB_T, true);\r
if (_timer_epg_t != NULL)\r
{\r
_timer_epg_t->fire();\r
}\r
}\r
}\r
-#endif\r
\r
// unlock\r
RaymUnlock(_controller);\r
_timer_periodic->setTimeInterval(1.005 - interval);\r
\r
#ifdef RAYM_MEMORY_CHECK\r
- DebugLog0("global_objc_count_ = %d", Raym::global_raym_count_);\r
+// DebugLog0("global_objc_count_ = %d", Raym::global_raym_count_);\r
#endif\r
}\r
\r