Exemplo n.º 1
0
int modAOS_OCF_Insert::svc() {
	svcStart_();

	AOS_Transfer_Frame* frame = 0;

	while ( continueService() ) {
		ndSafeRelease(frame);

		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		if ( (frame = dynamic_cast<AOS_Transfer_Frame*>(queueTop.first)) ) {
			MOD_DEBUG("Received %d byte AOS_Transfer_Frame to add a Secondary Header to.", frame->getUnitLength());

			// Test expected values.
			if (static_cast<int>(frame->getUnitLength()) != getFrameSize()) {
				MOD_WARNING("AOS Transfer Frame bad length: received %d octets, needed %d.",
					frame->getUnitLength(), getFrameSize());
				incBadLengthCount();
				if ( getDropBadFrames()) continue;
			}
			else incValidFrameCount();

			_receivedFrameUnitCount += 1;
			_receivedFrameOctetCount += frame->getUnitLength();

			_insertWaitingReport(frame);

			if ( links_[PrimaryOutputLink] ) {
				MOD_DEBUG("Sending %d octets.", frame->getUnitLength());

				links_[PrimaryOutputLink]->send(frame);
				frame = 0; // important
			}
			else {
				MOD_NOTICE("No output target defined yet, dropping data.");
			}
			frame = 0;
		}
		else {
			MOD_INFO("Received %d octets of unrecognized data! Dropping.", queueTop.first->getUnitLength());
			ndSafeRelease(queueTop.first);
			queueTop.first = 0;
			continue;
		}
	}

	return svcEnd_();

}
Exemplo n.º 2
0
int modAOS_B_PDU_Add::svc() {
	svcStart_();

	if ( ! _bpduLength) {
		if ( getMTU() > 0 ) {
			_bpduLength = getMTU();
			_mtuIsManual = true;
		}
		else if (links_[PrimaryOutputLink] ) {
			MOD_INFO("B_PDU length is unset, asking output target %s for MRU.", links_[PrimaryOutputLink]->getTarget()->getName().c_str());
			_bpduLength = links_[PrimaryOutputLink]->getTarget()->getMRU();
			_mtuIsManual = false;
		}
	}

	if (_bpduLength > 0) {
		rebuildIdleUnitTemplate_();

		while ( continueService() ) {
			std::pair<NetworkData*, int> queueTop = getData_();

			// Check every 11th unit for a new MTU
			if ( ! _mtuIsManual && getReceivedUnitCount() % 11 == 0 && links_[PrimaryOutputLink] ) {
				_bpduLength = links_[PrimaryOutputLink]->getTarget()->getMRU();
			}

			if ( msg_queue()->deactivated() ) break;

			if ( queueTop.second < 0 ) {
				MOD_ERROR("getData_() call failed.");
				continue;
			}
			else if ( ! queueTop.first ) {
				MOD_ERROR("getData_() returned with null data.");
				continue;
			}

			MOD_DEBUG("Received %d bytes to convert into AOS B_PDUs.", queueTop.first->getUnitLength());

			AOS_Bitstream_PDU* bpdu_list = _process_data(queueTop.first);
			// Deletion of received data is performed in _process_data.

			if ( ! getSendImmediately() ) {
				while (bpdu_list) {
					AOS_Bitstream_PDU* cur = bpdu_list;
					_send(cur);

					bpdu_list = (AOS_Bitstream_PDU*) bpdu_list->getNextPart();
				}
			}
			MOD_DEBUG("Finished processing incoming packets.");
		}
	}
	else {
		MOD_ERROR("No MTU obtainable, exiting service loop (pausing).");
	}

	return svcEnd_();
}
Exemplo n.º 3
0
int modTM_FSH_Extract::svc() {
	svcStart_();

	TM_Transfer_Frame* frame = 0;

	while ( continueService() ) {
		ndSafeRelease(frame);

		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		frame = dynamic_cast<TM_Transfer_Frame*>(queueTop.first);

		if ( !frame ) {
			MOD_ERROR("Received %d-octet buffer in %s wrapper (not TM_Transfer_Frame)! Must discard.",
				queueTop.first->getUnitLength(), queueTop.first->typeStr().c_str());
			ndSafeRelease(queueTop.first);
			continue;
		}

		queueTop.first = 0;

		MOD_DEBUG("Received %d-octet frame.", frame->getUnitLength());
		frame->setSecondaryHeaderLen(getFSHSize());

		// Test expected values.
		if (frame->getUnitLength() != getFrameSizeU()) {
			MOD_WARNING("TM Transfer Frame bad length: received %d octets, needed %d.", frame->getUnitLength(), getFrameSize());
			incBadLengthCount();
			if ( getDropBadFrames() ) continue;
		}
		else { incValidFrameCount(); }

		_extractAndSendFSH(frame);

		if ( links_[PrimaryOutputLink] ) {
			MOD_DEBUG("Sending a %d-octet TM Transfer Frame.", frame->getUnitLength());
			links_[PrimaryOutputLink]->send(frame);
			frame = 0; // important
		}
		else {
			MOD_ERROR("No output target defined, dropping frame.");
		}

		MOD_DEBUG("Finished processing incoming frame.");
	}

	return svcEnd_();
}
Exemplo n.º 4
0
int modTM_MC_Mux::svc() {
	svcStart_();

	TM_Transfer_Frame* frame = 0;

	while ( continueService() ) {
		ndSafeRelease(frame);

		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		frame = dynamic_cast<TM_Transfer_Frame*>(queueTop.first);

		if ( !frame ) {
			MOD_ERROR("Received %d-octet buffer in %s wrapper (not TM_Transfer_Frame)! Must discard.",
				queueTop.first->getUnitLength(), queueTop.first->typeStr().c_str());
			ndSafeRelease(queueTop.first);
			continue;
		}

		MOD_DEBUG("Received %d-octet frame to multiplex.", frame->getTotalUnitLength());

		// Test expected values.
		if (static_cast<int>(frame->getTotalUnitLength()) != getFrameSize()) {
			MOD_WARNING("TM Transfer Frame bad length: received %d octets, needed %d.", frame->getTotalUnitLength(), getFrameSize());
			incBadLengthCount();
			if ( getDropBadFrames() ) continue;
		}
		else {
			incValidFrameCount();
		}

		addErrorControlIfPossible(frame);

		if ( links_[PrimaryOutputLink] ) {
			MOD_DEBUG("Sending %d octets.", frame->getTotalUnitLength());

			links_[PrimaryOutputLink]->send(frame);
			frame = 0; // important
		}
		else {
			MOD_NOTICE("No output target defined yet, dropping data.");
		}
	}

	return svcEnd_();

}
Exemplo n.º 5
0
int modAOS_OCF_Extract::svc() {
	svcStart_();

	AOS_Transfer_Frame* frame = 0;

	while ( continueService() ) {
		ndSafeRelease(frame);
		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		frame = dynamic_cast<AOS_Transfer_Frame*>(queueTop.first);

		if ( ! frame ) {
			MOD_INFO("Received %d octets of non-AOS data! Dropping.", queueTop.first->getUnitLength());
			ndSafeRelease(queueTop.first);
			continue;
		}

		queueTop.first = 0;

		MOD_DEBUG("Received %d-octet frame.", frame->getUnitLength());
		frame->useOperationalControl(true);

		// Test expected values.
		if (frame->getUnitLength() != getFrameSizeU()) {
			MOD_WARNING("AOS Transfer Frame bad length: received %d octets, needed %d.", frame->getUnitLength(), getFrameSize());
			incBadLengthCount();
			if ( getDropBadFrames() ) continue;
		}
		else incValidFrameCount();

		_extractAndSendOCF(frame);

		if ( links_[PrimaryOutputLink] ) {
			MOD_DEBUG("Sending a %d-octet AOS Transfer Frame.", frame->getUnitLength());
			links_[PrimaryOutputLink]->send(frame);
			frame = 0; // important
		}
		else {
			MOD_ERROR("No output target defined, dropping frame.");
		}

		MOD_DEBUG("Finished processing incoming frame.");
	}

	return svcEnd_();
}
Exemplo n.º 6
0
void CALLBACK serviceHandler(DWORD ctl)
{
	switch (ctl)
	{
		case SERVICE_CONTROL_STOP:
		{
			serviceStatus.dwCheckPoint++;
			serviceStatus.dwCurrentState = SERVICE_STOP_PENDING;
			SetServiceStatus(serviceStatusHandle, &serviceStatus);

			stopService();

			serviceStatus.dwCheckPoint = 0;
			serviceStatus.dwCurrentState = SERVICE_STOPPED;
			SetServiceStatus(serviceStatusHandle, &serviceStatus);
			break;
		}
		case SERVICE_CONTROL_PAUSE:
		{
			pauseService();

			serviceStatus.dwCurrentState = SERVICE_PAUSED;
			SetServiceStatus(serviceStatusHandle, &serviceStatus);

			break;
		}
		case SERVICE_CONTROL_CONTINUE:
		{
			continueService();
			serviceStatus.dwCurrentState = SERVICE_RUNNING;
			SetServiceStatus(serviceStatusHandle, &serviceStatus);
			break;
		}
		default:
		{
			break;
		}
	}
}
Exemplo n.º 7
0
int modASM_Remove::svc() {
	svcStart_();
	ACE_UINT8* markerBuf = 0;
	size_t markerLen = 0;
	_rebuildMarker = true;
	NetworkData* data = 0;
	NetworkData* goodUnit = 0;
	size_t goodUnitLength = 0;
	size_t advanceLen = 0;
	size_t remainingLen = 0;
	size_t partialMarkerLen = 0;
	size_t markerOffset = 0;
	bool searching = false;

	while ( continueService() ) {
		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		data = queueTop.first;

		_updateMarker(markerBuf, markerLen);

		MOD_DEBUG("Received a %d-octet unit to test for ASMs.", data->getUnitLength());

		while ( data->getUnitLength() ) {
			if ( ! goodUnit ) { // no unit to continue, need to find next ASM
				partialMarkerLen = markerLen - markerOffset;

				// determine if enough buffer left to find ASM
				// if not, check what's left and check for remainder in next buffer
				if ( data->getUnitLength() < partialMarkerLen ) {
					if ( _markerMatch(data->ptrUnit(), markerBuf + markerOffset, data->getUnitLength()) ) {
						// this portion is correct
						markerOffset += data->getUnitLength();
					}
					else {
						MOD_DEBUG("Missed partial ASM, resetting marker offset and bit error count.");
						incPartialMismatchCount();
						markerOffset = 0;
						_currentBitErrors = 0;
					}

					advanceLen = data->getUnitLength();
				}
				// if so, look for ASM normally
				else if ( _markerMatch(data->ptrUnit(), markerBuf + markerOffset, partialMarkerLen) ) {
					MOD_DEBUG("Found ASM.");
					_asmCount++;

					if ( searching ) _asmDiscoveredCount++;
					else _asmValidCount++;

					searching = false;
					advanceLen = partialMarkerLen;
					markerOffset = 0;
					_currentBitErrors = 0;

					// determine if entire unit can be extracted from buffer
					// if so, wrap and send
                    if ( data->getUnitLength() - partialMarkerLen >= getExpectedUnitLength() ) {
						MOD_DEBUG("Found complete unit.");
						goodUnit = data->wrapInnerPDU<NetworkData>(getExpectedUnitLength(),
							data->ptrUnit() + partialMarkerLen);
						_send(goodUnit);
						advanceLen += getExpectedUnitLength();
                    }
					// if not, create a new unit to hold it
					else {
						MOD_DEBUG("Holding partial unit for expected completion.");
						goodUnitLength = data->getUnitLength() - partialMarkerLen;
						goodUnit = new NetworkData(getExpectedUnitLength());
						goodUnit->copyUnit(goodUnit->ptrUnit(), data->ptrUnit() + partialMarkerLen, goodUnitLength);
						advanceLen += goodUnitLength;
					};
				}
				else {
					MOD_DEBUG("Missed ASM, advancing one octet at a time.");
					if (! searching ) _asmMissedCount++; // Only increment for the first miss, or after another ASM was found.
					searching = true;
					incSearchCount();

					// data->dump();
					advanceLen = 1;
					markerOffset = 0;
					_currentBitErrors = 0;
				}
			}
			else { // continuing previous unit, don't look for ASM
				remainingLen = getExpectedUnitLength() - goodUnitLength;
				// determine if remaining unit fits in buffer
				// if so, append it and send, reset goodUnit to 0
				if ( data->getUnitLength() >= remainingLen ) {
					MOD_DEBUG("Completing partial unit with newly received data.");
					goodUnit->copyUnit(goodUnit->ptrUnit() + goodUnitLength, data->ptrUnit(),
						remainingLen);
					_send(goodUnit);
					advanceLen = remainingLen;
				}

				// if not, append it and don't send
				else {
					MOD_DEBUG("Adding to partial unit but will complete later.");

					goodUnit->copyUnit(goodUnit->ptrUnit() + goodUnitLength, data->ptrUnit(),
						data->getUnitLength());
					goodUnitLength += data->getUnitLength();
					advanceLen = data->getUnitLength();
				}
			}

			// advance read pointer by length just used up
			data->rd_ptr(advanceLen);
			MOD_DEBUG("Buffer length is now %d.", data->getUnitLength());
		}

		ndSafeRelease(data);
	}

	return svcEnd_();
}
Exemplo n.º 8
0
void main(int argc, char **argv)
{
	// Statup wx
	wxInitialize();

	wxFileName file = wxString::FromAscii(*argv++);
	file.MakeAbsolute();
	wxString executable = file.GetFullPath();

	if (argc < 3)
	{
		usage(executable);
		return;
	}

	wxString command;
	command = wxString::FromAscii(*argv++);

	if (command != wxT("DEBUG"))
	{
		serviceName = wxString::FromAscii(*argv++);
		argc -= 3;
	}
	else
		argc -= 2;

	if (command == wxT("INSTALL"))
	{
		wxString displayname = _("PostgreSQL Scheduling Agent - ") + serviceName;
		wxString args = wxT("RUN ") + serviceName;

		while (argc-- > 0)
		{
			if (argv[0][0] == '-')
			{
				switch (argv[0][1])
				{
					case 'u':
					{
						user = getArg(argc, argv);
						break;
					}
					case 'p':
					{
						password = getArg(argc, argv);
						break;
					}
					case 'd':
					{
						displayname = getArg(argc, argv);
						break;
					}
					default:
					{
						args += wxT(" ") + wxString::FromAscii(*argv);
						break;
					}
				}
			}
			else
			{
				args += wxT(" ") + wxString::FromAscii(*argv);
			}

			argv++;
		}

		bool rc = installService(serviceName, executable, args, displayname, user, password);
	}
	else if (command == wxT("REMOVE"))
	{
		bool rc = removeService(serviceName);
	}
	else if (command == wxT("DEBUG"))
	{
		setupForRun(argc, argv, true, executable);

		initService();
#if START_SUSPENDED
		continueService();
#endif

		WaitForSingleObject(threadHandle, INFINITE);
	}
	else if (command == wxT("RUN"))
	{
		wxString app = _("pgAgent Service");

		SERVICE_TABLE_ENTRY serviceTable[] =
		{ (LPWSTR)app.wc_str(), serviceMain, 0, 0};

		setupForRun(argc, argv, false, executable);

		if (!StartServiceCtrlDispatcher(serviceTable))
		{
			DWORD rc = GetLastError();
			if (rc)
			{
			}
		}
	}
	else
	{
		usage(executable);
	}

	return;
}
Exemplo n.º 9
0
int modTM_MC_Gen::svc() {
	svcStart_();

	TM_Transfer_Frame* frame = 0;

	while ( continueService() ) {
		ndSafeRelease(frame);

		bool frameIsValid = true;

		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		frame = dynamic_cast<TM_Transfer_Frame*>(queueTop.first);

		if ( !frame ) {
			MOD_ERROR("Received %d-octet buffer in %s wrapper (not TM_Transfer_Frame)! Must discard.",
				queueTop.first->getUnitLength(), queueTop.first->typeStr().c_str());
			ndSafeRelease(queueTop.first);
			continue;
		}

		queueTop.first = 0;

		if ( frame->getUnitLength() != getFrameSizeU() ) {
			MOD_ERROR("Received %d-octet unit when exactly %d octets are required.",
				frame->getUnitLength(), getFrameSizeU());
			incBadLengthCount();
			frameIsValid = false;
			if ( getDropBadFrames() ) continue;
		}

		if ( frame->getSpacecraftID() != getSCID() ) {
			MOD_WARNING("Spacecraft identifier (SCID) mismatch: Want %d, frame has %d.",
						getSCID(), frame->getSpacecraftID());
			incBadMCIDCount();
			frameIsValid = false;
			if ( getDropBadFrames() ) continue;
		}

		MOD_DEBUG("Received a %d-octet Transfer Frame with MCID %X.", frame->getUnitLength(), frame->getMCID());
		if (frameIsValid) incValidFrameCount();

		if ( links_[PrimaryOutputLink] ) {
			frame->setMCFrameCount(getCurrentFrameNumber());
			incCurrentFrameNumber(TM_Transfer_Frame::maxMCFrameCount);
			links_[PrimaryOutputLink]->send(frame);
			frame = 0; // important
			MOD_DEBUG("Finished processing incoming frame.");
		}
		else {
			MOD_ERROR("No output target defined, dropping frame.");
		}

	}

	return svcEnd_();
}
Exemplo n.º 10
0
int modAOS_VC_Frame::svc() {
	svcStart_();

	NetworkData* data = 0;
	AOS_Transfer_Frame* aos = 0;

	while ( continueService() ) {
		bool frameIsValid = true;
		ndSafeRelease(data); // Handle all cases from previous iteration

		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		data = queueTop.first;
		queueTop.first = 0;

		MOD_DEBUG("Channel GVCID %X: Received a %d-octet VC frame.", getGVCID(), data->getTotalUnitLength());

		if ( data->getTotalUnitLength() != getMRU() ) {
			MOD_ERROR("Received %d-octet frame when exactly %d octets are required.", data->getTotalUnitLength(), getMRU());
			incBadLengthCount();
			frameIsValid = false;
			if ( getDropBadFrames() ) continue;
		}

		if ( links_[PrimaryOutputLink] ) {
			ndSafeRelease(aos);
			aos = new AOS_Transfer_Frame(
				getFrameSize(), // all frames in MC have the same size
				data->ptrUnit() // copy the data buffer
			);

			if ( ! aos ) {
				MOD_ALERT("Failed to allocate an AOS_Transfer_Frame!", getName().c_str());
			}
			else if ( aos->getGVCID() != getGVCID() ) {
				ND_WARNING("[%s] Incoming frame GVCID %X does not match assigned GVCID %X.", aos->getGVCID(), getGVCID());
				incBadGVCIDCount();
				frameIsValid = false;
				if ( getDropBadFrames() ) continue;
			}

			if ( frameIsValid ) incValidFrameCount();

			if (aos) {
				MOD_DEBUG("Sending %-octet frame to next segment.", aos->getUnitLength());
				links_[PrimaryOutputLink]->send(aos);
				aos = 0; // important
			}
		}
		else {
			MOD_ERROR("No output target defined, dropping packet.");
		}
	}

	return svcEnd_();
}
Exemplo n.º 11
0
int modTM_MC_Frame::svc() {
	svcStart_();

	NetworkData* data = 0;
	TM_Transfer_Frame* frame = 0;

	while ( continueService() ) {
		ndSafeRelease(data);
		ndSafeRelease(frame);

		std::pair<NetworkData*, int> queueTop = getData_();

		if ( msg_queue()->deactivated() ) break;

		if ( queueTop.second < 0 ) {
			MOD_ERROR("getData_() call failed.");
			continue;
		}
		else if ( ! queueTop.first ) {
			MOD_ERROR("getData_() returned with null data.");
			continue;
		}

		data = queueTop.first;
		queueTop.first = 0;

		MOD_DEBUG("Channel MCID %X: Received a %d-octet MC frame.", getMCID(), data->getTotalUnitLength());

		if ( data->getTotalUnitLength() != getMRU() ) {
			MOD_ERROR("Received %d-octet frame when exactly %d octets are required.", data->getTotalUnitLength(), getMRU());
			incBadLengthCount();
			if ( getDropBadFrames() ) { ndSafeRelease(data); continue; }
		}

		TM_Transfer_Frame* frame = new TM_Transfer_Frame(
			getFrameSize(), // all frames in MC have the same size
			data->ptrUnit(), // copy the data
			getUseOperationalControl(), // existance of OCF is VC dependent
			getUseFrameErrorControl(), // all frames in MC have frame CRC, or not
			getFSHSize() // size of secondary header
		);

		if ( ! frame ) {
			MOD_ALERT("Failed to allocate a TM_Transfer_Frame!", getName().c_str());
			continue;
		}

		if ( frame->getMCID() != getMCID() ) {
			ND_WARNING("[%s] Incoming frame MCID %X does not match assigned MCID %X.", frame->getMCID(), getMCID());
			incBadMCIDCount();
			if ( getDropBadFrames() ) continue;
		}
		else {
			incValidFrameCount();
		}

		if ( links_[PrimaryOutputLink] ) {
			MOD_DEBUG("Sending %-octet frame to next segment.", frame->getUnitLength());
			links_[PrimaryOutputLink]->send(frame);
			frame = 0; // important
		}
		else {
			MOD_ERROR("No output target defined, dropping packet.");
		}
	}

	return svcEnd_();
}