OSDN Git Service

httpd 2
authorosx86_pt1 <rmitachi@ta2.so-net.ne.jp>
Mon, 7 Mar 2016 13:42:40 +0000 (22:42 +0900)
committerosx86_pt1 <rmitachi@ta2.so-net.ne.jp>
Mon, 7 Mar 2016 13:42:40 +0000 (22:42 +0900)
iPTd/iPTd.vcxproj
iPTd/iPTd.vcxproj.filters
iPTd_R2.sdf
src/ry0/iPTd/Controller.cpp
src/ry0/iPTd/Controller.h
src/ry0/iPTd/HTTPDaemon.cpp [deleted file]
src/ry0/iPTd/HTTPDaemon.h [deleted file]

index 49f3bdb..63cafe2 100644 (file)
       <GenerateDebugInformation>true</GenerateDebugInformation>\r
       <EnableCOMDATFolding>true</EnableCOMDATFolding>\r
       <OptimizeReferences>true</OptimizeReferences>\r
-      <AdditionalDependencies>ws2_32.lib;libxml2.lib;GlobalHook.lib;ARIB.lib;PT1.lib;PT3.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
+      <AdditionalDependencies>ws2_32.lib;Iphlpapi.lib;libxml2.lib;GlobalHook.lib;ARIB.lib;PT1.lib;PT3.lib;%(AdditionalDependencies)</AdditionalDependencies>\r
     </Link>\r
   </ItemDefinitionGroup>\r
   <ItemGroup>\r
     <ClInclude Include="..\src\mpeg2\ts\PMT.h" />\r
     <ClInclude Include="..\src\mpeg2\ts\SDT.h" />\r
     <ClInclude Include="..\src\mpeg2\ts\Table.h" />\r
+    <ClInclude Include="..\src\net\HTTPDaemon.h" />\r
+    <ClInclude Include="..\src\net\HTTPRequest.h" />\r
+    <ClInclude Include="..\src\net\HTTPResponse.h" />\r
+    <ClInclude Include="..\src\net\InternetTextMessage.h" />\r
+    <ClInclude Include="..\src\net\InternetTextMessageBody.h" />\r
+    <ClInclude Include="..\src\net\InternetTextMessageHeader.h" />\r
     <ClInclude Include="..\src\Raym\Application.h" />\r
     <ClInclude Include="..\src\Raym\Array.h" />\r
     <ClInclude Include="..\src\Raym\AutoreleasePool.h" />\r
     <ClInclude Include="..\src\Raym\Workspace.h" />\r
     <ClInclude Include="..\src\ry0\device\TunerFactory.h" />\r
     <ClInclude Include="..\src\ry0\iPTd\Controller.h" />\r
+    <ClInclude Include="..\src\ry0\iPTd\HTTPD.h" />\r
     <ClInclude Include="..\src\ry0\iPTd\Reservation.h" />\r
+    <ClInclude Include="..\src\ry0\iPTd\Streaming.h" />\r
     <ClInclude Include="iPTd.h" />\r
     <ClInclude Include="Resource.h" />\r
     <ClInclude Include="stdafx.h" />\r
     <ClCompile Include="..\src\mpeg2\ts\PMT.cpp" />\r
     <ClCompile Include="..\src\mpeg2\ts\SDT.cpp" />\r
     <ClCompile Include="..\src\mpeg2\ts\Table.cpp" />\r
+    <ClCompile Include="..\src\net\HTTPDaemon.cpp" />\r
+    <ClCompile Include="..\src\net\HTTPRequest.cpp" />\r
+    <ClCompile Include="..\src\net\HTTPResponse.cpp" />\r
+    <ClCompile Include="..\src\net\InternetTextMessage.cpp" />\r
+    <ClCompile Include="..\src\net\InternetTextMessageBody.cpp" />\r
+    <ClCompile Include="..\src\net\InternetTextMessageHeader.cpp" />\r
     <ClCompile Include="..\src\Raym\Application.cpp" />\r
     <ClCompile Include="..\src\Raym\Array.cpp" />\r
     <ClCompile Include="..\src\Raym\AutoreleasePool.cpp" />\r
     <ClCompile Include="..\src\Raym\Workspace.cpp" />\r
     <ClCompile Include="..\src\ry0\device\TunerFactory.cpp" />\r
     <ClCompile Include="..\src\ry0\iPTd\Controller.cpp" />\r
