Пример #1
0
/*
 * Apply the settings tio the given socket.
 */
void TA_Base_Core::TcpNoDelay::apply(int socketId) const
{
    // log that we are changing socket options
    LOG_GENERIC(SourceInfo, DebugUtil::DebugInfo,
        "Setting TCP_NODELAY socket option for socket ID %d to %d", socketId, m_enable);

    // used to collect the result
    int result = 0;

#if defined( WIN32 )
// WINDOWS

    // result will hold the error code if non zero
    result = setsockopt( socketId, IPPROTO_TCP, TCP_NODELAY,
               ( char * )& m_enable,  sizeof( m_enable ) );

#else
// LINUX AND UNIX
    
    // convert the boolean value to an int
    int value = (m_enable)?1:0;

    // result will be zero or -1
    result = setsockopt( socketId, IPPROTO_TCP, TCP_NODELAY,
               & value, sizeof(value) );

#endif // WIN32

    // if there was an error, log the fact, and give the code as well
    if (result != 0)
    {
        LOG_GENERIC(SourceInfo, DebugUtil::DebugError,
        "Setting TCP_NODELAY socket option for socket ID %d to %d failed with code %d ", socketId, m_enable, result);
    }
}
Пример #2
0
	TA_Base_Bus::DataPointCorbaTypes::DynamicSyncUpdateSequence * DataPointObserver::getUpdates()
	{
        std::vector < TA_Base_Bus::DataPointCorbaTypes::SDynamicSyncUpdate* > localList;
		localList.clear();

		{
			// stop multi threads accessing the update details list
			TA_THREADGUARD( m_updateDetailsLock );

			if ( 0 < m_listOfUpdateDetails.size() )
			{
				// clear the update list
                localList.swap( m_listOfUpdateDetails );
			}
			// else do nothing
		}

		TA_Base_Bus::DataPointCorbaTypes::DynamicSyncUpdateSequence * updateSequence = NULL;
		updateSequence = new TA_Base_Bus::DataPointCorbaTypes::DynamicSyncUpdateSequence();
		updateSequence->length ( localList.size() );

		// for each of the update details in the local list,
		unsigned int sequenceIndex = 0;
		std::vector < TA_Base_Bus::DataPointCorbaTypes::SDynamicSyncUpdate* >::iterator currentUpdateItr;
		for ( currentUpdateItr = localList.begin();
			  currentUpdateItr != localList.end();
			  currentUpdateItr++ )
		{
			// copy it to the specified output sequence. 
			//the updates are shared_ptr so no need to care about cleaning.
			(*updateSequence)[sequenceIndex++] = **currentUpdateItr;

			delete *currentUpdateItr;
			(*currentUpdateItr) = NULL;
		}

        // only log if there is something
        if (updateSequence->length() > 0)
        {
            LOG_GENERIC( SourceInfo, TA_Base_Core::DebugUtil::DebugTrace,
                         "Observer ID %d: has %d updates in the returned sequence",
                         m_observerID, updateSequence->length() );
        }

		// restart the timer
		m_purgeExistingUpdatesTimer->startTiming();

		localList.clear();
		return updateSequence;
	}
