Skip to content

Commit

Permalink
Merge pull request #47 from mvrdevelopment/migrate-changes-from-MVR
Browse files Browse the repository at this point in the history
Migrate changes from development repo
  • Loading branch information
moritzstaffel authored Apr 30, 2024
2 parents be85429 + efc17a3 commit 63e7147
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 53 deletions.
16 changes: 8 additions & 8 deletions buildAllConfigs_Win.bat
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
pushd .

call buildLib_Win.bat Release MT MZ
call buildLib_Win.bat Release MT MZ false
popd
pushd .

call buildLib_Win.bat Release MT NoMZ
call buildLib_Win.bat Release MT NoMZ false
popd
pushd .

call buildLib_Win.bat Release MD MZ
call buildLib_Win.bat Release MD MZ false
popd
pushd .

call buildLib_Win.bat Release MD NoMZ
call buildLib_Win.bat Release MD NoMZ false
popd
pushd .

call buildLib_Win.bat Debug MD MZ
call buildLib_Win.bat Debug MD MZ false
popd
pushd .

call buildLib_Win.bat Debug MD NoMZ
call buildLib_Win.bat Debug MD NoMZ false
popd
pushd .

call buildLib_Win.bat Debug MT MZ
call buildLib_Win.bat Debug MT MZ false
popd
pushd .

call buildLib_Win.bat Debug MT NoMZ
call buildLib_Win.bat Debug MT NoMZ false
popd
pushd .

Expand Down
9 changes: 5 additions & 4 deletions buildLib_Win.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if %3.==. goto ERROR
if %1 == Debug (set DCMAKE_CXX_FLAGS=-DCMAKE_CXX_FLAGS_DEBUG) else (set DCMAKE_CXX_FLAGS=-DCMAKE_CXX_FLAGS_RELEASE)
if %1 == Debug (set RunTimeLib=%2d) else (set RunTimeLib=%2)
if %3 == MZ (set noMZ=false) else (set noMZ=true)

if %3 == MZ (set noXerces=true) else (set noXerces=false)


@echo on
Expand All @@ -24,12 +24,12 @@ if exist build ( rd /S /Q build)

mkdir build && cd build


cmake -G "Visual Studio 15 2017 Win64" -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_INSTALL_PREFIX:PATH=libs -DCMAKE_CONFIGURATION_TYPES="%1" -Dxmlch-type=wchar_t %DCMAKE_CXX_FLAGS%:STRING="-%RunTimeLib% -O2 -Ob2 -DNDEBUG" -DDO_NOT_INCLUDE_MINI_ZIP=%noMZ% -DWIN_RUNTIME_LIB="-%RunTimeLib%" -DUNITTEST=%4 ..
cmake -G "Visual Studio 17 2022" -A x64 -DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_INSTALL_PREFIX:PATH=libs -DCMAKE_CONFIGURATION_TYPES="%1" -Dxmlch-type=wchar_t %DCMAKE_CXX_FLAGS%:STRING="-%RunTimeLib% -O2 -Ob2 -DNDEBUG" -DDO_NOT_INCLUDE_MINI_ZIP=%noMZ% -DWIN_RUNTIME_LIB="-%RunTimeLib%" -DDONT_USE_XERCES_AS_XMLLIB="%noXerces%" -DUNITTEST=%4 ..

cd ..

call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat"
call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat"

REM build libVectorworksMvrGdtf
cd build
MSBuild.exe MvrGdtf.sln /t:Build /p:Configuration=%1 /m
Expand All @@ -42,3 +42,4 @@ Color 04
echo Not all parameters are provided for this script!

:END