+    <ClCompile Include="..\src\ry0\iPTd\HTTPD.cpp" />\r
     <ClCompile Include="..\src\ry0\iPTd\Reservation.cpp" />\r
+    <ClCompile Include="..\src\ry0\iPTd\Streaming.cpp" />\r
     <ClCompile Include="iPTd.cpp" />\r
     <ClCompile Include="stdafx.cpp">\r
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>\r
index 04ed51f..0f6a348 100644 (file)
@@ -31,6 +31,9 @@
     <Filter Include="ソース ファイル\ry0\device">\r
       <UniqueIdentifier>{c9cb6401-8b98-4bbc-85c7-a76e677bab31}</UniqueIdentifier>\r
     </Filter>\r
+    <Filter Include="ソース ファイル\net">\r
+      <UniqueIdentifier>{74b5304d-6c0d-408c-85ac-31b815138d79}</UniqueIdentifier>\r
+    </Filter>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <Text Include="ReadMe.txt" />\r
     <ClInclude Include="..\src\ry0\iPTd\Reservation.h">\r
       <Filter>ソース ファイル\ry0\iPTd</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="..\src\ry0\iPTd\Streaming.h">\r
+      <Filter>ソース ファイル\ry0\iPTd</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\src\ry0\iPTd\HTTPD.h">\r
+      <Filter>ソース ファイル\ry0\iPTd</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\src\net\HTTPDaemon.h">\r
+      <Filter>ソース ファイル\net</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\src\net\HTTPRequest.h">\r
+      <Filter>ソース ファイル\net</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\src\net\HTTPResponse.h">\r
+      <Filter>ソース ファイル\net</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\src\net\InternetTextMessage.h">\r
+      <Filter>ソース ファイル\net</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\src\net\InternetTextMessageBody.h">\r
+      <Filter>ソース ファイル\net</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\src\net\InternetTextMessageHeader.h">\r
+      <Filter>ソース ファイル\net</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClCompile Include="stdafx.cpp">\r
     <ClCompile Include="..\src\ry0\iPTd\Reservation.cpp">\r
       <Filter>ソース ファイル\ry0\iPTd</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\src\ry0\iPTd\Streaming.cpp">\r
+      <Filter>ソース ファイル\ry0\iPTd</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\src\ry0\iPTd\HTTPD.cpp">\r
+      <Filter>ソース ファイル\ry0\iPTd</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\src\net\HTTPDaemon.cpp">\r
+      <Filter>ソース ファイル\net</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\src\net\HTTPRequest.cpp">\r
+      <Filter>ソース ファイル\net</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\src\net\HTTPResponse.cpp">\r
+      <Filter>ソース ファイル\net</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\src\net\InternetTextMessage.cpp">\r
+      <Filter>ソース ファイル\net</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\src\net\InternetTextMessageBody.cpp">\r
+      <Filter>ソース ファイル\net</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="..\src\net\InternetTextMessageHeader.cpp">\r
+      <Filter>ソース ファイル\net</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ResourceCompile Include="iPTd.rc">\r
index 026bf11..739f897 100644 (file)
Binary files a/iPTd_R2.sdf and b/iPTd_R2.sdf differ
index 1ba28e2..4b1f21e 100644 (file)
@@ -62,12 +62,12 @@ Controller::Controller()
 {\r
     DebugLog3("%s", __FUNCTION__);\r
 \r
-    InitializeCriticalSection(&_cs);\r
+//    InitializeCriticalSection(&_cs);\r
 }\r
 \r
 Controller::~Controller()\r
 {\r
-    DeleteCriticalSection(&_cs);\r
+//    DeleteCriticalSection(&_cs);\r
 \r
     DebugLog3("%s", __FUNCTION__);\r
 }\r
