Skip to content

Commit

Permalink
adding application
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbz-8 committed Sep 25, 2024
1 parent f2af06b commit c1e1039
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 103 deletions.
19 changes: 19 additions & 0 deletions Kanel/Runtime/Includes/Core/Application.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2024 kanel
// This file is part of "kanel-CLI"
// For conditions of distribution and use, see copyright notice in LICENSE

#ifndef KANEL_CLI_CORE_APPLICATION
#define KANEL_CLI_CORE_APPLICATION

#include <Core/CoreDefs.h>

typedef struct KbhCoreApplication
{

} KbhCoreApplication;

KbhCoreApplication* kbhCreateCoreApplication(int argc, char** argv);
KANEL_CLI_NONNULL(1) void kbhLaunchCoreApplication(const KbhCoreApplication* application);
KANEL_CLI_NONNULL(1) void kbhDestroyCoreApplication(const KbhCoreApplication* application);

#endif
1 change: 0 additions & 1 deletion Kanel/Runtime/Includes/Modules/GPU/Vulkan/VulkanCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ typedef struct KbhVulkanContextHandler
size_t devices_count;
} KbhVulkanContextHandler;


KANEL_CLI_NONNULL(1) KbhRHIResult kbhVulkanInit(KbhVulkanContext* context);
KbhRHIResult kbhVulkanLoadNewDevice(KbhVulkanContext context);
void kbhVulkanUninit(KbhVulkanContext context);
Expand Down
42 changes: 42 additions & 0 deletions Kanel/Runtime/Sources/Core/Application.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2024 kanel
// This file is part of "kanel-CLI"
// For conditions of distribution and use, see copyright notice in LICENSE

#include <Core/Application.h>
#include <Core/RuntimeOptions.h>
#include <Core/ModuleLoader.h>
#include <GPU/GPUSupport.h>

#include <stdlib.h>

KbhCoreApplication* kbhCreateCoreApplication(int argc, char** argv)
{
KbhCoreApplication* application = (KbhCoreApplication*)malloc(sizeof(KbhCoreApplication));
if(!application)
return KANEL_CLI_NULLPTR;
if(!kbhRuntimeOptionsParseCmd(argc, argv))
{
kbhRuntimeOptionsClear();
return 0;
}
kbhCoreLoadAllModulesFromCmdLine();
return application;
}

void kbhLaunchCoreApplication(const KbhCoreApplication* application)
{
// tests
char dummy[1024];
if(kbhRuntimeOptionsGetString("gpu", dummy, 1024))
{
kbhInitGPUSupport();
kbhUninitGPUSupport();
}
}

void kbhDestroyCoreApplication(const KbhCoreApplication* application)
{
kbhCoreUnloadAllModules();
kbhRuntimeOptionsClear();
free((void*)application);
}
14 changes: 7 additions & 7 deletions Kanel/Runtime/Sources/Core/ModuleLoader.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ typedef struct KbhCoreModuleDescriptor
KbhCoreModule type;
} KbhCoreModuleDescriptor;

static KbhCoreModuleDescriptor* head = KANEL_CLI_NULLPTR;
static KbhCoreModuleDescriptor* module_descriptors_head = KANEL_CLI_NULLPTR;

static void kbhAddLibModule(KbhLibModule module, KbhCoreModule type)
{
KbhCoreModuleDescriptor* descriptor = (KbhCoreModuleDescriptor*)malloc(sizeof(KbhCoreModuleDescriptor));
if(!descriptor)
kbhFatalError("allocation failed");
descriptor->next = head;
descriptor->next = module_descriptors_head;
descriptor->module = module;
descriptor->type = type;
head = descriptor;
module_descriptors_head = descriptor;
}

