diff options
Diffstat (limited to 'src/libjin/utils')
-rw-r--r-- | src/libjin/utils/endian.h | 23 | ||||
-rw-r--r-- | src/libjin/utils/log.cpp | 2 | ||||
-rw-r--r-- | src/libjin/utils/log.h | 134 | ||||
-rw-r--r-- | src/libjin/utils/macros.h | 17 | ||||
-rw-r--r-- | src/libjin/utils/unittest.cpp | 108 | ||||
-rw-r--r-- | src/libjin/utils/utils.h | 9 |
6 files changed, 0 insertions, 293 deletions
diff --git a/src/libjin/utils/endian.h b/src/libjin/utils/endian.h deleted file mode 100644 index 01def88..0000000 --- a/src/libjin/utils/endian.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef LIBJIN_LIL_ENDIAN && LIBJIN_BIG_ENDIAN - -#define LIBJIN_LIL_ENDIAN 2 -#define LIBJIN_BIG_ENDIAN 4 - -#endif - -#ifndef LIBJIN_BYTEORDER -#ifdef __linux__ -#include <endian.h> -#define LIBJIN_BYTEORDER __BYTE_ORDER -#else /* __linux__ */ -#if defined(__hppa__) || \ - defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \ - (defined(__MIPS__) && defined(__MISPEB__)) || \ - defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \ - defined(__sparc__) -#define LIBJIN_BYTEORDER LIBJIN_BIG_ENDIAN -#else -#define LIBJIN_BYTEORDER LIBJIN_LIL_ENDIAN -#endif -#endif /* __linux__ */ -#endif /* !SDL_BYTEORDER */
\ No newline at end of file diff --git a/src/libjin/utils/log.cpp b/src/libjin/utils/log.cpp deleted file mode 100644 index 5299942..0000000 --- a/src/libjin/utils/log.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#define LOGHELPER_IMPLEMENT -#include "log.h"
\ No newline at end of file diff --git a/src/libjin/utils/log.h b/src/libjin/utils/log.h deleted file mode 100644 index e4ed879..0000000 --- a/src/libjin/utils/log.h +++ /dev/null @@ -1,134 +0,0 @@ -/** -* Single.h/loghelper.h -* Copyright (C) 2017~2018 chai -*/ -#ifndef __LOG_HELPER_H -#define __LOG_HELPER_H -#include <string> -#include <iostream> -#include <fstream> -#include <stdarg.h> - -class Loghelper -{ -public: - // logĿ - enum Direction - { - DIR_CERR = 1 << 1, // - DIR_FILE = 1 << 2, // logļ - }; - - // ȼ - enum Level - { - LV_NONE = 0, // none - LV_ERROR = 1 << 1, // error - LV_WARN = 1 << 2, // warn - LV_INFO = 1 << 3, // info - LV_DEBUG = 1 << 4, // debug - LV_ALL = 0xffffffff - }; - - static void log(Level _level, const char* _fmt, ...); - - // ض - static void redirect(unsigned int _dir, char* _path = nullptr); - - // ɸѡȼ - static void restrict(unsigned int levels); - - static void close(); - -private: - static unsigned int dir; // Ŀ - static unsigned int levels; // ȼ - static std::ofstream fs; // ļ -}; - -typedef Loghelper::Level Loglevel; - -#ifdef LOGHELPER_IMPLEMENT - -#define hasbit(flag, bit) ((flag & bit) == bit) - -unsigned int Loghelper::dir = Loghelper::Direction::DIR_CERR; -unsigned int Loghelper::levels = Loghelper::Level::LV_ALL; -std::ofstream Loghelper::fs; - -void Loghelper::log(Level _level, const char* _fmt, ...) -{ - if (!hasbit(levels, _level)) - return; -#define FORMAT_MSG_BUFFER_SIZE (204800) - const char* levelStr = nullptr; - switch (_level) - { - case LV_ERROR: - levelStr = "[Jin Error]:"; - break; - case LV_WARN: - levelStr = "[Jin Warn]:"; - break; - case LV_INFO: - levelStr = "[Jin Info]:"; - break; - case LV_DEBUG: - levelStr = "[Jin Debug]:"; - break; - default: - levelStr = "[Jin Unknown]:"; - break; - } - char buffer[FORMAT_MSG_BUFFER_SIZE + 1] = { 0 }; - strcpy(buffer, levelStr); - va_list args; - va_start(args, _fmt); - vsnprintf(buffer + strlen(buffer), FORMAT_MSG_BUFFER_SIZE, _fmt, args); - va_end(args); - if (hasbit(dir, DIR_CERR)) - { - std::cerr << buffer << std::endl; - } - if (hasbit(dir, DIR_FILE)) - { - fs << buffer << std::endl; - } -#undef FORMAT_MSG_BUFFER_SIZE -} - -// ض -void Loghelper::redirect(unsigned int _dir, char* _path) -{ - dir = _dir; - if (hasbit(dir, DIR_FILE)) - { - try - { - fs.open(_path, std::ios_base::app); - } - catch (std::ios_base::failure& e) { - dir = DIR_CERR; - log(Level::LV_WARN, "ضlog· %s ʧ", _path); - } - } -} - -// ɸѡȼ -void Loghelper::restrict(unsigned int _levels) -{ - levels = _levels; -} - -void Loghelper::close() -{ - if (!fs.fail()) - fs.close(); - fs.clear(); -} - -#undef hasbit - -#endif - -#endif diff --git a/src/libjin/utils/macros.h b/src/libjin/utils/macros.h deleted file mode 100644 index e19193c..0000000 --- a/src/libjin/utils/macros.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __LIBJIN_MACROS_H -#define __LIBJIN_MACROS_H -#include <cstring> - -//#define implement // ʵֽӿ -// -//#define shared // ķ -// -//#define MASK // enum -// -//#define onlyonce // ֻһ -//#define CALLONCE(call) static char __dummy__=(call, 1) // ֻһ -//#define SAFECALL(func, params) if(func) func(params) -// -//#define zero(mem) memset(&mem, 0, sizeof(mem)) - -#endif
\ No newline at end of file diff --git a/src/libjin/utils/unittest.cpp b/src/libjin/utils/unittest.cpp deleted file mode 100644 index 44f1ae5..0000000 --- a/src/libjin/utils/unittest.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include "utils.h" -#if UNITTEST - -#include <iostream> -#include <stdio.h> -#include <fstream> -#include "../audio/sdl/source.h" -#include "../audio/sdl/audio.h" - -using namespace jin::audio; -using namespace std; - -int main(int argc, char* argv[]) -{ - SDLAudio* audio = SDLAudio::get(); - audio->init(0); - SDLSource* source = SDLSource::createSource("a.ogg"); - SDLSource* source2 = SDLSource::createSource("a.wav"); - //source->play(); - source2->play(); - source->setLoop(true); - source2->setLoop(true); - int i = 0; - while (true) - { - SDL_Delay(1000); - } - audio->quit(); - return 0; -} - -/* -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "SDL2/SDL.h" - -#include <3rdparty/cmixer/cmixer.h> - -static SDL_mutex* audio_mutex; - -static void lock_handler(cm_Event *e) { - if (e->type == CM_EVENT_LOCK) { - SDL_LockMutex(audio_mutex); - } - if (e->type == CM_EVENT_UNLOCK) { - SDL_UnlockMutex(audio_mutex); - } -} - - -static void audio_callback(void *udata, Uint8 *stream, int size) { - cm_process((cm_Int16*)stream, size / 2); -} - - -int main(int argc, char **argv) { - SDL_AudioDeviceID dev; - SDL_AudioSpec fmt, got; - cm_Source *src; - cm_Source* src2; - - - SDL_Init(SDL_INIT_AUDIO); - audio_mutex = SDL_CreateMutex(); - - memset(&fmt, 0, sizeof(fmt)); - fmt.freq = 44100; - fmt.format = AUDIO_S16; - fmt.channels = 2; - fmt.samples = 1024; - fmt.callback = audio_callback; - - dev = SDL_OpenAudioDevice(NULL, 0, &fmt, &got, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE); - if (dev == 0) { - fprintf(stderr, "Error: failed to open audio device '%s'\n", SDL_GetError()); - exit(EXIT_FAILURE); - } - - cm_init(got.freq); - cm_set_lock(lock_handler); - cm_set_master_gain(0.5); - - SDL_PauseAudioDevice(dev, 0); - - src = cm_new_source_from_file("a.ogg"); - src2 = cm_new_source_from_file("loop.wav"); - if (!src) { - fprintf(stderr, "Error: failed to create source '%s'\n", cm_get_error()); - exit(EXIT_FAILURE); - } - cm_set_loop(src2, 1); - - cm_play(src); - cm_play(src2); - - printf("Press [return] to exit\n"); - getchar(); - - cm_destroy_source(src); - SDL_CloseAudioDevice(dev); - SDL_Quit(); - - return EXIT_SUCCESS; -} -*/ - -#endif
\ No newline at end of file diff --git a/src/libjin/utils/utils.h b/src/libjin/utils/utils.h deleted file mode 100644 index 1654a8f..0000000 --- a/src/libjin/utils/utils.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __LIBJIN_UTILS_H -#define __LIBJIN_UTILS_H - -#include "macros.h" -#include "endian.h" - -#define UNITTEST 0 - -#endif
\ No newline at end of file |