Skip to content

Commit c3f45f0

Browse files
committed
Implementation
1 parent 827b654 commit c3f45f0

18 files changed

+912
-54
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
wsjcpp-hashes
22
tmp/*
3+
.vscode/*
34

45
# Prerequisites
56
*.d

.travis.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: cpp
2+
3+
branches:
4+
only:
5+
- master
6+
7+
dist: bionic
8+
9+
addons:
10+
apt:
11+
packages:
12+
- cmake
13+
- make
14+
- g++
15+
- pkg-config
16+
17+
# Build steps
18+
script:
19+
- ./build_simple.sh
20+
- cd unit-tests
21+
- ./build_simple.sh
22+
- ./unit-tests

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ set(EXECUTABLE_OUTPUT_PATH ${wsjcpp-hashes_SOURCE_DIR})
1212
# include header dirs
1313
list (APPEND WSJCPP_INCLUDE_DIRS "src")
1414

15+
list (APPEND WSJCPP_SOURCES "src/smallsha1.h")
16+
list (APPEND WSJCPP_SOURCES "src/smallsha1.cpp")
17+
list (APPEND WSJCPP_SOURCES "src/md5.h")
18+
list (APPEND WSJCPP_SOURCES "src/md5.cpp")
1519
list (APPEND WSJCPP_SOURCES "src/wsjcpp_hashes.h")
1620
list (APPEND WSJCPP_SOURCES "src/wsjcpp_hashes.cpp")
1721
list (APPEND WSJCPP_SOURCES "src/main.cpp")

src.wsjcpp/wsjcpp-core/wsjcpp.hold.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cmake_cxx_standard: 11
44
cmake_minimum_required: 3.0
55

66
name: wsjcpp/wsjcpp-core
7-
version: 0.0.1
7+
version: v0.0.1
88
description: Basic Utils for wsjcpp
99
issues: https://github.com/wsjcpp/wsjcpp-core/issues
1010
repositories:

src.wsjcpp/wsjcpp-core/wsjcpp_core.cpp

+22-20
Original file line numberDiff line numberDiff line change
@@ -380,21 +380,23 @@ std::string WSJCppCore::createUuid() {
380380
// WSJCppLog
381381

382382
// Last log messages
383-
std::deque<std::string> *g_LAST_LOG_MESSAGES = NULL;
384-
std::mutex *g_LOG_MUTEX = NULL;
385-
std::string WSJCppLog::g_LOG_DIR = "./";
386-
std::string WSJCppLog::g_LOG_FILE = "";
387-
std::string WSJCppLog::g_PREFIX_LOG_FILE = "";
388-
long WSJCppLog::g_LOG_START_TIME = 0;
383+
std::deque<std::string> * WSJCppLog::g_WSJCPP_LOG_LAST_MESSAGES = nullptr;
384+
std::mutex * WSJCppLog::g_WSJCPP_LOG_MUTEX = nullptr;
385+
std::string WSJCppLog::g_WSJCPP_LOG_DIR = "./";
386+
std::string WSJCppLog::g_WSJCPP_LOG_FILE = "";
387+
std::string WSJCppLog::g_WSJCPP_LOG_PREFIX_FILE = "";
388+
long WSJCppLog::g_WSJCPP_LOG_START_TIME = 0;
389389

390390
// ---------------------------------------------------------------------
391391

392392
void WSJCppLog::doLogRotateUpdateFilename(bool bForce) {
393393
long t = WSJCppCore::currentTime_seconds();
394394
long nEverySeconds = 51000; // rotate log if started now or if time left more then 1 day
395-
if (g_LOG_START_TIME == 0 || t - g_LOG_START_TIME > nEverySeconds || bForce) {
396-
g_LOG_START_TIME = t;
397-
g_LOG_FILE = g_LOG_DIR + "/" + WSJCppLog::g_PREFIX_LOG_FILE + "_" + WSJCppCore::formatTimeForFilename(g_LOG_START_TIME) + ".log";
395+
if (g_WSJCPP_LOG_START_TIME == 0 || t - g_WSJCPP_LOG_START_TIME > nEverySeconds || bForce) {
396+
g_WSJCPP_LOG_START_TIME = t;
397+
g_WSJCPP_LOG_FILE = g_WSJCPP_LOG_DIR + "/"
398+
+ WSJCppLog::g_WSJCPP_LOG_PREFIX_FILE + "_"
399+
+ WSJCppCore::formatTimeForFilename(g_WSJCPP_LOG_START_TIME) + ".log";
398400
}
399401
}
400402

@@ -437,28 +439,28 @@ void WSJCppLog::ok(const std::string &sTag, const std::string &sMessage) {
437439
// ---------------------------------------------------------------------
438440

439441
void WSJCppLog::setLogDirectory(const std::string &sDirectoryPath) {
440-
WSJCppLog::g_LOG_DIR = sDirectoryPath;
442+
WSJCppLog::g_WSJCPP_LOG_DIR = sDirectoryPath;
441443
WSJCppLog::doLogRotateUpdateFilename(true);
442444
}
443445

444446
// ---------------------------------------------------------------------
445447

446448
void WSJCppLog::setPrefixLogFile(const std::string &sPrefixLogFile) {
447-
WSJCppLog::g_PREFIX_LOG_FILE = sPrefixLogFile;
449+
WSJCppLog::g_WSJCPP_LOG_PREFIX_FILE = sPrefixLogFile;
448450
WSJCppLog::doLogRotateUpdateFilename(true);
449451
}
450452

451453
// ---------------------------------------------------------------------
452454

453455
void WSJCppLog::initGlobalVariables() {
454456
// create deque if not created
455-
if (g_LAST_LOG_MESSAGES == NULL) {
456-
g_LAST_LOG_MESSAGES = new std::deque<std::string>();
457+
if (WSJCppLog::g_WSJCPP_LOG_LAST_MESSAGES == nullptr) {
458+
WSJCppLog::g_WSJCPP_LOG_LAST_MESSAGES = new std::deque<std::string>();
457459
// std::cout << WSJCppCore::currentTime_logformat() + ", " + WSJCppCore::threadId() + " Init last messages deque\r\n";
458460
}
459461
// create mutex if not created
460-
if (g_LOG_MUTEX == NULL) {
461-
g_LOG_MUTEX = new std::mutex();
462+
if (WSJCppLog::g_WSJCPP_LOG_MUTEX == nullptr) {
463+
WSJCppLog::g_WSJCPP_LOG_MUTEX = new std::mutex();
462464
// std::cout << WSJCppCore::currentTime_logformat() + ", " + WSJCppCore::threadId() + " Init mutex for log\r\n";
463465
}
464466
}
@@ -469,19 +471,19 @@ void WSJCppLog::add(WSJCppColorModifier &clr, const std::string &sType, const st
469471
WSJCppLog::initGlobalVariables();
470472
WSJCppLog::doLogRotateUpdateFilename();
471473

472-
std::lock_guard<std::mutex> lock(*g_LOG_MUTEX);
474+
std::lock_guard<std::mutex> lock(*WSJCppLog::g_WSJCPP_LOG_MUTEX);
473475
WSJCppColorModifier def(WSJCppColorCode::FG_DEFAULT);
474476

475477
std::string sLogMessage = WSJCppCore::currentTime_logformat() + ", " + WSJCppCore::threadId()
476478
+ " [" + sType + "] " + sTag + ": " + sMessage;
477479
std::cout << clr << sLogMessage << def << std::endl;
478480

479-
g_LAST_LOG_MESSAGES->push_front(sLogMessage);
480-
while (g_LAST_LOG_MESSAGES->size() > 50) {
481-
g_LAST_LOG_MESSAGES->pop_back();
481+
g_WSJCPP_LOG_LAST_MESSAGES->push_front(sLogMessage);
482+
while (g_WSJCPP_LOG_LAST_MESSAGES->size() > 50) {
483+
g_WSJCPP_LOG_LAST_MESSAGES->pop_back();
482484
}
483485
// TODO try create global variable
484-
std::ofstream logFile(WSJCppLog::g_LOG_FILE, std::ios::app);
486+
std::ofstream logFile(WSJCppLog::g_WSJCPP_LOG_FILE, std::ios::app);
485487
if (!logFile) {
486488
std::cout << "Error Opening File" << std::endl;
487489
return;

src.wsjcpp/wsjcpp-core/wsjcpp_core.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ class WSJCppColorModifier {
8080

8181
class WSJCppLog {
8282
public:
83-
static std::string g_LOG_DIR;
84-
static std::string g_PREFIX_LOG_FILE;
85-
static std::string g_LOG_FILE;
86-
static long g_LOG_START_TIME;
83+
static std::string g_WSJCPP_LOG_DIR;
84+
static std::string g_WSJCPP_LOG_PREFIX_FILE;
85+
static std::string g_WSJCPP_LOG_FILE;
86+
static long g_WSJCPP_LOG_START_TIME;
87+
static std::mutex * g_WSJCPP_LOG_MUTEX;
88+
static std::deque<std::string> * g_WSJCPP_LOG_LAST_MESSAGES;
8789
static void doLogRotateUpdateFilename(bool bForce = false);
8890

8991
static void info(const std::string &sTag, const std::string &sMessage);
@@ -100,4 +102,4 @@ class WSJCppLog {
100102
static void add(WSJCppColorModifier &clr, const std::string &sType, const std::string &sTag, const std::string &sMessage);
101103
};
102104

103-
#endif // WSJCPP_CORE_H
105+
#endif // WSJCPP_CORE_H

0 commit comments

Comments
 (0)