output logs.
This commit is contained in:
@@ -27,3 +27,4 @@ sysinfo.txt
|
||||
.DS_Store
|
||||
/Assets/AssetStoreTools*
|
||||
/Assets/Extensions*
|
||||
/uDesktopDuplication.log
|
||||
|
||||
Binary file not shown.
@@ -39,9 +39,17 @@ public enum MonitorState
|
||||
AccessLost = 6,
|
||||
}
|
||||
|
||||
public enum DebugMode
|
||||
{
|
||||
None = 0,
|
||||
File = 1,
|
||||
UnityLog = 2, /* currently has bug when app exits. */
|
||||
}
|
||||
|
||||
public static class Lib
|
||||
{
|
||||
public delegate void MessageHandler(Message message);
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void DebugLogDelegate(string str);
|
||||
|
||||
[DllImport("uDesktopDuplication")]
|
||||
@@ -59,9 +67,11 @@ public static class Lib
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void DisableDebug();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void SetLogFunc(DebugLogDelegate func);
|
||||
public static extern void SetDebugMode(DebugMode mode);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void SetErrorFunc(DebugLogDelegate func);
|
||||
public static extern void SetLogFunc(IntPtr func);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void SetErrorFunc(IntPtr func);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetMonitorCount();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace uDesktopDuplication
|
||||
{
|
||||
@@ -51,21 +52,20 @@ public class Manager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] DebugMode debugMode = DebugMode.File;
|
||||
[SerializeField] int desktopDuplicationApiTimeout = 0;
|
||||
[SerializeField] float retryReinitializationDuration = 1f;
|
||||
|
||||
private Coroutine renderCoroutine_ = null;
|
||||
private bool shouldReinitialize = false;
|
||||
private float reinitializationTimer = 0f;
|
||||
private bool shouldReinitialize_ = false;
|
||||
private float reinitializationTimer_ = 0f;
|
||||
|
||||
public delegate void ReinitializeHandler();
|
||||
public static event ReinitializeHandler onReinitialized;
|
||||
|
||||
private Lib.DebugLogDelegate logFunc = msg => Debug.Log(msg);
|
||||
private Lib.DebugLogDelegate errorFunc = msg => Debug.LogError(msg);
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Lib.SetDebugMode(debugMode);
|
||||
Lib.InitializeUDD();
|
||||
|
||||
if (instance_ != null) return;
|
||||
@@ -84,16 +84,10 @@ public class Manager : MonoBehaviour
|
||||
void OnEnable()
|
||||
{
|
||||
renderCoroutine_ = StartCoroutine(OnRender());
|
||||
|
||||
Lib.SetLogFunc(logFunc);
|
||||
Lib.SetErrorFunc(errorFunc);
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
Lib.SetLogFunc(null);
|
||||
Lib.SetErrorFunc(null);
|
||||
|
||||
if (renderCoroutine_ != null) {
|
||||
StopCoroutine(renderCoroutine_);
|
||||
renderCoroutine_ = null;
|
||||
@@ -123,20 +117,20 @@ public class Manager : MonoBehaviour
|
||||
monitor.state == MonitorState.AccessLost ||
|
||||
monitor.state == MonitorState.AccessDenied ||
|
||||
monitor.state == MonitorState.SessionDisconnected) {
|
||||
if (!shouldReinitialize) {
|
||||
shouldReinitialize = true;
|
||||
reinitializationTimer = 0f;
|
||||
if (!shouldReinitialize_) {
|
||||
shouldReinitialize_ = true;
|
||||
reinitializationTimer_ = 0f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldReinitialize) {
|
||||
if (reinitializationTimer > retryReinitializationDuration) {
|
||||
if (shouldReinitialize_) {
|
||||
if (reinitializationTimer_ > retryReinitializationDuration) {
|
||||
Reinitialize();
|
||||
shouldReinitialize = false;
|
||||
shouldReinitialize_ = false;
|
||||
}
|
||||
reinitializationTimer += Time.deltaTime;
|
||||
reinitializationTimer_ += Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -136,10 +136,6 @@ void Cursor::UpdateTexture()
|
||||
rowMax = h;
|
||||
}
|
||||
|
||||
char buf[256];
|
||||
sprintf_s(buf, 256, "%d %d %d %d | %d %d %d %d", x_, y_, w, h, colMin, colMax, rowMin, rowMax);
|
||||
Debug::Log(buf);
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
desc.Width = w;
|
||||
desc.Height = h;
|
||||
|
||||
@@ -4,28 +4,81 @@
|
||||
#include "Debug.h"
|
||||
|
||||
|
||||
#define INIT_STATIC_MEMBER(Member, Value) \
|
||||
decltype(Debug::Member) Debug::Member = Value;
|
||||
INIT_STATIC_MEMBER(enabled_, true)
|
||||
INIT_STATIC_MEMBER(logFunc_, nullptr)
|
||||
INIT_STATIC_MEMBER(errFunc_, nullptr)
|
||||
decltype(Debug::mode_) Debug::mode_ = Debug::Mode::kFile;
|
||||
decltype(Debug::logFunc_) Debug::logFunc_ = nullptr;
|
||||
decltype(Debug::errFunc_) Debug::errFunc_ = nullptr;
|
||||
decltype(Debug::fs_) Debug::fs_;
|
||||
|
||||
|
||||
void Debug::Initialize()
|
||||
{
|
||||
if (mode_ == Mode::kFile)
|
||||
{
|
||||
fs_.open("uDesktopDuplication.log");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Debug::Finalize()
|
||||
{
|
||||
fs_.close();
|
||||
}
|
||||
|
||||
|
||||
void Debug::Log(const char* msg)
|
||||
{
|
||||
if (!enabled_ || logFunc_ == nullptr) return;
|
||||
|
||||
char buf[256];
|
||||
sprintf_s(buf, 256, "[uDD::Log] %s", msg);
|
||||
logFunc_(buf);
|
||||
switch (mode_)
|
||||
{
|
||||
case Mode::kNone:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case Mode::kFile:
|
||||
{
|
||||
if (fs_.good())
|
||||
{
|
||||
fs_ << "[uDD::Log] " << msg << std::endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Mode::kUnityLog:
|
||||
{
|
||||
if (logFunc_ == nullptr)
|
||||
{
|
||||
char buf[256];
|
||||
sprintf_s(buf, 256, "[uDD::Log] %s", msg);
|
||||
logFunc_(buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Debug::Error(const char* msg)
|
||||
{
|
||||
if (!enabled_ || errFunc_ == nullptr) return;
|
||||
|
||||
char buf[256];
|
||||
sprintf_s(buf, 256, "[uDD::Err] %s", msg);
|
||||
errFunc_(buf);
|
||||
switch (mode_)
|
||||
{
|
||||
case Mode::kNone:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case Mode::kFile:
|
||||
{
|
||||
if (fs_.good())
|
||||
{
|
||||
fs_ << "[uDD::Err] " << msg << std::endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Mode::kUnityLog:
|
||||
{
|
||||
if (logFunc_ == nullptr)
|
||||
{
|
||||
char buf[256];
|
||||
sprintf_s(buf, 256, "[uDD::Err] %s", msg);
|
||||
errFunc_(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,23 @@
|
||||
#pragma once
|
||||
#include <fstream>
|
||||
#include "IUnityInterface.h"
|
||||
|
||||
// Logging
|
||||
class Debug
|
||||
{
|
||||
public:
|
||||
static void Enable() { enabled_ = true; }
|
||||
static void Disable() { enabled_ = false; }
|
||||
enum class Mode
|
||||
{
|
||||
kNone = 0,
|
||||
kFile = 1,
|
||||
kUnityLog = 2,
|
||||
};
|
||||
|
||||
using DebugLogFuncPtr = void(*)(const char*);
|
||||
using DebugLogFuncPtr = void(UNITY_INTERFACE_API *)(const char*);
|
||||
|
||||
static void SetMode(Mode mode) { mode_ = mode; }
|
||||
static void Initialize();
|
||||
static void Finalize();
|
||||
static void SetLogFunc(DebugLogFuncPtr func) { logFunc_ = func; }
|
||||
static void SetErrorFunc(DebugLogFuncPtr func) { errFunc_ = func; }
|
||||
|
||||
@@ -16,7 +26,8 @@ public:
|
||||
static void Error(const char* msg);
|
||||
|
||||
private:
|
||||
static bool enabled_;
|
||||
static Mode mode_;
|
||||
static std::ofstream fs_;
|
||||
static DebugLogFuncPtr logFunc_;
|
||||
static DebugLogFuncPtr errFunc_;
|
||||
};
|
||||
@@ -14,6 +14,11 @@ Monitor::Monitor(int id)
|
||||
}
|
||||
|
||||
|
||||
Monitor::~Monitor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Monitor::Initialize(IDXGIOutput* output)
|
||||
{
|
||||
output->GetDesc(&outputDesc_);
|
||||
@@ -37,33 +42,33 @@ void Monitor::Initialize(IDXGIOutput* output)
|
||||
break;
|
||||
case E_INVALIDARG:
|
||||
state_ = State::InvalidArg;
|
||||
Debug::Error("Monitor::Initialize() => Invalid arguments.");
|
||||
break;
|
||||
case E_ACCESSDENIED:
|
||||
// For example, when the user presses Ctrl + Alt + Delete and the screen
|
||||
// switches to admin screen, this error occurs.
|
||||
state_ = State::AccessDenied;
|
||||
Debug::Error("Monitor::Initialize() => Access denied.");
|
||||
break;
|
||||
case DXGI_ERROR_UNSUPPORTED:
|
||||
// If the display adapter on the computer is running under the Microsoft Hybrid system,
|
||||
// this error occurs.
|
||||
state_ = State::Unsupported;
|
||||
Debug::Error("Monitor::Initialize() => Unsupported display.");
|
||||
break;
|
||||
case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE:
|
||||
// When other application use Desktop Duplication API, this error occurs.
|
||||
state_ = State::CurrentlyNotAvailable;
|
||||
Debug::Error("Monitor::Initialize() => Currently not available.");
|
||||
break;
|
||||
case DXGI_ERROR_SESSION_DISCONNECTED:
|
||||
state_ = State::SessionDisconnected;
|
||||
Debug::Error("Monitor::Initialize() => Session disconnected.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Monitor::~Monitor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Monitor::Render(UINT timeout)
|
||||
{
|
||||
if (!deskDupl_) return;
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
IUnityInterfaces* g_unity = nullptr;
|
||||
std::unique_ptr<MonitorManager> g_manager;
|
||||
std::unique_ptr<Debug> g_debug;
|
||||
std::queue<Message> g_messages;
|
||||
|
||||
|
||||
@@ -31,14 +30,20 @@ extern "C"
|
||||
if (g_unity && !g_manager)
|
||||
{
|
||||
g_manager = std::make_unique<MonitorManager>();
|
||||
g_debug = std::make_unique<Debug>();
|
||||
Debug::Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API FinalizeUDD()
|
||||
{
|
||||
g_manager.reset();
|
||||
g_debug.reset();
|
||||
|
||||
std::queue<Message> empty;
|
||||
g_messages.swap(empty);
|
||||
|
||||
Debug::SetLogFunc(nullptr);
|
||||
Debug::SetErrorFunc(nullptr);
|
||||
Debug::Finalize();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
|
||||
@@ -49,8 +54,8 @@ extern "C"
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginUnload()
|
||||
{
|
||||
g_unity = nullptr;
|
||||
FinalizeUDD();
|
||||
g_unity = nullptr;
|
||||
}
|
||||
|
||||
void UNITY_INTERFACE_API OnRenderEvent(int id)
|
||||
@@ -88,28 +93,19 @@ extern "C"
|
||||
return message;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API EnableDebug()
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetDebugMode(Debug::Mode mode)
|
||||
{
|
||||
if (!g_debug) return;
|
||||
g_debug->Enable();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API DisableDebug()
|
||||
{
|
||||
if (!g_debug) return;
|
||||
g_debug->Disable();
|
||||
Debug::SetMode(mode);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetLogFunc(Debug::DebugLogFuncPtr func)
|
||||
{
|
||||
if (!g_debug) return;
|
||||
g_debug->SetLogFunc(func);
|
||||
Debug::SetLogFunc(func);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetErrorFunc(Debug::DebugLogFuncPtr func)
|
||||
{
|
||||
if (!g_debug) return;
|
||||
g_debug->SetErrorFunc(func);
|
||||
Debug::SetErrorFunc(func);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT size_t UNITY_INTERFACE_API GetMonitorCount()
|
||||
|
||||
Reference in New Issue
Block a user