]> git.sesse.net Git - casparcg/commitdiff
Made the code more portable.
authorHelge Norberg <helge.norberg@svt.se>
Fri, 20 Mar 2015 21:39:29 +0000 (22:39 +0100)
committerHelge Norberg <helge.norberg@svt.se>
Fri, 20 Mar 2015 21:39:29 +0000 (22:39 +0100)
34 files changed:
CMakeLists.txt
common/CMakeLists.txt
common/base64.cpp
common/blocking_priority_queue.h
common/enum_class.h
common/env.cpp
common/except.h
common/executor.h
common/gl/gl_check.cpp
common/log.cpp
common/memory.h
common/os/general_protection_fault.h [new file with mode: 0644]
common/os/linux/signal_handlers.cpp [new file with mode: 0644]
common/os/linux/stack_trace.cpp [new file with mode: 0644]
common/os/linux/system_info.cpp [new file with mode: 0644]
common/os/page_locked_allocator.h [moved from common/page_locked_allocator.h with 100% similarity]
common/os/stack_trace.h [new file with mode: 0644]
common/os/system_info.h [new file with mode: 0644]
common/os/windows/page_locked_allocator.cpp [moved from common/page_locked_allocator.cpp with 93% similarity]
common/os/windows/prec_timer.cpp [moved from common/prec_timer.cpp with 97% similarity]
common/os/windows/stack_trace.cpp [new file with mode: 0644]
common/os/windows/system_info.cpp [moved from common/os/windows/system_info.h with 93% similarity]
common/os/windows/win32_exception.cpp [moved from common/except.cpp with 93% similarity]
common/os/windows/win32_exception.h [new file with mode: 0644]
common/os/windows/windows.h
common/polling_filesystem_monitor.cpp
common/prec_timer.h
common/semaphore.h
common/stdafx.h
common/tweener.cpp
core/producer/text/text_producer.cpp
modules/bluefish/util/memory.h
protocol/amcp/AMCPCommandsImpl.cpp
shell/main.cpp

index 0843a8ebb1e73f9a978540e5325cb9a64bb8817e..6fef136d11e94f9e1c5012c0216cafab952c6340 100644 (file)
@@ -59,9 +59,12 @@ if (${MSVC})
        set(CMAKE_CXX_FLAGS                     "${CMAKE_CXX_FLAGS}                     /EHa /Zi /W4 /WX /MP /fp:fast /FIcommon/compiler/vs/disable_silly_warnings.h")
        set(CMAKE_CXX_FLAGS_DEBUG       "${CMAKE_CXX_FLAGS_DEBUG}       /D TBB_USE_ASSERT=1 /D TBB_USE_DEBUG /bigobj")
        set(CMAKE_CXX_FLAGS_RELEASE     "${CMAKE_CXX_FLAGS_RELEASE}     /Oi /Ot /Gy")
+
+elseif (CMAKE_COMPILER_IS_GNUCXX)
+       add_compile_options( -std=c++11 )
 endif ()
 
-cmake_policy(SET CMP0045 OLD)
+#cmake_policy(SET CMP0045 OLD)
 include(CMake/PrecompiledHeader.cmake)
 
 add_subdirectory(accelerator)
index b895d723e28bdf1c5cc43ee1aaecfab0f9d3854c..5a8677f58e31f5acaec6d1268619764767dd6522 100644 (file)
@@ -2,34 +2,49 @@ cmake_minimum_required (VERSION 2.6)
 project (common)
 
 set(SOURCES
-               compiler/vs/stack_walker.cpp
-
                diagnostics/graph.cpp
 
                gl/gl_check.cpp
 
                base64.cpp
                env.cpp
-               except.cpp
                log.cpp
-               page_locked_allocator.cpp
                polling_filesystem_monitor.cpp
-               prec_timer.cpp
                stdafx.cpp
                tweener.cpp
                utf.cpp
 )
