DllExport  bool __cdecl RunTask(IAgent* agent,
			DWORD hxGridSessionId,
			IGenericStream* inStream,
			IGenericStream* outStream)
		{

			bool bRep = true;

			bUseHxGrid = true;
			__int32 sessionId = 0;
			inStream->Read(&sessionId, sizeof(sessionId));
			__int8 bDirectAccess = false;
			inStream->Read(&bDirectAccess, sizeof(bDirectAccess));

			istringstream iStream(string((char*)inStream->GetCurPointer(), inStream->GetLength()));
			ostringstream oStream;

			//RunModel(iStream, oStream);
			RunModel(agent, hxGridSessionId, iStream, oStream);

			const string& str = oStream.str();
			outStream->Write(&sessionId, sizeof(sessionId));
			outStream->Write(str.c_str(), (DWORD)str.length());

			if (agent && agent->TestConnection(hxGridSessionId) != S_OK)
				bRep = false;

			return bRep;
		}
Esempio n. 2
0
void ScanParseSkel::scanFile(const Char8 *szFilename)
{
    if(szFilename == NULL)
        return;

#ifdef OSG_FLEX_USE_IOSTREAM_INPUT
    std::ifstream iStream(szFilename);

    if(iStream.good())
    {
        PNOTICE << "Loading Stream: " << szFilename << std::endl;

        scanStream(iStream);

        iStream.close();
    }
#else
    FILE *pInFile = fopen(szFilename, "r");

    if(pInFile != NULL)
    {
        PNOTICE << "Loading File : " << szFilename << std::endl;

        OSGScanParseSkel_in = pInFile;

        OSGScanParseSkel_parse(this);

        fclose(pInFile);
    }
#endif
}
Esempio n. 3
0
void Summoners::msg_login(QDataStream &oStream)
{
    bool bRes;
    QString strTmp;
    qint32 Reason;
    oStream >> bRes;
    if (bRes)
    {
        strTmp += " login success.";
    }
    else
    {
        strTmp += " login fail. reason:";
        oStream >> Reason;
        if (Reason == 1) {
            strTmp += "username or password Validation failed.";
        } else if (Reason == 2) {
            strTmp += "client limit.";
        } else {
            strTmp += "unknow";
        }
    }
    ui.edit_display->setText(strTmp);

    if (bRes)
    {
        QByteArray datagram;
        QDataStream iStream(&datagram, QIODevice::WriteOnly);
        iStream.setByteOrder(QDataStream::LittleEndian);
        iStream << CS_RoleInfo;
        Socket->write(datagram);
    }
}
static double dGetVal(UT_UTF8String sVal)
{
	std::istringstream iStream(sVal.utf8_str());
	double d;
	iStream >> d;

	// any input succesfully converted?
	if(!iStream)
	{
		return 0;
	}
	// if so, and buffer is not empty yet, check
	// if all remaining characters are whitespaces
	if(iStream.rdbuf()->in_avail() != 0)
	{
		char c;
		do
		{
			iStream.get(c);
			if(!isspace(c))
			{
				return 0;
			}
		}
		while(iStream.gcount() != 0);
	}

	return d;
}
Esempio n. 5
0
void Summoners::on_btn_recovery_clicked(void)
{
    QByteArray datagram;
    QDataStream iStream(&datagram, QIODevice::WriteOnly);
    iStream.setByteOrder(QDataStream::LittleEndian);
    iStream << CS_Action << (qint32)at_Recovery;
    Socket->write(datagram);
}
Esempio n. 6
0
void Summoners::on_btn_startFight_clicked(void)
{
    QByteArray datagram;
    QDataStream iStream(&datagram, QIODevice::WriteOnly);
    iStream.setByteOrder(QDataStream::LittleEndian);
    iStream << CS_FightStart;
    Socket->write(datagram);
}
Esempio n. 7
0
bool Summoners::SendHeart(void)
{
    QByteArray datagram;
    QDataStream iStream(&datagram, QIODevice::WriteOnly);
    iStream.setByteOrder(QDataStream::LittleEndian);
    iStream << CS_HEART;
    Socket->write(datagram);

    return true;
}
bool ompl::tools::LightningDB::load(const std::string &fileName)
{
    // Error checking
    if (fileName.empty())
    {
        OMPL_ERROR("Empty filename passed to save function");
        return false;
    }
    if ( !boost::filesystem::exists( fileName ) )
    {
        OMPL_WARN("Database file does not exist: %s", fileName.c_str());
        return false;
    }

    // Load database from file, track loading time
    time::point start = time::now();

    OMPL_INFORM("Loading database from file: %s", fileName.c_str());

    // Open a binary input stream
    std::ifstream iStream(fileName.c_str(), std::ios::binary);

    // Get the total number of paths saved
    double numPaths = 0;
    iStream >> numPaths;

    // Check that the number of paths makes sense
    if (numPaths < 0 || numPaths > std::numeric_limits<double>::max())
    {
        OMPL_WARN("Number of paths to load %d is a bad value", numPaths);
        return false;
    }

    // Start loading all the PlannerDatas
    for (std::size_t i = 0; i < numPaths; ++i)
    {
        // Create a new planner data instance
        ompl::base::PlannerDataPtr plannerData(new ompl::base::PlannerData(si_));

        // Note: the StateStorage class checks if the states match for us
        plannerDataStorage_.load(iStream, *plannerData.get());

        // Add to nearest neighbor tree
        nn_->add(plannerData);
    }

    // Close file
    iStream.close();

    double loadTime = time::seconds(time::now() - start);
    OMPL_INFORM("Loaded database from file in %f sec with %d paths", loadTime, nn_->size());
    return true;
}
 //load qss file to change native UI of the application
