Compare commits

...

3 Commits

Author SHA1 Message Date
f7d4b28744 merge 2025-10-30 23:45:43 +05:30
9f9991494e merge 2025-10-30 23:44:39 +05:30
6c3090f3c6 Add Process, Thread and Environment 2025-10-24 21:11:23 +05:30
19 changed files with 420 additions and 16 deletions

View File

@ -1,5 +1,6 @@
{
"files.associations": {
"*.rml": "html",
"stdexcept": "cpp",
"chrono": "cpp",
"forward_list": "cpp",
@ -67,6 +68,11 @@
"iostream": "cpp",
"map": "cpp",
"ostream": "cpp",
"xtree": "cpp"
"xtree": "cpp",
"condition_variable": "cpp",
"coroutine": "cpp",
"resumable": "cpp",
"future": "cpp",
"mutex": "cpp"
}
}

View File

@ -0,0 +1,25 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "platform.inl"
#if (defined(IA_PLATFORM_WIN64) && (IA_PLATFORM_WIN64 > 0))
#include "win/environment.inl"
#else
#error "IACore Unsupported Platform"
#endif

View File

@ -0,0 +1,29 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <IACore/String.hpp>
namespace ia
{
class Environment
{
public:
INLINE STATIC String GetVar(IN CONST String& name);
INLINE STATIC BOOL SetVar(IN CONST String& name, IN CONST String& value);
};
}

View File