static void kbhRemoveLibModule(KbhCoreModule type)
{
KbhCoreModuleDescriptor* ptr = head;
KbhCoreModuleDescriptor* ptr = module_descriptors_head;
if(ptr == KANEL_CLI_NULLPTR)
return;
if(ptr->type == type)
{
head = ptr->next;
module_descriptors_head = ptr->next;
free((void*)ptr);
return;
}
Expand Down Expand Up @@ -93,8 +93,8 @@ KbhLibModule kbhCoreLoadModule(KbhCoreModule type)

void kbhCoreUnloadAllModules()
{
while(head != KANEL_CLI_NULLPTR)
kbhCoreUnloadModule(head->type);
while(module_descriptors_head != KANEL_CLI_NULLPTR)
kbhCoreUnloadModule(module_descriptors_head->type);
}

void kbhCoreUnloadModule(KbhCoreModule type)
Expand Down
34 changes: 17 additions & 17 deletions Kanel/Runtime/Sources/Core/RuntimeOptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,78 +35,78 @@ typedef struct KbhRuntimeOption
KbhRuntimeOptionType type;
} KbhRuntimeOption;

static KbhRuntimeOption* head = KANEL_CLI_NULLPTR;
static KbhRuntimeOption* runtime_options_head = KANEL_CLI_NULLPTR;

static void kbhAddRuntimeOptionStringToList(const char* name, const char* string)
{
KbhRuntimeOption* option = (KbhRuntimeOption*)malloc(sizeof(KbhRuntimeOption));
if(!option)
kbhFatalError("allocation failed");
option->next = head;
option->next = runtime_options_head;
option->name = strdup(name);
if(!option->name)
kbhFatalError("allocation failed");
option->string = strdup(string);
if(!option->string)
kbhFatalError("allocation failed");
option->type = KBH_RUNTIME_OPTION_STRING;
head = option;
runtime_options_head = option;
}

static void kbhAddRuntimeOptionFloat32ToList(const char* name, float f32)
{
KbhRuntimeOption* option = (KbhRuntimeOption*)malloc(sizeof(KbhRuntimeOption));
if(!option)
kbhFatalError("allocation failed");
option->next = head;
option->next = runtime_options_head;
option->name = strdup(name);
if(!option->name)
kbhFatalError("allocation failed");
option->f32 = f32;
option->type = KBH_RUNTIME_OPTION_FLOAT32;
head = option;
runtime_options_head = option;
}

static void kbhAddRuntimeOptionFloat64ToList(const char* name, double f64)
{
KbhRuntimeOption* option = (KbhRuntimeOption*)malloc(sizeof(KbhRuntimeOption));
if(!option)
kbhFatalError("allocation failed");
option->next = head;
option->next = runtime_options_head;
option->name = strdup(name);
if(!option->name)
kbhFatalError("allocation failed");
option->f64 = f64;
option->type = KBH_RUNTIME_OPTION_INT;
head = option;
runtime_options_head = option;
}

static void kbhAddRuntimeOptionIntegerToList(const char* name, int32_t integer)
{
KbhRuntimeOption* option = (KbhRuntimeOption*)malloc(sizeof(KbhRuntimeOption));
if(!option)
kbhFatalError("allocation failed");
option->next = head;
option->next = runtime_options_head;
option->name = strdup(name);
if(!option->name)
kbhFatalError("allocation failed");
option->integer = integer;
option->type = KBH_RUNTIME_OPTION_INT;
head = option;
runtime_options_head = option;
}

static void kbhAddRuntimeOptionBooleanToList(const char* name, bool boolean)
{
KbhRuntimeOption* option = (KbhRuntimeOption*)malloc(sizeof(KbhRuntimeOption));
if(!option)
kbhFatalError("allocation failed");
option->next = head;
option->next = runtime_options_head;
option->name = strdup(name);
if(!option->name)
kbhFatalError("allocation failed");
option->boolean = boolean;
option->type = KBH_RUNTIME_OPTION_BOOL;
head = option;
runtime_options_head = option;
}