@@ -398,6 +398,44 @@ bool Controller::isTunerEnabled(int tuner)
     return result;\r
 }\r
 \r
+bool Controller::isChannelEnabled(int tuner, int channel)\r
+{\r
+    DebugLog2("Controller::isChannelEnabled()");\r
+\r
+    bool result = false;\r
+\r
+    if ((0 <= tuner) && (tuner < _tunerCount) && (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
+            Dictionary *tunerInfo = tunersInfo->dictionaryForKey(_tuners[tuner]->name());\r
+            if (tunerInfo != NULL)\r
+            {\r
+                Dictionary *channels = tunerInfo->dictionaryForKey(KEY_CHANNELS);\r
+                if (channels != NULL)\r
+                {\r
+                    char key[4];\r
+                    sprintf_s(key, "%03d", channel);\r
+                    Dictionary *chInfo = channels->dictionaryForKey(key);\r
+                    if (chInfo != NULL)\r
+                    {\r
+                        result = chInfo->boolForKey(KEY_ENABLED);\r
+                    }\r
+                }\r
+            }\r
+        }\r
+\r
+        // unlock\r
+        LeaveCriticalSection(&_cs);\r
+    }\r
+\r
+    return result;\r
+}\r
+\r
 #ifndef _WIN32\r
 #pragma mark '\r
 #pragma mark ------- チューナ制御 -------\r
@@ -900,56 +938,27 @@ int Controller::restart()
         }\r
     }\r
 \r
-#if 0\r
     // UDPポートマッピング\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 < _tunerCount; ++tuner)\r
     {\r
-        uint max_channel = (_tuners[tuner]->type() == Tuner::ISDB_S ? Tuner::MAX_CHANNELS_ISDB_S : Tuner::MAX_CHANNELS_ISDB_T);\r
-        for (uint ch = 0; ch <= max_channel; ++ch)\r
+        int max_channel = (_tuners[tuner]->type() == Tuner::ISDB_S ? Tuner::MAX_CHANNELS_ISDB_S : Tuner::MAX_CHANNELS_ISDB_T);\r
+        for (int ch = 0; ch <= max_channel; ++ch)\r
         {\r
             if (isChannelEnabled(tuner, ch))\r
             {\r
                 DebugLog0("    %5d,%3d -> %5d", tuner, ch, udpport);\r
-\r
-                Dictionary *udp_to_tuner_channel = _streaming_ctrls->dictionaryForKey(KEY_MAPPING_UDP_TO_TUNER_CHANNEL);\r
-                if (udp_to_tuner_channel == NULL)\r
-                {\r
-                    udp_to_tuner_channel = Dictionary::dictionaryWithCapacity(0);\r
-                    _streaming_ctrls->setObject(udp_to_tuner_channel, KEY_MAPPING_UDP_TO_TUNER_CHANNEL);\r
-                }\r
-\r
-                Dictionary *tuner_channel_to_udp = _streaming_ctrls->dictionaryForKey(KEY_MAPPING_TUNER_CHANNEL_TO_UDP);\r
-                if (tuner_channel_to_udp == NULL)\r
-                {\r
-                    tuner_channel_to_udp = NSDictionary::dictionaryWithCapacity(0);\r
-                    _streaming_ctrls->setObject(tuner_channel_to_udp, KEY_MAPPING_TUNER_CHANNEL_TO_UDP);\r
-                }\r
-\r
-                char port_str[10];\r
-                sprintf_s(port_str, "%d", udpport);\r
-                char tuner_and_channel[10];\r
-                sprintf_s(tuner_and_channel, "%d,%d", tuner, ch);\r
-\r
-                udp_to_tuner_channel->setString(tuner_and_channel, port_str);\r
-                tuner_channel_to_udp->setString(port_str, tuner_and_channel);\r
-\r
-                ++udpport;\r
+                _streaming->mapping(tuner, ch, udpport++);\r
             }\r
         }\r
     }\r
-#endif\r
 \r
 #if 0\r
     // 周期タイマ起動\r
     _timer_periodic = Timer::alloc()->initWithTimeInterval(1.0, this, (void *)CMD_PERIODIC, true);\r
     _timer_periodic->fire();\r
