Add docker file

This commit is contained in:
2025-01-08 08:41:41 -06:00
parent 5cd54469de
commit 23bf0d94e9
14 changed files with 226 additions and 44 deletions

View File

@ -134,9 +134,14 @@ install(EXPORT TessesFrameworkTargets
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/TessesFrameworkConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesFramework)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/TessesFrameworkFeatures.h.in "${CMAKE_CURRENT_BINARY_DIR}/TessesFrameworkFeatures.h"
INSTALL_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/TessesFramework/TessesFrameworkFeatures.h)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/TessesFrameworkConfig.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesFramework)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/TessesFrameworkFeatures.h"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/TessesFramework)
endif()
if(TESSESFRAMEWORK_ENABLE_EXAMPLES)
add_executable(copyfile examples/copyfile.cpp)
@ -162,4 +167,4 @@ add_executable(tfileserver apps/tfileserver.cpp)
target_link_libraries(tfileserver PUBLIC tessesframework)
install(TARGETS tfileserver DESTINATION bin)
endif()
endif()

5
Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM ubuntu:noble
RUN apt update && apt install -y cmake g++ gcc libmbedtls-dev build-essential
RUN mkdir build && cd build && cmake -S .. -B . && make -j12 && make install

View File

@ -0,0 +1,8 @@
#pragma once
#define TESSES_FRAMEWORK_FLAG_OFF 0
#define TESSES_FRAMEWORK_FLAG_ON 1
#if TESSES_FRAMEWORK_FLAG_@TESSESFRAMEWORK_ENABLE_MBED@
#define TESSESFRAMEWORK_ENABLE_MBED
#endif
#undef TESSES_FRAMEWORK_FLAG_OFF
#undef TESSES_FRAMEWORK_FLAG_ON

View File

