More work

This commit is contained in:
Jordon Brooks 2024-05-27 13:18:50 +01:00
parent b35dec2fdc
commit 6b90c9f76a
Signed by: jordon
GPG key ID: DBD9758CD53E786A
30 changed files with 710 additions and 109 deletions

View file

@ -0,0 +1,155 @@
# Copyright (c) 2024 Jordon Brooks
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.10)
project(LibHarmonyLink VERSION 2.1.1)
# Specify the C++ standard
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)
# Find the current Git branch and the last commit timestamp
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%ct
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_TIMESTAMP
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
set(GIT_BRANCH_NAME "Unknown")
set(GIT_COMMIT_TIMESTAMP "Unknown")
endif()
configure_file(include/Version.h.in Version.generated.h)
# Define metadata variables
set(FILE_DESCRIPTION "Enhances handheld gaming with intelligent hardware recognition, dynamic adaptability, and robust API access for Windows and Linux, including Steam Deck and Wine support.")
set(INTERNAL_NAME "LibHarmonyLink")
set(ORIGINAL_FILENAME "LibHarmonyLink.dll")
set(PRODUCT_NAME "LibHarmonyLink")
set(COMMENTS "")
# Configure version.rc file for shared library
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Resources/Version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
# Explicitly list source files
set(COMMON_SOURCES
src/HarmonyLinkLib.c
src/Version.c
src/Utilities.c
src/Structs/Battery.c
src/Structs/CPUInfo.c
src/Structs/StringArray.c
src/Structs/Device.c
src/Structs/OSInfo.C
)
# Explicitly list include files
set(COMMON_INCLUDES
include/Core.h
include/HarmonyLinkLib.h
include/Version.h
include/Utilities.h
include/Enums/Device.h
include/Enums/Platform.h
include/Enums/SteamDeck.h
include/Structs/Battery.h
include/Structs/CPUInfo.h
include/Structs/StringArray.h
include/Structs/Device.h
include/Structs/OSInfo.h
)
set(WINDOWS_SOURCES
)
set(WINDOWS_INCLUDES
)
set(LINUX_SOURCES
)
set(LINUX_INCLUDES
)
set(MAC_SOURCES
)
set(MAC_INCLUDES
)
# Platform-specific definitions
if(WIN32)
message(STATUS "Compiling for Windows...")
list(APPEND LIB_SOURCES ${COMMON_SOURCES} ${WINDOWS_SOURCES})
list(APPEND LIB_INCLUDES ${COMMON_INCLUDES} ${WINDOWS_INCLUDES})
list(APPEND SHARED_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
elseif(UNIX)
message(STATUS "Compiling for Unix-based systems...")
if(APPLE)
message(STATUS "Compiling for Mac...")
list(APPEND LIB_SOURCES ${COMMON_SOURCES} ${MAC_SOURCES})
list(APPEND LIB_INCLUDES ${COMMON_INCLUDES} ${MAC_INCLUDES})
else()
message(STATUS "Compiling for Linux...")
list(APPEND LIB_SOURCES ${COMMON_SOURCES} ${LINUX_SOURCES})
list(APPEND LIB_INCLUDES ${COMMON_INCLUDES} ${LINUX_INCLUDES})
endif()
endif()
# Create the shared library
add_library(LibHarmonyLinkShared SHARED ${LIB_SOURCES} ${LIB_INCLUDES} ${SHARED_SOURCES})
target_include_directories(LibHarmonyLinkShared
PRIVATE
"${PROJECT_SOURCE_DIR}/src"
PUBLIC
"${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/include"
)
target_compile_definitions(LibHarmonyLinkShared PRIVATE HARMONYLINK_SHARED)
# Create the static library
add_library(LibHarmonyLinkStatic STATIC ${LIB_SOURCES} ${LIB_INCLUDES})
target_include_directories(LibHarmonyLinkStatic
PRIVATE
"${PROJECT_SOURCE_DIR}/src"
PUBLIC
"${PROJECT_BINARY_DIR}"
"${PROJECT_SOURCE_DIR}/include"
)
target_compile_definitions(LibHarmonyLinkStatic PRIVATE HARMONYLINK_STATIC)
# Set output directories for all build types
foreach(TYPE IN ITEMS DEBUG RELEASE)
string(TOUPPER ${TYPE} TYPE_UPPER)
set_target_properties(LibHarmonyLinkShared PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/bin/${TYPE}/HarmonyLinkLib"
LIBRARY_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/lib/${TYPE}/HarmonyLinkLib"
ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkLib"
)
set_target_properties(LibHarmonyLinkStatic PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_${TYPE_UPPER} "${CMAKE_BINARY_DIR}/archive/${TYPE}/HarmonyLinkLibStatic"
)
endforeach()

View file

@ -0,0 +1,49 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <windows.h>
#include <winver.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,0
PRODUCTVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@,0
FILEFLAGSMASK 0x3fL
FILEFLAGS 0x0L
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
{
BLOCK "StringFileInfo"
{
BLOCK "040904b0"
{
VALUE "CompanyName", "N/A"
VALUE "FileDescription", "@FILE_DESCRIPTION@"
VALUE "FileVersion", "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@.0"
VALUE "InternalName", "@INTERNAL_NAME@"
VALUE "OriginalFilename", "@ORIGINAL_FILENAME@"
VALUE "ProductName", "@PRODUCT_NAME@"
VALUE "ProductVersion", "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@.0"
VALUE "Comments", "@COMMENTS@"
VALUE "LegalCopyright", "N/A"
VALUE "LegalTrademarks", "N/A"
VALUE "PrivateBuild", "N/A"
VALUE "SpecialBuild", "N/A"
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x409, 1200
}
}

View file

@ -0,0 +1,30 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
// Use a preprocessor definition to switch between export and import declarations
#ifdef _WIN32
#ifdef HARMONYLINK_STATIC
#define HARMONYLINK_API
#else
#ifdef HARMONYLINK_SHARED
#define HARMONYLINK_API __declspec(dllexport)
#else
#define HARMONYLINK_API __declspec(dllimport)
#endif
#endif
#else
#define HARMONYLINKLIB_API
#endif

View file

@ -0,0 +1,52 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "Core.h"
// Undefine the LINUX macro to avoid conflicts with the enum definition.
#undef LINUX
#ifdef __cplusplus
namespace LibHarmonyLink {
extern "C" {
#endif
typedef enum {
EDevice_UNKNOWN,
EDevice_DESKTOP,
EDevice_LAPTOP,
EDevice_HANDHELD,
EDevice_STEAM_DECK,
// EDevice_ROG_ALLY
// EDevice_AYONEO_SLIDE
// etc...
} EDevice;
HARMONYLINK_API const char* Device_ToString(EDevice device) {
switch (device) {
case EDevice_DESKTOP: return "DESKTOP";
case EDevice_LAPTOP: return "LAPTOP";
case EDevice_HANDHELD: return "HANDHELD";
case EDevice_STEAM_DECK: return "STEAM_DECK";
default: return "UNKNOWN";
}
}
#ifdef __cplusplus
}
}
#endif

View file

@ -0,0 +1,46 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "Core.h"
#ifdef __cplusplus
namespace LibHarmonyLink {
extern "C" {
#endif
typedef enum {
EPlatform_UNKNOWN,
EPlatform_WINDOWS,
EPlatform_LINUX,
EPlatform_MAC,
EPlatform_UNIX,
} EPlatform;
// Helper functions to convert enums to strings (must be implemented somewhere in your code)
HARMONYLINK_API const char* Platform_ToString(EPlatform platform) {
switch (platform) {
case EPlatform_WINDOWS: return "WINDOWS";
case EPlatform_LINUX: return "LINUX";
case EPlatform_MAC: return "MAC";
case EPlatform_UNIX: return "UNIX";
default: return "UNKNOWN";
}
}
#ifdef __cplusplus
}
}
#endif

View file

@ -0,0 +1,44 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "Core.h"
#ifdef __cplusplus
namespace LibHarmonyLink {
extern "C" {
#endif
typedef enum {
ESteamDeck_NONE, // Device is not a steam deck
ESteamDeck_UNKNOWN, // Device is a steam deck but model cannot be determined
ESteamDeck_LCD,
ESteamDeck_OLED,
} ESteamDeck;
HARMONYLINK_API const char* SteamDeck_ToString(ESteamDeck steam_deck_model) {
switch (steam_deck_model) {
case ESteamDeck_NONE: return "NONE";
case ESteamDeck_LCD: return "STEAMDECK_LCD";
case ESteamDeck_OLED: return "STEAMDECK_OLED";
// Add other cases as needed
default: return "UNKNOWN";
}
}
#ifdef __cplusplus
}
}
#endif

View file

@ -0,0 +1,30 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdbool.h>
#include "Core.h"
#ifdef __cplusplus
namespace LibHarmonyLink {
extern "C" {
#endif
HARMONYLINK_API bool HarmonyLink_Init(void);
#ifdef __cplusplus
}
}
#endif

View file

@ -0,0 +1,40 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdbool.h>
#include "Core.h"
#ifdef __cplusplus
namespace LibHarmonyLink {
extern "C" {
#endif
typedef struct {
bool has_battery;
bool is_connected_to_ac;
unsigned char battery_percent;
} FBattery;
HARMONYLINK_API FBattery* HL_FBattery_Init(bool has_battery, bool is_connected_to_ac, unsigned char battery_percent);
HARMONYLINK_API void HL_FBattery_print(const FBattery *self);
#ifdef __cplusplus
}
}
#endif

View file

@ -0,0 +1,57 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// include/Structs/CPUInfo.h
#pragma once
#include <stdio.h>
#include <stdbool.h>
#include "Core.h"
#include "Structs/StringArray.h"
#ifdef __cplusplus
namespace LibHarmonyLink {
extern "C" {
#endif
typedef struct {
char *VendorID;
char *Model_Name;
unsigned int Physical_Cores;
unsigned int Logical_Cores;
StringArray flagsInfo;
} FCPUInfo;
// Initialize FCPUInfo
FCPUInfo* FCPUInfo_Init(const char *vendorID, const char *modelName, unsigned int physicalCores, unsigned int logicalCores,
size_t flagsCount);
// Print FlagsInfo
HARMONYLINK_API void HL_FlagsInfo_Print(const FCPUInfo *cpuInfo);
// Print FCPUInfo
HARMONYLINK_API void HL_FCPUInfo_Print(const FCPUInfo *cpuInfo);
// Free FCPUInfo
HARMONYLINK_API void HL_FCPUInfo_Free(FCPUInfo *cpuInfo);
// Check if a flag exists in FlagsInfo
HARMONYLINK_API bool HL_FlagsInfo_Contains(const FCPUInfo *cpuInfo, const char *flag);
#ifdef __cplusplus
}
}
#endif

View file

@ -0,0 +1,47 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "Core.h"
#include "Enums/Platform.h"
#include "Enums/Device.h"
#include "Enums/SteamDeck.h"
#define DEFAULT_INITIAL_FLAGS_SIZE 4
#ifdef __cplusplus
namespace LibHarmonyLink {
extern "C" {
#endif
typedef struct {
EPlatform platform;
EDevice device;
ESteamDeck steam_deck_model;
} FDevice;
// Initialize FlagsInfo
FDevice* Device_Init(EPlatform platform, EDevice device, ESteamDeck steam_deck_model);
// Print FlagsInfo
HARMONYLINK_API void HL_Device_Print(const FDevice* Device);
// Free FlagsInfo
HARMONYLINK_API void HL_Device_Free(FDevice* Device);
#ifdef __cplusplus
}
}
#endif

View file

@ -0,0 +1,49 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdio.h>
#include <stdbool.h>
#include "Core.h"
#ifdef __cplusplus
namespace LibHarmonyLink {
extern "C" {
#endif
typedef struct {
char* name;
char* version;
unsigned int id;
char* version_id;
char* version_codename;
char* pretty_name;
char* variant_id;
} FOSVerInfo;
// Initialize FCPUInfo
FOSVerInfo* FOSVerInfo_Init(char* name, char* version, unsigned int id, char* version_id, char* version_codename, char* pretty_name, char* variant_id);
// Print FlagsInfo
HARMONYLINK_API void HL_FOSVerInfo_Print(const FOSVerInfo* OSVerInfo);
// Free FCPUInfo
HARMONYLINK_API void HL_FOSVerInfo_Free(FOSVerInfo* OSVerInfo);
#ifdef __cplusplus
}
}
#endif

View file

@ -0,0 +1,61 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// include/Structs/StringArray.h
#pragma once
#include <stdio.h>
#include <stdbool.h>
#include "Core.h"
#define DEFAULT_INITIAL_FLAGS_SIZE 4
#ifdef __cplusplus
namespace LibHarmonyLink {
extern "C" {
#endif
typedef struct {
char **data; // Array of strings (flags)
size_t FlagsCount; // Number of flags
size_t AllocatedSize; // Number of allocated slots
} StringArray;
// Initialize FlagsInfo
void StringArray_Init(StringArray *flagsInfo, size_t overrideInitialSize);
// Print FlagsInfo
HARMONYLINK_API void HL_StringArray_Print(const StringArray *flagsInfo);
// Free FlagsInfo
HARMONYLINK_API void HL_StringArray_Free(StringArray *flagsInfo);
// Check if a flag exists in FlagsInfo
HARMONYLINK_API bool HL_StringArray_Contains(const StringArray *flagsInfo, const char *flag);
// Add a flag to FlagsInfo
void StringArray_AddFlag(StringArray *flagsInfo, const char *flag);
// Remove a flag from FlagsInfo by value
void StringArray_Remove(StringArray *flagsInfo, const char *flag);
// Resize FlagsInfo array
void StringArray_Resize(StringArray *flagsInfo, size_t newSize);
#ifdef __cplusplus
}
}
#endif

View file

@ -0,0 +1,28 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <wchar.h>
#ifdef __cplusplus
namespace LibHarmonyLink {
extern "C" {
#endif
// Utility function to convert char* to wchar_t*
wchar_t *convertToWideChar(const char *str);
#ifdef __cplusplus
}
}
#endif

View file

@ -0,0 +1,40 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdbool.h>
#include "Core.h"
#ifdef __cplusplus
namespace LibHarmonyLink {
extern "C" {
#endif
HARMONYLINK_API char* HL_version_get_string(void);
HARMONYLINK_API char* HL_version_build_timestamp(void);
HARMONYLINK_API char* HL_git_branch(void);
HARMONYLINK_API char* HL_git_commit_timestamp(void);
HARMONYLINK_API bool HL_is_debug(void);
HARMONYLINK_API void HL_version_print(void);
#ifdef __cplusplus
}
}
#endif

View file

@ -0,0 +1,25 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Version.h.in
#pragma once
#define HARMONYLINK_VERSION_MAJOR @LibHarmonyLink_VERSION_MAJOR@
#define HARMONYLINK_VERSION_MINOR @LibHarmonyLink_VERSION_MINOR@
#define HARMONYLINK_VERSION_PATCH @LibHarmonyLink_VERSION_PATCH@
#define HARMONYLINK_VERSION_TWEAK @LibHarmonyLink_VERSION_TWEAK@
#define HARMONYLINK_VERSION "@LibHarmonyLink_VERSION@"
#define GIT_BRANCH_NAME "@GIT_BRANCH_NAME@"
#define GIT_COMMIT_TIMESTAMP "@GIT_COMMIT_TIMESTAMP@"

View file

@ -0,0 +1,24 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdbool.h>
#include "HarmonyLinkLib.h"
#include "Version.h"
bool HarmonyLink_Init(void)
{
HL_version_print();
return 1;
}

View file

@ -0,0 +1,41 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Structs/Battery.h"
#include <wchar.h>
#include <malloc.h>
#include <stdio.h>
FBattery* HL_FBattery_Init(bool has_battery, bool is_connected_to_ac, unsigned char battery_percent) {
FBattery* battery = (FBattery*)malloc(sizeof(FBattery));
if (battery == NULL) {
fprintf(stderr, "Memory allocation failed for FCPUInfo.\n");
exit(EXIT_FAILURE);
}
battery->has_battery = has_battery;
battery->battery_percent = is_connected_to_ac;
battery->is_connected_to_ac = battery_percent;
return battery;
}
void FBattery_print(const FBattery* self)
{
wprintf(L"Battery present: %ls\n", self->has_battery ? L"'Yes'" : L"'No'");
wprintf(L"Connected to AC: %ls\n", self->is_connected_to_ac ? L"'Yes'" : L"'No'");
wprintf(L"Battery percent: %ls\n", self->battery_percent ? L"'Yes'" : L"'No'");
}

View file

@ -0,0 +1,83 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Structs/CPUInfo.h"
#include "Utilities.h"
#include <stdlib.h>
#include <string.h>
FCPUInfo* FCPUInfo_Init(const char *vendorID, const char *modelName, unsigned int physicalCores,
unsigned int logicalCores, size_t flagsCount) {
FCPUInfo *cpuInfo = (FCPUInfo*)malloc(sizeof(FCPUInfo));
if (cpuInfo == NULL) {
fprintf(stderr, "Memory allocation failed for FCPUInfo.\n");
exit(EXIT_FAILURE);
}
#if defined(BUILD_WINDOWS)
cpuInfo->VendorID = _strdup(vendorID);
cpuInfo->Model_Name = _strdup(modelName);
#else
cpuInfo->VendorID = strdup(vendorID);
cpuInfo->Model_Name = strdup(modelName);
#endif
cpuInfo->Physical_Cores = physicalCores;
cpuInfo->Logical_Cores = logicalCores;
StringArray_Init(&cpuInfo->flagsInfo, flagsCount);
return cpuInfo;
}
void HL_FlagsInfo_Print(const FCPUInfo* cpuInfo) {
if (!cpuInfo)
{
fprintf(stderr, "cpuInfo is nullptr!\n");
return;
}
HL_StringArray_Print(&cpuInfo->flagsInfo);
}
void HL_FCPUInfo_Print(const FCPUInfo *cpuInfo) {
wchar_t* wVendorID = convertToWideChar(cpuInfo->VendorID);
wchar_t* wModelName = convertToWideChar(cpuInfo->Model_Name);
wprintf(L"VendorID: %ls\n", wVendorID);
wprintf(L"Model Name: %ls\n", wModelName);
wprintf(L"Physical Cores: %u\n", cpuInfo->Physical_Cores);
wprintf(L"Logical Cores: %u\n", cpuInfo->Logical_Cores);
wprintf(L"Flags:\n");
HL_StringArray_Print(&cpuInfo->flagsInfo);
free(wVendorID);
free(wModelName);
}
bool HL_FlagsInfo_Contains(const FCPUInfo* cpuInfo, const char* flag) {
if (!cpuInfo)
{
fprintf(stderr, "cpuInfo is nullptr!\n");
return false;
}
return HL_StringArray_Contains(&cpuInfo->flagsInfo, flag);
}
void HL_FCPUInfo_Free(FCPUInfo *cpuInfo) {
free(cpuInfo->VendorID);
free(cpuInfo->Model_Name);
HL_StringArray_Free(&cpuInfo->flagsInfo);
}

View file

@ -0,0 +1,58 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Structs/Device.h"
#include "Utilities.h"
#include <malloc.h>
#include <stdio.h>
FDevice* Device_Init(EPlatform platform, EDevice device, ESteamDeck steam_deck_model) {
FDevice* newDevice = (FDevice*)malloc(sizeof(FDevice));
if (newDevice != NULL) {
newDevice->platform = platform;
newDevice->device = device;
newDevice->steam_deck_model = steam_deck_model;
}
return newDevice;
}
void HL_Device_Print(const FDevice *Device) {
if (Device == NULL) {
wprintf(L"Device is NULL\n");
return;
}
// Assuming that EPlatform, EDevice, and ESteamDeck have corresponding string representations
// which should be implemented for a proper print function
wchar_t* platformStr = convertToWideChar(Platform_ToString(Device->platform));
wchar_t* deviceStr = convertToWideChar(Device_ToString(Device->device));
wchar_t* steamDeckStr = convertToWideChar(SteamDeck_ToString(Device->steam_deck_model));
wprintf(L"Device Information:\n");
wprintf(L"Platform: %ls\n", platformStr);
wprintf(L"Device: %ls\n", deviceStr);
wprintf(L"Steam Deck Model: %ls\n", steamDeckStr);
free(platformStr);
free(deviceStr);
free(steamDeckStr);
}
void HL_Device_Free(FDevice *Device) {
if (Device != NULL) {
free(Device);
}
}

View file

@ -0,0 +1,40 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <malloc.h>
#include "Structs/OSInfo.h"
FOSVerInfo* FOSVerInfo_Init(char* name, char* version, unsigned int id, char* version_id, char* version_codename, char* pretty_name,
char* variant_id) {
FOSVerInfo* OSVerInfo = (FOSVerInfo*)malloc(sizeof(FOSVerInfo));
if (OSVerInfo == NULL) {
fprintf(stderr, "Memory allocation failed for FOSVerInfo.\n");
exit(EXIT_FAILURE);
}
OSVerInfo->name = name;
OSVerInfo->version = version;
OSVerInfo->id = id;
OSVerInfo->variant_id = version_id;
OSVerInfo->version_codename = version_codename;
OSVerInfo->pretty_name = pretty_name;
OSVerInfo->version_id = variant_id;
return OSVerInfo;
}
void HL_FOSVerInfo_Free(FOSVerInfo *OSVerInfo) {
}

View file

@ -0,0 +1,121 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Structs/StringArray.h"
#include "Utilities.h"
#include <stdlib.h>
#include <string.h>
// Initialize FlagsInfo with optional initial size
void StringArray_Init(StringArray *flagsInfo, size_t overrideInitialSize) {
size_t initialSize = DEFAULT_INITIAL_FLAGS_SIZE;
if (overrideInitialSize > 0) {
initialSize = overrideInitialSize;
}
flagsInfo->FlagsCount = 0;
flagsInfo->AllocatedSize = initialSize;
flagsInfo->data = (char**)malloc(initialSize * sizeof(char*));
for (size_t i = 0; i < initialSize; ++i) {
flagsInfo->data[i] = NULL;
}
}
void StringArray_AddFlag(StringArray *flagsInfo, const char *flag) {
// Check if we need to resize the array
if (flagsInfo->FlagsCount >= flagsInfo->AllocatedSize) {
StringArray_Resize(flagsInfo, flagsInfo->AllocatedSize * 2);
}
#if defined(BUILD_WINDOWS)
flagsInfo->data[flagsInfo->FlagsCount] = _strdup(flag);
#else
flagsInfo->data[flagsInfo->FlagsCount] = strdup(flag);
#endif
flagsInfo->FlagsCount++;
}
void HL_StringArray_Print(const StringArray *flagsInfo) {
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
if (flagsInfo->data[i] != NULL) {
wchar_t* wstr = convertToWideChar(flagsInfo->data[i]);
wprintf(L" %ls\n", wstr);
free(wstr);
}
}
}
void HL_StringArray_Free(StringArray *flagsInfo) {
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
free(flagsInfo->data[i]);
}
free(flagsInfo->data);
}
void StringArray_Remove(StringArray *flagsInfo, const char *flag) {
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
if (flagsInfo->data[i] && strcmp(flagsInfo->data[i], flag) == 0) {
free(flagsInfo->data[i]);
for (size_t j = i; j < flagsInfo->FlagsCount - 1; ++j) {
flagsInfo->data[j] = flagsInfo->data[j + 1];
}
flagsInfo->data[flagsInfo->FlagsCount - 1] = NULL;
flagsInfo->FlagsCount--;
break;
}
}
}
bool HL_StringArray_Contains(const StringArray *flagsInfo, const char *flag) {
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
if (flagsInfo->data[i] && strcmp(flagsInfo->data[i], flag) == 0) {
return true;
}
}
return false;
}
// Resize FlagsInfo array
void StringArray_Resize(StringArray* flagsInfo, size_t newSize) {
// Count the number of non-null pointers
size_t nonNullCount = 0;
for (size_t i = 0; i < flagsInfo->FlagsCount; ++i) {
if (flagsInfo->data[i] != NULL) {
nonNullCount++;
}
}
// Check if the new size is smaller than the number of non-null pointers
if (newSize < nonNullCount) {
fprintf(stderr, "Resize failed. New size is smaller than the number of non-null pointers.\n");
return;
}
char** temp = realloc(flagsInfo->data, newSize * sizeof(char*));
if (temp != NULL) {
flagsInfo->data = temp;
if (newSize > flagsInfo->AllocatedSize) {
// Initialize new elements to NULL
for (size_t i = flagsInfo->AllocatedSize; i < newSize; ++i) {
flagsInfo->data[i] = NULL;
}
}
flagsInfo->AllocatedSize = newSize;
} else {
// Handle realloc failure
fprintf(stderr, "Realloc failed. Memory not reallocated.\n");
exit(EXIT_FAILURE);
}
}