-\r
-    // 周期タイマ2起動\r
-    _timer_periodic_2 = Timer::alloc()->initWithTimeInterval(1.0, this, (void *)CMD_PERIODIC_2, true);\r
-    _timer_periodic_2->fire();\r
 #endif\r
 \r
     // lock\r
@@ -979,7 +988,6 @@ int Controller::start()
     _epgs_path          = NULL;\r
     _epgs               = NULL;\r
     _store_path         = NULL;\r
-    _reservation        = NULL;\r
 \r
     _timer_restart      = NULL;\r
     _timer_periodic     = NULL;\r
@@ -995,6 +1003,9 @@ int Controller::start()
 \r
     _cancel_epg_collect = false;\r
 \r
+    _reservation        = NULL;\r
+    _streaming          = NULL;\r
+    _httpd              = NULL;\r
 \r
     _tunerCount = 0;\r
     for (int i = 0; i < ry0::device::MAX_TUNERS; ++i)\r
@@ -1195,6 +1206,29 @@ int Controller::start()
         //\r
         _reservation = Reservation::alloc()->initWithController(this, String::stringWithFormat("%s%s.iptd.reservations.plist", _system_path->cString(), PLIST_PREFIX));\r
 \r
+        //\r
+        _streaming = Streaming::alloc()->initWithController(this);\r
+\r
+        // httpdのルートパス\r
+        String *rootPath = _system_path->stringByAppendingPathComponent("html");\r
+        FileManager *fm = FileManager::defaultManager();\r
+        bool isDir = false;\r
+        if (!fm->fileExistsAtPath(rootPath, &isDir))\r
+        {\r
+            isDir = false;\r
+        }\r
+        if (!isDir)\r
+        {\r
+/*\r
+            DebugLog0("error: \"%s\" is not exists.", rootPath->cString());\r
+            result = -1;\r
+            break;\r
+*/\r
+        }\r
+\r
+        //\r
+        _httpd = HTTPDaemon::alloc()->initWithController(this, _props->integerForKey(KEY_HTTP_PORT), rootPath);\r
+\r
 \r
         // プロパティファイルを保存\r
         if (updated)\r
@@ -1224,6 +1258,13 @@ int Controller::start()
             }\r
         }\r
 \r
+        if (!_httpd->start())\r
+        {\r
+            DebugLog0("Can't start httpd.");\r
+            result = -1;\r
+            break;\r
+        }\r
+\r
 \r
         // 再開タイマ起動\r
         _timer_restart = Timer::alloc()->initWithTimeInterval(1.0, this, (void *)CMD_RESTART, false);\r
@@ -1239,7 +1280,7 @@ int Controller::start()
         result = Application::start();\r
 \r
         // httpd終了待ち\r
-//        _httpd->stop();\r
+        _httpd->stop();\r
     }\r
 \r
 \r
@@ -1289,8 +1330,6 @@ int Controller::start()
     RELEASE(_timer_epg_t);\r
     RELEASE(_timer_periodic);\r
     RELEASE(_timer_periodic_2);\r
-//    RELEASE(_streaming_ctrls);\r
-//    RELEASE(_httpd);\r
     RELEASE(_system_path);\r
     RELEASE(_props_path);\r
     RELEASE(_props);\r
@@ -1299,7 +1338,10 @@ int Controller::start()
     RELEASE(_epgs_path);\r
     RELEASE(_epgs);\r
     RELEASE(_store_path);\r
+\r
     RELEASE(_reservation);\r
