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

Enable build on windows using mingw #358

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ vscode

# QtCreator
CMakeLists.txt.user

# Temporary files left by editors and such
*~
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ else(MSVC)
SET(EXECUTABLE_CXX_FLAGS)
SET(DYNAMIC_LIBRARY_CXX_FLAGS)
SET(D -D)
set(CMAKE_CXX_FLAGS " -std=c++11 -Wall -fPIC ${CMAKE_CXX_FLAGS} ")
if(WIN32)
set(CMAKE_CXX_FLAGS " -std=c++11 -Wall ${CMAKE_CXX_FLAGS} ")
else(WIN32)
set(CMAKE_CXX_FLAGS " -std=c++11 -Wall -fPIC ${CMAKE_CXX_FLAGS} ")
endif()
SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_INIT} $ENV{LDFLAGS}")
#set(CMAKE_SHARED_LINKER_FLAGS "--no-undefined" )
endif()
Expand Down Expand Up @@ -486,6 +490,7 @@ if(BUILD_SERVER)
opcuacore
opcuaprotocol
opcuaserver
${Boost_PROGRAM_OPTIONS_LIBRARY}
${TEST_LIBS}
)

Expand Down
5 changes: 2 additions & 3 deletions python/src/py_opcua_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static void Node_SetValue(Node & self, const object & obj, VariantType vtype)
// UaClient helpers
//--------------------------------------------------------------------------

static std::shared_ptr<Subscription> UaClient_CreateSubscription(UaClient & self, uint period, PySubscriptionHandler & callback)
static std::shared_ptr<Subscription> UaClient_CreateSubscription(UaClient & self, unsigned int period, PySubscriptionHandler & callback)
{
return self.CreateSubscription(period, callback);
}
Expand All @@ -256,7 +256,7 @@ static Node UaClient_GetNode(UaClient & self, ObjectId objectid)
// UaServer helpers
//--------------------------------------------------------------------------

static std::shared_ptr<Subscription> UaServer_CreateSubscription(UaServer & self, uint period, PySubscriptionHandler & callback)
static std::shared_ptr<Subscription> UaServer_CreateSubscription(UaServer & self, unsigned int period, PySubscriptionHandler & callback)
{
return self.CreateSubscription(period, callback);
}
Expand Down Expand Up @@ -554,4 +554,3 @@ BOOST_PYTHON_MODULE(opcua)
;

}

22 changes: 12 additions & 10 deletions src/client/binary_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,24 @@ class RequestCallback
public:
RequestCallback(const Common::Logger::SharedPtr & logger)
: Logger(logger)
, lock(m)
{
}

void OnData(std::vector<char> data, ResponseHeader h)
{
//std::cout << ToHexDump(data);
Data = std::move(data);
this->header = std::move(h);
{
std::unique_lock<std::mutex> lock{m};
Data = std::move(data);
this->header = std::move(h);
}
doneEvent.notify_all();
}

T WaitForData(std::chrono::milliseconds msec)
{
if (doneEvent.wait_for(lock, msec) == std::cv_status::timeout)
std::unique_lock<std::mutex> lock{m};
if (doneEvent.wait_for(lock, msec, // RequestHandle is 0 before the response is received
[&](){ return this->header.RequestHandle != 0; }) == false)
{ throw std::runtime_error("Response timed out"); }

T result;
Expand All @@ -123,7 +126,6 @@ class RequestCallback
std::vector<char> Data;
ResponseHeader header;
std::mutex m;
std::unique_lock<std::mutex> lock;
std::condition_variable doneEvent;
};

Expand Down Expand Up @@ -875,9 +877,10 @@ class BinaryClient
{
requestCallback.OnData(std::move(buffer), std::move(h));
};
std::unique_lock<std::mutex> lock(Mutex);
Callbacks.insert(std::make_pair(request.Header.RequestHandle, responseCallback));
lock.unlock();
{
std::unique_lock<std::mutex> lock(Mutex);
Callbacks.insert(std::make_pair(request.Header.RequestHandle, responseCallback));
}

LOG_DEBUG(Logger, "binary_client | send: id: {} handle: {}, UtcTime: {}", ToString(request.TypeId, true), request.Header.RequestHandle, request.Header.UtcTime);

Expand All @@ -895,7 +898,6 @@ class BinaryClient
//Remove the callback on timeout
std::unique_lock<std::mutex> lock(Mutex);
Callbacks.erase(request.Header.RequestHandle);
lock.unlock();
throw;
}

Expand Down
6 changes: 2 additions & 4 deletions src/core/common/uri_facade_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace Common
{

void Uri::Initialize(const char * uriString, std::size_t size)
void Uri::Initialize(const std::string& uriString)
{
URL_COMPONENTS url = {0};
url.dwStructSize = sizeof(url);
Expand All @@ -31,7 +31,7 @@ void Uri::Initialize(const char * uriString, std::size_t size)

// TODO msdn says do not use this function in services and in server patforms. :(
// TODO http://msdn.microsoft.com/en-us/library/windows/desktop/aa384376(v=vs.85).aspx
if (!InternetCrackUrl(uriString, size, options, &url))
if (!InternetCrackUrl(uriString.data(), uriString.size(), options, &url))
{
THROW_ERROR1(CannotParseUri, uriString);
}
Expand All @@ -50,5 +50,3 @@ void Uri::Initialize(const char * uriString, std::size_t size)
}

} // namespace Common


1 change: 1 addition & 0 deletions src/core/socket_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#ifdef _WIN32
#include <WinSock2.h>
#include <io.h>
#else
#include <arpa/inet.h>
#include <netinet/tcp.h>
Expand Down
9 changes: 8 additions & 1 deletion src/server/tcp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
///

#ifdef _WIN32
#include <winsock2.h>
#include <windows.h>
#endif

Expand Down Expand Up @@ -36,6 +37,7 @@


#ifdef _WIN32
#include <winsock.h>
#else
#include <arpa/inet.h>
#include <netdb.h>
Expand Down Expand Up @@ -178,7 +180,12 @@ class TcpServerConnection : private Common::ThreadObserver
{
LOG_INFO(Logger, "shutting down opc ua binary server");
Stopped = true;
shutdown(Socket, SHUT_RDWR);
#ifndef _WIN32
int how = SHUT_RDWR;
#else
int how = SD_BOTH;
#endif
shutdown(Socket, how);
ServerThread->Join();
ServerThread.reset();
}
Expand Down
4 changes: 4 additions & 0 deletions tests/server/model_object_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@

using namespace testing;

#if defined(_WIN32) && defined(GetObject)
#undef GetObject // windows.h defines GetObject to GetObjectA/GetObjectW
#endif


class ModelObject : public Test
{
Expand Down