@ -16,7 +16,7 @@
#pragma once
#include <IACore/base.hpp>
#include <IACore/Base.hpp>
namespace ia
{

View File

@ -0,0 +1,34 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <IACore/String.hpp>
namespace ia
{
class SubProcess
{
public:
INLINE SubProcess(IN CONST String &path);
INLINE ~SubProcess();
INLINE INT32 Launch(IN CONST String &args, IN Function<VOID(CONST String &)> onOutputLineCallback);
private:
CONST String m_path;
};
} // namespace ia

View File

@ -0,0 +1,25 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "platform.inl"
#if (defined(IA_PLATFORM_WIN64) && (IA_PLATFORM_WIN64 > 0))
#include "win/process.inl"
#else
#error "IACore Unsupported Platform"
#endif

View File

@ -0,0 +1,25 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
namespace ia
{
}

View File

@ -0,0 +1,40 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "../interface/environment.interface.inl"
#include "common.inl"
namespace ia
{
String Environment::GetVar(IN CONST String &name)
{
const auto l = GetEnvironmentVariableA(name.c_str(), nullptr, 0);
if (!l)
return "";
String result;
result.resize(l);
GetEnvironmentVariableA(name.c_str(), result.data(), l);
result.back() = '\0';
return result;
}
BOOL Environment::SetVar(IN CONST String &name, IN CONST String &value)
{
return SetEnvironmentVariableA(name.c_str(), value.c_str());
}
} // namespace ia

View File

@ -0,0 +1,137 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "../interface/process.interface.inl"
#include "common.inl"
#include <IACore/Exception.hpp>
namespace ia
{
SubProcess::SubProcess(IN CONST String &path) : m_path(path)
{
}
SubProcess::~SubProcess()
{
}
INT32 SubProcess::Launch(IN CONST String &args, IN Function<VOID(CONST String &)> onOutputLineCallback)
{
String szCmdline = BuildString(m_path, " ", args);
PROCESS_INFORMATION piProcInfo;
STARTUPINFOA siStartInfo;
BOOL bSuccess = FALSE;
ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
HANDLE hRdStdIn{};
HANDLE hWrStdIn{};
HANDLE hRdStdOut{};
HANDLE hWrStdOut{};
SECURITY_ATTRIBUTES saAttr;
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
if (!CreatePipe(&hRdStdIn, &hWrStdIn, &saAttr, 0))
THROW_UNKNOWN("Failed to create a win32 pipe");
if (!SetHandleInformation(hWrStdIn, HANDLE_FLAG_INHERIT, 0))
THROW_UNKNOWN("Failed to update a win32 pipe");
if (!CreatePipe(&hRdStdOut, &hWrStdOut, &saAttr, 0))
THROW_UNKNOWN("Failed to create a win32 pipe");
if (!SetHandleInformation(hRdStdOut, HANDLE_FLAG_INHERIT, 0))
THROW_UNKNOWN("Failed to update a win32 pipe");
ZeroMemory(&siStartInfo, sizeof(STARTUPINFOA));
siStartInfo.cb = sizeof(STARTUPINFOA);
siStartInfo.hStdError = hWrStdOut;
siStartInfo.hStdOutput = hWrStdOut;
siStartInfo.hStdInput = hRdStdIn;
siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
bSuccess = CreateProcessA(NULL,
szCmdline.data(), // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
if (!bSuccess)
THROW_UNKNOWN("Couldn't spawn the child process \"", m_path, "\"");
else
{
CloseHandle(piProcInfo.hProcess);
CloseHandle(piProcInfo.hThread);
CloseHandle(hWrStdOut);
CloseHandle(hRdStdIn);
}
CloseHandle(hWrStdIn);
DWORD exitCode{};
while (true)
{
GetExitCodeProcess(piProcInfo.hProcess, &exitCode);
if (exitCode != STILL_ACTIVE)
break;
}
Vector<CHAR> currentLine;
CHAR readBuffer[1024];
while (true)
{
DWORD readSize;
const auto success = ReadFile(hRdStdOut, readBuffer, sizeof(readBuffer), &readSize, NULL);
if ((!success) || (!readSize))
break;
for (DWORD i = 0; i < readSize; i++)
{
if (readBuffer[i] == '\n')
{
String result;
result.resize(currentLine.size() + 1);
memcpy(result.data(), currentLine.data(), currentLine.size());
result[currentLine.size()] = '\0';
currentLine.reset();
onOutputLineCallback(result);
}
else
{
currentLine.append(readBuffer[i]);
}
}
}
if (currentLine.size())
{
String result;
result.resize(currentLine.size() + 1);
memcpy(result.data(), currentLine.data(), currentLine.size());
result[currentLine.size()] = '\0';
onOutputLineCallback(result);
}
return exitCode;
}
} // namespace ia

View File

@ -203,7 +203,11 @@ namespace ia
for (const auto &v : t->Value.Switches)
{
<<<<<<< HEAD
printf(__CC_WHITE "\t/%s %s\n", v.ID.c_str(), v.Help.c_str());
=======
printf(__CC_WHITE "//%s %s\n", v.ID.c_str(), v.Help.c_str());
>>>>>>> 6c3090f3c6cff06c4f79f28cbc85f43242be4283
}
printf(__CC_DEFAULT "\n");

View File

@ -0,0 +1,23 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <IACore/platform/environment.inl>
namespace ia
{
} // namespace ia

View File

@ -0,0 +1,23 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <IACore/platform/process.inl>
namespace ia
{
} // namespace ia

View File

@ -0,0 +1,28 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <IACore/Types.hpp>
#include <thread>
#include <future>
namespace ia
{
using Mutex = std::mutex;
using ScopeMutex = std::lock_guard<Mutex>;
}

View File

@ -98,6 +98,9 @@ namespace ia
typedef CONST FLOAT32 PCFLOAT32;
typedef CONST FLOAT64 PCFLOAT64;
template<typename function_type>
using Function = std::function<function_type>;
/* Uses the UEFI standard GUID structure definition */
typedef struct _IA_GUID
{

View File

@ -1,34 +1,36 @@
#include <IACore/Logger.hpp>
#include <IACore/File.hpp>
#include <IACore/Logger.hpp>
#include <IACore/Vector.hpp>
#include <IACore/Map.hpp>
#include <IACore/Vector.hpp>
#include <IACore/Process.hpp>
#include <IACore/Environment.hpp>
using namespace ia;
template<typename _value_type>
VOID print(IN CONST Span<_value_type>& s)
template<typename _value_type> VOID print(IN CONST Span<_value_type> &s)
{
for(const auto& v: s)
for (const auto &v : s)
Logger::Info("IACore", v);
}
int main(int argc, char* argv[])
int main(int argc, char *argv[])
{
Vector<int> v1{10, 20, 32};
/*ector<int> v1{10, 20, 32};
print(v1);
List<int> l1;
Map<String, int> m1;
m1["sdd"] = 2;
m1["bx"] = 5;
for(const auto& v: m1)
{
for (const auto &v : m1)
printf("%s, %i\n", v->Key.c_str(), v->Value);
}
SubProcess p("clang++");
p.Launch("a.cpp", [](IN CONST String &line) { printf("[\n%s\n]\n", line.c_str()); });*/
printf("[%s]\n", Environment::GetVar("IAEDK_ROOT").c_str());
Environment::SetVar("IAEDK_ROOT", "C:\\IAEDK");
printf("[%s]\n", Environment::GetVar("IAEDK_ROOT").c_str());
return 0;
}