-set(HEADERS
-               compiler/vs/disable_silly_warnings.h
-               compiler/vs/stack_walker.h
+if (MSVC)
+       set(OS_SPECIFIC_SOURCES
+                       compiler/vs/disable_silly_warnings.h
+                       compiler/vs/stack_walker.cpp
+                       compiler/vs/stack_walker.h
 
+                       os/windows/current_version.h
+                       os/windows/page_locked_allocator.cpp
+                       os/windows/prec_timer.cpp
+                       os/windows/stack_trace.cpp
+                       os/windows/system_info.cpp
+                       os/windows/win32_exception.cpp
+                       os/windows/win32_exception.h
+                       os/windows/windows.h
+       )
+elseif (CMAKE_COMPILER_IS_GNUCXX)
+       set(OS_SPECIFIC_SOURCES
+                       os/linux/signal_handlers.cpp
+                       os/linux/stack_trace.cpp
+                       os/linux/system_info.cpp
+       )
+endif ()
+set(HEADERS
                diagnostics/graph.h
 
                gl/gl_check.h
 
-               os/windows/windows.h
-               os/windows/system_info.h
-               os/windows/windows.h
+               os/general_protection_fault.h
+               os/page_locked_allocator.h
+               os/stack_trace.h
+               os/system_info.h
 
                array.h
                assert.h
@@ -51,7 +66,6 @@ set(HEADERS
                log.h
                memory.h
                memshfl.h
-               page_locked_allocator.h
                param.h
                polling_filesystem_monitor.h
                prec_timer.h
@@ -62,7 +76,7 @@ set(HEADERS
                utf.h
 )
 
-add_library(common ${SOURCES} ${HEADERS})
+add_library(common ${SOURCES} ${HEADERS} ${OS_SPECIFIC_SOURCES})
 add_precompiled_header(common stdafx.h FORCEINCLUDE)
 
 include_directories(..)
index 8af634f7b1ed1e994cdcec41676e8b095293e5bb..e29f34e5308ae57ba454355fb53f9594fa822338 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <vector>
 #include <algorithm>
+#include <cstring>
 
 #include <boost/archive/iterators/insert_linebreaks.hpp>
 #include <boost/archive/iterators/base64_from_binary.hpp>
@@ -143,4 +144,4 @@ std::vector<unsigned char> from_base64(const std::string& data)
        }
 }
 
-}
\ No newline at end of file
+}
index 0bde37656fda0e0427b152228bcfd8f75915d79f..33c5b989b61177213d0a55c70d6738e85283fc5d 100644 (file)
@@ -47,8 +47,8 @@ public:
 private:       
        std::map<Prio, tbb::concurrent_queue<T>, std::greater<Prio>>    queues_by_priority_;
        size_type                                                                                                               capacity_;
