Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #376 from dnp3/bugfix/double-delete-dotnet
Browse files Browse the repository at this point in the history
Fix issue in TaskCallbackAdapter that was deleted twice
  • Loading branch information
jadamcrain committed May 20, 2020
2 parents 4191436 + 706e1a3 commit 3806d5c
Show file tree
Hide file tree
Showing 44 changed files with 1,680 additions and 1,681 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 3.0.1 ###
* :beetle: Fix double-delete issue in C# adapter. See PR
[#376](https://github.com/dnp3/opendnp3/pull/376).

### 3.0.0 ###

New features:
Expand Down
60 changes: 30 additions & 30 deletions dotnet/CLRAdapter/src/CallbackAdapters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,34 @@

namespace Automatak
{
namespace DNP3
{
namespace Adapter
{

opendnp3::CommandResultCallbackT CallbackAdapters::Get(TaskCompletionSource<CommandTaskResult^>^ tcs)
{
gcroot<TaskCompletionSource<CommandTaskResult^>^> handle(tcs);

return [handle](const opendnp3::ICommandTaskResult& res) -> void
{
auto result = Conversions::ConvertCommandTaskResult(res);
handle->SetResult(result);
};
}

opendnp3::RestartOperationCallbackT CallbackAdapters::Get(TaskCompletionSource<RestartResultType^>^ tcs)
{
gcroot<TaskCompletionSource<RestartResultType^>^> handle(tcs);

return [handle](const opendnp3::RestartOperationResult& res) -> void
{
auto result = gcnew RestartResultType((TaskCompletion)res.summary, Conversions::ConvertTimeDuration(res.restartTime));

handle->SetResult(result);
};
}

}
}
namespace DNP3
{
namespace Adapter
{

opendnp3::CommandResultCallbackT CallbackAdapters::Get(TaskCompletionSource<CommandTaskResult^>^ tcs)
{
gcroot<TaskCompletionSource<CommandTaskResult^>^> handle(tcs);

return [handle](const opendnp3::ICommandTaskResult& res) -> void
{
auto result = Conversions::ConvertCommandTaskResult(res);
handle->SetResult(result);
};
}

opendnp3::RestartOperationCallbackT CallbackAdapters::Get(TaskCompletionSource<RestartResultType^>^ tcs)
{
gcroot<TaskCompletionSource<RestartResultType^>^> handle(tcs);

return [handle](const opendnp3::RestartOperationResult& res) -> void
{
auto result = gcnew RestartResultType((TaskCompletion)res.summary, Conversions::ConvertTimeDuration(res.restartTime));

handle->SetResult(result);
};
}

}
}
}
24 changes: 12 additions & 12 deletions dotnet/CLRAdapter/src/CallbackAdapters.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ using namespace System::Threading::Tasks;

namespace Automatak
{
namespace DNP3
{
namespace Adapter
{
namespace DNP3
{
namespace Adapter
{

class CallbackAdapters : private opendnp3::StaticOnly
{
public:
class CallbackAdapters : private opendnp3::StaticOnly
{
public:

static opendnp3::CommandResultCallbackT Get(TaskCompletionSource<CommandTaskResult ^> ^ tcs);
static opendnp3::RestartOperationCallbackT Get(TaskCompletionSource<RestartResultType^>^ tcs);
};
static opendnp3::CommandResultCallbackT Get(TaskCompletionSource<CommandTaskResult ^> ^ tcs);
static opendnp3::RestartOperationCallbackT Get(TaskCompletionSource<RestartResultType^>^ tcs);
};

}
}
}
}
}

#endif
52 changes: 26 additions & 26 deletions dotnet/CLRAdapter/src/ChangeSetAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,39 @@ using namespace Automatak::DNP3::Interface;

namespace Automatak
{
namespace DNP3
{
namespace Adapter
{
namespace DNP3
{
namespace Adapter
{

private ref class DatabaseAdapter : public Automatak::DNP3::Interface::IDatabase
{
public:
private ref class DatabaseAdapter : public Automatak::DNP3::Interface::IDatabase
{
public:

DatabaseAdapter();
DatabaseAdapter();

~DatabaseAdapter();
~DatabaseAdapter();
!DatabaseAdapter();
virtual void Update(Binary^ update, System::UInt16 index, EventMode mode);
virtual void Update(DoubleBitBinary^ update, System::UInt16 index, EventMode mode);
virtual void Update(Analog^ update, System::UInt16 index, EventMode mode);
virtual void Update(Counter^ update, System::UInt16 index, EventMode mode);
virtual void Update(Binary^ update, System::UInt16 index, EventMode mode);
virtual void Update(DoubleBitBinary^ update, System::UInt16 index, EventMode mode);
virtual void Update(Analog^ update, System::UInt16 index, EventMode mode);
virtual void Update(Counter^ update, System::UInt16 index, EventMode mode);
virtual void FreezeCounter(System::UInt16 index, System::Boolean clear, EventMode mode);
virtual void Update(BinaryOutputStatus^ update, System::UInt16 index, EventMode mode);
virtual void Update(AnalogOutputStatus^ update, System::UInt16 index, EventMode mode);
virtual void Update(OctetString^ update, System::UInt16 index, EventMode mode);
virtual void Update(TimeAndInterval^ update, System::UInt16 index);
virtual void Update(BinaryOutputStatus^ update, System::UInt16 index, EventMode mode);
virtual void Update(AnalogOutputStatus^ update, System::UInt16 index, EventMode mode);
virtual void Update(OctetString^ update, System::UInt16 index, EventMode mode);
virtual void Update(TimeAndInterval^ update, System::UInt16 index);

void Apply(opendnp3::IOutstation& proxy);
private:
opendnp3::UpdateBuilder* builder;
};
void Apply(opendnp3::IOutstation& proxy);
private:
opendnp3::UpdateBuilder* builder;
};

}
}
}
}
}

#endif
116 changes: 58 additions & 58 deletions dotnet/CLRAdapter/src/ChannelAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,74 +34,74 @@ using namespace System::Collections::Generic;

namespace Automatak
{
namespace DNP3
{
namespace Adapter
{
namespace DNP3
{
namespace Adapter
{

ChannelAdapter::ChannelAdapter(const std::shared_ptr<opendnp3::IChannel>& channel)
ChannelAdapter::ChannelAdapter(const std::shared_ptr<opendnp3::IChannel>& channel)
: channel(new std::shared_ptr<opendnp3::IChannel>(channel))
{}

ChannelAdapter::~ChannelAdapter()
{
this->!ChannelAdapter();
}

ChannelAdapter::!ChannelAdapter()
{
delete channel;
}

LogFilter ChannelAdapter::GetLogFilters()
{
return LogFilter((*channel)->GetLogFilters().get_value());
}

IChannelStatistics^ ChannelAdapter::GetChannelStatistics()
{
auto stats = (*channel)->GetStatistics();
return Conversions::ConvertChannelStats(stats);
}

void ChannelAdapter::SetLogFilters(LogFilter filters)
{
{}

ChannelAdapter::~ChannelAdapter()
{
this->!ChannelAdapter();
}

ChannelAdapter::!ChannelAdapter()
{
delete channel;
}

LogFilter ChannelAdapter::GetLogFilters()
{
return LogFilter((*channel)->GetLogFilters().get_value());
}

IChannelStatistics^ ChannelAdapter::GetChannelStatistics()
{
auto stats = (*channel)->GetStatistics();
return Conversions::ConvertChannelStats(stats);
}

void ChannelAdapter::SetLogFilters(LogFilter filters)
{
(*channel)->SetLogFilters(opendnp3::LogLevel(filters.Flags));
}
}

void CallbackListener(gcroot < System::Action<ChannelState> ^ >* listener, opendnp3::ChannelState aState)
{
ChannelState state = Conversions::ConvertChannelState(aState);
(*listener)->Invoke(state);
}
void CallbackListener(gcroot < System::Action<ChannelState> ^ >* listener, opendnp3::ChannelState aState)
{
ChannelState state = Conversions::ConvertChannelState(aState);
(*listener)->Invoke(state);
}

IMaster^ ChannelAdapter::AddMaster(System::String^ loggerId, ISOEHandler^ handler, IMasterApplication^ application, MasterStackConfig^ config)
{
std::string stdLoggerId = Conversions::ConvertString(loggerId);
IMaster^ ChannelAdapter::AddMaster(System::String^ loggerId, ISOEHandler^ handler, IMasterApplication^ application, MasterStackConfig^ config)
{
std::string stdLoggerId = Conversions::ConvertString(loggerId);

auto SOEAdapter = std::shared_ptr<opendnp3::ISOEHandler>(new SOEHandlerAdapter(handler));
auto appAdapter = std::shared_ptr<opendnp3::IMasterApplication>(new MasterApplicationAdapter(application));
auto SOEAdapter = std::shared_ptr<opendnp3::ISOEHandler>(new SOEHandlerAdapter(handler));
auto appAdapter = std::shared_ptr<opendnp3::IMasterApplication>(new MasterApplicationAdapter(application));

auto master = (*channel)->AddMaster(stdLoggerId.c_str(), SOEAdapter, appAdapter, Conversions::ConvertConfig(config));
return master ? gcnew MasterAdapter(master) : nullptr;
}
auto master = (*channel)->AddMaster(stdLoggerId.c_str(), SOEAdapter, appAdapter, Conversions::ConvertConfig(config));
return master ? gcnew MasterAdapter(master) : nullptr;
}

IOutstation^ ChannelAdapter::AddOutstation(System::String^ loggerId, ICommandHandler^ cmdHandler, IOutstationApplication^ application, OutstationStackConfig^ config)
{
std::string stdLoggerId = Conversions::ConvertString(loggerId);
IOutstation^ ChannelAdapter::AddOutstation(System::String^ loggerId, ICommandHandler^ cmdHandler, IOutstationApplication^ application, OutstationStackConfig^ config)
{
std::string stdLoggerId = Conversions::ConvertString(loggerId);

auto commandAdapter = std::shared_ptr<opendnp3::ICommandHandler>(new OutstationCommandHandlerAdapter(cmdHandler));
auto appAdapter = std::shared_ptr<opendnp3::IOutstationApplication>(new OutstationApplicationAdapter(application));
auto commandAdapter = std::shared_ptr<opendnp3::ICommandHandler>(new OutstationCommandHandlerAdapter(cmdHandler));
auto appAdapter = std::shared_ptr<opendnp3::IOutstationApplication>(new OutstationApplicationAdapter(application));

auto outstation = (*channel)->AddOutstation(stdLoggerId.c_str(), commandAdapter, appAdapter, Conversions::ConvertConfig(config));
return outstation ? gcnew OutstationAdapter(outstation) : nullptr;
}
auto outstation = (*channel)->AddOutstation(stdLoggerId.c_str(), commandAdapter, appAdapter, Conversions::ConvertConfig(config));
return outstation ? gcnew OutstationAdapter(outstation) : nullptr;
}

void ChannelAdapter::Shutdown()
{
(*channel)->Shutdown();
}
void ChannelAdapter::Shutdown()
{
(*channel)->Shutdown();
}

}
}
}
}
}
42 changes: 21 additions & 21 deletions dotnet/CLRAdapter/src/ChannelAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,39 @@ using namespace System::Collections::ObjectModel;

namespace Automatak
{
namespace DNP3
{
namespace Adapter
{
namespace DNP3
{
namespace Adapter
{

ref class ChannelAdapter : IChannel
{
public:
ref class ChannelAdapter : IChannel
{
public:

ChannelAdapter(const std::shared_ptr<opendnp3::IChannel>& channel);
ChannelAdapter(const std::shared_ptr<opendnp3::IChannel>& channel);

~ChannelAdapter();
!ChannelAdapter();
~ChannelAdapter();
!ChannelAdapter();

virtual LogFilter GetLogFilters() sealed;
virtual LogFilter GetLogFilters() sealed;

virtual IChannelStatistics^ GetChannelStatistics() sealed;
virtual IChannelStatistics^ GetChannelStatistics() sealed;

virtual void SetLogFilters(LogFilter filters) sealed;
virtual void SetLogFilters(LogFilter filters) sealed;

virtual IMaster^ AddMaster(System::String^ loggerId, ISOEHandler^ publisher, IMasterApplication^ application, MasterStackConfig^ config) sealed;
virtual IMaster^ AddMaster(System::String^ loggerId, ISOEHandler^ publisher, IMasterApplication^ application, MasterStackConfig^ config) sealed;

virtual IOutstation^ AddOutstation(System::String^ loggerId, ICommandHandler^ cmdHandler, IOutstationApplication^ application, OutstationStackConfig^ config) sealed;
virtual IOutstation^ AddOutstation(System::String^ loggerId, ICommandHandler^ cmdHandler, IOutstationApplication^ application, OutstationStackConfig^ config) sealed;

virtual void Shutdown() sealed;
virtual void Shutdown() sealed;

private:
private:

std::shared_ptr<opendnp3::IChannel>* channel;
};
std::shared_ptr<opendnp3::IChannel>* channel;
};

}
}
}
}
}

#endif

0 comments on commit 3806d5c

Please sign in to comment.