]> git.sesse.net Git - casparcg/blobdiff - modules/bluefish/bluefish.cpp
more refinements to code due to move to RAII
[casparcg] / modules / bluefish / bluefish.cpp
index b9b027c44e23fab7e0e2086b6ff1ec3b34f3c975..cf50a7b2407e96c608c6ab9dc285328d283dd0b4 100644 (file)
@@ -1,84 +1,99 @@
-/*\r
-* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
-*\r
-*  This file is part of CasparCG.\r
-*\r
-*    CasparCG is free software: you can redistribute it and/or modify\r
-*    it under the terms of the GNU General Public License as published by\r
-*    the Free Software Foundation, either version 3 of the License, or\r
-*    (at your option) any later version.\r
-*\r
-*    CasparCG is distributed in the hope that it will be useful,\r
-*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-*    GNU General Public License for more details.\r
-\r
-*    You should have received a copy of the GNU General Public License\r
-*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
-*\r
-*/\r
-#include "bluefish.h"\r
-\r
-#include "util/blue_velvet.h"\r
-\r
-#include <core/consumer/frame_consumer.h>\r
-\r
-#include "consumer/bluefish_consumer.h"\r
-\r
-namespace caspar {\r
-\r
-void init_bluefish()\r
-{\r
-       try\r
-       {\r
-               blue_initialize();\r
-               core::register_consumer_factory([](const std::vector<std::wstring>& params)\r
-               {\r
-                       return create_bluefish_consumer(params);\r
-               });\r
-       }\r
-       catch(...)\r
-       {\r
-               CASPAR_LOG_CURRENT_EXCEPTION();\r
-               CASPAR_LOG(info) << L"Bluefish not supported.";\r
-       }\r
-}\r
-\r
-std::wstring get_bluefish_version()\r
-{\r
-       try\r
-       {\r
-               blue_initialize();\r
-       }\r
-       catch(...)\r
-       {\r
-               return L"Not found";\r
-       }\r
-\r
-       if(!BlueVelvetVersion)\r
-               return L"Unknown";\r
-\r
-       return widen(std::string(BlueVelvetVersion()));\r
-}\r
-\r
-std::vector<std::wstring> get_bluefish_device_list()\r
-{\r
-       std::vector<std::wstring> devices;\r
-\r
-       try\r
-       {               \r
-               blue_initialize();\r
-               \r
-               auto blue = create_blue();\r
-\r
-               for(int n = 1; BLUE_PASS(blue->device_attach(n, FALSE)); ++n)\r
-               {                               \r
-                       devices.push_back(std::wstring(get_card_desc(*blue)) + L" [" + boost::lexical_cast<std::wstring>(n) + L"]");\r
-                       blue->device_detach();          \r
-               }\r
-       }\r
-       catch(...){}\r
-\r
-       return devices;\r
-}\r
-}
\ No newline at end of file
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Robert Nagy, ronag89@gmail.com
+*/
+
+#include "StdAfx.h"
+
+#include "bluefish.h"
+
+#include "consumer/bluefish_consumer.h"
+
+#include "util/blue_velvet.h"
+
+#include <common/log.h>
+#include <common/utf.h>
+
+#include <core/consumer/frame_consumer.h>
+#include <core/system_info_provider.h>
+
+#include <boost/lexical_cast.hpp>
+#include <boost/property_tree/ptree.hpp>
+
+namespace caspar { namespace bluefish {
+
+std::wstring version()
+{
+       try
+       {
+               bvc_wrapper blue;
+               return u16(blue.get_version());
+       }
+       catch(...)
+       {
+               return L"Not found";
+       }
+}
+
+std::vector<std::wstring> device_list()
+{
+       std::vector<std::wstring> devices;
+
+       try
+       {               
+               bvc_wrapper blue;
+               int numCards = 0;
+               blue.enumerate(numCards);
+
+               for(int n = 1; n < (numCards+1); n++)
+               {                               
+                       blue.attach(n);
+                       devices.push_back(std::wstring(get_card_desc(blue, n)) + L" [" + boost::lexical_cast<std::wstring>(n) + L"]");  
+                       blue.detach();
+               }
+       }
+       catch(...){}
+
+       return devices;
+}
+
+void init(core::module_dependencies dependencies)
+{
+       try
+       {
+               bvc_wrapper blue;
+               int num_cards = 0;
+               blue.enumerate(num_cards);
+       }
+       catch(...){}
+
+       dependencies.consumer_registry->register_consumer_factory(L"Bluefish Consumer", create_consumer, describe_consumer);
+       dependencies.consumer_registry->register_preconfigured_consumer_factory(L"bluefish", create_preconfigured_consumer);
+       dependencies.system_info_provider_repo->register_system_info_provider([](boost::property_tree::wptree& info)
+       {
+               info.add(L"system.bluefish.version", version());
+
+               for (auto device : device_list())
+                       info.add(L"system.bluefish.device", device);
+       });
+
+}
+
+}}
+