Пример #3
0
void  SQLCode::_PrintSQL(const std::string& strSQLKey, SQLStatement& rSqlStatement)
{
	if (!rSqlStatement.strCommon.empty())
	{
		if ( rSqlStatement.strCommon.size() > MAXLOGMESGSIZE)
		{
			LOG_GENERIC(SourceInfo, DebugUtil::DebugSQL,"SQLID: %s, LargeSQL: ", strSQLKey.c_str());
			LOGLARGESTRING(SourceInfo, DebugUtil::DebugSQL, rSqlStatement.strCommon.c_str());
		}
		else
		{
			LOG_GENERIC(SourceInfo, DebugUtil::DebugSQL,
				"SQLID: %s, SQL: %s", strSQLKey.c_str(), rSqlStatement.strCommon.c_str());
		}
	}
	if (!rSqlStatement.strMySQL.empty())
	{
		if ( rSqlStatement.strMySQL.size() > MAXLOGMESGSIZE)
		{
			LOG_GENERIC(SourceInfo, DebugUtil::DebugSQL,"SQLID: %s, MySQL LargeSQL: ", strSQLKey.c_str());
			LOGLARGESTRING(SourceInfo, DebugUtil::DebugSQL, rSqlStatement.strMySQL.c_str());
		}
		else
		{
			LOG_GENERIC(SourceInfo, DebugUtil::DebugSQL,
				"SQLID: %s, MySQL SQL: %s", strSQLKey.c_str(), rSqlStatement.strMySQL.c_str());
		}
	}
	if (!rSqlStatement.strSqlite.empty())
	{
		if ( rSqlStatement.strSqlite.size() > MAXLOGMESGSIZE)
		{
			LOG_GENERIC(SourceInfo, DebugUtil::DebugSQL,"SQLID: %s, Oracle LargeSQL: ", strSQLKey.c_str());
			LOGLARGESTRING(SourceInfo, DebugUtil::DebugSQL, rSqlStatement.strSqlite.c_str());
		}
		else
		{
			LOG_GENERIC(SourceInfo, DebugUtil::DebugSQL,
				"SQLID: %s, Oracle SQL: %s", strSQLKey.c_str(), rSqlStatement.strSqlite.c_str());
		}
	}
}
Пример #4
0
	void DataPointObserver::processEvent( boost::shared_ptr<DpObserverUpdate> localList )
	{
        std::stringstream logMessage;
        logMessage << "processDataPointTempList : Processing " << localList->keys.size() << " DataPoints";
        LOG_GENERIC( SourceInfo, DebugUtil::DebugDebug, logMessage.str().c_str() );

		// for each of the data points in the local list
		unsigned int counter = 0;
		std::vector < unsigned long > ::iterator keyItr;
		for ( keyItr = localList->keys.begin();
			  keyItr != localList->keys.end();
			  keyItr++ )
		{
			unsigned long entityKey = (*keyItr);
			// First find out if this dn is already observed
			TA_Base_Bus::DataPoint * existingDataPoint = 0;
			existingDataPoint = findExistingDataPoint ( entityKey );

			// if found none
			if ( 0 == existingDataPoint )
			{
				// get the data point from the specific agent
				TA_Base_Bus::DataPoint * datapoint = 0;
				datapoint = m_specificDataPointAgent->getDataPoint (entityKey);

				// if found a data point with matched pkey
				if ( 0 != datapoint )
				{
					// peter low: register first then only get updates
					registerForUpdates ( datapoint );
					
					// get its complete internal state			
					try
					{
						boost::shared_ptr<TA_Base_Bus::DpCompleteDynamicSyncState> dpCompleteInternalState = datapoint->getCompleteDynamicUpdate();

						if ( NULL != dpCompleteInternalState.get() )
						{
							// save the data point complete state to updateDetails
							TA_Base_Bus::DataPointCorbaTypes::UDynamicSyncUpdate updateDetail;
							convertDpCompleteUpdate(*dpCompleteInternalState, updateDetail);							
							saveDataPointUpdateDetails ( datapoint->getEntityKey(), updateDetail );
                            counter++;
						}				
						else
						{
							LOG_GENERIC( SourceInfo, DebugUtil::DebugWarn, "DataPoint::getState returned NULL pointer for pkey %d",
										 entityKey);
						} 
					}
					catch ( ... )
					{
						LOG_GENERIC( SourceInfo, DebugUtil::DebugError, "Caught exception trying to retrieve DataPoint State for DataPoint key %d",
									 entityKey);
					}
				}
				else
				{
					LOG_GENERIC( SourceInfo, DebugUtil::DebugWarn, "processEvent() : No datapoint for entity: %d",
								 entityKey);
				}
				// else do nothing

				// take a little break after processing 20 data points
				if ( 20 <= counter )
				{
					TA_Base_Core::Thread::sleep  ( 1 );

					counter = 0;
				}
			}
		}

		localList->keys.clear();
	}