-       semaphore                                                                                                               space_available_        = capacity_;
-       semaphore                                                                                                               elements_available_     = 0u;
+       semaphore                                                                                                               space_available_        { capacity_ };
+       semaphore                                                                                                               elements_available_     { 0u };
        mutable boost::mutex                                                                                    capacity_mutex_;
 public:
        /**
index 76db19b1feccbe9e1e21917dd50708d295dfcb9c..fa8225ae8a2272848ba9f88b6285d0824fe8fb49 100644 (file)
@@ -31,10 +31,11 @@ const std::vector<E>& enum_constants()
 
        static const auto ints = boost::irange(static_cast<integer>(0), static_cast<integer>(E::count));
        static const auto result = cpplinq::from(ints.begin(), ints.end())
-               .cast<E>()
+               //.cast<E>()
+               .select([](int i) { return static_cast<E>(i); })
                .to_vector();
 
        return result;
 }
 
-}
\ No newline at end of file
+}
index 48a11b8fef36f0848e309725551d022556f8d117..08c6abc680aaa9ec3d68e6e1ea44590c4e6186b7 100644 (file)
 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/xml_parser.hpp>
 #include <boost/filesystem.hpp>
+#include <boost/filesystem/fstream.hpp>
 #include <boost/thread/once.hpp>
 
 #include <functional>
 #include <iostream>
+#include <fstream>
 
 namespace caspar { namespace env {
        
@@ -59,7 +61,7 @@ void configure(const std::wstring& filename)
        {
                auto initialPath = boost::filesystem::initial_path().wstring();
        
-               std::wifstream file(initialPath + L"\\" + filename);
+               boost::filesystem::wifstream file(initialPath + L"\\" + filename);
                boost::property_tree::read_xml(file, pt, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
 
                auto paths      = pt.get_child(L"configuration.paths");
@@ -213,4 +215,4 @@ std::wstring system_font_folder()
        return L"C:\\windows\\Fonts\\";
 }
 
-}}
\ No newline at end of file
+}}
index 0b7333f8ea6840087d29151678f14c3e57a00111..3d2bb454bba72151b4867d62daa8711f3ffd9bcf 100644 (file)
 
 #include "utf.h"
 
-#include "log.h"
+#include "os/stack_trace.h"
 
 #include <exception>
 #include <boost/exception/all.hpp>
 #include <boost/exception/error_info.hpp>
 #include <boost/throw_exception.hpp>
 
-struct _EXCEPTION_RECORD;
-struct _EXCEPTION_POINTERS;
-
-typedef _EXCEPTION_RECORD EXCEPTION_RECORD;
-typedef _EXCEPTION_POINTERS EXCEPTION_POINTERS;
-
 namespace caspar {
 
 typedef boost::error_info<struct tag_arg_name_info, std::string>       arg_name_info_t;
@@ -67,7 +61,13 @@ typedef boost::error_info<struct tag_nested_exception_, std::exception_ptr> nest
 struct caspar_exception                        : virtual boost::exception, virtual std::exception 
 {
        caspar_exception(){}
-       explicit caspar_exception(const char* msg) : std::exception(msg) {}
+       explicit caspar_exception(const char* msg) : msg_(msg) {}
+       const char* what() const noexcept override
+       {
+               return msg_;
+       }
+private:
+       const char* msg_ = "";
 };
 
 struct io_error                                        : virtual caspar_exception {};
@@ -88,48 +88,7 @@ struct timed_out                             : virtual caspar_exception {};
 struct not_supported                   : virtual caspar_exception {};
 struct not_implemented                 : virtual caspar_exception {};
 
-class win32_exception : public std::exception
-{
-public:
-       typedef const void* address;
-       static void install_handler();
-       static void ensure_handler_installed_for_thread(
-                       const char* thread_description = nullptr);
-
-       address location() const { return location_; }
-       unsigned int error_code() const { return errorCode_; }
-       virtual const char* what() const { return message_;     }
-
-protected:
-       win32_exception(const EXCEPTION_RECORD& info);
-       static void Handler(unsigned int errorCode, EXCEPTION_POINTERS* pInfo);
-
-private:
-       const char* message_;
-
-       address location_;
-       unsigned int errorCode_;
-};
-
-class win32_access_violation : public win32_exception
-{
-       mutable char messageBuffer_[256];
-
-public:
-       bool is_write() const { return isWrite_; }
-       address bad_address() const { return badAddress_;}
-       virtual const char* what() const;
-
-protected:
-       win32_access_violation(const EXCEPTION_RECORD& info);
-       friend void win32_exception::Handler(unsigned int errorCode, EXCEPTION_POINTERS* pInfo);
-
-private:
-       bool isWrite_;
-       address badAddress_;
-};
-
-#define CASPAR_THROW_EXCEPTION(e) BOOST_THROW_EXCEPTION(e << call_stack_info(caspar::log::internal::get_call_stack()))
+#define CASPAR_THROW_EXCEPTION(e) BOOST_THROW_EXCEPTION(e << call_stack_info(caspar::get_call_stack()))
 
 }
 
index 28d3d3fb81bb10f8044a944bd95e25dbda4d4b42..aec4876342bd277096787a40b6ba1c856138171e 100644 (file)
@@ -21,6 +21,7 @@
 
 #pragma once
 
+#include "os/general_protection_fault.h"
 #include "except.h"
 #include "log.h"
 #include "blocking_bounded_queue_adapter.h"
@@ -235,7 +236,7 @@ private:
 
        void run() // noexcept
        {
-               win32_exception::install_handler();             
+               ensure_gpf_handler_installed_for_thread(u8(name_).c_str());
                while(is_running_)
                {
                        try
@@ -252,4 +253,4 @@ private:
        }       
 };
 
-}
\ No newline at end of file
+}
index cc709280feba4c2e618e7e6019c7370d439d2b3a..2ff4642d86299c306b5b1bad843fd5d76d268b1f 100644 (file)
@@ -22,8 +22,6 @@
 //
 ///////////////////////////
 
-#pragma once
-
 #include "../stdafx.h"
 
 #include "gl_check.h"
@@ -102,4 +100,4 @@ void SMFL_GLCheckError(const std::string&, const std::string& file, unsigned int
        }
 }
 
-}}
\ No newline at end of file
+}}
index 9f68785c872e634ba9321aa16683dbf50c503768..0dd326cab49fce8bf3114d2f9168686dc237252c 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "except.h"
 #include "utf.h"
-#include "compiler/vs/stack_walker.h"
 
 #include <ios>
 #include <iomanip>
@@ -57,7 +56,6 @@
 #include <boost/lexical_cast.hpp>
 
 #include <tbb/atomic.h>
-#include <tbb/enumerable_thread_specific.h>
 
 namespace caspar { namespace log {
 
@@ -153,50 +151,6 @@ void init()
        boost::log::core::get()->add_sink(stream_sink);
 }
 
-std::wstring get_call_stack()
-{
-       class log_call_stack_walker : public stack_walker
-       {
-               std::string str_;
-       public:
-               log_call_stack_walker() : stack_walker() {}
-
-               std::string flush()
-               {
-                       return std::move(str_);
-               }
-       protected:              
-               virtual void OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName)
-               {
-               }
-               virtual void OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion)
-               {
-               }
-               virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr)
-               {
-               }
-               virtual void OnOutput(LPCSTR szText)
-               {
-                       std::string str = szText;
-
-                       if(str.find("internal::get_call_stack") == std::string::npos && str.find("stack_walker::ShowCallstack") == std::string::npos)
-                               str_ += std::move(str);
-               }
-       };
-
-       static tbb::enumerable_thread_specific<log_call_stack_walker> walkers;
-       try
-       {
-               auto& walker = walkers.local();
-               walker.ShowCallstack();
-               return u16(walker.flush());
-       }
-       catch(...)
-       {
-               return L"!!!";
-       }
-}
-
 }
 
 void add_file_sink(const std::wstring& folder)
@@ -242,4 +196,4 @@ void set_log_level(const std::wstring& lvl)
                boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::fatal);
 }
 
-}}
\ No newline at end of file
+}}
index 2927970c92730b07e147101342e37623912e1f47..3606c3a8e363d524be57ef5a584df6d26066b6b0 100644 (file)
@@ -113,8 +113,7 @@ public:
         p_.swap(other.p_); 
     } 
        
-    template<class D, class T2> 
-    D* get_deleter(shared_ptr<T2> const& ptr) 
+    D& get_deleter()
     { 
         return p_.get_deleter(); 
     }
@@ -448,16 +447,16 @@ public:
     { 
         return p_.owner_before(ptr); 
     }
-
-    template<class D, class T2> 
-    D* get_deleter(shared_ptr<T2> const& ptr) 
-    { 
-        return p_.get_deleter(); 
-    }
 private:    
     std::shared_ptr<T> p_;
 };
 
+template<class D, class T>
+D* get_deleter(shared_ptr<T> const& ptr)
+{
+    return ptr.get_deleter();
+}
+
 template<class T, class T2>
 bool operator==(const shared_ptr<T>& a, const shared_ptr<T2>& b)
 {
diff --git a/common/os/general_protection_fault.h b/common/os/general_protection_fault.h
new file mode 100644 (file)
index 0000000..3972188
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+* 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: Helge Norberg, helge.norberg@svt.se
+*/
+
+#pragma once
+
+#include <string>
+
+namespace caspar {
+
+void install_gpf_handler();
+void ensure_gpf_handler_installed_for_thread(
+                       const char* thread_description = nullptr);
+
+}
diff --git a/common/os/linux/signal_handlers.cpp b/common/os/linux/signal_handlers.cpp
new file mode 100644 (file)
index 0000000..c3cc937
--- /dev/null
@@ -0,0 +1,16 @@
+#include "../general_protection_fault.h"
+
+namespace caspar {
+
+void install_gpf_handler()
+{
+       // TODO: implement
+}
+
+void ensure_gpf_handler_installed_for_thread(
+               const char* thread_description)
+{
+       // TODO: implement
+}
+
+}
diff --git a/common/os/linux/stack_trace.cpp b/common/os/linux/stack_trace.cpp
new file mode 100644 (file)
index 0000000..1e09c70
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+* 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: Helge Norberg, helge.norberg@svt.se
+*/
+
+#include "../stack_trace.h"
+
+namespace caspar {
+
+std::wstring get_call_stack()
+{
+       // TODO: implement
+       return L"";
+}
+
+}
diff --git a/common/os/linux/system_info.cpp b/common/os/linux/system_info.cpp
new file mode 100644 (file)
index 0000000..f1da76a
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+* 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: Helge Norberg, helge.norberg@svt.se
+*/
+
+#include "../system_info.h"
+
+namespace caspar {
+       
+std::wstring cpu_info()
+{
+       // TODO: implement
+       return L"Unknown CPU";
+}
+
+std::wstring system_product_name()
+{
+       // TODO: implement
+       return L"Unknown System";
+}
+
+std::wstring os_description()
+{
+       // TODO: implement
+       return L"Unknown OS";
+}
+
+}
diff --git a/common/os/stack_trace.h b/common/os/stack_trace.h
new file mode 100644 (file)
index 0000000..2062372
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+* 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: Helge Norberg, helge.norberg@svt.se
+*/
+
+#pragma once
+
+#include <string>
+
+namespace caspar {
+
+std::wstring get_call_stack();
+
+}
diff --git a/common/os/system_info.h b/common/os/system_info.h
new file mode 100644 (file)
index 0000000..b6db326
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+* 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
+*/
+
+#pragma once
+
+#include <string>
+
+namespace caspar {
+       
+std::wstring cpu_info();
+std::wstring system_product_name();
+std::wstring os_description();
+
+}
similarity index 93%
rename from common/page_locked_allocator.cpp
rename to common/os/windows/page_locked_allocator.cpp
index ead2654dfddc3e2c18933eef30bb9e1f45b1345f..d59c61b0f7795aab5fb51219b39ed332e309cf84 100644 (file)
@@ -1,6 +1,8 @@
-#include "stdafx.h"
+#include "../../stdafx.h"
 
