Includes for linux build.

Some windows compat ensured
LIB-11
heck 2 years ago
parent 49ea80158e
commit f95efdb92d

@ -4,9 +4,19 @@
#ifndef LIBPEPADAPTER_PEPLOG_HH
#define LIBPEPADAPTER_PEPLOG_HH
// getpid
// Linux - unistd.h
// macOS - unistd.h
// Android - unistd.h
// Win - process.h
#ifdef WIN32
#include <process.h>
#else
#include <unistd.h>
#endif
#include <sstream>
#include <thread>
#include <unistd.h>
#include "std_utils.hh"
// pEpLog
@ -137,7 +147,7 @@ namespace pEp {
void log(const std::string& msg, Utils::Color col = Utils::Color::WHITE);
void logH1(const std::string& msg, Utils::Color col = Utils::Color::WHITE);
void logH2(const std::string& msg, Utils::Color col = Utils::Color::WHITE);
void logH3(const std::string&msg, Utils::Color col = Utils::Color::WHITE);
void logH3(const std::string& msg, Utils::Color col = Utils::Color::WHITE);
std::string decorate_three_lines(const std::string& msg, char decoration = '-');
std::string decorate_centered(const std::string& msg, char decoration = '-');
} // namespace pEpLog
@ -200,7 +210,7 @@ namespace pEp {
// Print a logging message in the format "thread - classname[instancename] - <msg>"
void log(const std::string& msg, Utils::Color col = Utils::Color::WHITE) const;
// Prints just "<msg>"
void logRaw(const std::string& msg, Utils::Color col = Utils::Color::WHITE) const;
void logRaw(const std::string& msg, Utils::Color col = Utils::Color::WHITE) const;
void set_enabled(const bool& enabled);
bool get_enabled() const;
std::string get_classname() const;

@ -4,6 +4,7 @@
#include <cstdio>
#include <stdexcept>
#include <string>
#include <cstring>
using namespace std;

@ -7,11 +7,14 @@
#include <cstdio>
#include <cerrno>
#include <cmath>
#include <dirent.h>
#include <sys/stat.h>
#include <algorithm>
#include <thread>
#include <random>
#include <cstring>
#ifndef WIN32
#include <dirent.h>
#include <sys/stat.h>
#endif
using namespace std;
using namespace pEp;
@ -42,18 +45,6 @@ namespace pEp {
return src;
}
// void print_exception(const exception &e, int level)
// {
// cerr << string(level, ' ') << "exception: " << e.what() << endl;
// try {
// rethrow_if_nested(e);
// } catch (const exception &e) {
// print_exception(e, level + 1);
// } catch (...) {
// }
// }
// File utils
bool path_exists(const string &filename)
{
@ -61,6 +52,16 @@ namespace pEp {
return (bool)ifile;
}
void path_delete(const string &filename)
{
int status = remove(filename.c_str());
if (status) {
runtime_error e{ string("path_delete(\"" + filename + "\") - " + strerror(errno)) };
throw(e);
}
}
#ifndef WIN32
bool path_is_dir(const string &path)
{
bool ret = false;
@ -75,15 +76,6 @@ namespace pEp {
return ret;
}
void path_delete(const string &filename)
{
int status = remove(filename.c_str());
if (status) {
runtime_error e{ string("path_delete(\"" + filename + "\") - " + strerror(errno)) };
throw(e);
}
}
void path_delete_all(const string &path)
{
try {
@ -106,6 +98,7 @@ namespace pEp {
throw_with_nested(e);
}
}
#endif
ofstream file_create(const string &filename)
{
@ -132,6 +125,7 @@ namespace pEp {
}
}
#ifndef WIN32
void dir_create(const string &dirname, const mode_t mode)
{
if (mkdir(dirname.c_str(), mode) != 0) {
@ -140,7 +134,6 @@ namespace pEp {
}
}
void dir_ensure(const std::string &path)
{
if (!Utils::path_exists(path)) {
@ -217,6 +210,7 @@ namespace pEp {
ret.end());
return ret;
}
#endif
// Attention, it pads left...
string padTo(const string &str, const size_t num, const char paddingChar)
@ -237,6 +231,8 @@ namespace pEp {
return ret;
}
// prints the beginning and the end of the string and clips out
// content in the middle replaced by "... tldr ..."
std::string tldr(const std::string &str, const size_t len)
{
std::string decoration = "...";

@ -26,11 +26,15 @@ namespace pEp {
// File utils
// ----------
// path (file&dir)
// path (file & dir)
bool path_exists(const std::string &filename);
bool path_is_dir(const std::string &path);
void path_delete(const std::string &filename);
bool path_is_dir(const std::string &path);
#ifndef WIN32
void path_delete_all(const std::string &path);
#endif
void path_ensure_not_existing(const std::string &path);
// file
@ -38,9 +42,10 @@ namespace pEp {
std::string file_read(const std::string &filename);
// dir
#ifndef WIN32
void dir_create(const std::string &dirname, const mode_t mode = 0775);
void dir_ensure(const std::string& path);
void dir_recreate(const std::string& path);
void dir_ensure(const std::string &path);
void dir_recreate(const std::string &path);
std::vector<std::string> dir_list_all(
const std::string &path,
@ -51,6 +56,7 @@ namespace pEp {
const bool incl_dot_and_dotdot = false);
std::vector<std::string> dir_list_files(const std::string &dirname);
#endif
//String formatting
std::string padTo(const std::string &str, const size_t num, const char paddingChar);
@ -70,7 +76,7 @@ namespace pEp {
WHITE,
};
std::string to_termcol(const Color& col);
std::string to_termcol(const Color &col);
// Time

@ -1,7 +1,7 @@
include ../Makefile.conf
LDFLAGS:=-L../src $(LDFLAGS) -L./pitytest11/src
LDLIBS=-lstdc++ -lpEpEngine -lpEpAdapter -lPityTest
LDLIBS=-lstdc++ -lpEpEngine -lpEpAdapter -lPityTest -lpthread -ldl
CXXFLAGS:=-I../src -DENGINE_TEST=$(ENGINE_TEST) $(CXXFLAGS)
# Test
@ -25,7 +25,7 @@ OBJ_FRAMEWORK=$(subst .cc,.o,$(SRC_FRAMEWORK))
.PHONY: all clean rmtestdata pitytest pitytest-clean
.DEFAULT_GOAL := all
all: $(BIN_TEST)
all: pitytest $(BIN_TEST)
$(BIN_TEST): $(OBJ_FRAMEWORK)

@ -8,7 +8,6 @@
#include <utility>
#include <exception>
#include <thread>
#include <unistd.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>

@ -9,7 +9,7 @@
#include <exception>
#include <chrono>
#include <thread>
#include <unistd.h>
#include <cstring>
#include <tuple>
#include <pEp/pEpEngine.h>
#include <pEp/identity_list.h>

@ -8,11 +8,11 @@
#include "../../../src/std_utils.hh"
#include "fs_mutex.hh"
#include "PityTransport.hh"
//#include "PityPerspective.hh"
#include <string>
#include <map>
#include <memory>
#include <unordered_map>
#include <functional>
// Yes, the mem mgmt is purely static on purpose (so far)

@ -15,6 +15,7 @@
#include <exception>
#include <memory>
#include <unordered_map>
#include <sys/wait.h>
namespace pEp {

@ -5,7 +5,6 @@
#include "framework/utils.hh"
#include <iostream>
#include <assert.h>
#include <unistd.h>
#include <pEp/sync_api.h>
#include <pEp/keymanagement.h>

@ -5,7 +5,6 @@
#include "framework/utils.hh"
#include <iostream>
#include <assert.h>
#include <unistd.h>
#include <pEp/keymanagement.h>
#include <pEp/sync_api.h>

@ -3,21 +3,11 @@
#include "framework/framework.hh"
//#include <iostream>
//#include <fstream>
//#include <sstream>
//#include <unistd.h>
#include <assert.h>
//#include <stdlib.h>
//#include <string.h>
//#include <sys/param.h>
//#include <pEp/message_api.h>
#include <cassert>
#include <pEp/keymanagement.h>
#include <pEp/key_reset.h>
#include "../src/passphrase_cache.hh"
//#include "../src/status_to_string.hh"
#include "../src/Adapter.hh"
using namespace pEp;

@ -5,7 +5,6 @@
#include <iostream>
#include <vector>
#include <unistd.h>
#include <pEp/sync_api.h>

@ -1,10 +1,9 @@
#include "../src/listmanager_dummy.hh"
#include "../src/utils.hh"
#include "../src/std_utils.hh"
#include "framework/utils.hh"
#include <iostream>
#include <exception>
#include <map>
#include <cassert>
using namespace std;

@ -6,7 +6,7 @@
#include <iostream>
#include <cassert>
#include <sys/param.h>
#include <unistd.h>
#include <cstring>
#include "../src/message_cache.hh"
#include "../src/Adapter.hh"

@ -5,6 +5,7 @@
#include "framework/utils.hh"
#include <fstream>
#include <cassert>
using namespace std;
using namespace pEp;

@ -4,7 +4,6 @@
#include "framework/framework.hh"
#include <iostream>
#include <unistd.h>
#include <assert.h>
#include <sys/param.h>

@ -3,8 +3,7 @@
#include <iostream>
#include <thread>
#include <unistd.h>
#include "../src/std_utils.hh"
#include "../src/Semaphore.hh"
using namespace std;
@ -24,7 +23,7 @@ int main()
cout << "1: keep going\n";
});
sleep(1);
Utils::sleep_millis(1000);
thread thread2([&]() {
cout << "2: setting go\n";

Loading…
Cancel
Save