add namespace

This commit is contained in:
DevWiki 2024-09-29 10:18:35 +08:00
parent ccf642ef92
commit 5c8f902c11
15 changed files with 151 additions and 142 deletions

View File

@ -13,44 +13,42 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH_DIR "x64")
else()
set(ARCH_DIR "x86")
endif()
# option(IS_DEBUG "Enable debug mode" OFF)
# if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# set(IS_DEBUG ON)
# else()
# set(IS_DEBUG OFF)
# endif()
option(IS_DEBUG "Enable debug mode" OFF)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(IS_DEBUG ON)
else()
set(IS_DEBUG OFF)
endif()
# set(WinDevice_OUTPUT "../WinDevice/output")
# message("WinDevice_OUTPUT: ${WinDevice_OUTPUT}")
# #
# if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# set(ARCH_DIR "x64")
# else()
# set(ARCH_DIR "x86")
# endif()
# set(WinDevice_INCLUDE_DIR "${WinDevice_OUTPUT}/include/")
# message("WinDevice_INCLUDE_DIR: ${WinDevice_INCLUDE_DIR}")
# set(WinDevice_THIRD_INCLUDE_DIR "${WinDevice_OUTPUT}/third_lib/")
# message("WinDevice_THIRD_INCLUDE_DIR: ${WinDevice_THIRD_INCLUDE_DIR}")
# if (IS_DEBUG)
# set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/debug/")
# else()
# set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/release/")
# endif()
# message("WinDevice_LIB_DIR: ${WinDevice_LIB_DIR}")
# message("build WinDecie in: ${CMAKE_BUILD_TYPE} mode")
set(WinDevice_OUTPUT "../WinDevice/output")
message("WinDevice_OUTPUT: ${WinDevice_OUTPUT}")
#
set(WinDevice_INCLUDE_DIR "${WinDevice_OUTPUT}/include/")
message("WinDevice_INCLUDE_DIR: ${WinDevice_INCLUDE_DIR}")
set(WinDevice_THIRD_INCLUDE_DIR "${WinDevice_OUTPUT}/third_lib/")
message("WinDevice_THIRD_INCLUDE_DIR: ${WinDevice_THIRD_INCLUDE_DIR}")
if (IS_DEBUG)
set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/debug/")
else()
set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/release/")
endif()
message("WinDevice_LIB_DIR: ${WinDevice_LIB_DIR}")
message("build WinDecie in: ${CMAKE_BUILD_TYPE} mode")
add_custom_target(BuildWinDevice ALL
COMMAND ${CMAKE_COMMAND} -E echo "Starting to build WinDevice project..."
COMMAND ${CMAKE_COMMAND} -S ../WinDevice -B ../WinDevice/build -G "Visual Studio 17 2022" -A ${ARCH_DIR} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
COMMAND ${CMAKE_COMMAND} --build ../WinDevice/build --config ${CMAKE_BUILD_TYPE}
COMMENT "Building WinDevice project in ${CMAKE_BUILD_TYPE} mode"
)
# add_custom_target(BuildWinDevice ALL
# COMMAND ${CMAKE_COMMAND} -E echo "Starting to build WinDevice project..."
# COMMAND ${CMAKE_COMMAND} -S ../WinDevice -B ../WinDevice/build -G "Visual Studio 17 2022" -A ${ARCH_DIR} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
# COMMAND ${CMAKE_COMMAND} --build ../WinDevice/build --config ${CMAKE_BUILD_TYPE}
# COMMENT "Building WinDevice project in ${CMAKE_BUILD_TYPE} mode"
# )
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

View File

@ -12,7 +12,7 @@ int main(int argc, char *argv[])
qInstallMessageHandler(LogManager::CustomMessageHandler);
WinDevice::WinDeviceManager::Init();
ScreenManager screenManager;
WinDevice::ScreenManager screenManager;
screenManager.UpdateDisplayInfo();
qDebug("Adapter Count: %d", screenManager._displayDeviceList.size());

View File

@ -1,7 +1,9 @@
#pragma once
namespace WinDevice {
enum AudioDeviceType
{
Render,
Capture
};
}

View File

