blob: a5444dbd8d232cea661ba5b30965ba98e9efa5d8 [file] [log] [blame]
Nicolas Jagereeef17c2016-08-16 10:21:54 -04001/***************************************************************************
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
atraczykc25f69d2016-11-22 19:55:16 -050020#define UWP_DBG_CLIENT 0
21#define UWP_DBG_VS 1
22#define UWP_DBG_FILE 0
23
Nicolas Jagere30847e2016-10-14 14:05:24 -040024using namespace Windows::Storage;
25
Nicolas Jagereeef17c2016-08-16 10:21:54 -040026namespace RingClientUWP
27{
28
29/* forward declaration */
30ref class RingDebug;
31
32/* delegate */
33delegate void debugMessageToScreen(Platform::String^ message);
34
35/* this is how to implement a singleton class*/
36public ref class RingDebug sealed
37{
38public:
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 */
52internal:
atraczykc25f69d2016-11-22 19:55:16 -050053 enum class Type { DMN, MSG, WNG, ERR };
54 void print(const std::string& message, const Type& type,
55 std::string file, int line);
56 void print(String^ message, const Type& type,
57 std::string file, int line);
58 void print(Exception^ e, std::string file, int line);
Nicolas Jagerdf0a0672016-10-18 09:25:37 -040059
Nicolas Jagereeef17c2016-08-16 10:21:54 -040060 /* event */
61 event debugMessageToScreen^ messageToScreen;
62
63private:
Nicolas Jagere30847e2016-10-14 14:05:24 -040064 RingDebug(); // singleton
Nicolas Jagereeef17c2016-08-16 10:21:54 -040065};
66
atraczyk14ba30c2016-09-22 18:31:59 -040067void WriteLine(String^ str)
68{
69 std::wstringstream wStringstream;
70 wStringstream << str->Data() << "\n";
71 OutputDebugString(wStringstream.str().c_str());
72}
73
74void WriteException(Exception^ ex)
75{
76 std::wstringstream wStringstream;
77 wStringstream << "0x" << ex->HResult << ": " << ex->Message->Data();
78 OutputDebugString(wStringstream.str().c_str());
79}
80
atraczykc25f69d2016-11-22 19:55:16 -050081#define DMSG_(str) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
82ref new DispatchedHandler([=]() { RingDebug::instance->print(str, RingDebug::Type::DMN, __FILE__, __LINE__); }))
Nicolas Jagereeef17c2016-08-16 10:21:54 -040083
atraczykc25f69d2016-11-22 19:55:16 -050084#define MSG_(str) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
85ref new DispatchedHandler([=]() { RingDebug::instance->print(str, RingDebug::Type::MSG, __FILE__, __LINE__); }))
Nicolas Jagereeef17c2016-08-16 10:21:54 -040086
atraczykc25f69d2016-11-22 19:55:16 -050087#define WNG_(str) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
88ref new DispatchedHandler([=]() { RingDebug::instance->print(str, RingDebug::Type::WNG, __FILE__, __LINE__); }))
89
90#define ERR_(str) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
91ref new DispatchedHandler([=]() { RingDebug::instance->print(str, RingDebug::Type::ERR, __FILE__, __LINE__); }))
92
93#define EXC_(e) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
94ref new DispatchedHandler([=]() { RingDebug::instance->print(e, __FILE__, __LINE__); }))
Nicolas Jagereeef17c2016-08-16 10:21:54 -040095
Nicolas Jager32ed1a22016-08-17 08:36:02 -040096}