-#include "os/windows/windows.h"
+#include "../page_locked_allocator.h"
+
+#include "windows.h"
 
 #include <unordered_map>
 #include <tbb/mutex.h>
@@ -63,4 +65,4 @@ void free_page_locked(void* p)
        g_map.erase(p);
 }
 
-}}
\ No newline at end of file
+}}
similarity index 97%
rename from common/prec_timer.cpp
rename to common/os/windows/prec_timer.cpp
index 12d94f1ab579b84ce7fc9584b5a4074d905d94a7..3aff808831e1063ea3245961adf950b80ae5dca1 100644 (file)
@@ -19,9 +19,9 @@
 * Author: Robert Nagy, ronag89@gmail.com
 */
 
-#include "stdafx.h"
+#include "../../stdafx.h"
 
-#include "prec_timer.h"
+#include "../../prec_timer.h"
 
 #include "os/windows/windows.h"
 
@@ -80,4 +80,4 @@ void prec_timer::tick_millis(int64_t ticks_to_wait)
        time_ = t;
 }
 
-}
\ No newline at end of file
+}
diff --git a/common/os/windows/stack_trace.cpp b/common/os/windows/stack_trace.cpp
new file mode 100644 (file)
index 0000000..ac25bd9
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+* 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: Helge Norberg, helge.norberg@svt.se
+*/
+
+#include "../../stdafx.h"
+
+#include "../stack_trace.h"
+
+#include "../../compiler/vs/stack_walker.h"
+
+#include <utility>
+
+#include <tbb/enumerable_thread_specific.h>
+
+namespace caspar {
+
+std::wstring get_call_stack()
+{
+       class log_call_stack_walker : public stack_walker
+       {
+               std::string str_;
+       public:
+               log_call_stack_walker() : stack_walker() {}
+
+               std::string flush()
+               {
+                       return std::move(str_);
+               }
+       protected:
+               virtual void OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName)
+               {
+               }
+               virtual void OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion)
+               {
+               }
+               virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr)
+               {
+               }
+               virtual void OnOutput(LPCSTR szText)
+               {
+                       std::string str = szText;
+
+                       if(str.find("internal::get_call_stack") == std::string::npos && str.find("stack_walker::ShowCallstack") == std::string::npos)
+                               str_ += std::move(str);
+               }
+       };
+
+       static tbb::enumerable_thread_specific<log_call_stack_walker> walkers;
+       try
+       {
+               auto& walker = walkers.local();
+               walker.ShowCallstack();
+               return u16(walker.flush());
+       }
+       catch(...)
+       {
+               return L"!!!";
+       }
+}
+
+}
similarity index 93%
rename from common/os/windows/system_info.h
rename to common/os/windows/system_info.cpp
index ee8d2de9cbdedd5726ad7575241deea026e74983..d87b72a65067e2497f37be64249df4cd91d10e0f 100644 (file)
 * Author: Robert Nagy, ronag89@gmail.com
 */
 
