Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 1 | /***************************************************************************
|
| 2 | * Copyright (C) 2016 by Savoir-faire Linux *
|
| 3 | * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
|
| 4 | * *
|
| 5 | * This program is free software; you can redistribute it and/or modify *
|
| 6 | * it under the terms of the GNU General Public License as published by *
|
| 7 | * the Free Software Foundation; either version 3 of the License, or *
|
| 8 | * (at your option) any later version. *
|
| 9 | * *
|
| 10 | * This program is distributed in the hope that it will be useful, *
|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
| 13 | * GNU General Public License for more details. *
|
| 14 | * *
|
| 15 | * You should have received a copy of the GNU General Public License *
|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
| 17 | **************************************************************************/
|
| 18 | #pragma once
|
| 19 |
|
atraczyk | c25f69d | 2016-11-22 19:55:16 -0500 | [diff] [blame] | 20 | #define UWP_DBG_CLIENT 0
|
| 21 | #define UWP_DBG_VS 1
|
atraczyk | aeb4a5c | 2016-12-01 19:17:18 -0500 | [diff] [blame] | 22 | #define UWP_DBG_FILE 1
|
atraczyk | c25f69d | 2016-11-22 19:55:16 -0500 | [diff] [blame] | 23 |
|
Nicolas Jager | e30847e | 2016-10-14 14:05:24 -0400 | [diff] [blame] | 24 | using namespace Windows::Storage;
|
| 25 |
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 26 | namespace RingClientUWP
|
| 27 | {
|
| 28 |
|
| 29 | /* forward declaration */
|
| 30 | ref class RingDebug;
|
| 31 |
|
| 32 | /* delegate */
|
| 33 | delegate void debugMessageToScreen(Platform::String^ message);
|
| 34 |
|
| 35 | /* this is how to implement a singleton class*/
|
| 36 | public ref class RingDebug sealed
|
| 37 | {
|
| 38 | public:
|
| 39 | /* singleton */
|
| 40 | static property RingDebug^ instance
|
| 41 | {
|
| 42 | RingDebug^ get()
|
| 43 | {
|
| 44 | static RingDebug^ instance_ = ref new RingDebug();
|
| 45 | return instance_;
|
| 46 | }
|
| 47 | }
|
| 48 |
|
| 49 | /* properties */
|
| 50 |
|
| 51 | /* functions */
|
| 52 | internal:
|
atraczyk | c25f69d | 2016-11-22 19:55:16 -0500 | [diff] [blame] | 53 | enum class Type { DMN, MSG, WNG, ERR };
|
| 54 | void print(const std::string& message, const Type& type,
|
Nicolas Jager | cba46f7 | 2016-12-02 16:04:50 -0500 | [diff] [blame] | 55 | std::string file, int line);
|
atraczyk | c25f69d | 2016-11-22 19:55:16 -0500 | [diff] [blame] | 56 | void print(String^ message, const Type& type,
|
Nicolas Jager | cba46f7 | 2016-12-02 16:04:50 -0500 | [diff] [blame] | 57 | std::string file, int line);
|
atraczyk | c25f69d | 2016-11-22 19:55:16 -0500 | [diff] [blame] | 58 | void print(Exception^ e, std::string file, int line);
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 59 |
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 60 | /* event */
|
| 61 | event debugMessageToScreen^ messageToScreen;
|
| 62 |
|
| 63 | private:
|
Nicolas Jager | e30847e | 2016-10-14 14:05:24 -0400 | [diff] [blame] | 64 | RingDebug(); // singleton
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 65 | };
|
| 66 |
|
atraczyk | 14ba30c | 2016-09-22 18:31:59 -0400 | [diff] [blame] | 67 | void WriteLine(String^ str)
|
| 68 | {
|
| 69 | std::wstringstream wStringstream;
|
| 70 | wStringstream << str->Data() << "\n";
|
| 71 | OutputDebugString(wStringstream.str().c_str());
|
| 72 | }
|
| 73 |
|
| 74 | void WriteException(Exception^ ex)
|
| 75 | {
|
| 76 | std::wstringstream wStringstream;
|
| 77 | wStringstream << "0x" << ex->HResult << ": " << ex->Message->Data();
|
| 78 | OutputDebugString(wStringstream.str().c_str());
|
| 79 | }
|
| 80 |
|
atraczyk | c25f69d | 2016-11-22 19:55:16 -0500 | [diff] [blame] | 81 | #define DMSG_(str) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
|
| 82 | ref new DispatchedHandler([=]() { RingDebug::instance->print(str, RingDebug::Type::DMN, __FILE__, __LINE__); }))
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 83 |
|
atraczyk | c25f69d | 2016-11-22 19:55:16 -0500 | [diff] [blame] | 84 | #define MSG_(str) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
|
| 85 | ref new DispatchedHandler([=]() { RingDebug::instance->print(str, RingDebug::Type::MSG, __FILE__, __LINE__); }))
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 86 |
|
atraczyk | c25f69d | 2016-11-22 19:55:16 -0500 | [diff] [blame] | 87 | #define WNG_(str) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
|
| 88 | ref new DispatchedHandler([=]() { RingDebug::instance->print(str, RingDebug::Type::WNG, __FILE__, __LINE__); }))
|
| 89 |
|
| 90 | #define ERR_(str) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
|
| 91 | ref new DispatchedHandler([=]() { RingDebug::instance->print(str, RingDebug::Type::ERR, __FILE__, __LINE__); }))
|
| 92 |
|
| 93 | #define EXC_(e) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
|
| 94 | ref new DispatchedHandler([=]() { RingDebug::instance->print(e, __FILE__, __LINE__); }))
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 95 |
|
Nicolas Jager | 32ed1a2 | 2016-08-17 08:36:02 -0400 | [diff] [blame] | 96 | }
|