@ -11,19 +11,23 @@ namespace Tesses::Framework::Filesystem
public:
static VFSPath RelativeCurrentDirectory();
bool relative;
static std::vector<std::string> SplitPath(std::string path,bool native=false);
static std::vector<std::string> SplitPath(std::string path);
std::vector<std::string> path;
VFSPath();
VFSPath(std::vector<std::string> path);
VFSPath(std::string path);
VFSPath(VFSPath p, std::string subent);
VFSPath(VFSPath p, VFSPath p2);
VFSPath GetParent();
VFSPath CollapseRelativeParents();
std::string GetFileName();
bool HasExtension();
std::string GetExtension();
void ChangeExtension(std::string ext);
void RemoveExtension();
std::string ToString();
};
VFSPath operator/(VFSPath p, VFSPath p2);
@ -32,7 +36,12 @@ namespace Tesses::Framework::Filesystem
VFSPath operator+(VFSPath p, VFSPath p2);
VFSPath operator+(VFSPath p, std::string p2);
VFSPath operator+(std::string p, VFSPath p2);
bool operator==(VFSPath p,VFSPath p2);
bool operator!=(VFSPath p,VFSPath p2);
bool operator==(std::string p,VFSPath p2);
bool operator!=(std::string p,VFSPath p2);
bool operator==(VFSPath p,std::string p2);
bool operator!=(VFSPath p,std::string p2);
class VFSPathEnumeratorData {
public:
VFSPathEnumeratorData(std::function<bool(VFSPath&)> moveNext, std::function<void()> destroy)

View File

@ -0,0 +1,51 @@
#pragma once
#include "Common.hpp"
#include "Threading/Mutex.hpp"
#include <functional>
namespace Tesses::Framework {
template<typename T>
class Lazy {
Threading::Mutex mtx;
T value;
bool hasInit=false;
std::function<T()> init;
std::function<void(T)> free;
public:
Lazy(std::function<T()> init, std::function<void(T)> free)
{
this->init = init;
this->free = free;
}
Lazy(std::function<T()> init) : Lazy(init, [](T item)->void {})
{
}
bool HasInit()
{
mtx.Lock();
bool hI = this->hasInit;
mtx.Unlock();
return hI;
}
T& GetValue()
{
mtx.Lock();
if(hasInit)
{
mtx.Unlock();
return this->value;
}
else
{
this->value = this->init();
mtx.Unlock();
return this->value;
}
mtx.Unlock();
}
~Lazy()
{
if(hasInit) this->free(this->value);
}
};
}

View File

@ -17,4 +17,5 @@
#include "Filesystem/NullFilesystem.hpp"
#include "Filesystem/MountableFilesystem.hpp"
#include "Filesystem/MemoryFilesystem.hpp"
#include "Crypto/ClientTLSStream.hpp"
#include "Crypto/ClientTLSStream.hpp"
#include "Lazy.hpp"

View File

@ -4,7 +4,7 @@
#elif defined(GEKKO)
#include <ogc/mutex.h>
#else
#include <threads.h>
#include <pthread.h>
#endif
namespace Tesses::Framework::Threading
{
@ -14,7 +14,8 @@ namespace Tesses::Framework::Threading
#elif defined(GEKKO)
mutex_t mtx;
#else
mtx_t mtx;
pthread_mutex_t mtx;
pthread_mutexattr_t attr;
#endif
public:
Mutex();

View File

@ -5,7 +5,7 @@
#elif defined(GEKKO)
#include <ogc/lwp.h>
#else
#include <threads.h>
#include <pthread.h>
#endif
#include <atomic>
namespace Tesses::Framework::Threading
@ -22,8 +22,8 @@ namespace Tesses::Framework::Threading
lwp_t thrd;
static void* cb(void* ptr);
#else
thrd_t thrd;
static int cb(void* ptr);
pthread_t thrd;
static void* cb(void* ptr);
#endif
std::function<void()> fn;

View File

@ -117,7 +117,7 @@ namespace Tesses::Framework::Filesystem
VFSPath LocalFilesystem::SystemToVFSPath(std::string path)
{
VFSPath p;
p.path = VFSPath::SplitPath(path,true);
p.path = VFSPath::SplitPath(path);
p.relative=true;
if(!path.empty())
{

View File

@ -153,6 +153,39 @@ namespace Tesses::Framework::Filesystem
{
return VFSPath(p) + p2;
}
bool operator==(VFSPath p,VFSPath p2)
{
if(p.relative != p2.relative) return false;
if(p.path.size() != p2.path.size()) return false;
for(size_t i = 0; i < p.path.size(); i++)
if(p.path[i] != p2.path[i]) return false;
return true;
}
bool operator!=(VFSPath p,VFSPath p2)
{
if(p.relative != p2.relative) return true;
if(p.path.size() != p2.path.size()) return true;
for(size_t i = 0; i < p.path.size(); i++)
if(p.path[i] != p2.path[i]) return true;
return false;
}
bool operator==(std::string p,VFSPath p2)
{
return VFSPath(p) == p2;
}
bool operator!=(std::string p,VFSPath p2)
{
return VFSPath(p) != p2;
}
bool operator==(VFSPath p,std::string p2)
{
return p == VFSPath(p2);
}
bool operator!=(VFSPath p,std::string p2)
{
return p != VFSPath(p2);
}
VFSPath VFS::ReadLink(VFSPath path)
{
return VFSPath("/");
@ -191,7 +224,7 @@ namespace Tesses::Framework::Filesystem
return path;
}
std::vector<std::string> VFSPath::SplitPath(std::string path,bool nativePath)
std::vector<std::string> VFSPath::SplitPath(std::string path)
{
std::vector<std::string> parts;
std::string curPath = {};
@ -206,7 +239,7 @@ namespace Tesses::Framework::Filesystem
}
}
#if defined(WIN32)
else if(c == '\\' && nativePath)
else if(c == '\\')
{
if(!curPath.empty())
{
@ -236,6 +269,47 @@ namespace Tesses::Framework::Filesystem
{
this->path = p;
}
bool VFSPath::HasExtension()
{
if(this->path.empty()) return false;
auto& str = this->path.back();
auto index = str.find_last_of('.');
if(index == std::string::npos) return false;
return true;
}
std::string VFSPath::GetExtension()
{
if(this->path.empty()) return {};
auto& str = this->path.back();
auto index = str.find_last_of('.');
if(index == std::string::npos) return {};
return str.substr(index);
}
void VFSPath::ChangeExtension(std::string ext)
{
if(this->path.empty()) return;
auto& str = this->path.back();
auto index = str.find_last_of('.');
if(index != std::string::npos)
{
str = str.substr(0,index);
}
if(ext.empty()) return;
if(ext[0] != '.')
{
str += '.' + ext;
}
else
{
str += ext;
}
}
void VFSPath::RemoveExtension()
{
ChangeExtension({});
}
VFSPath::VFSPath(std::string str)
{
this->path = SplitPath(str);
@ -247,7 +321,7 @@ namespace Tesses::Framework::Filesystem
{
auto firstPartPath = this->path.front();
if(!firstPartPath.empty() && firstPartPath.back() == '/') this->relative=false;
if(!firstPartPath.empty() && firstPartPath.back() == ':') this->relative=false;
}
}
}
@ -265,6 +339,8 @@ namespace Tesses::Framework::Filesystem
{
std::vector<std::string> paths;
if(this->path.empty()) return VFSPath();
if(!this->relative && this->path.size() == 1 && !this->path[0].empty() && this->path[0].back() == ':') return *this;
paths.insert(paths.begin(), this->path.begin(), this->path.end()-1);
auto res= VFSPath(paths);
res.relative = this->relative;
@ -280,6 +356,7 @@ namespace Tesses::Framework::Filesystem
std::string VFSPath::ToString()
{
if(this->path.empty() && !this->relative) return "/";
if(!this->relative && this->path.size() == 1 && !this->path[0].empty() && this->path[0].back() == ':') return this->path[0] + "/";
bool first=true;
std::string p = {};
for(auto item : this->path)

View File

@ -94,6 +94,31 @@ namespace Tesses::Framework::Http
{
if(this->queryParams.kvp.empty()) return this->originalPath;
return this->originalPath + "?" + HttpUtils::QueryParamsEncode(this->queryParams);
}
void ServerContext::ReadStream(Stream* strm)
{
if(strm == nullptr) return;
auto strm2 = this->OpenRequestStream();
if(strm2 != nullptr)
{
strm2->CopyTo(strm);
delete strm2;
}
}
void ServerContext::ReadStream(Stream& strm)
{
ReadStream(&strm);
}
std::string ServerContext::ReadString()
{
if(strm == nullptr) return {};
auto strm2 = this->OpenRequestStream();
if(strm2 != nullptr)
{
TextStreams::StreamReader reader(strm2,true);
return reader.ReadToEnd();
}
return {};
}
bool ServerContext::NeedToParseFormData()
{
@ -628,7 +653,7 @@ namespace Tesses::Framework::Http
uint8_t* buffer = new uint8_t[len];
len = bStrm.ReadBlock(buffer,len);
std::string query((const char*)buffer,len);
delete buffer;
delete[] buffer;
HttpUtils::QueryParamsDecode(ctx.queryParams, query);
}
@ -658,4 +683,4 @@ namespace Tesses::Framework::Http
if(bStrm.EndOfStream()) return;
}
}
}
}

View File

@ -32,7 +32,7 @@ extern "C" {
#if defined(GEKKO)
extern "C" uint32_t if_config( char *local_ip, char *netmask, char *gateway,bool use_dhcp, int max_retries);
#elif !defined(_WIN32)
#elif !defined(_WIN32) && !defined(__ANDROID__)
#include <ifaddrs.h>
#endif
@ -71,7 +71,7 @@ namespace Tesses::Framework::Streams {
char gateway[16];
if_config(localIp,netmask, gateway, true, 1);
ipConfig.push_back(std::pair<std::string,std::string>("net",localIp));
#elif defined(_WIN32)
#elif defined(_WIN32) || defined(__ANDROID__)
#else
struct ifaddrs *ifAddrStruct = NULL;
@ -503,7 +503,10 @@ namespace Tesses::Framework::Streams {
if(!this->success) return 0;
ssize_t sz2 = NETWORK_SEND(this->sock,(const char*)buff,sz, 0);
if(sz2 < 0) return 0;
if(sz2 <= 0) {
this->endOfStream=true;
return 0;
}
return (size_t)sz;
}
@ -550,4 +553,4 @@ namespace Tesses::Framework::Streams {
if(this->owns && this->success)
NETWORK_CLOSE(this->sock);
}
}
}

View File

@ -1,5 +1,6 @@
#include "TessesFramework/Threading/Mutex.hpp"
#include <cstring>
#include <iostream>
namespace Tesses::Framework::Threading
{
Mutex::Mutex()
@ -10,9 +11,10 @@ namespace Tesses::Framework::Threading
mtx = LWP_MUTEX_NULL;
LWP_MutexInit(&mtx, true);
#else
memset(&mtx, 0, sizeof(mtx_t));
mtx_init(&mtx, mtx_recursive);
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mtx,&attr);
#endif
}
void Mutex::Lock()
@ -22,7 +24,7 @@ namespace Tesses::Framework::Threading
#elif defined(GEKKO)
LWP_MutexLock(mtx);
#else
mtx_lock(&mtx);
pthread_mutex_lock(&mtx);
#endif
}
void Mutex::Unlock()
@ -32,7 +34,7 @@ namespace Tesses::Framework::Threading
#elif defined(GEKKO)
LWP_MutexUnlock(mtx);
#else
mtx_unlock(&mtx);
pthread_mutex_unlock(&mtx);
#endif
}
bool Mutex::TryLock()
@ -42,7 +44,7 @@ namespace Tesses::Framework::Threading
#elif defined(GEKKO)
return LWP_MutexTryLock(mtx) == 0;
#else
return mtx_trylock(&mtx) == thrd_success;
return pthread_mutex_trylock(&mtx) == 0;
#endif
}
Mutex::~Mutex()
@ -52,8 +54,9 @@ namespace Tesses::Framework::Threading
#elif defined(GEKKO)
LWP_MutexDestroy(mtx);
#else
mtx_destroy(&mtx);
pthread_mutex_destroy(&mtx);
pthread_mutexattr_destroy(&attr);
#endif
}
};
};