-#pragma once
+#include "../../stdafx.h"
+
+#include "../system_info.h"
+#include "current_version.h"
 
 #include "windows.h"
 
-#include <string>
 #include <sstream>
 #include <map>
 
 namespace caspar {
        
-static std::wstring cpu_info()
+std::wstring cpu_info()
 {
        std::wstring cpu_name = L"Unknown CPU";
        HKEY hkey; 
@@ -58,7 +60,7 @@ static std::wstring cpu_info()
        return s.str();
 }
 
-static std::wstring system_product_name()
+std::wstring system_product_name()
 {
        std::wstring system_product_name = L"Unknown System";
        HKEY hkey; 
@@ -79,6 +81,12 @@ static std::wstring system_product_name()
        return system_product_name;
 }
 
+std::wstring os_description()
+{
+       return win_product_name() + L" " + win_sp_version();
+}
+
+
 /*static std::map<std::wstring, std::wstring> enumerate_fonts()
 {
        std::map<std::wstring, std::wstring> result;
@@ -116,4 +124,4 @@ static std::wstring system_product_name()
        return result;
 }*/
 
-}
\ No newline at end of file
+}
similarity index 93%
rename from common/except.cpp
rename to common/os/windows/win32_exception.cpp
index 63ccf7a61de2556fd9f16ca8da18919e98e20bef..0d7684d4e6c5b7d2c67925f52917a93276b29c01 100644 (file)
@@ -1,6 +1,6 @@
-#include "stdafx.h"
+#include "../../stdafx.h"
 
