OSDN Git Service

_tunerCount/_tuners をコピーして使うように変更
authorosx86_pt1 <rmitachi@ta2.so-net.ne.jp>
Tue, 15 Mar 2016 14:03:08 +0000 (23:03 +0900)
committerosx86_pt1 <rmitachi@ta2.so-net.ne.jp>
Tue, 15 Mar 2016 14:03:08 +0000 (23:03 +0900)
iPTd_R2.sdf
src/Raym/Object.h
src/ry0/iPTd/Controller.h
src/ry0/iPTd/HTTPD.cpp
src/ry0/iPTd/HTTPD.h
src/ry0/iPTd/Reservation.cpp
src/ry0/iPTd/Reservation.h
src/ry0/iPTd/Streaming.cpp
src/ry0/iPTd/Streaming.h

index a20447a..79d493b 100644 (file)
Binary files a/iPTd_R2.sdf and b/iPTd_R2.sdf differ
index 0c39a12..ae60093 100644 (file)
@@ -146,7 +146,7 @@ inline void RaymUnlock(Object *obj)
 #endif\r
 }\r
 \r
-#define RaymCriticalSection(OBJ, BLOCK) RaymLock(OBJ); BLOCK; RaymUnlock(OBJ);\r
+//#define RaymCriticalSection(OBJ, BLOCK) RaymLock(OBJ); BLOCK; RaymUnlock(OBJ);\r
 \r
 } // Raym\r
 \r
index afa6df4..eccf530 100644 (file)
@@ -6,7 +6,7 @@
 #pragma once\r
 \r
 \r
-#include <Raym/Raym.h>\r
+#include "Raym/Raym.h"\r
 \r
 #include "keys.h"\r
 #include "ry0/device/TunerFactory.h"\r
index 99b4bce..e69a686 100644 (file)
@@ -22,18 +22,18 @@ namespace iPTd
 \r
 HTTPD::HTTPD()\r
 {\r
-    _controller = NULL;\r
-    _httpd      = NULL;\r
-    _port       = -1;\r
-    _path       = NULL;\r
+    _controller  = NULL;\r
+    _tuner_count = -1;\r
+    _tuners      = NULL;\r
+    _httpd       = NULL;\r
+    _port        = -1;\r
+    _path        = NULL;\r
 }\r
 \r
 HTTPD::~HTTPD()\r
 {\r
     RELEASE(_httpd);\r
     RELEASE(_path);\r
-\r
-    _controller = NULL;\r
 }\r
 \r
 HTTPD *HTTPD::alloc()\r
@@ -43,9 +43,12 @@ HTTPD *HTTPD::alloc()
 \r
 HTTPD *HTTPD::initWithController(Controller *controller, int port, String *path)\r
 {\r
-    _controller = controller;\r
-    _port = port;\r
-    _path = path->retain();\r
+    _controller  = controller;\r
+    _tuner_count = controller->_tunerCount;\r
+    _tuners      = controller->_tuners;\r
+\r
+    _port        = port;\r
+    _path        = path->retain();\r
 \r
     return this;\r
 }\r
@@ -90,17 +93,15 @@ HTTPResponse *HTTPD::request(HTTPRequest *request, SOCKADDR_IN *client)
         DebugLog0("request: %s\n", uri->cString());\r
         if (uri->isMatch("^/config.xml$"))\r
         {\r
-            RaymCriticalSection(_controller,\r
-            {\r
-                response = responseWithDictionary(request, _controller->_props);\r
-            });\r
+            RaymLock(_controller);\r
+            response = responseWithDictionary(request, _controller->_props);\r
+            RaymUnlock(_controller);\r
         }\r
         else if (uri->isMatch("^/status.xml$"))\r
         {\r
-            RaymCriticalSection(_controller,\r
-            {\r
-                response = responseWithDictionary(request, _controller->_status);\r
-            });\r
+            RaymLock(_controller);\r
+            response = responseWithDictionary(request, _controller->_status);\r
+            RaymUnlock(_controller);\r
         }\r
         //\r
         // tuner control\r
