Skip to content

Commit

Permalink
Static log library, readd logging to all sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Azif committed Dec 15, 2021
1 parent 8910f4c commit 38092e0
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 117 deletions.
5 changes: 3 additions & 2 deletions Makefile
@@ -1,11 +1,12 @@
# Package metadata
TITLE := PS4 Vibe
VERSION := 1.00
VERSION := 1.02
TITLE_ID := AZIF00001
CONTENT_ID := IV0000-AZIF00001_00-PS4VIBE000000000

# Libraries linked into the ELF
LIBS := -lc -lkernel -lc++ -lSceSystemService -lSceSysmodule -lSceVideoOut -lSceUserService -lScePad -lSceFreeType
LIBS += -Llibs -lLog

# Directorys to include
INCLUDES := -Iinclude -Iexternal
Expand Down Expand Up @@ -89,4 +90,4 @@ $(ODIR):

.PHONY: clean
clean:
rm -rf $(CONTENT_ID).pkg pkg.gp4 sce_sys/param.sfo eboot.bin $(ODIR)
rm -rf *.pkg pkg.gp4 sce_sys/param.sfo eboot.bin $(ODIR)
78 changes: 0 additions & 78 deletions external/libLog_stub.h → external/libLog.h
Expand Up @@ -7,8 +7,6 @@
#define LIBLOG_H

#ifdef __cplusplus
// TODO: C++ stream bindings includes here

