Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move general common code to "core" library #1868

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
894495c
Remove unused SStaticDesktop
CendioOssman Nov 15, 2024
fa2d9cb
Reduce header #include:s
CendioOssman Nov 15, 2024
1ed6481
Order libraries for Xvnc in dependency order
CendioOssman Oct 31, 2024
50be221
Move getHostAndPort() to network library
CendioOssman Sep 10, 2022
8abc4ed
Use initializer lists for basic data types
CendioOssman Nov 9, 2024
7d1523b
Remove rfb:: prefix from rfb::Region
CendioOssman Nov 11, 2024
92c170c
Move basic data types to core library
CendioOssman Nov 16, 2022
c4e23b8
Move utility functions to core library
CendioOssman Nov 16, 2022
7d1ab8b
Move base exception classes to core library
CendioOssman Nov 16, 2022
053363b
Use more standard value for array length
CendioOssman Nov 18, 2024
68ab2b3
Reduce number of inline casts
CendioOssman Nov 18, 2024
35ae7e2
Move configuration to core library
CendioOssman Nov 22, 2024
ae2081f
Move logging to core library
CendioOssman Nov 19, 2024
ffba0dc
Move timers to core library
CendioOssman Nov 11, 2024
fa89cd4
Move time utilities to separate file
CendioOssman Nov 18, 2022
a00fd6f
Handle bad ordering to time helpers
CendioOssman Jan 3, 2023
5e6e040
Keep all time helpers in a single place
CendioOssman Jan 3, 2023
bfa6859
Get rid of __rfbmax()/__rfbmin()
CendioOssman Jan 3, 2023
0c12ab6
Rename core/util to core/string
CendioOssman Jan 5, 2023
ce9fc22
Move application directory handling to core
CendioOssman Oct 31, 2024
137e43e
Move winerrno.h to core
CendioOssman Oct 31, 2024
7f1387f
Move concurrency abstration layer to core
CendioOssman Nov 2, 2024
aa20347
Remove unused libnetwork dependency from vncconfig
CendioOssman Oct 31, 2024
3a015bd
Revert Xvnc double slash hack
CendioOssman Nov 4, 2024
e893b44
Use absolute paths for libraries
CendioOssman Oct 31, 2024
a7a4d68
Stop relying on "using namespace"
CendioOssman Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ if(ENABLE_TSAN AND NOT WIN32 AND NOT APPLE AND CMAKE_SIZEOF_VOID_P MATCHES 8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
endif()

if(MSVC)
# undef min and max macro
target_compile_definitions(rfb PRIVATE NOMINMAX)
endif()

if(NOT DEFINED BUILD_WINVNC)
set(BUILD_WINVNC 1)
endif()
Expand Down
4 changes: 2 additions & 2 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_subdirectory(os)
add_subdirectory(core)
add_subdirectory(rdr)
add_subdirectory(network)
add_subdirectory(rfb)
Expand All @@ -9,6 +9,6 @@ add_subdirectory(rfb)
# is passed (additionally, libvnc is not used on Windows.)

if(NOT WIN32)
set_target_properties(os rdr network rfb
set_target_properties(core rdr network rfb
PROPERTIES COMPILE_FLAGS -fPIC)
endif()
36 changes: 36 additions & 0 deletions common/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
add_library(core STATIC
Configuration.cxx
Exception.cxx
Logger.cxx
Logger_file.cxx
Logger_stdio.cxx
LogWriter.cxx
Mutex.cxx
Region.cxx
Timer.cxx
Thread.cxx
string.cxx
time.cxx
xdgdirs.cxx)

target_include_directories(core PUBLIC ${CMAKE_SOURCE_DIR}/common)
target_include_directories(core SYSTEM PUBLIC ${PIXMAN_INCLUDE_DIRS})
target_link_libraries(core ${PIXMAN_LIBRARIES})
target_link_directories(core PUBLIC ${PIXMAN_LIBRARY_DIRS})

if(UNIX)
target_sources(core PRIVATE Logger_syslog.cxx)
target_link_libraries(core pthread)
endif()

if(WIN32)
target_link_libraries(core ws2_32)
endif()

if(UNIX)
target_sources(core PRIVATE Logger_syslog.cxx)
endif()

if(UNIX)
libtool_create_control_file(core)
endif()
16 changes: 7 additions & 9 deletions common/rfb/Configuration.cxx → common/core/Configuration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,19 @@

#include <stdexcept>

#include <os/Mutex.h>

#include <rfb/util.h>
#include <rfb/Configuration.h>
#include <rfb/LogWriter.h>

#define LOCK_CONFIG os::AutoMutex a(mutex)
#include <core/Configuration.h>
#include <core/LogWriter.h>
#include <core/Mutex.h>
#include <core/string.h>

#include <rdr/HexOutStream.h>
#include <rdr/HexInStream.h>

using namespace rfb;
using namespace core;

static LogWriter vlog("Config");

#define LOCK_CONFIG AutoMutex a(mutex)

// -=- The Global/server/viewer Configuration objects
Configuration* Configuration::global_ = nullptr;
Expand Down Expand Up @@ -210,7 +208,7 @@ VoidParameter::VoidParameter(const char* name_, const char* desc_,
_next = conf->head;
conf->head = this;

mutex = new os::Mutex();
mutex = new Mutex();
}

VoidParameter::~VoidParameter() {
Expand Down
12 changes: 6 additions & 6 deletions common/rfb/Configuration.h → common/core/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@
// NB: NO LOCKING is performed when linking Configurations to groups
// or when adding Parameters to Configurations.

#ifndef __RFB_CONFIGURATION_H__
#define __RFB_CONFIGURATION_H__
#ifndef __CORE_CONFIGURATION_H__
#define __CORE_CONFIGURATION_H__

#include <limits.h>
#include <stdint.h>

#include <string>
#include <vector>

namespace os { class Mutex; }
namespace core {

namespace rfb {
class Mutex;
class VoidParameter;
struct ParameterIterator;

Expand Down Expand Up @@ -189,7 +189,7 @@ namespace rfb {
const char* name;
const char* description;

os::Mutex* mutex;
Mutex* mutex;
};

class AliasParameter : public VoidParameter {
Expand Down Expand Up @@ -297,4 +297,4 @@ namespace rfb {

};

#endif // __RFB_CONFIGURATION_H__
#endif // __CORE_CONFIGURATION_H__
31 changes: 15 additions & 16 deletions common/rdr/Exception.cxx → common/core/Exception.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
#include <stdio.h>
#include <stdarg.h>

#include <rdr/Exception.h>
#include <rdr/TLSException.h>
#include <rfb/util.h>
#include <core/Exception.h>
#include <core/string.h>

#ifdef _WIN32
#include <winsock2.h>
Expand All @@ -40,20 +39,20 @@

#include <string.h>

using namespace rdr;
using namespace core;


getaddrinfo_error::getaddrinfo_error(const char* s, int err_) noexcept
: std::runtime_error(rfb::format("%s: %s (%d)", s,
strerror(err_).c_str(), err_)),
: std::runtime_error(core::format("%s: %s (%d)", s,
strerror(err_).c_str(), err_)),
err(err_)
{
}

getaddrinfo_error::getaddrinfo_error(const std::string& s,
int err_) noexcept
: std::runtime_error(rfb::format("%s: %s (%d)", s.c_str(),
strerror(err_).c_str(), err_)),
: std::runtime_error(core::format("%s: %s (%d)", s.c_str(),
strerror(err_).c_str(), err_)),
err(err_)
{
}
Expand All @@ -73,15 +72,15 @@ std::string getaddrinfo_error::strerror(int err_) const noexcept
}

posix_error::posix_error(const char* what_arg, int err_) noexcept
: std::runtime_error(rfb::format("%s: %s (%d)", what_arg,
strerror(err_).c_str(), err_)),
: std::runtime_error(core::format("%s: %s (%d)", what_arg,
strerror(err_).c_str(), err_)),
err(err_)
{
}

posix_error::posix_error(const std::string& what_arg, int err_) noexcept
: std::runtime_error(rfb::format("%s: %s (%d)", what_arg.c_str(),
strerror(err_).c_str(), err_)),
: std::runtime_error(core::format("%s: %s (%d)", what_arg.c_str(),
strerror(err_).c_str(), err_)),
err(err_)
{
}
Expand All @@ -102,16 +101,16 @@ std::string posix_error::strerror(int err_) const noexcept

#ifdef WIN32
win32_error::win32_error(const char* what_arg, unsigned err_) noexcept
: std::runtime_error(rfb::format("%s: %s (%d)", what_arg,
strerror(err_).c_str(), err_)),
: std::runtime_error(core::format("%s: %s (%d)", what_arg,
strerror(err_).c_str(), err_)),
err(err_)
{
}

win32_error::win32_error(const std::string& what_arg,
unsigned err_) noexcept
: std::runtime_error(rfb::format("%s: %s (%d)", what_arg.c_str(),
strerror(err_).c_str(), err_)),
: std::runtime_error(core::format("%s: %s (%d)", what_arg.c_str(),
strerror(err_).c_str(), err_)),
err(err_)
{
}
Expand Down
11 changes: 3 additions & 8 deletions common/rdr/Exception.h → common/core/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
* USA.
*/

#ifndef __RDR_EXCEPTION_H__
#define __RDR_EXCEPTION_H__
#ifndef __CORE_EXCEPTION_H__
#define __CORE_EXCEPTION_H__

#include <stdexcept>
#include <string>

namespace rdr {
namespace core {

class posix_error : public std::runtime_error {
public:
Expand Down Expand Up @@ -70,11 +70,6 @@ namespace rdr {
std::string strerror(int err_) const noexcept;
};

class end_of_stream : public std::runtime_error {
public:
end_of_stream() noexcept : std::runtime_error("End of stream") {}
};

}

#endif
13 changes: 6 additions & 7 deletions common/rfb/LogWriter.cxx → common/core/LogWriter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@
#include <config.h>
#endif

#include <string.h>

#include <rfb/LogWriter.h>
#include <rfb/Configuration.h>
#include <rfb/util.h>
#include <stdlib.h>
#include <string.h>

rfb::LogParameter rfb::logParams;
#include <core/Configuration.h>
#include <core/LogWriter.h>
#include <core/string.h>

using namespace rfb;
using namespace core;

LogParameter core::logParams;

LogWriter::LogWriter(const char* name)
: m_name(name), m_level(0), m_log(nullptr), m_next(log_writers) {
Expand Down
15 changes: 7 additions & 8 deletions common/rfb/LogWriter.h → common/core/LogWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

// -=- LogWriter.h - The Log writer class.

#ifndef __RFB_LOG_WRITER_H__
#define __RFB_LOG_WRITER_H__
#ifndef __CORE_LOG_WRITER_H__
#define __CORE_LOG_WRITER_H__

#include <stdarg.h>
#include <rfb/Logger.h>
#include <rfb/Configuration.h>

#include <core/Configuration.h>
#include <core/Logger.h>

// Each log writer instance has a unique textual name,
// and is attached to a particular Log instance and
Expand All @@ -46,9 +47,7 @@
} \
}

namespace rfb {

class LogWriter;
namespace core {

class LogWriter {
public:
Expand Down Expand Up @@ -110,4 +109,4 @@ namespace rfb {

};

#endif // __RFB_LOG_WRITER_H__
#endif // __CORE_LOG_WRITER_H__
6 changes: 3 additions & 3 deletions common/rfb/Logger.cxx → common/core/Logger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
#include <stdio.h>
#include <string.h>

#include <rfb/Logger.h>
#include <rfb/LogWriter.h>
#include <core/Logger.h>
#include <core/LogWriter.h>

using namespace rfb;
using namespace core;

Logger* Logger::loggers = nullptr;

Expand Down
8 changes: 4 additions & 4 deletions common/rfb/Logger.h → common/core/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

// -=- Logger.h - The Logger class.

#ifndef __RFB_LOGGER_H__
#define __RFB_LOGGER_H__
#ifndef __CORE_LOGGER_H__
#define __CORE_LOGGER_H__

#include <stdarg.h>
#include <stdio.h>
Expand All @@ -28,7 +28,7 @@
// and is attached to a particular Logger instance and
// is assigned a particular log level.

namespace rfb {
namespace core {

class Logger {
public:
Expand Down Expand Up @@ -68,4 +68,4 @@ namespace rfb {

};

#endif // __RFB_LOGGER_H__
#endif // __CORE_LOGGER_H__
14 changes: 7 additions & 7 deletions common/rfb/Logger_file.cxx → common/core/Logger_file.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,17 @@
#include <stdlib.h>
#include <string.h>

#include <os/Mutex.h>
#include <core/Logger_file.h>
#include <core/Mutex.h>

#include <rfb/Logger_file.h>

using namespace rfb;
using namespace core;

Logger_File::Logger_File(const char* loggerName)
: Logger(loggerName), indent(13), width(79), m_file(nullptr),
m_lastLogTime(0)
{
m_filename[0] = '\0';
mutex = new os::Mutex();
mutex = new Mutex();
}

Logger_File::~Logger_File()
Expand All @@ -48,7 +47,7 @@ Logger_File::~Logger_File()

void Logger_File::write(int /*level*/, const char *logname, const char *message)
{
os::AutoMutex a(mutex);
AutoMutex a(mutex);

if (!m_file) {
if (m_filename[0] == '\0')
Expand Down Expand Up @@ -121,7 +120,8 @@ void Logger_File::closeFile()

static Logger_File logger("file");

bool rfb::initFileLogger(const char* filename) {
bool core::initFileLogger(const char* filename)
{
logger.setFilename(filename);
logger.registerLogger();
return true;
Expand Down
Loading
Loading