]> git.sesse.net Git - casparcg/commitdiff
Merged from trunk
authorhellgore <hellgore@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 14 Jun 2012 17:31:18 +0000 (17:31 +0000)
committerhellgore <hellgore@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 14 Jun 2012 17:31:18 +0000 (17:31 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.1.0@3115 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

common/log.cpp
common/log.h
protocol/amcp/AMCPProtocolStrategy.cpp
protocol/cii/CIIProtocolStrategy.cpp
protocol/util/ClientInfo.h
shell/main.cpp

index 8c055d652d22a5b0bfdb81445c761788e370e94a..f47e2a996fa9c997e58f3045ff42dd205bf4d3b9 100644 (file)
@@ -36,6 +36,7 @@
 #include <string>\r
 #include <ostream>\r
 \r
+#include <boost/bind.hpp>\r
 #include <boost/shared_ptr.hpp>\r
 #include <boost/make_shared.hpp>\r
 #include <boost/filesystem/convenience.hpp>\r
@@ -72,21 +73,7 @@ namespace caspar { namespace log {
 \r
 using namespace boost;\r
 \r
-template<typename T>\r
-inline void replace_nonprintable(std::basic_string<T, std::char_traits<T>, std::allocator<T>>& str, T with)\r
-{\r
-       std::locale loc;\r
-       std::replace_if(str.begin(), str.end(), [&](T c)->bool { return !std::isprint(c, loc) && c != '\r' && c != '\n'; }, with);\r
-}\r
-\r
-template<typename T>\r
-inline std::basic_string<T> replace_nonprintable_copy(std::basic_string<T, std::char_traits<T>, std::allocator<T>> str, T with)\r
-{\r
-       replace_nonprintable(str, with);\r
-       return str;\r
-}\r
-\r
-void my_formatter(std::wostream& strm, boost::log::basic_record<wchar_t> const& rec)\r
+void my_formatter(bool print_all_characters, std::wostream& strm, boost::log::basic_record<wchar_t> const& rec)\r
 {\r
     namespace lambda = boost::lambda;\r
        \r
@@ -113,7 +100,14 @@ void my_formatter(std::wostream& strm, boost::log::basic_record<wchar_t> const&
                        strm << L" ";\r
        }\r
 \r
-    strm << replace_nonprintable_copy(rec.message(), L'?');\r
+       if (print_all_characters)\r
+       {\r
+               strm << rec.message();\r
+       }\r
+       else\r
+       {\r
+           strm << replace_nonprintable_copy(rec.message(), L'?');\r
+       }\r
 }\r
 \r
 namespace internal{\r
@@ -139,7 +133,7 @@ void init()
 //     stream_sink->set_filter(boost::log::filters::attr<severity_level>(boost::log::sources::aux::severity_attribute_name<wchar_t>::get()) >= debug);\r
 //#endif\r
 \r
-       stream_sink->locked_backend()->set_formatter(&my_formatter);\r
+       stream_sink->locked_backend()->set_formatter(boost::bind(my_formatter, false, _1, _2));\r
 \r
        boost::log::wcore::get()->add_sink(stream_sink);\r
 }\r
@@ -209,7 +203,7 @@ void add_file_sink(const std::wstring& folder)
                        boost::log::keywords::open_mode = std::ios::app\r
                );\r
                \r
-               file_sink->locked_backend()->set_formatter(&my_formatter);\r
+               file_sink->locked_backend()->set_formatter(boost::bind(my_formatter, true, _1, _2));\r
 \r
 //#ifdef NDEBUG\r
 //             file_sink->set_filter(boost::log::filters::attr<severity_level>(boost::log::sources::aux::severity_attribute_name<wchar_t>::get()) >= debug);\r
index eb6dfbef4576c7a357ec15200a01eec2350d3d60..2b2dd13a4e544a5895519092f3059867b72e2e3c 100644 (file)
@@ -46,6 +46,26 @@ void init();
 std::wstring get_call_stack();\r
 }\r
 \r
+template<typename T>\r
+inline void replace_nonprintable(std::basic_string<T, std::char_traits<T>, std::allocator<T>>& str, T with)\r
+{\r
+       std::locale loc;\r
+       std::replace_if(str.begin(), str.end(), [&](T c)->bool {\r
+               return \r
+                       (!std::isprint(c, loc) \r
+                       && c != '\r' \r
+                       && c != '\n')\r
+                       || c > static_cast<T>(127);\r
+       }, with);\r
+}\r
+\r
+template<typename T>\r
+inline std::basic_string<T> replace_nonprintable_copy(std::basic_string<T, std::char_traits<T>, std::allocator<T>> str, T with)\r
+{\r
+       replace_nonprintable(str, with);\r
+       return str;\r
+}\r
+\r
 void add_file_sink(const std::wstring& folder);\r
 \r
 enum severity_level\r
index caf440e29aa79a40c2c624c65776555f8ea39629..c4d02f7c44a71d992d2cce243642c258691f9fde 100644 (file)
@@ -112,7 +112,7 @@ void AMCPProtocolStrategy::Parse(const TCHAR* pData, int charCount, ClientInfoPt
 \r
 void AMCPProtocolStrategy::ProcessMessage(const std::wstring& message, ClientInfoPtr& pClientInfo)\r
 {      \r
-       CASPAR_LOG(info) << L"Received message from " << pClientInfo->print() << ": " << message + L"\\r\\n";\r
+       CASPAR_LOG(info) << L"Received message from " << pClientInfo->print() << ": " << message << L"\\r\\n";\r
        \r
        bool bError = true;\r
        MessageParserState state = New;\r
index bf312cb16b710642ef52609aa6aea3377a238244..46c8d337e3a5e6ffec678beabc6bfe3c7e640f95 100644 (file)
@@ -85,7 +85,7 @@ void CIIProtocolStrategy::Parse(const TCHAR* pData, int charCount, IO::ClientInf
 \r
 void CIIProtocolStrategy::ProcessMessage(const std::wstring& message, IO::ClientInfoPtr pClientInfo)\r
 {      \r
-       CASPAR_LOG(info) << L"Received message from " << pClientInfo->print() << ": " << message + L"\\r\\n";\r
+       CASPAR_LOG(info) << L"Received message from " << pClientInfo->print() << ": " << message << L"\\r\\n";\r
 \r
        std::vector<std::wstring> tokens;\r
        int tokenCount = TokenizeMessage(message, &tokens);\r
index c7fd4285dad8f6db200f428dece2a54ea06cd235..0b6412ffacaf76e6ef478f48e29809f7bfdd6a5f 100644 (file)
@@ -25,6 +25,8 @@
 #include <string>\r
 #include <iostream>\r
 \r
+#include <common/log.h>\r
+\r
 namespace caspar { namespace IO {\r
 \r
 class ClientInfo \r
@@ -47,7 +49,7 @@ struct ConsoleClientInfo : public caspar::IO::ClientInfo
 {\r
        void Send(const std::wstring& data)\r
        {\r
-               std::wcout << (L"#" + data);\r
+               std::wcout << (L"#" + caspar::log::replace_nonprintable_copy(data, L'?'));\r
        }\r
        void Disconnect(){}\r
        virtual std::wstring print() const {return L"Console";}\r
index f9e827305259949c6d32282e2a362bc8878a0bd1..6f07d1d173d47ec15de5704a670bc2e5798fdc3e 100644 (file)
@@ -65,6 +65,7 @@
 #include <boost/property_tree/detail/file_parser_error.hpp>\r
 #include <boost/property_tree/xml_parser.hpp>\r
 #include <boost/foreach.hpp>\r
+#include <boost/locale.hpp>\r
 \r
 #include <signal.h>\r
 \r
@@ -83,6 +84,14 @@ void change_icon( const HICON hNewIcon )
    ::FreeLibrary(hMod);\r
 }\r
 \r
+void setup_global_locale()\r
+{\r
+       boost::locale::generator gen;\r
+       gen.categories(boost::locale::codepage_facet);\r
+\r
+       std::locale::global(gen(""));\r
+}\r
+\r
 void setup_console_window()\r
 {       \r
        auto hOut = GetStdHandle(STD_OUTPUT_HANDLE);\r
@@ -279,6 +288,8 @@ int main(int argc, wchar_t* argv[])
        SetUnhandledExceptionFilter(UserUnhandledExceptionFilter);\r
        signal(SIGABRT, on_abort);\r
 \r
+       setup_global_locale();\r
+\r
        std::wcout << L"Type \"q\" to close application." << std::endl;\r
        \r
        // Set debug mode.\r