View file

@ -0,0 +1,44 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Utilities.h"
#include <stdlib.h>
wchar_t* convertToWideChar(const char* str) {
size_t len = 0;
#if defined(BUILD_WINDOWS)
// Use mbstowcs_s on Windows
mbstowcs_s(&len, NULL, 0, str, 0);
#else
// Use mbstowcs on Linux
len = mbstowcs(NULL, str, 0) + 1;
#endif
// Allocate memory for the wide string
wchar_t* wstr = (wchar_t*)malloc(len * sizeof(wchar_t));
if (wstr == NULL) {
return NULL; // Handle memory allocation failure
}
#if defined(BUILD_WINDOWS)
// Use mbstowcs_s on Windows
mbstowcs_s(&len, wstr, len, str, len - 1);
#else
// Use mbstowcs on Linux
mbstowcs(wstr, str, len);
#endif
return wstr;
}

View file

@ -0,0 +1,55 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "Version.h"
#include <Version.generated.h>
#include <stdio.h>
char* HL_version_get_string(void)
{
return HARMONYLINK_VERSION;
}
char* HL_version_build_timestamp(void)
{
return __TIMESTAMP__;
}
char* HL_git_branch(void)
{
return GIT_BRANCH_NAME;
}
char* HL_git_commit_timestamp(void)
{
return GIT_COMMIT_TIMESTAMP;
}
bool HL_is_debug(void)
{
#ifdef DEBUG_MODE
return true;
#else
return false;
#endif
}
void HL_version_print(void) {
wprintf(L"HarmonyLink V%hs Copyright (C) 2023 Jordon Brooks\n", HL_version_get_string());
wprintf(L"Build Timestamp: %hs\n", HL_version_build_timestamp());
wprintf(L"Git Branch: %hs\n", HL_git_branch());
wprintf(L"Git Commit Timestamp: %hs\n", HL_git_commit_timestamp());
wprintf(L"Build type: %ls\n", HL_is_debug() ? L"True" : L"False");
}