aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/utils')
-rw-r--r--src/libjin/utils/endian.h8
-rw-r--r--src/libjin/utils/log.cpp102
-rw-r--r--src/libjin/utils/log.h76
-rw-r--r--src/libjin/utils/macros.h2
-rw-r--r--src/libjin/utils/unittest.cpp116
5 files changed, 152 insertions, 152 deletions
diff --git a/src/libjin/utils/endian.h b/src/libjin/utils/endian.h
index db8c8fd..ee22775 100644
--- a/src/libjin/utils/endian.h
+++ b/src/libjin/utils/endian.h
@@ -11,10 +11,10 @@
#define jin_byte_order __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__)
+ defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
+ (defined(__MIPS__) && defined(__MISPEB__)) || \
+ defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
+ defined(__sparc__)
#define jin_byte_order jin_endian_big
#else
#define jin_byte_order jin_endian_lil
diff --git a/src/libjin/utils/log.cpp b/src/libjin/utils/log.cpp
index 560afa8..ad9d793 100644
--- a/src/libjin/utils/log.cpp
+++ b/src/libjin/utils/log.cpp
@@ -9,73 +9,73 @@ std::ofstream Loghelper::fs;
void Loghelper::log(Level _level, const char* _fmt, ...)
{
- if (!hasbit(levels, _level))
- return;
+ 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_WARNING:
- levelStr = "[Jin Warning]: ";
- break;
- case LV_INFO:
- levelStr = "[Jin Info]: ";
- break;
- case LV_DEBUG:
- levelStr = "[Jin Debug]: ";
- break;
- default:
- levelStr = "[Jin Unknow]: ";
- 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;
- }
+ const char* levelStr = nullptr;
+ switch (_level)
+ {
+ case LV_ERROR:
+ levelStr = "[Jin Error]: ";
+ break;
+ case LV_WARNING:
+ levelStr = "[Jin Warning]: ";
+ break;
+ case LV_INFO:
+ levelStr = "[Jin Info]: ";
+ break;
+ case LV_DEBUG:
+ levelStr = "[Jin Debug]: ";
+ break;
+ default:
+ levelStr = "[Jin Unknow]: ";
+ 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_WARNING, "ضlog· %s ʧ", _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_WARNING, "ضlog· %s ʧ", _path);
+ }
+ }
}
// ɸѡȼ
void Loghelper::restrict(unsigned int _levels)
{
- levels = _levels;
+ levels = _levels;
}
void Loghelper::close()
{
- if (!fs.fail())
- fs.close();
- fs.clear();
+ if (!fs.fail())
+ fs.close();
+ fs.clear();
}
#undef hasbit
diff --git a/src/libjin/utils/log.h b/src/libjin/utils/log.h
index 11b4897..961df7a 100644
--- a/src/libjin/utils/log.h
+++ b/src/libjin/utils/log.h
@@ -11,52 +11,52 @@
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_WARNING = 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();
+ // logĿ
+ enum Direction
+ {
+ DIR_CERR = 1 << 1, // ׼
+ DIR_FILE = 1 << 2, // logļ
+ };
+
+ // ȼ
+ enum Level
+ {
+ LV_NONE = 0, // none
+ LV_ERROR = 1 << 1, // error
+ LV_WARNING = 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; // ļ
+ static unsigned int dir; // Ŀ
+ static unsigned int levels; // ȼ
+ static std::ofstream fs; // ļ
};
typedef Loghelper::Level Loglevel;
#if defined(jin_debug)
- #define jin_log_error(f, ...) Loghelper::log(Loghelper::LV_ERROR, f, __VA_ARGS__)
- #define jin_log_info(f, ...) Loghelper::log(Loghelper::LV_INFO, f, __VA_ARGS__)
- #define jin_log_warning(f, ...) Loghelper::log(Loghelper::LV_WARNING, f, __VA_ARGS__)
- #define jin_log_debug(f, ...) Loghelper::log(Loghelper::LV_DEBUG, f, __VA_ARGS__)
+ #define jin_log_error(f, ...) Loghelper::log(Loghelper::LV_ERROR, f, __VA_ARGS__)
+ #define jin_log_info(f, ...) Loghelper::log(Loghelper::LV_INFO, f, __VA_ARGS__)
+ #define jin_log_warning(f, ...) Loghelper::log(Loghelper::LV_WARNING, f, __VA_ARGS__)
+ #define jin_log_debug(f, ...) Loghelper::log(Loghelper::LV_DEBUG, f, __VA_ARGS__)
#else
- #define jin_log_error(f, ...)
- #define jin_log_info(f, ...)
- #define jin_log_warning(f, ...)
- #define jin_log_debug(f, ...)
+ #define jin_log_error(f, ...)
+ #define jin_log_info(f, ...)
+ #define jin_log_warning(f, ...)
+ #define jin_log_debug(f, ...)
#endif
#endif // __LOG_H__ELPER_H__ \ No newline at end of file
diff --git a/src/libjin/utils/macros.h b/src/libjin/utils/macros.h
index 6e4e7a9..d807a91 100644
--- a/src/libjin/utils/macros.h
+++ b/src/libjin/utils/macros.h
@@ -8,7 +8,7 @@
//
//#define MASK // enum
//
-//#define onlyonce // ֻһ
+//#define onlyonce // ֻһ
//#define CALLONCE(call) static char __dummy__=(call, 1) // ֻһ
//#define SAFECALL(func, params) if(func) func(params)
//
diff --git a/src/libjin/utils/unittest.cpp b/src/libjin/utils/unittest.cpp
index 83af6ce..4ab598a 100644
--- a/src/libjin/utils/unittest.cpp
+++ b/src/libjin/utils/unittest.cpp
@@ -12,21 +12,21 @@ 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;
+ 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;
}
/*
@@ -40,68 +40,68 @@ int main(int argc, char* argv[])
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);
- }
+ 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);
+ 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_AudioDeviceID dev;
+ SDL_AudioSpec fmt, got;
+ cm_Source *src;
+ cm_Source* src2;
- SDL_Init(SDL_INIT_AUDIO);
- audio_mutex = SDL_CreateMutex();
+ 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;
+ 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);
- }
+ 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);
+ cm_init(got.freq);
+ cm_set_lock(lock_handler);
+ cm_set_master_gain(0.5);
- SDL_PauseAudioDevice(dev, 0);
+ 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);
+ 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);
+ cm_play(src);
+ cm_play(src2);
- printf("Press [return] to exit\n");
- getchar();
+ printf("Press [return] to exit\n");
+ getchar();
- cm_destroy_source(src);
- SDL_CloseAudioDevice(dev);
- SDL_Quit();
+ cm_destroy_source(src);
+ SDL_CloseAudioDevice(dev);
+ SDL_Quit();
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
*/