Example #1
0
void ACS_Base::ThrowInvalidState(const std::string& arLocation)
{
#ifndef OPENDNP3_STRIP_LOG_MESSAGES
	MACRO_THROW_EXCEPTION_COMPLEX(InvalidStateException, "State: " << this->Name());
#else
	MACRO_THROW_EXCEPTION_COMPLEX(InvalidStateException, "");
#endif
}
void PhysicalLayerAsyncBase::OnOpenCallback(const boost::system::error_code& arErr)
{
	if(mState.mOpening) {
		mState.mOpening = false;

		this->DoOpenCallback();

		if(arErr) {
			LOG_BLOCK(LEV_WARNING, arErr.message());
			mState.CheckForClose();
			this->DoOpenFailure();
			if(mpHandler) mpHandler->OnOpenFailure();
		}
		else { // successful connection
			if(this->IsClosing()) { // but the connection was closed
				mState.CheckForClose();
				this->DoClose();
				if(mpHandler) mpHandler->OnOpenFailure();
			}
			else {
				mState.mOpen = true;
				this->DoOpenSuccess();
				if(mpHandler) mpHandler->OnLowerLayerUp();
			}
		}
	}
	else {
		MACRO_THROW_EXCEPTION_COMPLEX(InvalidStateException, "OnOpenCallback: " << this->ConvertStateToString());
	}
}
Example #3
0
///////////////////////////////////////
// ILayerDown NVII implementations
///////////////////////////////////////
void TransportLayer::_Send(const uint8_t* apData, size_t aNumBytes)
{
	if(aNumBytes == 0 || aNumBytes > M_FRAG_SIZE) {
		MACRO_THROW_EXCEPTION_COMPLEX(ArgumentException, "Illegal arg: " << aNumBytes << ", Array length must be in the range [1," << M_FRAG_SIZE << "]");
	}

	mpState->Send(apData, aNumBytes, this);
}
void PhysicalLayerAsyncBase::AsyncOpen()
{
	if(mState.CanOpen()) {
		mState.mOpening = true;
		this->DoOpen();
	}
	else {
		MACRO_THROW_EXCEPTION_COMPLEX(InvalidStateException, "AsyncOpen: " << this->ConvertStateToString());
	}
}
Example #5
0
BufferTypes Convert(DataTypes aType)
{
	switch(aType) {
	case(DT_BINARY):	return BT_BINARY;
	case(DT_ANALOG):	return BT_ANALOG;
	case(DT_COUNTER):	return BT_COUNTER;
	default:
		MACRO_THROW_EXCEPTION_COMPLEX(ArgumentException, "Invalid conversion to BufferType: " << aType);
	}
}
void PhysicalLayerAsyncBase::AsyncRead(uint8_t* apBuff, size_t aMaxBytes)
{
	if(aMaxBytes < 1) {
		MACRO_THROW_EXCEPTION(ArgumentException, "aMaxBytes must be > 0");
	}

	if(mState.CanRead()) {
		mState.mReading = true;
		this->DoAsyncRead(apBuff, aMaxBytes);
	}
	else {
		MACRO_THROW_EXCEPTION_COMPLEX(InvalidStateException, "AsyncRead: " << this->ConvertStateToString());
	}
}
void PhysicalLayerAsyncBase::AsyncWrite(const uint8_t* apBuff, size_t aNumBytes)
{
	if(aNumBytes < 1) {
		MACRO_THROW_EXCEPTION(ArgumentException, "aNumBytes must be > 0");
	}

	if(mState.CanWrite()) {
		mState.mWriting = true;
		this->DoAsyncWrite(apBuff, aNumBytes);
	}
	else {
		MACRO_THROW_EXCEPTION_COMPLEX(InvalidStateException, "AsyncWrite: " << this->ConvertStateToString());
	}
}
void PhysicalLayerAsyncBase::StartClose()
{
	if(!mState.IsClosing()) { //TODO - kind of hack as it deviates from the current model.
		if(mState.CanClose()) {
			mState.mClosing = true;

			if(mState.mOpening) this->DoOpeningClose();
			else this->DoClose();
		}
		else {
			MACRO_THROW_EXCEPTION_COMPLEX(InvalidStateException, "StartClose: " << this->ConvertStateToString());
		}
	}
}
Example #9
0
IOutstation* DNP3Channel::AddOutstation(const std::string& arLoggerId, FilterLevel aLevel, ICommandHandler* apCmdHandler, const SlaveStackConfig& arCfg)
{
	LinkRoute route(arCfg.link.RemoteAddr, arCfg.link.LocalAddr);
	ExecutorPause p(mpPhys->GetExecutor());
	if(mRouter.IsRouteInUse(route)) {
		MACRO_THROW_EXCEPTION_COMPLEX(ArgumentException, "Route already in use: " << route);
	}
	else {
		auto pLogger = mpLogger->GetSubLogger(arLoggerId, aLevel);
		auto pOutstation = new OutstationStackImpl(pLogger, mpService, mpPhys->GetExecutor(), apCmdHandler, arCfg, [this, route](IStack * apStack) {
			this->OnStackShutdown(apStack, route);
		});
		pOutstation->SetLinkRouter(&mRouter);
		mStacks.insert(pOutstation);
		mRouter.AddContext(pOutstation->GetLinkContext(), route);
		return pOutstation;
	}		
}
Example #10
0
IMaster* DNP3Channel::AddMaster(const std::string& arLoggerId, FilterLevel aLevel, IDataObserver* apPublisher, const MasterStackConfig& arCfg)
{	
	LinkRoute route(arCfg.link.RemoteAddr, arCfg.link.LocalAddr);
	ExecutorPause p(mpPhys->GetExecutor());
	if(mRouter.IsRouteInUse(route)) {
		MACRO_THROW_EXCEPTION_COMPLEX(ArgumentException, "Route already in use: " << route);
	}
	else {
		auto pLogger = mpLogger->GetSubLogger(arLoggerId, aLevel);
		auto pMaster = new MasterStackImpl(pLogger, mpService, mpPhys->GetExecutor(), apPublisher, &mGroup, arCfg, [this, route](IStack * apStack) {
			this->OnStackShutdown(apStack, route);
		});
		pMaster->SetLinkRouter(&mRouter);
		mStacks.insert(pMaster);
		mRouter.AddContext(pMaster->GetLinkContext(), route);
		return pMaster;
	}		
}
void PhysicalLayerAsyncBase::OnWriteCallback(const boost::system::error_code& arErr, size_t aNumBytes)
{
	if(mState.mWriting) {
		mState.mWriting = false;

		if(arErr) {
			LOG_BLOCK(LEV_WARNING, arErr.message());
			if(mState.CanClose()) this->StartClose();
		}
		else {
			if(mState.mClosing) {
				LOG_BLOCK(LEV_DEBUG, "Ignoring written bytes since layer is closing: " << aNumBytes);
			}
			else {
				this->DoWriteSuccess();
			}
		}

		if(mState.CheckForClose()) this->DoThisLayerDown();
	}
	else {
		MACRO_THROW_EXCEPTION_COMPLEX(InvalidStateException, "OnWriteCallback: " << this->ConvertStateToString());
	}
}
void PhysicalLayerAsyncBase::OnReadCallback(const boost::system::error_code& arErr, uint8_t* apBuff, size_t aSize)
{
	if(mState.mReading) {
		mState.mReading = false;

		if(arErr) {
			LOG_BLOCK(LEV_WARNING, arErr.message());
			if(mState.CanClose()) this->StartClose();
		}
		else {
			if(mState.mClosing) {
				LOG_BLOCK(LEV_DEBUG, "Ignoring received bytes since layer is closing: " << aSize);
			}
			else {
				this->DoReadCallback(apBuff, aSize);
			}
		}

		if(mState.CheckForClose()) this->DoThisLayerDown();
	}
	else {
		MACRO_THROW_EXCEPTION_COMPLEX(InvalidStateException, "OnReadCallback: " << this->ConvertStateToString());
	}
}