extern "C" {
#endif

Expand All @@ -18,9 +16,7 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>

#ifndef __LIBLOG_PC__
#include <orbis/libkernel.h>
#endif

enum LogLevels {
LL_None,
Expand All @@ -40,75 +36,6 @@ enum PrintTypes {
PT_File,
};

#ifndef __LIBLOG_PC__
void (*_logPrint)(enum LogLevels p_LogLevel, enum PrintTypes p_PrintType, bool p_Meta, const char *p_File, int p_Line, const char *p_Format, ...) = NULL;
void (*_logPrintHex)(enum LogLevels p_LogLevel, enum PrintTypes p_PrintType, bool p_Meta, const char *p_File, int p_Line, const void *p_Pointer, int p_Length) = NULL;
void (*_logPrintBin)(enum LogLevels p_LogLevel, enum PrintTypes p_PrintType, const char *p_Input, uint16_t p_Port, const void *p_Pointer, int p_Length) = NULL;

bool (*logSocketOpen)(const char *p_IpAddress, uint16_t p_Port) = NULL;
bool (*logSocketClose)() = NULL;
bool (*logSocketIsOpen)() = NULL;

const char *(*logSocketGetIpAddress)() = NULL;
uint16_t (*logSocketGetPort)() = NULL;

bool (*logFileOpen)(const char *p_Path) = NULL;
bool (*logFileClose)() = NULL;
const char *(*logFileGetFilename)() = NULL;

void (*logSetLogLevel)(enum LogLevels p_LogLevel) = NULL;
enum LogLevels (*logGetLogLevel)() = NULL;

void (*logPrintSetLogLevel)(enum LogLevels p_LogLevel) = NULL;
enum LogLevels (*logPrintGetLogLevel)() = NULL;

void (*logKernelSetLogLevel)(enum LogLevels p_LogLevel) = NULL;
enum LogLevels (*logKernelGetLogLevel)() = NULL;

void (*logFileSetLogLevel)(enum LogLevels p_LogLevel) = NULL;
enum LogLevels (*logFileGetLogLevel)() = NULL;

void (*logSocketSetLogLevel)(enum LogLevels p_LogLevel) = NULL;
enum LogLevels (*logSocketGetLogLevel)() = NULL;

int32_t logInitalize(int handle) {
if (sceKernelDlsym(handle, "_logPrint", (void **)&_logPrint) != 0 ||
sceKernelDlsym(handle, "_logPrintHex", (void **)&_logPrintHex) != 0 ||
sceKernelDlsym(handle, "_logPrintBin", (void **)&_logPrintBin) != 0 ||

sceKernelDlsym(handle, "logSocketOpen", (void **)&logSocketOpen) != 0 ||
sceKernelDlsym(handle, "logSocketClose", (void **)&logSocketClose) != 0 ||
sceKernelDlsym(handle, "logSocketIsOpen", (void **)&logSocketIsOpen) != 0 ||

sceKernelDlsym(handle, "logSocketGetIpAddress", (void **)&logSocketGetIpAddress) != 0 ||
sceKernelDlsym(handle, "logSocketGetPort", (void **)&logSocketGetPort) != 0 ||

sceKernelDlsym(handle, "logFileOpen", (void **)&logFileOpen) != 0 ||
sceKernelDlsym(handle, "logFileClose", (void **)&logFileClose) != 0 ||
sceKernelDlsym(handle, "logFileGetFilename", (void **)&logFileGetFilename) != 0 ||

sceKernelDlsym(handle, "logSetLogLevel", (void **)&logSetLogLevel) != 0 ||
sceKernelDlsym(handle, "logGetLogLevel", (void **)&logGetLogLevel) != 0 ||

sceKernelDlsym(handle, "logPrintSetLogLevel", (void **)&logPrintSetLogLevel) != 0 ||
sceKernelDlsym(handle, "logPrintGetLogLevel", (void **)&logPrintGetLogLevel) != 0 ||

sceKernelDlsym(handle, "logKernelSetLogLevel", (void **)&logKernelSetLogLevel) != 0 ||
sceKernelDlsym(handle, "logKernelGetLogLevel", (void **)&logKernelGetLogLevel) != 0 ||

sceKernelDlsym(handle, "logFileSetLogLevel", (void **)&logFileSetLogLevel) != 0 ||
sceKernelDlsym(handle, "logFileGetLogLevel", (void **)&logFileGetLogLevel) != 0 ||

sceKernelDlsym(handle, "logSocketSetLogLevel", (void **)&logSocketSetLogLevel) != 0 ||
sceKernelDlsym(handle, "logSocketGetLogLevel", (void **)&logSocketGetLogLevel) != 0) {
return -1;
}

return 0;
}

#else

void _logPrint(enum LogLevels p_LogLevel, enum PrintTypes p_PrintType, bool p_Meta, const char *p_File, int p_Line, const char *p_Format, ...);
void _logPrintHex(enum LogLevels p_LogLevel, enum PrintTypes p_PrintType, bool p_Meta, const char *p_File, int p_Line, const void *p_Pointer, int p_Length);
void _logPrintBin(enum LogLevels p_LogLevel, enum PrintTypes p_PrintType, const char *p_Input, uint16_t p_Port, const void *p_Pointer, int p_Length);
Expand Down Expand Up @@ -139,8 +66,6 @@ enum LogLevels logFileGetLogLevel();
void logSocketSetLogLevel(enum LogLevels p_LogLevel);
enum LogLevels logSocketGetLogLevel();

#endif

#define logPrint(p_LogLevel, ...) _logPrint(p_LogLevel, PT_Print, true, __FILE__, __LINE__, __VA_ARGS__)
#define logPrintUnformatted(p_LogLevel, ...) _logPrint(p_LogLevel, PT_Print, false, __FILE__, __LINE__, __VA_ARGS__)
#define logPrintHexdump(p_LogLevel, p_Pointer, p_Length) _logPrintHex(p_LogLevel, PT_Print, true, __FILE__, __LINE__, p_Pointer, p_Length)
Expand All @@ -166,9 +91,6 @@ enum LogLevels logSocketGetLogLevel();

#ifdef __cplusplus
}

// TODO: C++ stream bindings here

#endif

#endif
Binary file added libs/libLog.a
Binary file not shown.
Binary file removed sce_module/libLog.prx
Binary file not shown.
6 changes: 4 additions & 2 deletions src/controller.cpp
Expand Up @@ -2,6 +2,8 @@

#include "controller.h"

#include "libLog.h"

Controller::Controller() {
}

Expand All @@ -11,7 +13,7 @@ Controller::~Controller() {
bool Controller::Init(int controllerUserID) {
// Initialize the Pad library
if (scePadInit() != 0) {
// DEBUGLOG << "[DEBUG] [ERROR] Failed to initialize pad library!";
logKernel(LL_Error, "%s", "Failed to initialize pad library!");
return false;
}

Expand All @@ -29,7 +31,7 @@ bool Controller::Init(int controllerUserID) {
this->pad = scePadOpen(this->userID, 0, 0, NULL);

if (this->pad < 0) {
// DEBUGLOG << "[DEBUG] [ERROR] Failed to open pad!";
logKernel(LL_Error, "%s", "Failed to open pad!");
return false;
}

Expand Down
23 changes: 13 additions & 10 deletions src/graphics.cpp
@@ -1,14 +1,16 @@
// OpenOrbis Toolchain, https://github.com/OpenOrbis/OpenOrbis-PS4-Toolchain

#include "graphics.h"

#include "libLog.h"

#include <string>

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <string>

#include "graphics.h"

Scene2D::Scene2D(int w, int h, int pixelDepth) {
this->width = w;
this->height = h;
Expand All @@ -24,7 +26,7 @@ bool Scene2D::Init(size_t memSize, int numFrameBuffers) {
this->videoMem = NULL;

if (this->video < 0) {
// DEBUGLOG << "Failed to open a video out handle: " << std::string(strerror(errno));
logKernel(LL_Error, "Failed to open a video out handle: %s", std::string(strerror(errno)).c_str());
return false;
}

Expand All @@ -33,31 +35,32 @@ bool Scene2D::Init(size_t memSize, int numFrameBuffers) {
rc = sceSysmoduleLoadModule(0x009A);

if (rc < 0) {
// DEBUGLOG << "Failed to load freetype: " << std::string(strerror(errno));
logKernel(LL_Error, "Failed to load freetype: %s", std::string(strerror(errno)).c_str());

return false;
}

// Initialize freetype
rc = FT_Init_FreeType(&this->ftLib);

if (rc != 0) {
// DEBUGLOG << "Failed to initialize freetype: " << std::string(strerror(errno));
logKernel(LL_Error, "Failed to initialize freetype: %s", std::string(strerror(errno)).c_str());
return false;
}
#endif

if (!initFlipQueue()) {
// DEBUGLOG << "Failed to initialize flip queue: " << std::string(strerror(errno));
logKernel(LL_Error, "Failed to initialize flip queue: %s", std::string(strerror(errno)).c_str());
return false;
}

if (!allocateVideoMem(memSize, 0x200000)) {
// DEBUGLOG << "Failed to allocate video memory: " << std::string(strerror(errno));
logKernel(LL_Error, "Failed to allocate video memory: %s", std::string(strerror(errno)).c_str());
return false;
}

if (!allocateFrameBuffers(numFrameBuffers)) {
// DEBUGLOG << "Failed to allocate frame buffers: " << std::string(strerror(errno));
logKernel(LL_Error, "Failed to allocate frame buffers: %s", std::string(strerror(errno)).c_str());
return false;
}

Expand Down
33 changes: 8 additions & 25 deletions src/main.cpp
Expand Up @@ -3,21 +3,19 @@

// License: GPL-3.0

#include <cstddef>
#include <cstdlib>
#include "controller.h"
#include "graphics.h"

#include "libLog.h"
#include "notifi.h"

#include <orbis/Pad.h>
#include <orbis/SystemService.h>
#include <orbis/UserService.h>
#include <orbis/libkernel.h>

#include "controller.h"
#include "graphics.h"
#include "libLog_stub.h"
#include "notifi.h"

// Handle for libLog
int g_LibLogHandle = -1;
#include <cstddef>
#include <cstdlib>

// Dimensions for the 2D scene
#define FRAME_WIDTH 1920
Expand Down Expand Up @@ -49,33 +47,18 @@ void terminate() {
g_Controller->SetVibration(&g_Vibra);

g_Controller->ResetLightBar();

if (g_LibLogHandle >= 0) {
sceKernelStopUnloadModule(g_LibLogHandle, 0, 0, 0, NULL, NULL);
}
}

// This function will display p_Message, then "cleanly" close the application
void fail(const char *p_Message) {
printf("%s", p_Message); // Flawfinder: ignore
logKernel(LL_Fatal, "%s", p_Message);
notifi(NULL, "%s", p_Message);
terminate();
sceSystemServiceLoadExec("exit", NULL);
}

// Initalize
void initialize() {
if ((g_LibLogHandle = sceKernelLoadStartModule("/app0/sce_module/libLog.prx", 0, 0, 0, NULL, NULL)) < 0) {
fail("Failed to start the libLog library");
}

if (logInitalize(g_LibLogHandle) != 0) {
fail("Failed to initialize the libLog library's functions");
}

// We know the logging is initalized here so we can use it after this point
logKernel(LL_Info, "%s", "libLog.prx Initialized");

g_Vibra.lgMotor = 0;
g_Vibra.smMotor = 0;

Expand Down

0 comments on commit 38092e0

Please sign in to comment.