@ -2,16 +2,16 @@
#include <iostream>
AudioManager::AudioManager()
WinDevice::AudioManager::AudioManager()
{
// 创建设备枚举器
}
AudioManager::~AudioManager()
WinDevice::AudioManager::~AudioManager()
{
}
HRESULT AudioManager::Init()
HRESULT WinDevice::AudioManager::Init()
{
HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), reinterpret_cast<void**>(&pEnumerator));
if (FAILED(hr))
@ -31,7 +31,7 @@ HRESULT AudioManager::Init()
return hr;
}
HRESULT AudioManager::Uninit()
HRESULT WinDevice::AudioManager::Uninit()
{
pEnumerator = nullptr;
pCaptureCollection = nullptr;
@ -41,7 +41,7 @@ HRESULT AudioManager::Uninit()
return S_OK;
}
IMMDeviceCollection* AudioManager::GetDeviceList(EDataFlow flow)
IMMDeviceCollection* WinDevice::AudioManager::GetDeviceList(EDataFlow flow)
{
if (flow == eCapture)
{
@ -66,7 +66,7 @@ IMMDeviceCollection* AudioManager::GetDeviceList(EDataFlow flow)
return nullptr;
}
IMMDevice* AudioManager::GetDefaultDevice(EDataFlow flow)
IMMDevice* WinDevice::AudioManager::GetDefaultDevice(EDataFlow flow)
{
if (flow == eCapture)
{
@ -79,7 +79,7 @@ IMMDevice* AudioManager::GetDefaultDevice(EDataFlow flow)
return nullptr;
}
HRESULT AudioManager::_UpdateDeviceList(EDataFlow flow)
HRESULT WinDevice::AudioManager::_UpdateDeviceList(EDataFlow flow)
{
HRESULT hr = S_OK;
if (flow == eCapture)
@ -93,7 +93,7 @@ HRESULT AudioManager::_UpdateDeviceList(EDataFlow flow)
return hr;
}
HRESULT AudioManager::_UpdateDefaultDevice(EDataFlow flow)
HRESULT WinDevice::AudioManager::_UpdateDefaultDevice(EDataFlow flow)
{
HRESULT hr = S_OK;
if (flow == eCapture)

View File

@ -2,6 +2,7 @@
#include <Mmdeviceapi.h>
namespace WinDevice {
class AudioManager
{
public:
@ -24,3 +25,4 @@ private:
HRESULT _UpdateDeviceList(EDataFlow flow);
HRESULT _UpdateDefaultDevice(EDataFlow flow);
};
}

View File

@ -7,7 +7,7 @@
using namespace std;
std::string CmdUtil::ExecuteCommand(const std::string& command)
std::string WinDevice::CmdUtil::ExecuteCommand(const std::string& command)
{
spdlog::info("ExecuteCommand command:{0}", command);
auto cmd_result = std::string();

View File

@ -1,8 +1,11 @@
#pragma once
#include <string>
namespace WinDevice {
class CmdUtil
{
public:
static std::string ExecuteCommand(const std::string& command);
};
}

View File

@ -3,18 +3,18 @@
#include "spdlog/sinks/stdout_sinks.h"
void Log::Init(LogLevel level, std::string fileName)
void WinDevice::Log::Init(LogLevel level, std::string fileName)
{
spdlog::stdout_logger_mt("console");
spdlog::set_level(static_cast<spdlog::level::level_enum>(level)); // 设置日志级别为 debug
spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
}
void Log::Info(std::string format, std::string args...)
void WinDevice::Log::Info(std::string format, std::string args...)
{
}
void Log::WInfo(std::wstring format, std::wstring args...)
void WinDevice::Log::WInfo(std::wstring format, std::wstring args...)
{
}

View File

@ -4,6 +4,7 @@
#define LOG_FUNC_START() spdlog::info("=====> {0} start <=====", __FUNCTION__)
#define LOG_FUNC_END() spdlog::info("=====> {0} end <=====", __FUNCTION__)
namespace WinDevice {
enum LogLevel : int
{
Debug = spdlog::level::debug,
@ -18,3 +19,5 @@ public:
static void Info(std::string format, std::string args...);
static void WInfo(std::wstring format, std::wstring args...);
};
}

View File

@ -2,9 +2,7 @@
#include <locale>
#include <codecvt>
namespace WinDevcie {
namespace Utils {
namespace WinDevice {
template<typename To, typename From>
To Convert(const From& input) {
@ -20,6 +18,5 @@ namespace Utils {
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
return converter.to_bytes(input);
}
}
}

View File

@ -1,9 +1,8 @@
#include "TimeUtil.h"
#include "spdlog/spdlog.h"
template <typename Func>
void TimeUtil<Func>::CalExecuteTime(Func func)
void WinDevice::TimeUtil<Func>::CalExecuteTime(Func func)
{
// 测量函数调用的耗时
const auto start = std::chrono::high_resolution_clock::now();

View File

@ -1,8 +1,11 @@
#pragma once
template <typename Func>
namespace WinDevice {
template <typename Func>
class TimeUtil
{
public:
static void CalExecuteTime(Func func);
};
}

View File

@ -4,24 +4,24 @@
#include "../Utils/Log.h"
#include <dxgi.h>
ScreenManager::ScreenManager()
WinDevice::ScreenManager::ScreenManager()
{
}
ScreenManager::~ScreenManager()
WinDevice::ScreenManager::~ScreenManager()
{
}
void ScreenManager::UpdateDisplayInfo()
void WinDevice::ScreenManager::UpdateDisplayInfo()
{
_UpdateDisplayDeviceList();
_UpdateMonitorInfoMap();
_UpdateDisplayAdapterList();
}
void ScreenManager::_UpdateDisplayDeviceList()
void WinDevice::ScreenManager::_UpdateDisplayDeviceList()
{
spdlog::info("=====GetInfoByEnumDisplayDevices start=====");
DISPLAY_DEVICE displayDevice;
@ -39,7 +39,7 @@ void ScreenManager::_UpdateDisplayDeviceList()
spdlog::info("=====GetInfoByEnumDisplayDevices end=====");
}
void ScreenManager::_UpdateDisplayAdapterList()
void WinDevice::ScreenManager::_UpdateDisplayAdapterList()
{
LOG_FUNC_START();
HRESULT hr = S_OK;
@ -56,7 +56,7 @@ void ScreenManager::_UpdateDisplayAdapterList()
DXGI_ADAPTER_DESC adapterDesc;
pAdapter->GetDesc(&adapterDesc);
spdlog::info("Adapter Index:{0}, Description:{1}, DeviceId:{2}, VendorId:{3}, SubSysId:{4}, Revision:{5}, AdapterLuid(H-L):{6}-{7} ",
adapterIndex, WinDevcie::Utils::Wchar2String(adapterDesc.Description), adapterDesc.DeviceId, adapterDesc.VendorId, adapterDesc.SubSysId,
adapterIndex, WinDevice::Wchar2String(adapterDesc.Description), adapterDesc.DeviceId, adapterDesc.VendorId, adapterDesc.SubSysId,
adapterDesc.Revision, adapterDesc.AdapterLuid.HighPart, adapterDesc.AdapterLuid.LowPart);
// print adapter output info
@ -72,7 +72,7 @@ void ScreenManager::_UpdateDisplayAdapterList()
{
// 输出友好名称
spdlog::info("Adapter Output Index:{0}, DeviceName:{1}, szDevice:{2}, right:{3}, bottom:{4}",
j, WinDevcie::Utils::Wchar2String(outputDesc.DeviceName), monitorInfo.szDevice, monitorInfo.rcMonitor.right, monitorInfo.rcMonitor.bottom);
j, WinDevice::Wchar2String(outputDesc.DeviceName), monitorInfo.szDevice, monitorInfo.rcMonitor.right, monitorInfo.rcMonitor.bottom);
}
}
}
@ -80,7 +80,7 @@ void ScreenManager::_UpdateDisplayAdapterList()
LOG_FUNC_END();
}
BOOL ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
BOOL WinDevice::ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
{
MONITORINFOEX monitorInfo;
monitorInfo.cbSize = sizeof(MONITORINFOEX);
@ -110,7 +110,7 @@ BOOL ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
if (DisplayConfigGetDeviceInfo(&targetDeviceName.header) == ERROR_SUCCESS)
{
spdlog::info("_UpdateMonitorInfoMap, monitorDevicePath:{0}, monitorFriendlyDeviceName:{1}",
WinDevcie::Utils::Wchar2String(targetDeviceName.monitorDevicePath), WinDevcie::Utils::Wchar2String(targetDeviceName.monitorFriendlyDeviceName));
WinDevice::Wchar2String(targetDeviceName.monitorDevicePath), WinDevice::Wchar2String(targetDeviceName.monitorFriendlyDeviceName));
// 获取指定 HMONITOR 的分辨率信息
DEVMODE dm;
@ -133,12 +133,12 @@ BOOL ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
return TRUE;
}
BOOL CALLBACK ScreenManager::EnumMonitorsProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
BOOL CALLBACK WinDevice::ScreenManager::EnumMonitorsProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
return ((ScreenManager*)dwData)->_EnumMonitorProc(hMonitor);
}
void ScreenManager::_UpdateMonitorInfoMap()
void WinDevice::ScreenManager::_UpdateMonitorInfoMap()
{
spdlog::info("=====GetInfoByEnumDisplayMonitors start=====");
// 枚举显示器

View File

@ -3,6 +3,7 @@
#include <map>
#include <dxgi.h>
namespace WinDevice {
class ScreenManager
{
public:
@ -21,3 +22,4 @@ private:
static BOOL CALLBACK EnumMonitorsProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData);
BOOL _EnumMonitorProc(HMONITOR hMonitor);
};
}

View File

@ -4,7 +4,7 @@
#include <iostream>
#include "Video/ScreenManager.h"
int main() {
ScreenManager screenManager;
WinDevice::ScreenManager screenManager;
screenManager.UpdateDisplayInfo();
std::cout << "Press Enter to exit..." << std::endl; // 输出提示信息
std::cin.get(); // 等待用户输入