bool kbhRuntimeOptionsParseCmd(int argc, char** argv)
Expand Down Expand Up @@ -140,7 +140,7 @@ bool kbhRuntimeOptionsParseCmd(int argc, char** argv)

bool kbhRuntimeOptionsGetString(const char* opt_name, char* dst, size_t dst_len)
{
KbhRuntimeOption* ptr = head;
KbhRuntimeOption* ptr = runtime_options_head;
while(ptr != KANEL_CLI_NULLPTR)
{
if(strcmp(ptr->name, opt_name) == 0)
Expand All @@ -163,7 +163,7 @@ bool kbhRuntimeOptionsGetString(const char* opt_name, char* dst, size_t dst_len)

bool kbhRuntimeOptionsGetFloat64(const char* opt_name, double* dst)
{
KbhRuntimeOption* ptr = head;
KbhRuntimeOption* ptr = runtime_options_head;
while(ptr != KANEL_CLI_NULLPTR)
{
if(strcmp(ptr->name, opt_name) == 0)
Expand All @@ -181,7 +181,7 @@ bool kbhRuntimeOptionsGetFloat64(const char* opt_name, double* dst)

bool kbhRuntimeOptionsGetFloat32(const char* opt_name, float* dst)
{
KbhRuntimeOption* ptr = head;
KbhRuntimeOption* ptr = runtime_options_head;
while(ptr != KANEL_CLI_NULLPTR)
{
if(strcmp(ptr->name, opt_name) == 0)
Expand All @@ -199,7 +199,7 @@ bool kbhRuntimeOptionsGetFloat32(const char* opt_name, float* dst)

bool kbhRuntimeOptionsGetInt(const char* opt_name, int32_t* dst)
{
KbhRuntimeOption* ptr = head;
KbhRuntimeOption* ptr = runtime_options_head;
while(ptr != KANEL_CLI_NULLPTR)
{
if(strcmp(ptr->name, opt_name) == 0)
Expand All @@ -217,7 +217,7 @@ bool kbhRuntimeOptionsGetInt(const char* opt_name, int32_t* dst)

bool kbhRuntimeOptionsGetBool(const char* opt_name, bool* dst)
{
KbhRuntimeOption* ptr = head;
KbhRuntimeOption* ptr = runtime_options_head;
while(ptr != KANEL_CLI_NULLPTR)
{
if(strcmp(ptr->name, opt_name) == 0)
Expand All @@ -235,7 +235,7 @@ bool kbhRuntimeOptionsGetBool(const char* opt_name, bool* dst)

void kbhRuntimeOptionsClear()
{
KbhRuntimeOption* ptr = head;
KbhRuntimeOption* ptr = runtime_options_head;
while(ptr != KANEL_CLI_NULLPTR)
{
KbhRuntimeOption* tmp = ptr->next;
Expand Down
27 changes: 6 additions & 21 deletions Kanel/Runtime/Sources/Core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,14 @@
// This file is part of "kanel-CLI"
// For conditions of distribution and use, see copyright notice in LICENSE

#include <Core/RuntimeOptions.h>
#include <Core/ModuleLoader.h>

#include <GPU/GPUSupport.h>
#include <Core/Application.h>

int main(int argc, char *argv[])
{
if(!kbhRuntimeOptionsParseCmd(argc, argv))
{
kbhRuntimeOptionsClear();
return 0;
}
kbhCoreLoadAllModulesFromCmdLine();

// tests
char dummy[1024];
if(kbhRuntimeOptionsGetString("gpu", dummy, 1024))
{
kbhInitGPUSupport();
kbhUninitGPUSupport();
}

kbhCoreUnloadAllModules();
kbhRuntimeOptionsClear();
KbhCoreApplication* application = kbhCreateCoreApplication(argc, argv);
if(!application)
return 1;
kbhLaunchCoreApplication(application);
kbhDestroyCoreApplication(application);
return 0;
}
Loading

0 comments on commit c1e1039

Please sign in to comment.