blob: 20467badd281a746ba0847328eabcbe86f0a42e1 [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
Nicolas Jagere30847e2016-10-14 14:05:24 -040020using namespace Windows::Storage;
21
Nicolas Jagereeef17c2016-08-16 10:21:54 -040022namespace RingClientUWP
23{
24
25/* forward declaration */
26ref class RingDebug;
27
28/* delegate */
29delegate void debugMessageToScreen(Platform::String^ message);
30
31/* this is how to implement a singleton class*/
32public ref class RingDebug sealed
33{
34public:
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
Nicolas Jagere30847e2016-10-14 14:05:24 -040045 property StorageFile^ _logFile;
Nicolas Jagerdf0a0672016-10-18 09:25:37 -040046 property StorageFile^ _videoFile;
Nicolas Jagere30847e2016-10-14 14:05:24 -040047
Nicolas Jagereeef17c2016-08-16 10:21:54 -040048 /* properties */
49
50 /* functions */
51internal:
52 enum class Type { MSG, WNG, ERR };
53 void print(const std::string& message, const Type& type = Type::MSG);
54
Nicolas Jagerdf0a0672016-10-18 09:25:37 -040055 void WriteLine(String^ str);
56
Nicolas Jagereeef17c2016-08-16 10:21:54 -040057 /* event */
58 event debugMessageToScreen^ messageToScreen;
59
60private:
Nicolas Jagere30847e2016-10-14 14:05:24 -040061 RingDebug(); // singleton
Nicolas Jagereeef17c2016-08-16 10:21:54 -040062};
63
atraczyk14ba30c2016-09-22 18:31:59 -040064void WriteLine(String^ str)
65{
66 std::wstringstream wStringstream;
67 wStringstream << str->Data() << "\n";
68 OutputDebugString(wStringstream.str().c_str());
69}
70
71void WriteException(Exception^ ex)
72{
73 std::wstringstream wStringstream;
74 wStringstream << "0x" << ex->HResult << ": " << ex->Message->Data();
75 OutputDebugString(wStringstream.str().c_str());
76}
77
Nicolas Jager9edbea32016-10-03 09:13:53 -040078#define MSG_(cstr) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
Nicolas Jagereeef17c2016-08-16 10:21:54 -040079ref new DispatchedHandler([=]() { RingDebug::instance->print(cstr); }))
80
Nicolas Jager9edbea32016-10-03 09:13:53 -040081#define WNG_(cstr) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
Nicolas Jagereeef17c2016-08-16 10:21:54 -040082ref new DispatchedHandler([=]() { RingDebug::instance->print(std::string(cstr), RingDebug::Type::WNG); }))
83
Nicolas Jager9edbea32016-10-03 09:13:53 -040084#define ERR_(cstr) CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High, \
Nicolas Jagereeef17c2016-08-16 10:21:54 -040085ref new DispatchedHandler([=]() { RingDebug::instance->print(std::string(cstr), RingDebug::Type::ERR); }))
86
Nicolas Jager32ed1a22016-08-17 08:36:02 -040087}