10 changes: 9 additions & 1 deletion mdns_cpp/src/mdns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,19 @@ QueryResList mDNS::executeQuery2(const std::string &service) {
if(in.addr != comp.addr) {return false;}

bool add = false;
std::string service(in.canonicalName.begin(), in.canonicalName.begin() + in.canonicalName.find('.'));

add = add || in.canonicalName == comp.canonicalName;
add = add || in.canonicalName == comp.data.name;

add = add || (comp.canonicalName.length() >= in.canonicalName.length() && in.canonicalName == std::string(comp.canonicalName.end() - in.canonicalName.length(), comp.canonicalName.end()));

auto pos = in.canonicalName.find('.');
if(pos == std::string::npos)
{
pos = in.canonicalName.size();
}

std::string service(in.canonicalName.begin(), in.canonicalName.begin() + pos);
add = add || (comp.canonicalName.length() >= service.length() && service == std::string(comp.canonicalName.begin(), comp.canonicalName.begin() + service.length()));

return add;
Expand Down
12 changes: 2 additions & 10 deletions src/Implementation/CSceneObjImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,17 +1266,9 @@ VectorworksMVR::VCOMError VectorworksMVR::CSceneObjImpl::GetConnectionAt(size_t

VectorworksMVR::VCOMError VectorworksMVR::CSceneObjImpl::CreateConnection(MvrString own, MvrString other, MvrUUID ToObject, IConnection** addedObj)
{
ASSERTN(kEveryone,fType == ESceneObjType::Fixture);
if( fType != ESceneObjType::Fixture) return kVCOMError_NoFixtureObj;

SceneData::SceneDataFixtureObjPtr fixture = static_cast<SceneData::SceneDataFixtureObjPtr>(fPtr);

ASSERTN(kEveryone, fixture != nullptr);
if ( ! fixture) { return kVCOMError_Failed; }

const auto nObj = fixture->AddConnectionObj(own, other, VWUUID(ToObject.a, ToObject.b, ToObject.c, ToObject.d));
const auto nObj = fPtr->AddConnectionObj(own, other, VWUUID(ToObject.a, ToObject.b, ToObject.c, ToObject.d));

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Initialize Object
CConnectionImpl* pConnectionImpl = nullptr;

Expand Down
4 changes: 4 additions & 0 deletions src/Include/IMediaRessourceVectorInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,11 @@ class DYNAMIC_ATTRIBUTE IGdtfMacro : public IVWUnknown

MVRxchangeString& operator=(const char* str)
{
#pragma warning(push) // Save the current warning state
#pragma warning(disable : 4996) // Disable strncpy warning
std::strncpy(fBuffer, str, 1024);
#pragma warning(pop)

fBuffer[1023] = '\0'; // In case str is longer than 1024, no terminator is set by strncpy
return *this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SceneDataExchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,7 @@ ESceneDataObjectType SceneDataFocusPointObj::GetObjectType()

// ----------------------------------------------------------------------------------------------------------------------------------
// SceneDataTrussObj
SceneDataTrussObj::SceneDataTrussObj(const SceneDataGUID& guid) : SceneDataGroupObj(guid)
SceneDataTrussObj::SceneDataTrussObj(const SceneDataGUID& guid) : SceneDataGDTFSpecObj(guid)
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/SceneDataExchange.h
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ namespace SceneData

// ----------------------------------------------------------------------------------------------------------------------------------
// SceneDataObjWithMatrix
class SceneDataTrussObj : public SceneDataGroupObj
class SceneDataTrussObj : public SceneDataGDTFSpecObj
{

public:
Expand Down
88 changes: 66 additions & 22 deletions src/mvrxchange/CMVRxchangeService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,39 @@
#include <boost/date_time/posix_time/posix_time.hpp>
#include <unordered_map>
#include <thread>
#include <regex>

VectorworksMVR::CMVRxchangeServiceImpl::CMVRxchangeServiceImpl()
VectorworksMVR::CMVRxchangeServiceImpl::CMVRxchangeServiceImpl(): fmdns_long_timer(fmdns_IO_Context)
{
fServer = nullptr;
}

VectorworksMVR::CMVRxchangeServiceImpl::~CMVRxchangeServiceImpl()
{
this->mDNS_Client_Stop();
if(fmdns_Thread.joinable())
{
fmdns_Thread.join();
}
this->TCP_Stop();
}

void FilterServiceName(MVRxchangeString& service)
{
std::string s(service.fBuffer);
std::string out;

if(s.empty())
{
return;
}

std::regex_replace(std::back_inserter(out), s.begin(), s.end(), std::regex("[^a-zA-Z0-9\\-_]"), "");

service = out.c_str();
}


VCOMError VectorworksMVR::CMVRxchangeServiceImpl::ConnectToLocalService(const ConnectToLocalServiceArgs& service)
{
this->LeaveLocalService();
Expand All @@ -30,6 +51,7 @@ VCOMError VectorworksMVR::CMVRxchangeServiceImpl::ConnectToLocalService(const Co
fCurrentService = service;
this->TCP_Start();

FilterServiceName(fCurrentService.Service);

//---------------------------------------------------------------------------------------------
// Start mDNS Service
Expand Down Expand Up @@ -95,10 +117,10 @@ VCOMError VectorworksMVR::CMVRxchangeServiceImpl::ConnectToLocalService(const Co

if (fmdns_Thread.joinable())
{
fmdns_IO_Context.stop();
fmdns_Thread.join();
mDNS_Client_Stop();
}
fmdns_Thread = std::thread(&CMVRxchangeServiceImpl::mDNS_Client_Start, this);

mDNS_Client_Start();

return kVCOMError_NoError;
}
Expand All @@ -112,6 +134,7 @@ VCOMError VectorworksMVR::CMVRxchangeServiceImpl::LeaveLocalService()
leaveMessage.Message.Type = MVRxchangeMessageType::MVR_LEAVE;
leaveMessage.Message.LEAVE.FromStationUUID = fCurrentService.StationUUID;
this->Send_message(leaveMessage);
mDNS_Client_Stop();

for(auto& s : fmdns)
{
Expand All @@ -126,8 +149,21 @@ VCOMError VectorworksMVR::CMVRxchangeServiceImpl::LeaveLocalService()

VCOMError VCOM_CALLTYPE CMVRxchangeServiceImpl::QueryLocalServices(size_t& out_Count)
{
this->mDNS_Client_Task();


if(fmdns_Thread.joinable())
{
std::condition_variable cv;
std::mutex mut;
std::unique_lock<std::mutex> lock(mut);
boost::asio::post(fmdns_IO_Context, [this, &cv](){
this->mDNS_Client_Task();
cv.notify_all();
});
cv.wait(lock);
}else{
this->mDNS_Client_Task();
}

{
std::lock_guard<std::mutex> lock (fQueryLocalServicesResult_mtx);
out_Count = fQueryLocalServicesResult.size();
Expand Down Expand Up @@ -303,9 +339,12 @@ IMVRxchangeService::IMVRxchangeMessage CMVRxchangeServiceImpl::TCP_OnIncommingMe
if(GetSingleMemberOfService(in.LEAVE.FromStationUUID, newItem) != kVCOMError_NoError)
{
std::lock_guard<std::mutex> lock(fMvrGroupMutex);
std::remove_if(fMVRGroup.begin(), fMVRGroup.end(), [&newItem](const MVRxchangeGroupMember& it){
return it.stationUUID == newItem.stationUUID;
});
fMVRGroup.erase(
std::remove_if(fMVRGroup.begin(), fMVRGroup.end(), [&newItem](const MVRxchangeGroupMember& it){
return it.stationUUID == newItem.stationUUID;
}),
fMVRGroup.end()
);
}
}

Expand All @@ -315,6 +354,7 @@ IMVRxchangeService::IMVRxchangeMessage CMVRxchangeServiceImpl::TCP_OnIncommingMe
ret = fCallBack.IncomingCallback(in, fCallBack.Context);
}


return ret;
}

Expand Down Expand Up @@ -400,34 +440,40 @@ VCOMError CMVRxchangeServiceImpl::GetSingleMemberOfService(const MvrUUID& statio
return kVCOMError_Failed;
}


void CMVRxchangeServiceImpl::mDNS_Client_Tick(boost::asio::deadline_timer* t)
void CMVRxchangeServiceImpl::mDNS_Client_Tick()
{
MVRXCHANGE_DEBUG("mDNS_Client_Tick");
mDNS_Client_Task();

t->async_wait(boost::bind(&CMVRxchangeServiceImpl::mDNS_Client_Tick, this, t));
fmdns_long_timer.expires_from_now(boost::posix_time::seconds(45));
fmdns_long_timer.async_wait(boost::bind(&CMVRxchangeServiceImpl::mDNS_Client_Tick, this));
}

void CMVRxchangeServiceImpl::mDNS_Client_Start()
{
boost::asio::deadline_timer t_long (fmdns_IO_Context, boost::posix_time::seconds(45));
void CMVRxchangeServiceImpl::mDNS_Client_RFun()
{
while(!fmdns_stop_flag)
{
boost::asio::deadline_timer t_short(fmdns_IO_Context, boost::posix_time::seconds(1));
t_short.async_wait(boost::bind(&CMVRxchangeServiceImpl::mDNS_Client_Tick, this, &t_long));
fmdns_IO_Context.run_for(std::chrono::seconds(1));
}
fmdns_IO_Context.run();
}

void CMVRxchangeServiceImpl::mDNS_Client_Start()
{
fmdns_stop_flag = false;
boost::asio::post(fmdns_IO_Context, boost::bind(&CMVRxchangeServiceImpl::mDNS_Client_Tick, this));
fmdns_Thread = std::thread(&CMVRxchangeServiceImpl::mDNS_Client_RFun, this);
}

void CMVRxchangeServiceImpl::mDNS_Client_Stop()
{
if (fmdns_Thread.joinable())
fmdns_stop_flag = true;
if(fmdns_Thread.joinable())
{
fmdns_IO_Context.stop();
fmdns_Thread.join();
}
}


mdns_cpp::QueryResList CMVRxchangeServiceImpl::mDNS_Filter_Queries(mdns_cpp::QueryResList &input)
{
// IPv6 is currently not supported
Expand Down Expand Up @@ -493,8 +539,6 @@ mdns_cpp::QueryResList CMVRxchangeServiceImpl::mDNS_Filter_Queries(mdns_cpp::Que

void CMVRxchangeServiceImpl::mDNS_Client_Task()
{


mdns_cpp::mDNS mdns;
auto query_res = mdns.executeQuery2(MVRXChange_Service);
std::vector<ConnectToLocalServiceArgs> result;
Expand Down
14 changes: 10 additions & 4 deletions src/mvrxchange/CMVRxchangeService.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,22 @@ namespace VectorworksMVR
virtual VCOMError VCOM_CALLTYPE OnMessage(OnMessageArgs& messageHandler);
virtual VCOMError VCOM_CALLTYPE Send_message(const SendMessageArgs& messageHandler);

void mDNS_Client_Task();

private:
void mDNS_Client_Start();
void mDNS_Client_Task(); // actual mdns task

void mDNS_Client_Tick(); // mdns tick function (executed by RFun function)
void mDNS_Client_RFun(); // thread function (executed by fmdns_Thread)

void mDNS_Client_Stop();
void mDNS_Client_Tick(boost::asio::deadline_timer* t);
void mDNS_Client_Start();



std::vector<std::unique_ptr<mdns_cpp::mDNS>> fmdns;
std::thread fmdns_Thread;
boost::asio::io_context fmdns_IO_Context;
boost::asio::deadline_timer fmdns_long_timer;
std::atomic<bool> fmdns_stop_flag;

std::mutex fQueryLocalServicesResult_mtx;
std::vector<ConnectToLocalServiceArgs> fQueryLocalServicesResult;
Expand Down
2 changes: 1 addition & 1 deletion src/rapidxmlsupport/XMLFileImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ VCOMError CXMLFileImpl::WriteBuffer(IXMLFileIOBuffer* pOutputBuffer, EXMLEncodin
{
tinyxml2::XMLPrinter printer;
fDoc.Print(&printer);
pOutputBuffer->SetData((void*)printer.CStr(), printer.CStrSize());
pOutputBuffer->SetData((void*)printer.CStr(), printer.CStrSize()-2);
return kVCOMError_NoError;
}

Expand Down
2 changes: 1 addition & 1 deletion unittest/MvrXchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ bool MvrXChangeUnitTest::ExecuteTest()

{
// fill data-part (json) with random data
std::independent_bits_engine<std::default_random_engine, CHAR_BIT, unsigned char> rbe;
std::independent_bits_engine<std::default_random_engine, CHAR_BIT, unsigned long> rbe;
std::generate(testBuffer.begin() + hLength, testBuffer.end(), std::ref(rbe));
}

Expand Down

0 comments on commit 63e7147

Please sign in to comment.