-#include "except.h"
+#include "win32_exception.h"
 
 #include <boost/thread.hpp>
 
@@ -49,7 +49,7 @@ bool& installed_for_thread()
        return *for_thread;
 }
 
-void win32_exception::install_handler() 
+void install_gpf_handler()
 {
 //#ifndef _DEBUG
        _set_se_translator(win32_exception::Handler);
@@ -57,12 +57,12 @@ void win32_exception::install_handler()
 //#endif
 }
 
-void win32_exception::ensure_handler_installed_for_thread(
+void ensure_gpf_handler_installed_for_thread(
                const char* thread_description)
 {
        if (!installed_for_thread())
        {
-               install_handler();
+               install_gpf_handler();
 
                if (thread_description)
                        detail::SetThreadName(GetCurrentThreadId(), thread_description);
@@ -108,4 +108,4 @@ const char* win32_access_violation::what() const
        return messageBuffer_;
 }
 
-}
\ No newline at end of file
+}
diff --git a/common/os/windows/win32_exception.h b/common/os/windows/win32_exception.h
new file mode 100644 (file)
index 0000000..1e10694
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+* 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
+*/
+
+#pragma once
+
+#include "../../except.h"
+
+struct _EXCEPTION_RECORD;
+struct _EXCEPTION_POINTERS;
+
+typedef _EXCEPTION_RECORD EXCEPTION_RECORD;
+typedef _EXCEPTION_POINTERS EXCEPTION_POINTERS;
+
+namespace caspar {
+
+class win32_exception : public std::exception
+{
+public:
+       typedef const void* address;
+
+       address location() const { return location_; }
+       unsigned int error_code() const { return errorCode_; }
+       virtual const char* what() const noexcept override { return message_;   }
+
+protected:
+       win32_exception(const EXCEPTION_RECORD& info);
+       static void Handler(unsigned int errorCode, EXCEPTION_POINTERS* pInfo);
+
+private:
+       const char* message_;
+
+       address location_;
+       unsigned int errorCode_;
+};
+
+class win32_access_violation : public win32_exception
+{
+       mutable char messageBuffer_[256];
+
+public:
+       bool is_write() const { return isWrite_; }
+       address bad_address() const { return badAddress_;}
+       virtual const char* what() const noexcept override;
+
+protected:
+       win32_access_violation(const EXCEPTION_RECORD& info);
+       friend void win32_exception::Handler(unsigned int errorCode, EXCEPTION_POINTERS* pInfo);
+
+private:
+       bool isWrite_;
+       address badAddress_;
+};
+
+}
+
index 40f410f3383260b47435cb685def657441d1309f..bbee8206a9fd4c4ff3728bef10a7d976ba6b3607 100644 (file)
@@ -23,4 +23,4 @@
 #undef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
 
