]> git.sesse.net Git - casparcg/commitdiff
Added RESTART AMCP command and batch file to perform the relaunch
authorHelge Norberg <helge.norberg@svt.se>
Wed, 17 Apr 2013 12:19:05 +0000 (14:19 +0200)
committerHelge Norberg <helge.norberg@svt.se>
Wed, 17 Apr 2013 12:19:05 +0000 (14:19 +0200)
Start via casarcg_auto_restart.bat to make the RESTART command work as expected

#112

protocol/amcp/AMCPCommandsImpl.cpp
protocol/amcp/AMCPCommandsImpl.h
protocol/amcp/AMCPProtocolStrategy.cpp
shell/casparcg_auto_restart.bat [new file with mode: 0644]
shell/main.cpp
shell/shell.vcxproj
shell/shell.vcxproj.filters

index 32d0e7afc326d7b8775d10ef00863ba8747a4326..77bda2f9071cfe965590acdb381f5f4518efef80 100644 (file)
@@ -1823,7 +1823,13 @@ bool SetCommand::DoExecute()
 \r
 bool KillCommand::DoExecute()\r
 {\r
-       GetShutdownServerNow().set_value(false); // False for not waiting until a key is pressed before terminating.\r
+       GetShutdownServerNow().set_value(false); // False for not attempting to restart.\r
+       return true;\r
+}\r
+\r
+bool RestartCommand::DoExecute()\r
+{\r
+       GetShutdownServerNow().set_value(true); // True for attempting to restart\r
        return true;\r
 }\r
 \r
index 37c4f2c5dec7601c19b585eee65f2e41dda5205b..7986cc5912863a45967c662361b51444b4e0b6c1 100644 (file)
@@ -211,6 +211,12 @@ class KillCommand : public AMCPCommandBase<false, AddToQueue, 0>
        bool DoExecute();\r
 };\r
 \r
+class RestartCommand : public AMCPCommandBase<false, AddToQueue, 0>\r
+{\r
+       std::wstring print() const { return L"RestartCommand";}\r
+       bool DoExecute();\r
+};\r
+\r
 }      //namespace amcp\r
 }}     //namespace caspar\r
 \r
index 4398459695271037fabb85eecb2118833334e8e6..ae39ace463af317e6f7cbef0c19b5831be34b557 100644 (file)
@@ -338,6 +338,7 @@ AMCPCommandPtr AMCPProtocolStrategy::CommandFactory(const std::wstring& str)
        //      result = AMCPCommandPtr(new MonitorCommand());\r
        //}\r
        else if(s == TEXT("KILL"))                      return std::make_shared<KillCommand>();\r
+       else if(s == TEXT("RESTART"))           return std::make_shared<RestartCommand>();\r
        return nullptr;\r
 }\r
 \r
diff --git a/shell/casparcg_auto_restart.bat b/shell/casparcg_auto_restart.bat
new file mode 100644 (file)
index 0000000..0fac00b
--- /dev/null
@@ -0,0 +1,5 @@
+@Echo off
+:Start
+casparcg.exe
+
+if ERRORLEVEL 5 goto :Start
index de925251b8210c0357361570d68c833c90b2e0c7..8487f3dc46428493332c84eff95bf2752837fd9b 100644 (file)
@@ -232,6 +232,7 @@ int main(int argc, wchar_t* argv[])
                }\r
        } tbb_thread_installer;\r
 \r
+       bool restart = false;\r
        tbb::task_scheduler_init init;\r
        \r
        try \r
@@ -260,7 +261,8 @@ int main(int argc, wchar_t* argv[])
                boost::property_tree::xml_writer_settings<wchar_t> w(' ', 3);\r
                boost::property_tree::write_xml(str, caspar::env::properties(), w);\r
                CASPAR_LOG(info) << L"casparcg.config:\n-----------------------------------------\n" << str.str().c_str() << L"-----------------------------------------";\r
-               bool wait_for_keypress;\r
+               tbb::atomic<bool> wait_for_keypress;\r
+               wait_for_keypress = false;\r
 \r
                {\r
                        boost::promise<bool> shutdown_server_now;\r
@@ -268,11 +270,10 @@ int main(int argc, wchar_t* argv[])
 \r
                        // Create server object which initializes channels, protocols and controllers.\r
                        caspar::server caspar_server(shutdown_server_now);\r
-                       \r
 \r
                        // Use separate thread for the blocking console input, will be terminated \r
                        // anyway when the main thread terminates.\r
-                       boost::thread stdin_thread([&caspar_server, &shutdown_server_now]\r
+                       boost::thread stdin_thread([&caspar_server, &shutdown_server_now, &wait_for_keypress]\r
                        {\r
                                // Create a amcp parser for console commands.\r
                                caspar::protocol::amcp::AMCPProtocolStrategy amcp(\r
@@ -293,7 +294,8 @@ int main(int argc, wchar_t* argv[])
 \r
                                        if(upper_cmd == L"EXIT" || upper_cmd == L"Q" || upper_cmd == L"QUIT" || upper_cmd == L"BYE")\r
                                        {\r
-                                               shutdown_server_now.set_value(true); // True to wait for keypress\r
+                                               wait_for_keypress = true;\r
+                                               shutdown_server_now.set_value(false); // False to not restart server\r
                                                break;\r
                                        }\r
                                \r
@@ -358,7 +360,7 @@ int main(int argc, wchar_t* argv[])
                                }       \r
                        });\r
                        stdin_thread.detach();\r
-                       wait_for_keypress = shutdown_server.get();\r
+                       restart = shutdown_server.get();\r
                }\r
                Sleep(500);\r
                CASPAR_LOG(info) << "Successfully shutdown CasparCG Server.";\r
@@ -381,5 +383,5 @@ int main(int argc, wchar_t* argv[])
                Sleep(4000);\r
        }       \r
        \r
