Skip to content

Commit

Permalink
Implement log as own module for better style
Browse files Browse the repository at this point in the history
  • Loading branch information
harlequin committed Jun 6, 2016
1 parent 2af3bb1 commit b565360
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ GIT_VERSION := $(shell git describe --dirty --always --abbrev=4)

all: ${TARGETS}

libdvbapi.so: dvbapi.c hook.c C_support.c $(wildcard *.h) $(wildcard ../include/*.h)
$(CC) $(filter %.c %.cpp,$^) ${CFLAGS} -mel -shared -Wl,-soname,$@ -o $@
libdvbapi.so: dvbapi.c hook.c C_support.c log.c $(wildcard *.h) $(wildcard ../include/*.h)
$(CROSS)gcc $(filter %.c %.cpp,$^) ${CFLAGS} -mel -shared -Wl,-soname,$@ -o $@

clean:
rm -f ${TARGETS}
Expand Down
2 changes: 2 additions & 0 deletions dvbapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
#include "types.h"
#include "util.h"

#include "log.h"

/* CONFIGURATION */
static u8* oscam_server_ip = NULL;
static u16 oscam_server_port = 0;
Expand Down
38 changes: 38 additions & 0 deletions log.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2016 harlequin
* https://github.com/harlequin/samygo-plugin-dvbapi
*
* This file is part of samygo-plugin-dvbapi.
*
* samygo-plugin-dvbapi 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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdarg.h>
#include "log.h"

void LOG(const char *fmt, ...) {
#ifdef LOG_FILE
va_list ap;

FILE *f = fopen(LOG_FILE, "a+");
if(f) {
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);

fflush(f);
fclose(f);
}
#endif
}
33 changes: 33 additions & 0 deletions log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2016 harlequin
* https://github.com/harlequin/samygo-plugin-dvbapi
*
* This file is part of samygo-plugin-dvbapi.
*
* samygo-plugin-dvbapi 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 <http://www.gnu.org/licenses/>.
*/
#ifndef LOG_H_
#define LOG_H_

#define LIB_NAME "dvbapi"
#define LIB_VERSION "v0.0.1"
#define LIB_TV_MODELS "D (MIPS/MSTAR)"
#define INFO_VERSION "samygo-plugin-dvbapi " LIB_VERSION " / MODEL " LIB_TV_MODELS
#define LOG_FILE "/dtv/"LIB_NAME".log"
void LOG(const char *fmt, ...);
#define log(...) LOG("["LIB_NAME"] "__VA_ARGS__);
#define logh(fmt,...) LOG("["LIB_NAME"] %s, "fmt,__func__+2,__VA_ARGS__)
#define logf(fmt,...) LOG("["LIB_NAME"] %s, "fmt,__func__,__VA_ARGS__)

#endif /* LOG_H_ */
6 changes: 0 additions & 6 deletions types.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,3 @@ typedef struct ca_descr_mode {
enum ca_descr_algo algo;
enum ca_descr_cipher_mode cipher_mode;
} ca_descr_mode_t;

//////////////////////////////////////////////////////////////////////////////
#define LIB_NAME "dvbapi"
#define LIB_VERSION "v0.0.1"
#define LIB_TV_MODELS "D (MIPS/MSTAR)"
#define INFO_VERSION "samygo-plugin-dvbapi " LIB_VERSION " / MODEL " LIB_TV_MODELS
44 changes: 5 additions & 39 deletions util.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define LOG_FILE "/dtv/"LIB_NAME".log"
#define STATIC static

#define _FILE_OFFSET_BITS 64
Expand All @@ -13,45 +12,11 @@
#include <sys/types.h>
#include <sys/stat.h>

#include "log.h"

static int patch_adbg_CheckSystem(void *h)
{
static int patch_adbg_CheckSystem(void *h) {
return 0;
}
void LOG(
const char *fmt, ...)
{
#ifdef LOG_FILE
va_list ap;

FILE *f = fopen(LOG_FILE, "a+");
if(f)
{
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);

fflush(f);
fclose(f);
}
#endif
}
void vLOG(const char * restrict fmt, va_list ap)
{
#ifdef LOG_FILE
FILE *f = fopen(LOG_FILE, "a+");
if(f)
{
vfprintf(f, fmt, ap);
fflush(f);
fclose(f);
}
#endif
}
#define log(...) LOG("["LIB_NAME"] "__VA_ARGS__)
#define logh(fmt,...) LOG("["LIB_NAME"] %s, "fmt,__func__+2,__VA_ARGS__)
#define logf(fmt,...) LOG("["LIB_NAME"] %s, "fmt,__func__,__VA_ARGS__)


static void dumpbin(
const char *path, const void *data, size_t cnt)
Expand Down Expand Up @@ -224,10 +189,11 @@ STATIC int samyGO_whacky_t_init(void *h, void *paramCTX, uint32_t cnt)
if(!fn)
fn = dlsym(h, ctx->procs[i]);

if(!fn && !(fn=C_find(h,ctx->procs[i])))
if(!fn && !(fn=C_find(h,ctx->procs[i]))) {
log("dlsym '%s' failed.\n", ctx->procs[i]);
else
} else {
log("%s [%p].\n", ctx->procs[i], fn);
}
ctx->procs[i] = fn;
}
return 0;
Expand Down

0 comments on commit b565360

Please sign in to comment.