-#include <windows.h>
\ No newline at end of file
+#include <windows.h>
index e9c2f59a9729047843df1d979287ce85b2cdc905..224ace2a45408e18f58721913799ab68684c88f6 100644 (file)
@@ -252,9 +252,7 @@ public:
 private:
        void scanner()
        {
-               win32_exception::install_handler();
-
-               //detail::SetThreadName(GetCurrentThreadId(), "polling_filesystem_monitor");
+               ensure_gpf_handler_installed_for_thread("polling_filesystem_monitor");
 
                bool running = scan(false);
                initial_scan_completion_.set_value();
@@ -268,7 +266,7 @@ private:
                try
                {
                        if (sleep)
-                               boost::this_thread::sleep(boost::posix_time::milliseconds(scan_interval_millis_));
+                               boost::this_thread::sleep_for(boost::chrono::milliseconds(scan_interval_millis_));
 
                        if (reemmit_all_.fetch_and_store(false))
                                root_monitor_.reemmit_all();
@@ -329,4 +327,4 @@ filesystem_monitor::ptr polling_filesystem_monitor_factory::create(
                        initial_files_handler);
 }
 
-}
\ No newline at end of file
+}
index e41fccc5f0d88bf63e4ad375e37066cde795e40f..4a5bf9be57ddb246f745c17fb45b91b868ba0b94 100644 (file)
@@ -30,9 +30,13 @@ class prec_timer
 public:
        prec_timer();
 
+       void tick(double interval)
+       {
+               tick_millis(static_cast<int64_t>(interval * 1000.0));
+       }
+
        // Author: Ryan M. Geiss
        // http://www.geisswerks.com/ryan/FAQS/timing.html
-       void tick(double interval);
        void tick_millis(int64_t interval);
 
 private:       
@@ -40,4 +44,4 @@ private:
 };
 
 
-}
\ No newline at end of file
+}
index 1d94f015c836c74cb0439596bcdd17de3fd19293..a8563ea20078786132deb67d2bbca76d39fc51eb 100644 (file)
@@ -52,7 +52,7 @@ public:
         *
         * @param permits The initial number of permits.
         */
-       semaphore(unsigned int permits)
+       explicit semaphore(unsigned int permits)
                : permits_(permits)
        {
        }
index 8467bf2e718a392b9afb22844c908c28b94fc4ef..460d4e6a280cf6abfbec251c339533854a8ac244 100644 (file)
@@ -21,4 +21,4 @@
 
 #pragma once
 
-#include "os/windows/windows.h"
\ No newline at end of file
+//#include "os/windows/windows.h"
index cadeec4733ed0ff72a599e3fd8a656f9ed7f3b23..49411187259bd03744199922e9f406eeb686eb18 100644 (file)
@@ -28,7 +28,7 @@
 //
 //Open source under the BSD License.
 //
