shengine pre-release
shengine by mrsinho
Loading...
Searching...
No Matches
shApplicationHost.h File Reference

Platform-specific shared library loading functions. More...

#include <dlfcn.h>
#include <stdint.h>
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  ShApplicationHost
 Represents the host for a shared application. More...
 

Macros

#define shLoadShared(path)   dlopen(path, RTLD_LAZY)
 Macro to load a shared library on non-Windows platforms.
 
#define shSharedLoadSymbol(handle, symbol)   dlsym(handle, symbol)
 Macro to load a symbol from a shared library on non-Windows platforms.
 
#define shSharedFree(handle)   dlclose(handle)
 Macro to free a loaded shared library on non-Windows platforms.
 
#define shSharedHostError(condition, msg, failure_expression)    if ((int)(condition)) { printf("shsharedhost error: %s\n", msg); failure_expression; }
 Macro to handle errors in the shared host.
 
#define shSharedRelease(p_shared)    if ((p_shared) != NULL) { if (*(p_shared) != NULL) { shSharedFree(*(p_shared)); *(p_shared) = NULL; } }
 Releases the shared library.
 

Typedefs

typedef void * ShSharedHandle
 Represents a handle to a loaded shared library.
 
typedef uint8_t() ShApplicationFunc(void *)
 Represents the function signature for the application's main function.
 
typedef uint64_t() ShApplicationThreadFunc(void *)
 Represents the function signature for a thread within the application.
 
typedef struct ShApplicationHost ShApplicationHost
 

Functions

uint64_t shApplicationRun (void *p_engine, ShApplicationFunc *p_func)
 Runs a shared application.
 
uint8_t shGetSharedApplication (const char *shared_name, const char *s_start, const char *s_update, const char *s_main_cmd_buffer, const char *s_main_renderpass, const char *s_frame_resize, const char *s_close, ShApplicationHost *p_application)
 Retrieves the shared application information.
 

Detailed Description

Platform-specific shared library loading functions.

This file provides platform-specific macros and functions for loading shared libraries dynamically.

Macro Definition Documentation

◆ shLoadShared

#define shLoadShared (   path)    dlopen(path, RTLD_LAZY)

Macro to load a shared library on non-Windows platforms.

This macro uses the POSIX function dlopen to load a shared library.

Parameters
pathPath to the shared library.
Returns
A handle to the loaded shared library.

◆ shSharedFree

#define shSharedFree (   handle)    dlclose(handle)

Macro to free a loaded shared library on non-Windows platforms.

This macro uses the POSIX function dlclose to free a loaded shared library.

Parameters
handleHandle to the loaded shared library.

◆ shSharedHostError

#define shSharedHostError (   condition,
  msg,
  failure_expression 
)     if ((int)(condition)) { printf("shsharedhost error: %s\n", msg); failure_expression; }

Macro to handle errors in the shared host.

This macro prints an error message and executes a failure expression if a condition is true.

Parameters
conditionThe condition to check.
msgThe error message.
failure_expressionThe expression to execute in case of failure.

◆ shSharedLoadSymbol

#define shSharedLoadSymbol (   handle,
  symbol 
)    dlsym(handle, symbol)

Macro to load a symbol from a shared library on non-Windows platforms.

This macro uses the POSIX function dlsym to load a symbol from a shared library.

Parameters
handleHandle to the loaded shared library.
symbolSymbol name to load.
Returns
A pointer to the loaded symbol.

◆ shSharedRelease

#define shSharedRelease (   p_shared)     if ((p_shared) != NULL) { if (*(p_shared) != NULL) { shSharedFree(*(p_shared)); *(p_shared) = NULL; } }

Releases the shared library.

This macro frees the loaded shared library if it is not NULL.

Parameters
p_sharedA pointer to the shared library handle.

Typedef Documentation

◆ ShApplicationFunc

ShApplicationFunc

Represents the function signature for the application's main function.

It takes A pointer as argument to manage some data that the application may use.

Returns
An 8-bit unsigned integer representing the success or failure of the application.

◆ ShApplicationHost

◆ ShApplicationThreadFunc

ShApplicationThreadFunc

Represents the function signature for a thread within the application.

It takes A pointer as argument to manage some data that the application may use.

Returns
A 64-bit unsigned integer representing the success or failure of the thread.

◆ ShSharedHandle

Represents a handle to a loaded shared library.

Function Documentation

◆ shApplicationRun()

uint64_t shApplicationRun ( void *  p_engine,
ShApplicationFunc p_func 
)
extern

Runs a shared application.

This function runs the shared application by executing the provided application function.

Parameters
p_engineA pointer to the engine data.
p_funcThe application function to run.
Returns
A 64-bit unsigned integer representing the success or failure of the application.

◆ shGetSharedApplication()

uint8_t shGetSharedApplication ( const char *  shared_name,
const char *  s_start,
const char *  s_update,
const char *  s_main_cmd_buffer,
const char *  s_main_renderpass,
const char *  s_frame_resize,
const char *  s_close,
ShApplicationHost p_application 
)
extern

Retrieves the shared application information.

This function retrieves information about the shared application from the shared library.

Parameters
shared_nameThe name of the shared library.
s_startThe symbol name for the start function.
s_updateThe symbol name for the update function.
s_main_cmd_bufferThe symbol name for the main command buffer function.
s_main_renderpassThe symbol name for the main render pass function.
s_frame_resizeThe symbol name for the frame resize function.
s_closeThe symbol name for the close function.
p_applicationA pointer to the application host structure to fill.
Returns
An 8-bit unsigned integer representing the success or failure of retrieving the shared application.