static void loadQssFile(QApplication &app, const QString &qssFileName){
    QFile qssFile(qssFileName);
    QString qssContent("");

    if(qssFile.open(QFile::ReadOnly)){
        QTextStream iStream(&qssFile);
        qssContent = iStream.readAll();
        qssFile.close();
    }

    app.setStyleSheet(qssContent);
}
Esempio n. 10
0
QString FileUtils::fileMd5(const QString & filePath)
{
	QFile theFile(filePath);

	if(!theFile.open(QIODevice::ReadOnly))
	{
		theFile.close();
		return "";
	}
	QTextStream iStream(&theFile);
	QString strMd5 =  StringUtils::md5(iStream.readAll());
	theFile.close();
	return strMd5;
}
Esempio n. 11
0
////////////////////////////////////////////////////////////////////////////////
/// CChanceTreeGraph::load
///
/// @description      This function loads data from the indicated file.
/// @pre              None
/// @post             The data is loaded from the file, if it is a valid file.
///
/// @param fileName:  This is the filename to load the data from.  If no
///                   filename is specified, the name stored in the class will
///                   be used.
///
/// @limitations      None
///
////////////////////////////////////////////////////////////////////////////////
void CChanceTreeGraph::load( const QString &fileName )
{
    //Check that either the given filename or the one stored within the class
    //are valid.  If both are NULL, return without loading a file.
    if ( fileName.isNull() && m_fileName.isNull() )
        return;

    //Check if the given filename is not NULL.  As long as it's not NULL,
    //set the name stored in the class to the given name.
    if ( fileName.isNull() == false )
        setFileName( fileName );

    //Open the indicated file in read only mode.
    QFile iFile( m_fileName );
    iFile.open( QIODevice::ReadOnly );
    if ( !iFile.isOpen() )
    {
        QMessageBox::critical( NULL, "File Error!", "There was an error "
                               "opening the requested file, so the operation "
                               "has been terminated.", QMessageBox::Ok,
                               QMessageBox::NoButton );
        return;
    }
    QDataStream iStream(&iFile);

    //These variables are used for reading in the program magic number and the
    //program mode, respectively.
    quint32 magicNum;
    int     i;

    //Read the magic number of program mode from the data stream to get to the
    //data stored in the file.  These values were checked previously before
    //this load function was called.
    iStream >> magicNum;
    iStream >> i;

    //Check if there is currently a tree loaded in the program.  If there is,
    //delete it.
    if ( m_rootNode != NULL )
        delete m_rootNode;

    //Create a new root node and load the data from the save file.
    m_rootNode = new SChanceTreeNode;
    loadHelper( m_rootNode, iStream );
}
Esempio n. 12
0
Config::Config( const char *configname )
{
    // Attempt to open the file
  std::ifstream iStream( configname );

  if ( iStream.is_open() )
  {
    std::string dataname;
    iStream >> dataname;

    while ( iStream.good() )
    {
      std::transform( dataname.begin(), dataname.end(), dataname.begin(), toupper );

      if ( dataname == "[USERNAME]" )     // Specifing username.
      {
        std::string name;

          // Ignore the newline character still left in the stream before the next line of our file
          //  so we can read in the user's name's line.
        iStream.ignore();
        std::getline(iStream, name);
        //iStream.getline( name, sizeof(name) - 1 );
        unsigned len = name.size();
        username_.assign( name.c_str(), (len > 31 ? 31 : len) );
        //username_.push_back('\0');
      }
      else if ( dataname == "[SERVER]" )  // Specifing server information.
      {
        iStream >> dataname;

        while ( iStream.good() )
        {
          std::transform( dataname.begin(), dataname.end(), dataname.begin(), toupper );

          if ( dataname == "IP:" )        // Specifing server ip address.
          {
            iStream >> ip_;
          }
          else if ( dataname == "PORT:" ) // Server port.
          {
            iStream >> port_;
          }
Esempio n. 13
0
void Summoners::on_btn_login_clicked()
{
    quint32 port = ui.edit_port->text().toUInt();
    QHostAddress addr(ui.edit_addr->text());

    Socket = new QTcpSocket;
    Socket->connectToHost(addr, port);

    connect(Socket, SIGNAL(connected()), this, SLOT(processConnection()));
    connect(Socket, SIGNAL(readyRead()), this, SLOT(receiveMessage()));

    timer_heart = startTimer(1000);		//假设每秒1次心跳。不同的游戏,心跳间隔不一样。

    QByteArray datagram;
    QDataStream iStream(&datagram, QIODevice::WriteOnly);
    iStream.setByteOrder(QDataStream::LittleEndian);
    iStream << CS_Login;
    Socket->write(datagram);
}
Esempio n. 14
0
void SynthAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
    // You should use this method to restore your parameters from this memory block,
    // whose contents will have been created by the getStateInformation() call.

	MemoryInputStream iStream(data, static_cast<size_t> (sizeInBytes), false);
	*oscP = iStream.readFloat();
	*detP = iStream.readFloat();
	*ampP = iStream.readFloat();
	*freqP = iStream.readFloat();
	*qP = iStream.readFloat();
	*envP = iStream.readFloat();
	*speedP = iStream.readFloat();

	//*oscP =   MemoryInputStream(data, static_cast<size_t> (sizeInBytes), false).readFloat();

	//*speedP = MemoryInputStream(data, static_cast<size_t> (sizeInBytes), false).readFloat();

}
Esempio n. 15
0
void AlarmNotifier::readyNodeId()
{
    QDataStream iStream(m_socket);
    quint8 type = 0;
    quint8 nodesNb = 0;
    quint16 nodeId = 0;
    quint32 duration = 0;
    QList<int> nodesId;

    iStream >> type;

    qDebug() << "AlarmNotifier: type" << type;

    if (type == 1) {
        iStream >> nodesNb;
        for (int i = 0; i < nodesNb; i++) {
            iStream >> nodeId;
            nodesId << nodeId;
        }
        qDebug() << "RECEIVED ALARM" << nodesId;
        iStream >> duration;
        emit nodesAlarm(nodesId, duration);
    } else if (type == 2) {
Esempio n. 16
0
bool ompl::tools::ThunderDB::load(const std::string &fileName)
{
    // Error checking
    if (fileName.empty())
    {
        OMPL_ERROR("Empty filename passed to save function");
        return false;
    }
    if (!boost::filesystem::exists(fileName))
    {
        OMPL_INFORM("Database file does not exist: %s.", fileName.c_str());
        return false;
    }
    if (!spars_)
    {
        OMPL_ERROR("SPARSdb planner has not been passed into the ThunderDB yet");
        return false;
    }

    // Load database from file, track loading time
    time::point start = time::now();

    OMPL_INFORM("Loading database from file: %s", fileName.c_str());

    // Open a binary input stream
    std::ifstream iStream(fileName.c_str(), std::ios::binary);

    // Get the total number of paths saved
    double numPaths = 0;
    iStream >> numPaths;

    // Check that the number of paths makes sense
    if (numPaths < 0 || numPaths > std::numeric_limits<double>::max())
    {
        OMPL_WARN("Number of paths to load %d is a bad value", numPaths);
        return false;
    }

    if (numPaths > 1)
    {
        OMPL_ERROR("Currently more than one planner data is disabled from loading");
        return false;
    }

    // Create a new planner data instance
    auto plannerData(std::make_shared<ompl::base::PlannerData>(si_));

    // Note: the StateStorage class checks if the states match for us
    plannerDataStorage_.load(iStream, *plannerData.get());

    OMPL_INFORM("ThunderDB: Loaded planner data with \n  %d vertices\n  %d edges\n  %d start states\n  %d goal states",
                plannerData->numVertices(), plannerData->numEdges(), plannerData->numStartVertices(),
                plannerData->numGoalVertices());

    // Add to SPARSdb
    OMPL_INFORM("Adding plannerData to SPARSdb:");
    spars_->setPlannerData(*plannerData);

    // Output the number of connected components
    OMPL_INFORM("  %d connected components", spars_->getNumConnectedComponents());

    // Close file
    iStream.close();

    double loadTime = time::seconds(time::now() - start);
    OMPL_INFORM("Loaded database from file in %f sec ", loadTime);
    return true;
}
	ERMsg BeginSession(IAgent* agent, __int32 sessionId, DWORD hxGridSessionId, IGenericStream* globalDataStream = NULL)
	{
		ERMsg msg;
		//EnterCriticalSection(&sessionDataCache.m_CS);
		CS.Enter();

		CSessionDataCache::iterator i = sessionDataCache.find(sessionId);

		if (i == sessionDataCache.end())
		{
			//----------- read global data -------------
			//CStdString tmp;
			//tmp.Format("Before init\nsessionId = %d\nhxGridSessionId = %d",sessionId, hxGridSessionId);
			//MessageBox(NULL, (LPCTSTR)tmp, "BeginSession", MB_OK);   
			if (globalDataStream == NULL)
			{
				ASSERT(agent);
				HRESULT rz = agent->GetData(hxGridSessionId, SIMULATED_ANNEALING_DATA_DESCRIPTOR, &globalDataStream);

				if (rz != S_OK)
				{
					CS.Leave();

					msg.ajoute(string("ERROR: agent->GetData from ") + SIMULATED_ANNEALING_DATA_DESCRIPTOR + " failed");
					return msg;
				}
			}

			//insert a new session
			sessionDataCache.insert(std::make_pair(sessionId, TSessionData()));
			i = sessionDataCache.find(sessionId);
			ASSERT(i != sessionDataCache.end());


			TSessionData& sd = i->second;

			istringstream iStream(string((char*)globalDataStream->GetBasePointer(), globalDataStream->GetLength()));
			msg = sd.m_modelVector.ReadStream(iStream);
			if (!msg)
				return msg;

			//free global stream. No longer need for this session
			if (agent)
			{
				//release global stream 
				globalDataStream->Release();
				agent->FreeCachedData(hxGridSessionId, SIMULATED_ANNEALING_DATA_DESCRIPTOR);

				//set agent on model
				for (CSimulatedAnnealingVector::iterator it = sd.m_modelVector.begin(); it != sd.m_modelVector.end(); it++)
				{
					(*it)->m_pAgent = agent;
					(*it)->m_hxGridSessionID = hxGridSessionId;
				}
			}
		}

		CS.Leave();

		return msg;
	}