-//Copyright © 2001 Robert Penner
+//Copyright  2001 Robert Penner
 //All rights reserved.
 //
 //Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -435,7 +435,7 @@ const std::unordered_map<std::wstring, tween_t>& get_tweens()
 
 tweener_t get_tweener(std::wstring name)
 {
-       std::transform(name.begin(), name.end(), name.begin(), std::tolower);
+       std::transform(name.begin(), name.end(), name.begin(), std::towlower);
 
        if(name == L"linear")
                return [](double t, double b, double c, double d){return ease_none(t, b, c, d, std::vector<double>());};
index 6ffd377d1dd48a1697304e41445c9ed7d39cc72f..73f24135c810e729cb46a7ac90f9527454773bbd 100644 (file)
@@ -42,7 +42,6 @@
 #include <common/env.h>
 #include <common/future.h>
 #include <common/param.h>
-#include <common/os/windows/system_info.h>
 #include <memory>
 
 #include <boost/algorithm/string.hpp>
index 3de2922800fe2929f4a0db0bfe48117d98716d61..994cb8aeeb1aa8adf72292a832add296801b5ab6 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <BlueVelvet4.h>
 
-#include <common/page_locked_allocator.h>
+#include <common/os/page_locked_allocator.h>
 
 #include <vector>
 
@@ -61,4 +61,4 @@ private:
 };
 typedef std::shared_ptr<blue_dma_buffer> blue_dma_buffer_ptr;
 
-}}
\ No newline at end of file
+}}
index 1113388211f397251a7f43c43bb81c289ebc2f4d..f1e8e876840ac1d34e27638f14c60153b7c4abf1 100644 (file)
@@ -32,8 +32,7 @@
 
 #include <common/log.h>
 #include <common/param.h>
-#include <common/os/windows/current_version.h>
-#include <common/os/windows/system_info.h>
+#include <common/os/system_info.h>
 #include <common/base64.h>
 
 #include <core/producer/frame_producer.h>
@@ -1529,8 +1528,7 @@ bool InfoCommand::DoExecute()
                        boost::property_tree::wptree info;
                        
                        info.add(L"system.name",                                        caspar::system_product_name());
-                       info.add(L"system.windows.name",                        caspar::win_product_name());
-                       info.add(L"system.windows.service-pack",        caspar::win_sp_version());
+                       info.add(L"system.os.description",                      caspar::os_description());
                        info.add(L"system.cpu",                                         caspar::cpu_info());
        
                        for (auto& device : caspar::decklink::device_list())
@@ -1983,4 +1981,4 @@ bool RestartCommand::DoExecute()
 }
 
 }      //namespace amcp
-}}     //namespace caspar
\ No newline at end of file
+}}     //namespace caspar
index 5a850369089350aa5bf986ea4131cdc11f4aba69..6993caa85813941ead51cf9eca14a04b32d26107 100644 (file)
@@ -58,8 +58,7 @@
 #include <common/except.h>
 #include <common/log.h>
 #include <common/gl/gl_check.h>
-#include <common/os/windows/current_version.h>
-#include <common/os/windows/system_info.h>
+#include <common/os/system_info.h>
 
 #include <boost/property_tree/detail/file_parser_error.hpp>
 #include <boost/property_tree/xml_parser.hpp>
@@ -143,7 +142,7 @@ void print_info()
        CASPAR_LOG(info) << L"http://www.casparcg.com/";
        CASPAR_LOG(info) << L"############################################################################";
        CASPAR_LOG(info) << L"Starting CasparCG Video and Graphics Playout Server " << env::version();
-       CASPAR_LOG(info) << L"on " << win_product_name() << L" " << win_sp_version();
+       CASPAR_LOG(info) << L"on " << os_description();
        CASPAR_LOG(info) << cpu_info();
        CASPAR_LOG(info) << system_product_name();
        
@@ -411,4 +410,4 @@ int main(int argc, wchar_t* argv[])
        }               
        
        return return_code;
-}
\ No newline at end of file
+}