Got it working on Windows using Mingw
This commit is contained in:
parent
5b89d8c5de
commit
f1bae988c4
|
@ -31,7 +31,7 @@ src/Crypto/ClientTLSStream.cpp
|
||||||
src/TF_Init.cpp
|
src/TF_Init.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(TESSESFRAMEWORK_CERT_BUNDLE_FILE "/etc/ssl/certs/ca-certificates.crt")
|
set(TESSESFRAMEWORK_CERT_BUNDLE_FILE "/etc/ssl/certs/ca-certificates.crt" CACHE FILEPATH "Path to ca-chain")
|
||||||
option(TESSESFRAMEWORK_EMBED_CERT_BUNDLE "Embed the certificate chain bundle" ON)
|
option(TESSESFRAMEWORK_EMBED_CERT_BUNDLE "Embed the certificate chain bundle" ON)
|
||||||
option(TESSESFRAMEWORK_ENABLE_MBED "Enable Tesses Framework mbedtls" ON)
|
option(TESSESFRAMEWORK_ENABLE_MBED "Enable Tesses Framework mbedtls" ON)
|
||||||
option(TESSESFRAMEWORK_ENABLE_EXAMPLES "Enable Tesses Framework examples" ON)
|
option(TESSESFRAMEWORK_ENABLE_EXAMPLES "Enable Tesses Framework examples" ON)
|
||||||
|
@ -54,7 +54,7 @@ file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/include/CertificateChain.h "\n")
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
set(MBEDTLS_DIR "")
|
set(MBEDTLS_DIR "" CACHE PATH "Mbed tls directory")
|
||||||
|
|
||||||
function(link_deps TessesFramework_TARGET)
|
function(link_deps TessesFramework_TARGET)
|
||||||
if(TESSESFRAMEWORK_ENABLE_MBED)
|
if(TESSESFRAMEWORK_ENABLE_MBED)
|
||||||
|
@ -83,6 +83,11 @@ endif()
|
||||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii")
|
if("${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii")
|
||||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC wiisocket)
|
target_link_libraries(${TessesFramework_TARGET} PUBLIC wiisocket)
|
||||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_USE_WII_SOCKET)
|
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_USE_WII_SOCKET)
|
||||||
|
endif()
|
||||||
|
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
|
||||||
|
|
||||||
|
target_link_libraries(${TessesFramework_TARGET} PUBLIC ws2_32)
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "VFS.hpp"
|
#include "VFS.hpp"
|
||||||
|
#include "VFSFix.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Filesystem
|
namespace Tesses::Framework::Filesystem
|
||||||
{
|
{
|
||||||
class LocalFilesystem : public VFS
|
class LocalFilesystem : public VFS
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Tesses::Framework::Streams::Stream* OpenFile(VFSPath path, std::string mode);
|
Tesses::Framework::Streams::Stream* OpenFile(VFSPath path, std::string mode);
|
||||||
|
|
||||||
void CreateDirectory(VFSPath path);
|
void CreateDirectory(VFSPath path);
|
||||||
void DeleteDirectory(VFSPath path);
|
void DeleteDirectory(VFSPath path);
|
||||||
bool RegularFileExists(VFSPath path);
|
bool RegularFileExists(VFSPath path);
|
||||||
|
@ -15,11 +19,14 @@ namespace Tesses::Framework::Filesystem
|
||||||
bool SocketFileExists(VFSPath path);
|
bool SocketFileExists(VFSPath path);
|
||||||
bool FIFOFileExists(VFSPath path);
|
bool FIFOFileExists(VFSPath path);
|
||||||
bool DirectoryExists(VFSPath path);
|
bool DirectoryExists(VFSPath path);
|
||||||
|
|
||||||
void DeleteFile(VFSPath path);
|
void DeleteFile(VFSPath path);
|
||||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||||
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||||
|
|
||||||
void MoveFile(VFSPath src, VFSPath dest);
|
void MoveFile(VFSPath src, VFSPath dest);
|
||||||
|
|
||||||
void MoveDirectory(VFSPath src, VFSPath dest);
|
void MoveDirectory(VFSPath src, VFSPath dest);
|
||||||
VFSPath ReadLink(VFSPath path);
|
VFSPath ReadLink(VFSPath path);
|
||||||
std::string VFSPathToSystem(VFSPath path);
|
std::string VFSPathToSystem(VFSPath path);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "VFS.hpp"
|
#include "VFS.hpp"
|
||||||
|
#include "VFSFix.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Filesystem
|
namespace Tesses::Framework::Filesystem
|
||||||
{
|
{
|
||||||
class MountableDirectory {
|
class MountableDirectory {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "VFS.hpp"
|
#include "VFS.hpp"
|
||||||
|
#include "VFSFix.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Filesystem
|
namespace Tesses::Framework::Filesystem
|
||||||
{
|
{
|
||||||
class NullFilesystem : public VFS
|
class NullFilesystem : public VFS
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "VFS.hpp"
|
#include "VFS.hpp"
|
||||||
|
#include "VFSFix.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Filesystem
|
namespace Tesses::Framework::Filesystem
|
||||||
{
|
{
|
||||||
class SubdirFilesystem : public VFS
|
class SubdirFilesystem : public VFS
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include "../Streams/Stream.hpp"
|
#include "../Streams/Stream.hpp"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include "VFSFix.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Filesystem
|
namespace Tesses::Framework::Filesystem
|
||||||
{
|
{
|
||||||
class VFSPath {
|
class VFSPath {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#if defined(GEKKO)
|
#if defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#elif defined(GEKKO)
|
||||||
#include <ogc/mutex.h>
|
#include <ogc/mutex.h>
|
||||||
#else
|
#else
|
||||||
#include <threads.h>
|
#include <threads.h>
|
||||||
|
@ -7,7 +9,9 @@
|
||||||
namespace Tesses::Framework::Threading
|
namespace Tesses::Framework::Threading
|
||||||
{
|
{
|
||||||
class Mutex {
|
class Mutex {
|
||||||
#if defined(GEKKO)
|
#if defined(_WIN32)
|
||||||
|
HANDLE mtx;
|
||||||
|
#elif defined(GEKKO)
|
||||||
mutex_t mtx;
|
mutex_t mtx;
|
||||||
#else
|
#else
|
||||||
mtx_t mtx;
|
mtx_t mtx;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#if defined(GEKKO)
|
#if defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#elif defined(GEKKO)
|
||||||
#include <ogc/lwp.h>
|
#include <ogc/lwp.h>
|
||||||
#else
|
#else
|
||||||
#include <threads.h>
|
#include <threads.h>
|
||||||
|
@ -10,8 +12,13 @@ namespace Tesses::Framework::Threading
|
||||||
{
|
{
|
||||||
class Thread
|
class Thread
|
||||||
{
|
{
|
||||||
std::atomic<bool> hasInvoked;
|
#if defined(_WIN32)
|
||||||
#if defined(GEKKO)
|
|
||||||
|
HANDLE thrd;
|
||||||
|
DWORD thrdId;
|
||||||
|
|
||||||
|
public:
|
||||||
|
#elif defined(GEKKO)
|
||||||
lwp_t thrd;
|
lwp_t thrd;
|
||||||
static void* cb(void* ptr);
|
static void* cb(void* ptr);
|
||||||
#else
|
#else
|
||||||
|
@ -19,6 +26,8 @@ namespace Tesses::Framework::Threading
|
||||||
static int cb(void* ptr);
|
static int cb(void* ptr);
|
||||||
#endif
|
#endif
|
||||||
std::function<void()> fn;
|
std::function<void()> fn;
|
||||||
|
|
||||||
|
std::atomic<bool> hasInvoked;
|
||||||
public:
|
public:
|
||||||
Thread(std::function<void()> fn);
|
Thread(std::function<void()> fn);
|
||||||
void Join();
|
void Join();
|
||||||
|
|
|
@ -25,7 +25,8 @@ namespace Tesses::Framework::Filesystem
|
||||||
}
|
}
|
||||||
VFSPath LocalFilesystem::ReadLink(VFSPath path)
|
VFSPath LocalFilesystem::ReadLink(VFSPath path)
|
||||||
{
|
{
|
||||||
return this->SystemToVFSPath(std::filesystem::read_symlink(this->VFSPathToSystem(path)));
|
auto res = std::filesystem::read_symlink(this->VFSPathToSystem(path)).string();
|
||||||
|
return this->SystemToVFSPath(res.c_str());
|
||||||
}
|
}
|
||||||
Tesses::Framework::Streams::Stream* LocalFilesystem::OpenFile(VFSPath path, std::string mode)
|
Tesses::Framework::Streams::Stream* LocalFilesystem::OpenFile(VFSPath path, std::string mode)
|
||||||
{
|
{
|
||||||
|
@ -97,12 +98,12 @@ namespace Tesses::Framework::Filesystem
|
||||||
}
|
}
|
||||||
std::string LocalFilesystem::VFSPathToSystem(VFSPath path)
|
std::string LocalFilesystem::VFSPathToSystem(VFSPath path)
|
||||||
{
|
{
|
||||||
#if defined(WIN32)
|
#if defined(_WIN32)
|
||||||
bool first=true;
|
bool first=true;
|
||||||
std::string p = {};
|
std::string p = {};
|
||||||
for(auto item : path.path)
|
for(auto item : path.path)
|
||||||
{
|
{
|
||||||
if(!(first && !item.empty() && item.back()==':') && !(first && this->relative))
|
if(!(first && !item.empty() && item.back()==':') && !(first && path.relative))
|
||||||
p.push_back('\\');
|
p.push_back('\\');
|
||||||
p.append(item);
|
p.append(item);
|
||||||
first=false;
|
first=false;
|
||||||
|
|
|
@ -15,8 +15,8 @@ namespace Tesses::Framework::Http
|
||||||
}
|
}
|
||||||
FileServer::FileServer(std::filesystem::path path,bool allowListing, bool spa, std::vector<std::string> defaultNames)
|
FileServer::FileServer(std::filesystem::path path,bool allowListing, bool spa, std::vector<std::string> defaultNames)
|
||||||
{
|
{
|
||||||
LocalFilesystem* lfs=new LocalFilesystem;
|
LocalFilesystem* lfs=new LocalFilesystem();
|
||||||
SubdirFilesystem* sdfs=new SubdirFilesystem(lfs,lfs->SystemToVFSPath(path),true);
|
SubdirFilesystem* sdfs=new SubdirFilesystem(lfs,lfs->SystemToVFSPath(path.string()),true);
|
||||||
this->vfs = sdfs;
|
this->vfs = sdfs;
|
||||||
this->spa = spa;
|
this->spa = spa;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "TessesFramework/Streams/FileStream.hpp"
|
#include "TessesFramework/Streams/FileStream.hpp"
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
namespace Tesses::Framework::Streams
|
namespace Tesses::Framework::Streams
|
||||||
{
|
{
|
||||||
void FileStream::SetMode(std::string mode)
|
void FileStream::SetMode(std::string mode)
|
||||||
|
@ -32,7 +34,8 @@ namespace Tesses::Framework::Streams
|
||||||
}
|
}
|
||||||
FileStream::FileStream(std::filesystem::path p, std::string mode)
|
FileStream::FileStream(std::filesystem::path p, std::string mode)
|
||||||
{
|
{
|
||||||
this->f = fopen(p.c_str(),mode.c_str());
|
std::string str = p.string();
|
||||||
|
this->f = fopen(str.c_str(),mode.c_str());
|
||||||
this->canSeek = true;
|
this->canSeek = true;
|
||||||
this->owns=true;
|
this->owns=true;
|
||||||
this->SetMode(mode);
|
this->SetMode(mode);
|
||||||
|
@ -66,7 +69,11 @@ namespace Tesses::Framework::Streams
|
||||||
}
|
}
|
||||||
int64_t FileStream::GetPosition()
|
int64_t FileStream::GetPosition()
|
||||||
{
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
return (int64_t)_ftelli64(this->f);
|
||||||
|
#else
|
||||||
return (int64_t)ftello(this->f);
|
return (int64_t)ftello(this->f);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
void FileStream::Flush()
|
void FileStream::Flush()
|
||||||
{
|
{
|
||||||
|
@ -74,7 +81,11 @@ namespace Tesses::Framework::Streams
|
||||||
}
|
}
|
||||||
void FileStream::Seek(int64_t pos, SeekOrigin whence)
|
void FileStream::Seek(int64_t pos, SeekOrigin whence)
|
||||||
{
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
_fseeki64(this->f,pos,whence == SeekOrigin::Begin ? SEEK_SET : whence == SeekOrigin::Current ? SEEK_CUR : SEEK_END);
|
||||||
|
#else
|
||||||
fseeko(this->f,(off_t)pos,whence == SeekOrigin::Begin ? SEEK_SET : whence == SeekOrigin::Current ? SEEK_CUR : SEEK_END);
|
fseeko(this->f,(off_t)pos,whence == SeekOrigin::Begin ? SEEK_SET : whence == SeekOrigin::Current ? SEEK_CUR : SEEK_END);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
FileStream::~FileStream()
|
FileStream::~FileStream()
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,7 +14,12 @@ using HttpUtils = Tesses::Framework::Http::HttpUtils;
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#pragma comment(lib, "ws2_32.lib")
|
||||||
|
#else
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
@ -23,10 +28,11 @@ extern "C" {
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#if defined(GEKKO)
|
#if defined(GEKKO)
|
||||||
|
|
||||||
extern "C" uint32_t if_config( char *local_ip, char *netmask, char *gateway,bool use_dhcp, int max_retries);
|
extern "C" uint32_t if_config( char *local_ip, char *netmask, char *gateway,bool use_dhcp, int max_retries);
|
||||||
#else
|
#elif !defined(_WIN32)
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -42,8 +48,12 @@ extern "C" uint32_t if_config( char *local_ip, char *netmask, char *gateway,bool
|
||||||
#define NETWORK_ACCEPT accept
|
#define NETWORK_ACCEPT accept
|
||||||
#define NETWORK_GETADDRINFO getaddrinfo
|
#define NETWORK_GETADDRINFO getaddrinfo
|
||||||
#define NETWORK_FREEADDRINFO freeaddrinfo
|
#define NETWORK_FREEADDRINFO freeaddrinfo
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#define NETWORK_CLOSE closesocket
|
||||||
|
#else
|
||||||
#define NETWORK_CLOSE close
|
#define NETWORK_CLOSE close
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#undef AF_INET6
|
#undef AF_INET6
|
||||||
|
|
||||||
|
@ -61,6 +71,8 @@ namespace Tesses::Framework::Streams {
|
||||||
char gateway[16];
|
char gateway[16];
|
||||||
if_config(localIp,netmask, gateway, true, 1);
|
if_config(localIp,netmask, gateway, true, 1);
|
||||||
ipConfig.push_back(std::pair<std::string,std::string>("net",localIp));
|
ipConfig.push_back(std::pair<std::string,std::string>("net",localIp));
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
struct ifaddrs *ifAddrStruct = NULL;
|
struct ifaddrs *ifAddrStruct = NULL;
|
||||||
getifaddrs(&ifAddrStruct);
|
getifaddrs(&ifAddrStruct);
|
||||||
|
@ -367,7 +379,7 @@ namespace Tesses::Framework::Streams {
|
||||||
if(broadcast)
|
if(broadcast)
|
||||||
{
|
{
|
||||||
int broadcast = 1;
|
int broadcast = 1;
|
||||||
if (NETWORK_SETSOCKOPT(sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)) != 0) {
|
if (NETWORK_SETSOCKOPT(sock, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof(broadcast)) != 0) {
|
||||||
this->success=false;
|
this->success=false;
|
||||||
NETWORK_CLOSE(this->sock);
|
NETWORK_CLOSE(this->sock);
|
||||||
continue;
|
continue;
|
||||||
|
@ -434,7 +446,7 @@ namespace Tesses::Framework::Streams {
|
||||||
{
|
{
|
||||||
if(!this->success) return;
|
if(!this->success) return;
|
||||||
int broadcast = 1;
|
int broadcast = 1;
|
||||||
if (NETWORK_SETSOCKOPT(sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast)) != 0)
|
if (NETWORK_SETSOCKOPT(sock, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof(broadcast)) != 0)
|
||||||
{
|
{
|
||||||
this->success=false;
|
this->success=false;
|
||||||
if(this->owns)
|
if(this->owns)
|
||||||
|
@ -462,7 +474,7 @@ namespace Tesses::Framework::Streams {
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!this->success) return 0;
|
if(!this->success) return 0;
|
||||||
ssize_t r = NETWORK_RECV(this->sock,buff,sz,0);
|
ssize_t r = NETWORK_RECV(this->sock,(char*)buff,sz,0);
|
||||||
|
|
||||||
if(r <= 0)
|
if(r <= 0)
|
||||||
{
|
{
|
||||||
|
@ -477,7 +489,7 @@ namespace Tesses::Framework::Streams {
|
||||||
|
|
||||||
if(!this->success) return 0;
|
if(!this->success) return 0;
|
||||||
|
|
||||||
ssize_t sz2 = NETWORK_SEND(this->sock,buff,sz, 0);
|
ssize_t sz2 = NETWORK_SEND(this->sock,(const char*)buff,sz, 0);
|
||||||
if(sz2 < 0) return 0;
|
if(sz2 < 0) return 0;
|
||||||
|
|
||||||
return (size_t)sz;
|
return (size_t)sz;
|
||||||
|
@ -487,7 +499,7 @@ namespace Tesses::Framework::Streams {
|
||||||
if(!this->success) return 0;
|
if(!this->success) return 0;
|
||||||
struct sockaddr_storage storage;
|
struct sockaddr_storage storage;
|
||||||
socklen_t addrlen=(socklen_t)sizeof(storage);
|
socklen_t addrlen=(socklen_t)sizeof(storage);
|
||||||
ssize_t r = NETWORK_RECVFROM(this->sock,buff,sz,0, (struct sockaddr*)&storage, (socklen_t*)&addrlen);
|
ssize_t r = NETWORK_RECVFROM(this->sock,(char*)buff,sz,0, (struct sockaddr*)&storage, (socklen_t*)&addrlen);
|
||||||
ip = StringifyIP((struct sockaddr*)&storage);
|
ip = StringifyIP((struct sockaddr*)&storage);
|
||||||
port = GetPort((struct sockaddr*)&storage);
|
port = GetPort((struct sockaddr*)&storage);
|
||||||
if(r < 0) return 0;
|
if(r < 0) return 0;
|
||||||
|
@ -516,7 +528,7 @@ namespace Tesses::Framework::Streams {
|
||||||
}
|
}
|
||||||
|
|
||||||
SetPort((struct sockaddr*)&addr, port);
|
SetPort((struct sockaddr*)&addr, port);
|
||||||
ssize_t sz2 = NETWORK_SENDTO(this->sock,buff,sz, 0, (const sockaddr*)&addr, (socklen_t)sizeof(addr));
|
ssize_t sz2 = NETWORK_SENDTO(this->sock,(const char*)buff,sz, 0, (const sockaddr*)&addr, (socklen_t)sizeof(addr));
|
||||||
if(sz2 < 0) return 0;
|
if(sz2 < 0) return 0;
|
||||||
return (size_t)sz2;
|
return (size_t)sz2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
#include "TessesFramework/Streams/NetworkStream.hpp"
|
#include "TessesFramework/Streams/NetworkStream.hpp"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#if defined(GEKKO)
|
#if defined(_WIN32)
|
||||||
|
#include <windows.h>
|
||||||
|
#include <cstdio>
|
||||||
|
#elif defined(GEKKO)
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <gccore.h>
|
#include <gccore.h>
|
||||||
|
@ -63,10 +66,22 @@ namespace Tesses::Framework
|
||||||
|
|
||||||
void TF_Init()
|
void TF_Init()
|
||||||
{
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
system(" ");
|
||||||
|
#endif
|
||||||
|
|
||||||
isRunning=true;
|
isRunning=true;
|
||||||
#if defined(GEKKO)
|
#if defined(_WIN32)
|
||||||
|
WSADATA wsaData;
|
||||||
|
int iResult;
|
||||||
|
|
||||||
|
// Initialize Winsock
|
||||||
|
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
|
||||||
|
if (iResult != 0) {
|
||||||
|
printf("WSAStartup failed: %d\n", iResult);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#elif defined(GEKKO)
|
||||||
fatInitDefault();
|
fatInitDefault();
|
||||||
VIDEO_Init();
|
VIDEO_Init();
|
||||||
PAD_Init();
|
PAD_Init();
|
||||||
|
|
|
@ -4,7 +4,9 @@ namespace Tesses::Framework::Threading
|
||||||
{
|
{
|
||||||
Mutex::Mutex()
|
Mutex::Mutex()
|
||||||
{
|
{
|
||||||
#if defined(GEKKO)
|
#if defined(_WIN32)
|
||||||
|
this->mtx = CreateMutex(NULL,false,NULL);
|
||||||
|
#elif defined(GEKKO)
|
||||||
mtx = LWP_MUTEX_NULL;
|
mtx = LWP_MUTEX_NULL;
|
||||||
LWP_MutexInit(&mtx, true);
|
LWP_MutexInit(&mtx, true);
|
||||||
#else
|
#else
|
||||||
|
@ -15,7 +17,9 @@ namespace Tesses::Framework::Threading
|
||||||
}
|
}
|
||||||
void Mutex::Lock()
|
void Mutex::Lock()
|
||||||
{
|
{
|
||||||
#if defined(GEKKO)
|
#if defined(_WIN32)
|
||||||
|
WaitForSingleObject(mtx, INFINITE);
|
||||||
|
#elif defined(GEKKO)
|
||||||
LWP_MutexLock(mtx);
|
LWP_MutexLock(mtx);
|
||||||
#else
|
#else
|
||||||
mtx_lock(&mtx);
|
mtx_lock(&mtx);
|
||||||
|
@ -23,7 +27,9 @@ namespace Tesses::Framework::Threading
|
||||||
}
|
}
|
||||||
void Mutex::Unlock()
|
void Mutex::Unlock()
|
||||||
{
|
{
|
||||||
#if defined(GEKKO)
|
#if defined(_WIN32)
|
||||||
|
ReleaseMutex(mtx);
|
||||||
|
#elif defined(GEKKO)
|
||||||
LWP_MutexUnlock(mtx);
|
LWP_MutexUnlock(mtx);
|
||||||
#else
|
#else
|
||||||
mtx_unlock(&mtx);
|
mtx_unlock(&mtx);
|
||||||
|
@ -31,7 +37,9 @@ namespace Tesses::Framework::Threading
|
||||||
}
|
}
|
||||||
bool Mutex::TryLock()
|
bool Mutex::TryLock()
|
||||||
{
|
{
|
||||||
#if defined(GEKKO)
|
#if defined(_WIN32)
|
||||||
|
return WaitForSingleObject(mtx, 100) == WAIT_OBJECT_0;
|
||||||
|
#elif defined(GEKKO)
|
||||||
return LWP_MutexTryLock(mtx) == 0;
|
return LWP_MutexTryLock(mtx) == 0;
|
||||||
#else
|
#else
|
||||||
return mtx_trylock(&mtx) == thrd_success;
|
return mtx_trylock(&mtx) == thrd_success;
|
||||||
|
@ -39,7 +47,9 @@ namespace Tesses::Framework::Threading
|
||||||
}
|
}
|
||||||
Mutex::~Mutex()
|
Mutex::~Mutex()
|
||||||
{
|
{
|
||||||
#if defined(GEKKO)
|
#if defined(_WIN32)
|
||||||
|
CloseHandle(mtx);
|
||||||
|
#elif defined(GEKKO)
|
||||||
LWP_MutexDestroy(mtx);
|
LWP_MutexDestroy(mtx);
|
||||||
#else
|
#else
|
||||||
mtx_destroy(&mtx);
|
mtx_destroy(&mtx);
|
||||||
|
|
|
@ -2,6 +2,22 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
namespace Tesses::Framework::Threading
|
namespace Tesses::Framework::Threading
|
||||||
{
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
static DWORD __stdcall cb(LPVOID data)
|
||||||
|
{
|
||||||
|
auto thrd = static_cast<Thread*>(data);
|
||||||
|
|
||||||
|
auto fn = thrd->fn;
|
||||||
|
thrd->hasInvoked=true;
|
||||||
|
fn();
|
||||||
|
#if defined(GEKKO)
|
||||||
|
return NULL;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
#if defined(GEKKO)
|
#if defined(GEKKO)
|
||||||
void* Thread::cb(void* data)
|
void* Thread::cb(void* data)
|
||||||
#else
|
#else
|
||||||
|
@ -19,12 +35,14 @@ namespace Tesses::Framework::Threading
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
Thread::Thread(std::function<void()> fn)
|
Thread::Thread(std::function<void()> fn)
|
||||||
{
|
{
|
||||||
this->hasInvoked=false;
|
this->hasInvoked=false;
|
||||||
this->fn = fn;
|
this->fn = fn;
|
||||||
|
#if defined(_WIN32)
|
||||||
#if defined(GEKKO)
|
this->thrd = CreateThread(NULL,0,cb,static_cast<LPVOID>(this), 0, &this->thrdId);
|
||||||
|
#elif defined(GEKKO)
|
||||||
thrd = LWP_THREAD_NULL;
|
thrd = LWP_THREAD_NULL;
|
||||||
LWP_CreateThread(&thrd, cb, static_cast<void*>(this), NULL, 12000, LWP_PRIO_HIGHEST);
|
LWP_CreateThread(&thrd, cb, static_cast<void*>(this), NULL, 12000, LWP_PRIO_HIGHEST);
|
||||||
#else
|
#else
|
||||||
|
@ -35,13 +53,19 @@ namespace Tesses::Framework::Threading
|
||||||
void Thread::Detach()
|
void Thread::Detach()
|
||||||
{
|
{
|
||||||
#if !defined(GEKKO)
|
#if !defined(GEKKO)
|
||||||
|
#if defined(_WIN32)
|
||||||
|
CloseHandle(thrd);
|
||||||
|
#else
|
||||||
thrd_detach(thrd);
|
thrd_detach(thrd);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread::Join()
|
void Thread::Join()
|
||||||
{
|
{
|
||||||
#if defined(GEKKO)
|
#if defined(_WIN32)
|
||||||
|
WaitForSingleObject(this->thrd, INFINITE);
|
||||||
|
#elif defined(GEKKO)
|
||||||
void* res;
|
void* res;
|
||||||
LWP_JoinThread(thrd,&res);
|
LWP_JoinThread(thrd,&res);
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in New Issue