-       return 0;\r
+       return restart ? 5 : 0;\r
 }
\ No newline at end of file
index 21d8c075f340792ea1864d170b641ba96a80b746..18bb39c9bd41d8a8fd9be900ce1afce9d3820758 100644 (file)
@@ -65,6 +65,7 @@
       <SubType>Designer</SubType>\r
     </None>\r
     <None Include="CasparCG.ico" />\r
+    <None Include="casparcg_auto_restart.bat" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="server.h" />\r
@@ -205,7 +206,8 @@ copy "$(SolutionDir)dependencies\tbb\bin\ia32\vc10\*.dll" "$(OutDir)"
 copy "$(SolutionDir)dependencies\zlib\*.dll" "$(OutDir)"\r
 copy "$(SolutionDir)dependencies\SFML-1.6\lib\*.dll" "$(OutDir)"\r
 copy "$(SolutionDir)dependencies\SFML-1.6\extlibs\bin\*.dll" "$(OutDir)"\r
-copy "$(ProjectDir)casparcg.config" "$(OutDir)"</Command>\r
+copy "$(ProjectDir)casparcg.config" "$(OutDir)"\r
+copy "$(ProjectDir)casparcg_auto_restart.bat" "$(OutDir)"</Command>\r
     </PostBuildEvent>\r
   </ItemDefinitionGroup>\r
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
@@ -267,7 +269,8 @@ copy "$(SolutionDir)dependencies\tbb\bin\ia32\vc10\*.dll" "$(OutDir)"
 copy "$(SolutionDir)dependencies\zlib\*.dll" "$(OutDir)"\r
 copy "$(SolutionDir)dependencies\SFML-1.6\lib\*.dll" "$(OutDir)"\r
 copy "$(SolutionDir)dependencies\SFML-1.6\extlibs\bin\*.dll" "$(OutDir)"\r
-copy "$(ProjectDir)casparcg.config" "$(OutDir)"</Command>\r
+copy "$(ProjectDir)casparcg.config" "$(OutDir)"\r
+copy "$(ProjectDir)casparcg_auto_restart.bat" "$(OutDir)"</Command>\r
     </PostBuildEvent>\r
   </ItemDefinitionGroup>\r
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">\r
@@ -328,7 +331,8 @@ copy "$(SolutionDir)dependencies\tbb\bin\ia32\vc10\*.dll" "$(OutDir)"
 copy "$(SolutionDir)dependencies\zlib\*.dll" "$(OutDir)"\r
 copy "$(SolutionDir)dependencies\SFML-1.6\lib\*.dll" "$(OutDir)"\r
 copy "$(SolutionDir)dependencies\SFML-1.6\extlibs\bin\*.dll" "$(OutDir)"\r
-copy "$(ProjectDir)casparcg.config" "$(OutDir)"</Command>\r
+copy "$(ProjectDir)casparcg.config" "$(OutDir)"\r
+copy "$(ProjectDir)casparcg_auto_restart.bat" "$(OutDir)"</Command>\r
     </PostBuildEvent>\r
   </ItemDefinitionGroup>\r
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">\r
@@ -389,7 +393,8 @@ copy "$(SolutionDir)dependencies\tbb\bin\ia32\vc10\*.dll" "$(OutDir)"
 copy "$(SolutionDir)dependencies\zlib\*.dll" "$(OutDir)"\r
 copy "$(SolutionDir)dependencies\SFML-1.6\lib\*.dll" "$(OutDir)"\r
 copy "$(SolutionDir)dependencies\SFML-1.6\extlibs\bin\*.dll" "$(OutDir)"\r
-copy "$(ProjectDir)casparcg.config" "$(OutDir)"</Command>\r
+copy "$(ProjectDir)casparcg.config" "$(OutDir)"\r
+copy "$(ProjectDir)casparcg_auto_restart.bat" "$(OutDir)"</Command>\r
     </PostBuildEvent>\r
   </ItemDefinitionGroup>\r
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
index 9208de209c6ee3e73b66d040029d07beb555b078..afd009a62c29ad2a4422241913a062df8c7eb9fa 100644 (file)
@@ -11,6 +11,7 @@
   <ItemGroup>\r
     <None Include="casparcg.config" />\r
     <None Include="CasparCG.ico" />\r
+    <None Include="casparcg_auto_restart.bat" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="server.h">\r