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 |
|
Nicolas Jager | e30847e | 2016-10-14 14:05:24 -0400 | [diff] [blame] | 20 | using namespace Windows::Storage;
|
| 21 |
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 22 | namespace RingClientUWP
|
| 23 | {
|
| 24 |
|
| 25 | /* forward declaration */
|
| 26 | ref class RingDebug;
|
| 27 |
|
| 28 | /* delegate */
|
| 29 | delegate void debugMessageToScreen(Platform::String^ message);
|
| 30 |
|
| 31 | /* this is how to implement a singleton class*/
|
| 32 | public ref class RingDebug sealed
|
| 33 | {
|
| 34 | public:
|
| 35 | /* singleton */
|
| 36 | static property RingDebug^ instance
|
| 37 | {
|
| 38 | RingDebug^ get()
|
| 39 | {
|
| 40 | static RingDebug^ instance_ = ref new RingDebug();
|
| 41 | return instance_;
|
| 42 | }
|
| 43 | }
|
| 44 |
|
| 45 | /* properties */
|
| 46 |
|
| 47 | /* functions */
|
| 48 | internal:
|
| 49 | enum class Type { MSG, WNG, ERR };
|
| 50 | void print(const std::string& message, const Type& type = Type::MSG);
|
| 51 |
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 52 | void WriteLine(String^ str);
|
| 53 |
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 54 | /* event */
|
| 55 | event debugMessageToScreen^ messageToScreen;
|
| 56 |
|
| 57 | private:
|
Nicolas Jager | e30847e | 2016-10-14 14:05:24 -0400 | [diff] [blame] | 58 | RingDebug(); // singleton
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 59 | };
|
| 60 |
|
atraczyk | 14ba30c | 2016-09-22 18:31:59 -0400 | [diff] [blame] | 61 | void WriteLine(String^ str)
|
| 62 | {
|
| 63 | std::wstringstream wStringstream;
|
| 64 | wStringstream << str->Data() << "\n";
|
| 65 | OutputDebugString(wStringstream.str().c_str());
|
| 66 | }
|
| 67 |
|
| 68 | void WriteException(Exception^ ex)
|
| 69 | {
|
| 70 | std::wstringstream wStringstream;
|
| 71 | wStringstream << "0x" << ex->HResult << ": " << ex->Message->Data();
|
| 72 | OutputDebugString(wStringstream.str().c_str());
|
| 73 | }
|
| 74 |
|
Nicolas Jager | 9edbea3 | 2016-10-03 09:13:53 -0400 | [diff] [blame] | 75 | #define MSG_(cstr) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 76 | ref new DispatchedHandler([=]() { RingDebug::instance->print(cstr); }))
|
| 77 |
|
Nicolas Jager | 9edbea3 | 2016-10-03 09:13:53 -0400 | [diff] [blame] | 78 | #define WNG_(cstr) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 79 | ref new DispatchedHandler([=]() { RingDebug::instance->print(std::string(cstr), RingDebug::Type::WNG); }))
|
| 80 |
|
Nicolas Jager | 9edbea3 | 2016-10-03 09:13:53 -0400 | [diff] [blame] | 81 | #define ERR_(cstr) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 82 | ref new DispatchedHandler([=]() { RingDebug::instance->print(std::string(cstr), RingDebug::Type::ERR); }))
|
| 83 |
|
Nicolas Jager | 32ed1a2 | 2016-08-17 08:36:02 -0400 | [diff] [blame] | 84 | }
|