Start working on build system.

This commit is contained in:
jmsgrogan 2023-12-20 16:58:22 +00:00
parent 4b308f6c32
commit 521486be62
88 changed files with 1065 additions and 349 deletions

View file

@ -0,0 +1,26 @@
#pragma once
#include <memory>
class IApplicationContext
{
public:
IApplicationContext() = default;
virtual ~IApplicationContext() = default;
};
class AbstractApp
{
public:
AbstractApp() = default;
virtual ~AbstractApp() = default;
IApplicationContext* GetApplicationContext() const
{
return mApplicationContext.get();
}
protected:
std::unique_ptr<IApplicationContext> mApplicationContext{ nullptr };
};
using AbstractAppPtr = std::unique_ptr<AbstractApp>;

View file

@ -0,0 +1,12 @@
#pragma once
#include "AbstractApp.h"
class HttpRequest;
class HttpResponse;
class AbstractWebApp : public AbstractApp
{
public:
virtual HttpResponse onHttpRequest(const HttpRequest& request) = 0;
};

View file

@ -0,0 +1,80 @@
#include "CommandLineArgs.h"
#include "UnicodeUtils.h"
#ifdef _WIN32
#include "Win32BaseIncludes.h"
#endif
CommandLineArgs::CommandLineArgs()
: mArugments(),
mLaunchPath()
{
}
void CommandLineArgs::initialize(CommandLineArgs* args)
{
#ifdef _WIN32
int nArgs{ 0 };
auto szArglist = ::CommandLineToArgvW(::GetCommandLineW(), &nArgs);
if (szArglist == nullptr)
{
return;
}
std::vector<std::string> windowsArgs(nArgs);
for (int idx = 0; idx < nArgs; idx++)
{
windowsArgs[idx] = UnicodeUtils::utf16ToUtf8String(szArglist[idx]);
}
::LocalFree(szArglist);
args->process(windowsArgs);
#else
(void)args;
#endif
}
Ptr<CommandLineArgs> CommandLineArgs::Create()
{
return Ptr<CommandLineArgs>::create();
}
FileSystemPath CommandLineArgs::getLaunchPath()
{
return mLaunchPath;
}
void CommandLineArgs::recordLaunchPath()
{
mLaunchPath = FileSystemPath::current_dir().value();
}
void CommandLineArgs::process(int argc, char *argv[])
{
for(int idx=0; idx<argc; idx++)
{
mArugments.push_back(String(argv[idx]));
}
}
void CommandLineArgs::process(const Vector<String>& args)
{
mArugments = args;
}
Vector<String> CommandLineArgs::getUserArgs() const
{
Vector<String> user_args;
for(unsigned idx=1; idx<mArugments.size(); idx++)
{
user_args.push_back(mArugments[idx]);
}
return user_args;
}
const Vector<String> CommandLineArgs::getArgs() const
{
return mArugments;
}

View file

@ -0,0 +1,31 @@
#pragma once
#include "Pointer.h"
#include "Vector.h"
#include "String.h"
#include "FileSystemPath.h"
class CommandLineArgs
{
public:
CommandLineArgs();
static Ptr<CommandLineArgs> Create();
FileSystemPath getLaunchPath();
const Vector<String> getArgs() const;
Vector<String> getUserArgs() const;
static void initialize(CommandLineArgs* args);
void process(int argc, char *argv[]);
void process(const Vector<String>& args);
void recordLaunchPath();
private:
Vector<String> mArugments;
FileSystemPath mLaunchPath;
};

View file

@ -0,0 +1,40 @@
#pragma once
#include "String.h"
#include "File.h"
#include "Result.h"
#include <unistd.h>
class Process
{
public:
Status launch(const String& command)
{
const auto pid = fork();
if (pid < 0)
{
ON_ERRNO("Failed to fork");
}
if (pid == 0)
{
//pass
}
return {};
}
static Result<String> get_self_name()
{
FileSystemPath path(String("/proc/self/cmdline"));
File sys_file(path);
Result<String> ret;
const auto rc = sys_file.readText(ret.value());
if (!rc.ok())
{
ret.on_error(rc.error());
}
return ret;
}
};