View File

@ -18,22 +18,17 @@ namespace Tesses::Framework::Threading
}
#else
#if defined(GEKKO)
void* Thread::cb(void* data)
#else
int Thread::cb(void* data)
#endif
{
{
auto thrd = static_cast<Thread*>(data);
auto fn = thrd->fn;
thrd->hasInvoked=true;
fn();
#if defined(GEKKO)
return NULL;
#else
return 0;
#endif
}
#endif
Thread::Thread(std::function<void()> fn)
@ -43,10 +38,10 @@ namespace Tesses::Framework::Threading
#if defined(_WIN32)
this->thrd = CreateThread(NULL,0,cb,static_cast<LPVOID>(this), 0, &this->thrdId);
#elif defined(GEKKO)
thrd = LWP_THREAD_NULL;
LWP_CreateThread(&thrd, cb, static_cast<void*>(this), NULL, 12000, LWP_PRIO_HIGHEST);
auto res = LWP_CreateThread(&this->thrd, cb, static_cast<void*>(this), nullptr,12000, 98);
#else
thrd_create(&thrd, cb, static_cast<void*>(this));
pthread_create(&thrd,NULL,cb,static_cast<void*>(this));
//thrd_create(&thrd, cb, static_cast<void*>(this));
#endif
while(!this->hasInvoked);
}
@ -56,7 +51,7 @@ namespace Tesses::Framework::Threading
#if defined(_WIN32)
CloseHandle(thrd);
#else
thrd_detach(thrd);
pthread_detach(thrd);
#endif
#endif
}
@ -69,9 +64,8 @@ namespace Tesses::Framework::Threading
void* res;
LWP_JoinThread(thrd,&res);
#else
int res;
thrd_join(thrd,&res);
pthread_join(thrd,NULL);
#endif
}
}
}