Exemplo n.º 1
0
void	PhysicsServer::stepSimulation(float deltaTime)
{

    bool wantsShutdown = false;
    
    if (m_testBlock1)
    {
        ///we ignore overflow of integer for now
        if (m_testBlock1->m_numClientCommands> m_testBlock1->m_numProcessedClientCommands)
        {
            
            //until we implement a proper ring buffer, we assume always maximum of 1 outstanding commands
            btAssert(m_testBlock1->m_numClientCommands==m_testBlock1->m_numProcessedClientCommands+1);
            
            const SharedMemoryCommand& clientCmd =m_testBlock1->m_clientCommands[0];
             m_testBlock1->m_numProcessedClientCommands++;
            
            //consume the command
            switch (clientCmd.m_type)
            {
                case CMD_LOAD_URDF:
                {
                    b3Printf("Processed CMD_LOAD_URDF:%s",clientCmd.m_urdfArguments.m_urdfFileName);
                    
                    //load the actual URDF and send a report: completed or failed

                    
                    bool completedOk = loadUrdf(clientCmd.m_urdfArguments.m_urdfFileName,
                                               btVector3(0,0,0), btQuaternion(0,0,0,1),true,true );
                    SharedMemoryCommand& serverCmd =m_testBlock1->m_serverCommands[0];
 
                    if (completedOk)
                    {
                        serverCmd.m_type =CMD_URDF_LOADING_COMPLETED;
                    } else
                    {
                        serverCmd.m_type =CMD_URDF_LOADING_FAILED;
                    
                    }
                    m_testBlock1->m_numServerCommands++;
                    break;
                }
                case CMD_STEP_FORWARD_SIMULATION:
                {
                   
                    b3Printf("Step simulation request");
                    double timeStep = clientCmd.m_stepSimulationArguments.m_deltaTimeInSeconds;
                    m_dynamicsWorld->stepSimulation(timeStep);
                    
                    SharedMemoryCommand& serverCmd =m_testBlock1->m_serverCommands[0];
                    
                    serverCmd.m_type =CMD_STEP_FORWARD_SIMULATION_COMPLETED;
                    m_testBlock1->m_numServerCommands++;
 
                    break;
                }
                case CMD_SHUTDOWN:
                {
                    wantsShutdown = true;
                    break;
                }
                default:
                {
                    b3Error("Unsupported command encountered");
                    btAssert(0);
                }
            };
            
           
            
            //process the command right now
            
        }
    }
    if (wantsShutdown)
    {
        m_wantsShutdown = true;
        releaseSharedMemory();
    }
}
Exemplo n.º 2
0
PhysicsServer::~PhysicsServer()
{
    releaseSharedMemory();
}
Exemplo n.º 3
0
void writeEncDecLog(int syslogType, eCRYPT_LOG_MESSAGE logMessage, void* data)
{
	if( IS_SUCCESS )
	{
		if( logMessage == eCryptLogMessage_Allow )
			*IS_SUCCESS = true;
		else
			*IS_SUCCESS = false;
	}

	void* logSM = getSharedMemory(LOG_SHARED_MEMORY_KEY, LOG_SHARED_MEMORY_SIZE);

	if( logSM == NULL )
		logSM = createSharedMemory(LOG_SHARED_MEMORY_KEY, LOG_SHARED_MEMORY_SIZE);

	char dbsLogBuf[256] = {'\0', };

	size_t logSMLength = strlen((char*)logSM);

	bool isFind = false;

	int dbsLogReplaceIndex = 0;
	int dbsLogCnt = 0;
	char** dbsLog = strSplitWithLength(logSM, logSMLength, LINE_SPLIT_STR, &dbsLogCnt);
	for(int i = 0 ; i < dbsLogCnt ; ++i)
	{
		if( i > 0 )
			dbsLogReplaceIndex += strlen(LINE_SPLIT_STR);

		int logDataCnt = 0;
		int logDataLength = strlen(dbsLog[i]);
		char** logData = strSplitWithLength(dbsLog[i], logDataLength, LOG_SPLIT_STR, &logDataCnt);

		char* smLogThreadID = logData[1];
		int smLogType = atoi(logData[2]);
		char* smLogAccessIP = logData[3];
		char* smLogAccessUser = logData[4];
		char* smLogProgramName = logData[5];

		int smLogMessage = atoi(logData[6]);

		int smLogCnt = atoi(logData[7]);

		if( memcmp(LOG_THREAD_ID, smLogThreadID, LOG_THREAD_ID_LENGTH) != 0 ||
			LOG_TYPE != smLogType ||
			memcmp(LOG_ACCESS_IP, smLogAccessIP, LOG_ACCESS_IP_LENGTH) != 0 ||
			memcmp(LOG_ACCESS_USER, smLogAccessUser, LOG_ACCESS_USER_LENGTH) != 0 ||
			memcmp(LOG_PROGRAM_NAME, smLogProgramName, LOG_PROGRAM_NAME_LENGTH) != 0 ||
			smLogMessage != logMessage )
		{
			dbsLogReplaceIndex += logDataLength;

			freeSplit(logData, logDataCnt);
			continue;
		}
		else
		{
			if( smLogMessage == eCryptLogMessage_Over_Behavior && strcmp((char*)data, logData[8]) != 0 )
			{
				dbsLogReplaceIndex += logDataLength;

				freeSplit(logData, logDataCnt);
				continue;
			}
		}

		isFind = true;

		sprintf(dbsLogBuf, "%d%s%s%s%d%s%s%s%s%s%s%s%d%s%d"
			, syslogType, LOG_SPLIT_STR
			, LOG_THREAD_ID, LOG_SPLIT_STR
			, LOG_TYPE, LOG_SPLIT_STR
			, LOG_ACCESS_IP, LOG_SPLIT_STR
			, LOG_ACCESS_USER, LOG_SPLIT_STR
			, LOG_PROGRAM_NAME, LOG_SPLIT_STR
			, logMessage, LOG_SPLIT_STR
			, smLogCnt + 1);

		if( logMessage == eCryptLogMessage_Over_Behavior )
		{
			char dataBuf[64] = {'\0', };
			sprintf(dataBuf, "%s%s", LOG_SPLIT_STR, (char*)data);
			strcat(dbsLogBuf, dataBuf);
		}

		char* dbsFinalLog = replaceIndexWithLength(logSM, dbsLogReplaceIndex, logSMLength, dbsLog[i], dbsLogBuf);

		writeSharedMemory(logSM, dbsFinalLog);

		free(dbsFinalLog);

		freeSplit(logData, logDataCnt);
		break;
	}
	freeSplit(dbsLog, dbsLogCnt);

	if( !isFind )
	{
		sprintf(dbsLogBuf, "%s%d%s%s%s%d%s%s%s%s%s%s%s%d%s%d"
			, ( dbsLogCnt > 0 ) ? LINE_SPLIT_STR : ""
			, syslogType, LOG_SPLIT_STR
			, LOG_THREAD_ID, LOG_SPLIT_STR
			, LOG_TYPE, LOG_SPLIT_STR
			, LOG_ACCESS_IP, LOG_SPLIT_STR
			, LOG_ACCESS_USER, LOG_SPLIT_STR
			, LOG_PROGRAM_NAME, LOG_SPLIT_STR
			, logMessage, LOG_SPLIT_STR
			, 1);

		if( logMessage == eCryptLogMessage_Over_Behavior )
		{
			char dataBuf[64] = {'\0', };
			sprintf(dataBuf, "|%s", (char*)data);
			strcat(dbsLogBuf, dataBuf);
		}

		strcat(logSM, dbsLogBuf);
	}

	releaseSharedMemory(logSM);
}