+    RELEASE(_streaming);\r
+    RELEASE(_httpd);\r
 \r
     if (_multi2_dll != NULL)\r
     {\r
index 68ddd68..2f8a5c5 100644 (file)
@@ -12,6 +12,8 @@
 #include "ry0/device/TunerFactory.h"\r
 \r
 #include "ry0/iPTd/Reservation.h"\r
+#include "ry0/iPTd/Streaming.h"\r
+#include "ry0/iPTd/HTTPD.h"\r
 \r
 #define VERSION "1.00"\r
 #define REVISION 3\r
@@ -30,7 +32,7 @@ class Controller : public Raym::Application,
                    public Raym::TimerDelegate\r
 {\r
 private:\r
-    CRITICAL_SECTION    _cs;\r
+//    CRITICAL_SECTION    _cs;\r
 \r
     Raym::String *      _system_path;           // システムパス(実行ファイルが配置されているディレクトリ)\r
     Raym::String *      _props_path;            // プロパティファイルのパス\r
@@ -40,7 +42,6 @@ private:
     Raym::String *      _epgs_path;             // 番組データファイルのパス\r
     Raym::Dictionary *  _epgs;                  // 番組データ\r
     Raym::String *      _store_path;            // 録画データ格納先\r
-    Reservation *       _reservation;           // 予約情報制御\r
     int                 _idle_count;            // アイドルカウンタ\r
 \r
     // 非同期処理用タイマ\r
@@ -50,13 +51,14 @@ private:
     Raym::Timer *       _timer_epg_s;           // EPG(ISDB-S)収集用\r
     Raym::Timer *       _timer_epg_t;           // EPG(ISDB-T)収集用\r
 \r
-//    Raym::Dictionary *      _streaming_ctrls;       // ストリーミング制御情報格納用\r
+    Reservation *       _reservation;           // 予約録画制御\r
+    Streaming *         _streaming;             // ストリーミング制御\r
+    HTTPDaemon *        _httpd;                 // HTTP制御\r
 \r
     bool                            _initialized;           // 初期化済み\r
     HMODULE                         _multi2_dll;\r
     bool                            _cancel_epg_collect;    // EPG収集キャンセル\r
 \r
-//    NET::HTTPDaemon *               _httpd;\r
 \r
 public:\r
     int                             _tunerCount;\r
diff --git a/src/ry0/iPTd/HTTPDaemon.cpp b/src/ry0/iPTd/HTTPDaemon.cpp
deleted file mode 100644 (file)
index a0ddae9..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/**\r
- * @file HTTPDaemon.cpp\r
- *\r
- */\r
-\r
-#include <time.h>\r
-\r
-#define DBG_LEVEL 3\r
-#include "Raym/Log.h"\r
-\r
-#include "keys.h"\r
-#include "ry0/iPTd/HTTPDaemon.h"\r
-#include "ry0/iPTd/Controller.h"\r
-\r
-using namespace Raym;\r
-\r
-namespace ry0\r
-{\r
-namespace iPTd\r
-{\r
-\r
-HTTPDaemon::HTTPDaemon()\r
-{\r
-    _controller         = NULL;\r
-}\r
-\r
-HTTPDaemon::~HTTPDaemon()\r
-{\r
-    _controller = NULL;\r
-}\r
-\r
-HTTPDaemon *HTTPDaemon::alloc()\r
-{\r
-    return new HTTPDaemon();\r
-}\r
-\r
-HTTPDaemon *HTTPDaemon::initWithController(Controller *controller)\r
-{\r
-    _controller = controller;\r
-\r
-    return this;\r
-}\r
-\r
-} // iPTd\r
-} // ry0\r
diff --git a/src/ry0/iPTd/HTTPDaemon.h b/src/ry0/iPTd/HTTPDaemon.h
deleted file mode 100644 (file)
index 7614ec4..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/**\r
- * @file HTTPDaemon.h\r
- *\r
- */\r
-\r
-#pragma once\r
-\r
-#include <Raym/Raym.h>\r
-\r
-namespace ry0\r
-{\r
-namespace iPTd\r
-{\r
-\r
-class Controller;\r
-\r
-class HTTPDaemon : public Raym::Object\r
-{\r
-private:\r
-    Controller *        _controller;\r
-\r
-protected:\r
-    HTTPDaemon();\r
-    ~HTTPDaemon();\r
-\r
-public:\r
-    static HTTPDaemon *alloc();\r
-    HTTPDaemon *initWithController(Controller *controller);\r
-};\r
-\r
-\r
-} // iPTd\r
-} // ry0\r