@@ -110,7 +111,7 @@ HTTPResponse *HTTPD::request(HTTPRequest *request, SOCKADDR_IN *client)
             // String::substringWithRange() の実装は後回しなので。。\r
             std::string s = uri->cString();\r
             int tuner = atoi(s.substr(1, 3).c_str());\r
-            if ((0 <= tuner) && (tuner < _controller->_tunerCount))\r
+            if ((0 <= tuner) && (tuner < _tuner_count))\r
             {\r
                 response = requestTunerControl(request, client, tuner);\r
             }\r
@@ -236,7 +237,7 @@ HTTPResponse *HTTPD::requestTunerControl(HTTPRequest *request, SOCKADDR_IN *clie
             }\r
             else\r
             {\r
-                channel = _controller->_tuners[tuner]->channel();\r
+                channel = _tuners[tuner]->channel();\r
             }\r
 \r
             if (channel >= 0)\r
@@ -408,7 +409,7 @@ HTTPResponse *HTTPD::requestTunerControl(HTTPRequest *request, SOCKADDR_IN *clie
             }\r
             dst_addr.sin_port = htons(p_udp->intValue());\r
             \r
-            if (_controller->_tuners[tuner]->startStreaming(&dst_addr))\r
+            if (_tuners[tuner]->startStreaming(&dst_addr))\r
             {\r
                 // success\r
                 DebugLog2("success.\n");\r
@@ -480,7 +481,7 @@ HTTPResponse *HTTPD::requestTunerControl(HTTPRequest *request, SOCKADDR_IN *clie
             {\r
             }\r
 \r
-            _controller->_tuners[tuner]->stopStreaming();\r
+            _tuners[tuner]->stopStreaming();\r
             \r
             // success\r
             DebugLog2("success.\n");\r
index 8403df0..e2cd8bf 100644 (file)
@@ -6,6 +6,7 @@
 #pragma once\r
 \r
 #include "Raym/Raym.h"\r
+#include "ry0/device/Tuner.h"\r
 #include "net/HTTPDaemon.h"\r
 \r
 namespace ry0\r
@@ -19,10 +20,13 @@ class HTTPD : public Raym::Object,
               public NET::HTTPDaemonDelegate\r
 {\r
 private:\r
-    Controller *        _controller;\r
-    NET::HTTPDaemon *   _httpd;\r
-    int                 _port;\r
-    Raym::String *      _path;\r
+    Controller *            _controller;\r
+    int                     _tuner_count;\r
+    ry0::device::Tuner **   _tuners;\r
+\r
+    NET::HTTPDaemon *       _httpd;\r
+    int                     _port;\r
+    Raym::String *          _path;\r
 \r
 protected:\r
     HTTPD();\r
index dc00064..ee258b5 100644 (file)
@@ -31,6 +31,8 @@ static const time_t OFFSET_OF_SUPPRESSION_TIME  = -600;     // 録画開始前
 Reservation::Reservation()\r
 {\r
     _controller         = NULL;\r
+    _tuner_count        = -1;\r
+    _tuners             = NULL;\r
     _reservations_path  = NULL;\r
     _reservations       = NULL;\r
     _reservation_seq_id = -1;\r
@@ -38,7 +40,6 @@ Reservation::Reservation()
 \r
 Reservation::~Reservation()\r
 {\r
-    _controller = NULL;\r
     RELEASE(_reservations_path);\r
     RELEASE(_reservations);\r
 }\r
@@ -50,7 +51,9 @@ Reservation *Reservation::alloc()
 \r
 Reservation *Reservation::initWithController(Controller *controller)\r
 {\r
-    _controller = controller;\r
+    _controller  = controller;\r
+    _tuner_count = controller->_tunerCount;\r
+    _tuners      = controller->_tuners;\r
 \r
     _reservations_path = String::alloc()->initWithFormat("%s%s.iptd.reservations.plist", _controller->_system_path->cString(), Controller::_plist_prefix);\r
     if (_reservations_path == NULL)\r
@@ -75,11 +78,9 @@ Reservation *Reservation::initWithController(Controller *controller)
     {\r
         DebugLog1("reservations file: \"%s\"", _reservations_path->cString());\r
 \r
-        // 予約情報シーケンスID\r
         _reservation_seq_id = _reservations->integerForKey(KEY_EPG_LAST_RESV_ID);\r
     }\r
 \r
-    // 周期タイマ起動\r
     _timer_periodic = Timer::alloc()->initWithTimeInterval(1.0, this, NULL, true);\r
     if (_timer_periodic == NULL)\r
     {\r
@@ -99,9 +100,9 @@ bool Reservation::canTerminate()
     // 現在時刻取得\r
     time_t now = time(NULL);\r
 \r
-    for (int tuner = 0; tuner < _controller->_tunerCount; ++tuner)\r
+    for (int tuner = 0; tuner < _tuner_count; ++tuner)\r
     {\r
-        Array *array = _reservations->arrayForKey(_controller->_tuners[tuner]->name());\r
+        Array *array = _reservations->arrayForKey(_tuners[tuner]->name());\r
         if ((array == NULL) || (array->count() == 0))\r
         {\r
             // next tuner\r
@@ -137,7 +138,7 @@ bool Reservation::reserve(int tuner, Dictionary *in_epg)
     // lock\r
     RaymLock(_controller);\r
 \r
-    while ((0 <= tuner) && (tuner < _controller->_tunerCount) && (in_epg != NULL))\r
+    while ((0 <= tuner) && (tuner < _tuner_count) && (in_epg != NULL))\r
     {\r
         Dictionary *epg = Dictionary::dictionaryWithDictionary(in_epg);\r
         if (epg == NULL)\r
@@ -146,11 +147,11 @@ bool Reservation::reserve(int tuner, Dictionary *in_epg)
             break;\r
         }\r
 \r
-        Array *array = _reservations->arrayForKey(_controller->_tuners[tuner]->name());\r
+        Array *array = _reservations->arrayForKey(_tuners[tuner]->name());\r
         if (array == NULL)\r
         {\r
             array = Array::arrayWithCapacity(0);\r
-            _reservations->setObject(array, _controller->_tuners[tuner]->name());\r
+            _reservations->setObject(array, _tuners[tuner]->name());\r
         }\r
 \r
         time_t epg_start;\r
@@ -225,9 +226,9 @@ bool Reservation::cancel(int tuner, int reserve_id)
     RaymLock(_controller);\r
 \r
     //\r
-    if ((0 <= tuner) && (tuner < _controller->_tunerCount))\r
+    if ((0 <= tuner) && (tuner < _tuner_count))\r
     {\r
-        Array *array = _reservations->arrayForKey(_controller->_tuners[tuner]->name());\r
+        Array *array = _reservations->arrayForKey(_tuners[tuner]->name());\r
         if (array != NULL)\r
         {\r
             if (array->count() > 0)\r
@@ -249,9 +250,9 @@ bool Reservation::cancel(int tuner, int reserve_id)
     //\r
     else if ((tuner < 0) && (0 <= reserve_id) && (reserve_id < 1000000))\r
     {\r
-        for (int i = 0; i < _controller->_tunerCount; ++i)\r
+        for (int i = 0; i < _tuner_count; ++i)\r
         {\r
-            Array *array = _reservations->arrayForKey(_controller->_tuners[i]->name());\r
+            Array *array = _reservations->arrayForKey(_tuners[i]->name());\r
             if (array != NULL)\r
             {\r
                 for (uint j = 0; j < array->count(); ++j)\r
@@ -367,7 +368,7 @@ std::string Reservation::createVideoPath(int tuner)
         if (sprintf_s(tmp, sizeof(tmp),\r
                       "\\%04d%02d%02d_%02d%02d%02d_%03d_%s.ts",\r
                       tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,\r
-                      _controller->_tuners[tuner]->channel(), _controller->_tuners[tuner]->name()) < 0)\r
+                      _tuners[tuner]->channel(), _tuners[tuner]->name()) < 0)\r
         {\r
             DebugLog0("sprintf_s() error: filename");\r
             result = "";\r
@@ -399,9 +400,9 @@ void Reservation::timerExpired(Timer *timer, void *userInfo)
     DebugLog2("periodic: %d", now);\r
 \r
     //\r
-    for (int tuner = 0; tuner < _controller->_tunerCount; ++tuner)\r
+    for (int tuner = 0; tuner < _tuner_count; ++tuner)\r
     {\r
-        Array *array = _reservations->arrayForKey(_controller->_tuners[tuner]->name());\r
+        Array *array = _reservations->arrayForKey(_tuners[tuner]->name());\r
         if ((array == NULL) || (array->count() == 0))\r
         {\r
             // next tuner\r
@@ -442,7 +443,7 @@ void Reservation::timerExpired(Timer *timer, void *userInfo)
         if (stop_need)\r
         {\r
             DebugLog2("I try stop\n");\r
-            int fd = _controller->_tuners[tuner]->stopRecording();\r
+            int fd = _tuners[tuner]->stopRecording();\r
             if (fd < 0)\r
             {\r
                 DebugLog1("stopRecording() error.\n");\r
@@ -450,7 +451,7 @@ void Reservation::timerExpired(Timer *timer, void *userInfo)
             else\r
             {\r
                 DebugLog2("stopRecording() ok\n");\r
-                DebugLog0("stop recording of \"%s\"", _controller->_tuners[tuner]->name());\r
+                DebugLog0("stop recording of \"%s\"", _tuners[tuner]->name());\r
                 _close(fd);\r
             }\r
             array->removeObject(epg);\r
@@ -513,7 +514,7 @@ void Reservation::timerExpired(Timer *timer, void *userInfo)
                     {\r
                         DebugLog2("open ok.\n");\r
                         bool startResult = true;\r
-                        if (_controller->_tuners[tuner]->channel() != channel)\r
+                        if (_tuners[tuner]->channel() != channel)\r
                         {\r
                             if (!_controller->setChannel(tuner, channel))\r
                             {\r
@@ -524,10 +525,10 @@ void Reservation::timerExpired(Timer *timer, void *userInfo)
 \r
                         if (startResult)\r
                         {\r
-                            if (_controller->_tuners[tuner]->startRecording(fd))\r
+                            if (_tuners[tuner]->startRecording(fd))\r
                             {\r
                                 DebugLog2("startRecording() ok.");\r
-                                DebugLog0("start recording of \"%s\" to %s.", _controller->_tuners[tuner]->name(), videopath.c_str());\r
+                                DebugLog0("start recording of \"%s\" to %s.", _tuners[tuner]->name(), videopath.c_str());\r
                             }\r
                             else\r
                             {\r
index 96b51dc..e431e58 100644 (file)
@@ -5,7 +5,8 @@
 \r
 #pragma once\r
 \r
-#include <Raym/Raym.h>\r
+#include "Raym/Raym.h"\r
+#include "ry0/device/Tuner.h"\r
 \r
 namespace ry0\r
 {\r
@@ -16,14 +17,16 @@ class Controller;
 \r
 class Reservation : public Raym::Object,\r
                     public Raym::TimerDelegate\r
-\r
 {\r
 private:\r
-    Controller *        _controller;\r
-    Raym::String *      _reservations_path;\r
-    Raym::Dictionary *  _reservations;          // 予約情報\r
-    int                 _reservation_seq_id;    // 予約情報シーケンスID\r
-    Raym::Timer *       _timer_periodic;\r
+    Controller *            _controller;\r
+    int                     _tuner_count;\r
+    ry0::device::Tuner **   _tuners;\r
+\r
+    Raym::String *          _reservations_path;\r
+    Raym::Dictionary *      _reservations;\r
+    int                     _reservation_seq_id;\r
+    Raym::Timer *           _timer_periodic;\r
 \r
 \r
 protected:\r
index 5039930..56d5c71 100644 (file)
@@ -26,6 +26,8 @@ Streaming::Streaming()
     DebugLog2("%s", __FUNCTION__);\r
 \r
     _controller     = NULL;\r
+    _tuner_count    = -1;\r
+    _tuners         = NULL;\r
     _ctrls          = NULL;\r
     _timer_periodic = NULL;\r
 }\r
@@ -52,7 +54,9 @@ Streaming *Streaming::alloc()
 \r
 Streaming *Streaming::initWithController(Controller *controller)\r
 {\r
-    _controller = controller;\r
+    _controller  = controller;\r
+    _tuner_count = controller->_tunerCount;\r
+    _tuners      = controller->_tuners;\r
 \r
     // 制御情報\r
     _ctrls = Dictionary::alloc()->initWithCapacity(0);\r
@@ -100,7 +104,7 @@ void Streaming::mapping(int tuner, int channel, int port)
     tuner_channel_to_udp->setString(port_str, tuner_and_channel);\r
 }\r
 \r
-void Streaming::timerExpired(Timer *timer, void *userInfo)\r
+void Streaming::timerExpired(Timer *timer, void *user_info)\r
 {\r
     DebugLog2("%s", __FUNCTION__);\r
 \r
@@ -175,7 +179,7 @@ void Streaming::timerExpired(Timer *timer, void *userInfo)
 \r
                                             DebugLog0("auto streaming stop: %s", ((String *)using_ports->objectAtIndex(i))->cString());\r
 \r
-                                            _controller->_tuners[tuner]->stopStreaming();\r
+                                            _tuners[tuner]->stopStreaming();\r
                                             using_port->removeObjectForKey((String *)using_ports->objectAtIndex(i));\r
                                         }\r
                                     }\r
@@ -249,11 +253,11 @@ void Streaming::timerExpired(Timer *timer, void *userInfo)
                                     EnterCriticalSection(&_cs);\r
 \r
                                     // 非ストリーミング中 かつ 非レコーディング中 または チャンネルが同じ 場合\r
-                                    if (!_controller->_tuners[tuner]->isStreaming() && (!_controller->_tuners[tuner]->isRecording() || _controller->_tuners[tuner]->channel() == channel))\r
+                                    if (!_tuners[tuner]->isStreaming() && (!_tuners[tuner]->isRecording() || _tuners[tuner]->channel() == channel))\r
                                     {\r
                                         // ストリーミング開始可能\r
 \r
-                                        if (_controller->_tuners[tuner]->channel() != channel)\r
+                                        if (_tuners[tuner]->channel() != channel)\r
                                         {\r
                                             _controller->setChannel(tuner, channel);\r
                                         }\r
@@ -263,7 +267,7 @@ void Streaming::timerExpired(Timer *timer, void *userInfo)
                                         dst_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);\r
                                         dst_addr.sin_port = (WORD)udptable->table[i].dwLocalPort;\r
 \r
-                                        if (_controller->_tuners[tuner]->startStreaming(&dst_addr))\r
+                                        if (_tuners[tuner]->startStreaming(&dst_addr))\r
                                         {\r
                                             // 成功\r
                                             DebugLog0("auto streaming start: %d", ntohs((WORD)udptable->table[i].dwLocalPort));\r
index b84968b..44dcbaf 100644 (file)
@@ -5,7 +5,9 @@
 \r
 #pragma once\r
 \r
-#include <Raym/Raym.h>\r
+#include "Raym/Raym.h"\r
+#include "ry0/device/Tuner.h"\r
+\r
 \r
 namespace ry0\r
 {\r
@@ -18,9 +20,12 @@ class Streaming : public Raym::Object,
                   public Raym::TimerDelegate\r
 {\r
 private:\r
-    Controller *        _controller;\r
-    Raym::Dictionary *  _ctrls;           // 制御情報\r
-    Raym::Timer *       _timer_periodic;\r
+    Controller *           _controller;\r
+    int                    _tuner_count;\r
+    ry0::device::Tuner **  _tuners;\r
+\r
+    Raym::Dictionary *     _ctrls;\r
+    Raym::Timer *          _timer_periodic;\r
 \r
 protected:\r
     Streaming();\r
@@ -32,10 +37,8 @@ public:
 \r
     void mapping(int tuner, int channel, int port);\r
 \r
-    // タイマ満了IF (from Timer)\r
-    void timerExpired(Raym::Timer *timer, void *userInfo);\r
+    void timerExpired(Raym::Timer *timer, void *user_info);\r
 };\r
 \r
-\r
 } // iPTd\r
 } // ry0\r