Esempio n. 1
0
//-------------------------------------------------------------------------------------
void MercuryProfileHandler::timeout()
{
	MemoryStream s;

	s << timinglen_;

	ArraySize size = profileVals_.size();
	s << size;

	MercuryProfileHandler::PROFILEVALS::iterator iter = profileVals_.begin();
	for(; iter != profileVals_.end(); iter++)
	{
		MercuryProfileHandler::ProfileVal& profileVal = iter->second;

		s << profileVal.name;

		s << profileVal.send_count << profileVal.send_size << profileVal.send_avgsize << 
			profileVal.total_send_size << profileVal.total_send_count;

		s << profileVal.recv_count << profileVal.recv_size << profileVal.recv_avgsize << 
			profileVal.total_recv_size << profileVal.total_recv_count;
	}

	sendStream(&s);
}
Esempio n. 2
0
void BaseRequest::dispatch() {
    if (*static_cast<char*>(m_path + 1) == '\0') {
        sendLanding();
    } else {
        sendStream(m_path + 1);
    }
}
Esempio n. 3
0
//-------------------------------------------------------------------------------------
void EventProfileHandler::timeout()
{
	MemoryStream s;

	s << timinglen_;

	ArraySize size = profileMaps_.size();
	s << size;

	EventProfileHandler::PROFILEVALMAP::iterator iter = profileMaps_.begin();
	for(; iter != profileMaps_.end(); iter++)
	{
		std::string type_name = iter->first;
		PROFILEVALS& vals = iter->second;
		
		s << type_name;

		size = vals.size();
		s << size;

		EventProfileHandler::PROFILEVALS::iterator iter1 = vals.begin();
		for(; iter1 != vals.end(); iter1++)
		{
			ProfileVal& val = iter1->second;

			s << val.name;
			s << val.count;
			s << val.size;
		}
	}

	sendStream(&s);
}
Esempio n. 4
0
//-------------------------------------------------------------------------------------
bool PyTickProfileHandler::process()
{
	MemoryStream s;
	script::PyProfile::stop(name_);
	script::PyProfile::addToStream(name_, &s);
	script::PyProfile::remove(name_);
	script::PyProfile::start(name_);
	sendStream(&s);
	return true;
}
Esempio n. 5
0
//-------------------------------------------------------------------------------------
void PyProfileHandler::timeout()
{
	if(name_ != "kbengine" || !g_kbeSrvConfig.getBaseApp().profiles.open_pyprofile)
		script::PyProfile::stop(name_);

	MemoryStream s;
	script::PyProfile::addToStream(name_, &s);

	if(name_ == "kbengine" && g_kbeSrvConfig.getBaseApp().profiles.open_pyprofile)
		script::PyProfile::start(name_);
	
	sendStream(&s);
}
Esempio n. 6
0
//-------------------------------------------------------------------------------------
void PyProfileHandler::timeout()
{
	if(name_ != "kbengine" || !(g_componentType == BASEAPP_TYPE ? g_kbeSrvConfig.getBaseApp().profiles.open_pyprofile : 
		g_kbeSrvConfig.getCellApp().profiles.open_pyprofile))
		script::PyProfile::stop(name_);

	MemoryStream s;
	script::PyProfile::addToStream(name_, &s);

	if(name_ == "kbengine" && (g_componentType == BASEAPP_TYPE ? g_kbeSrvConfig.getBaseApp().profiles.open_pyprofile : 
		g_kbeSrvConfig.getCellApp().profiles.open_pyprofile))
		script::PyProfile::start(name_);
	
	sendStream(&s);
}
Esempio n. 7
0
		void MjpegServer::client(sockets::Socket_handle& fd) {
			connections_number++;
			last_connection_time = utils::getMilliseconds();
			LOG("MjpegServer (%d): HTTP client (%d) connected. Current number of clients: %d", port_, fd, connections_number);
			
			// start to send video stream to client

			sendStream(fd);

			// finish sending stream
			ugcs::vstreamer::sockets::Close_socket(fd);
			connections_number--;
			LOG("MjpegServer (%d): Disconnecting HTTP client. Clients left: %d.", port_, connections_number);
			return;
		}
Esempio n. 8
0
void CommandMaker::Start ()
{
  try {
    tcp::iostream socketStream (ip.toStdString().c_str(), port.toStdString().c_str() ); // Trying to connect

	if (!socketStream.fail() ) {
      cout << "CommandMaker: Connected!" << endl; // TODO: write in log
      #ifdef ENABLE_LOGGING
	  RAW_LOG (INFO, "CommandMaker: Connected!");
	  #endif
	  

	  boost::archive::xml_oarchive oa(socketStream); // We want to send commands in XML
	  
	  Command com;

	  while (!socketStream.fail() ) {
		// Reading command
		cout << "input command type (int):" << endl;
		cin >> com.ComType;
		cout << "input command condition (int):" << endl;
        cin >> com.ComCondition;
		cout << "input condition value (float):" << endl;
        cin >> com.Value;

		QByteArray block;
        QDataStream sendStream(&block, QIODevice::ReadWrite);
 
        sendStream << quint16(0) << com;
        sendStream.device()->seek(0);
        sendStream << (quint16)(block.size() - sizeof(quint16));
		socketStream.write(block,block.size());
		//oa << BOOST_SERIALIZATION_NVP(com); // Sending command
	  }
	
	}
  }
  catch (exception& e) {
    cout << "CommandMaker: Exception: " << e.what () << endl; // TODO: write in log
    #ifdef ENABLE_LOGGING
	  RAW_LOG (INFO, "CommandMaker: Exception: %s", e.what());
    #endif
  }
}
Esempio n. 9
0
void SendSender::Start ()
{
  try {
    
    boost::asio::io_service io_service;
	  tcp::endpoint endpoint (tcp::v4 (), port);
    tcp::acceptor acceptor (io_service, endpoint);

    tcp::iostream socketStream;

    cout << "SendSender: Waiting for connection.." << endl; //TODO: write in log
    #ifdef ENABLE_LOGGING
	  RAW_LOG (INFO, "SendSender: Waiting for connection..");
    #endif
    acceptor.accept (*socketStream.rdbuf ()); // waiting from connection from any IP
    cout << "SendSender: Connected!" << endl; //TODO: write in log
	  #ifdef ENABLE_LOGGING
    RAW_LOG (INFO, "SendSender: Connected!");
    #endif 
	
	  while (!socketStream.fail() ) {
		//boost::archive::xml_oarchive oa (socketStream); // We want to send objects in XML
	    boost::shared_ptr<Send> sendData;
	    sendData = buffer->Dequeue(); // Reading Send object from buffer
		QByteArray block;
        QDataStream sendStream(&block, QIODevice::ReadWrite);
 
        sendStream << quint16(0) << sendData;
        sendStream.device()->seek(0);
        sendStream << (quint16)(block.size() - sizeof(quint16));
		socketStream.write(block,block.size());
		//oa << BOOST_SERIALIZATION_NVP (sendData); // Serializing and sending it
	  } 
  }
  catch (exception& e) {
    cout << "SendSender: Exception: " << e.what () << endl; //TODO: write in log
    #ifdef ENABLE_LOGGING
	  RAW_LOG (INFO, "SendSender: Exception: %s", e.what());
    #endif
  }

}
Esempio n. 10
0
//-------------------------------------------------------------------------------------
void CProfileHandler::timeout()
{
	MemoryStream s;
	
	s << timinglen_;

	ArraySize size = profileVals_.size();
	s << size - 1;

	CProfileHandler::PROFILEVALS::iterator iter = profileVals_.begin();
	for(; iter != profileVals_.end(); iter++)
	{
		if(iter->first == "RunningTime")
		{
			continue;
		}

		uint32 count = iter->second.diff_count;

		float lastTime = (float)stampsToSeconds(iter->second.diff_lastTime);
		float sumTime = (float)stampsToSeconds(iter->second.diff_sumTime);
		float lastIntTime = (float)stampsToSeconds(iter->second.diff_lastIntTime);
		float sumIntTime = (float)stampsToSeconds(iter->second.diff_sumIntTime);

		if(lastTime < 0.000f)
			lastTime = 0.0f;

		if(sumTime < 0.000f)
			sumTime = 0.0f;

		if(lastIntTime < 0.000f)
			lastIntTime = 0.0f;

		if(sumIntTime < 0.000f)
			sumIntTime = 0.0f;

		s << iter->first << count << lastTime << sumTime << lastIntTime << sumIntTime;
	}

	sendStream(&s);
}
Esempio n. 11
0
//-------------------------------------------------------------------------------------
void SpaceViewer::initClient()
{
	MemoryStream s;

	// 先下发脚本ID对应脚本模块的名称,便于降低后面实体同步量,实体只同步id过去
	const EntityDef::SCRIPT_MODULES& scriptModules = EntityDef::getScriptModules();
	s << scriptModules.size();

	EntityDef::SCRIPT_MODULES::const_iterator moduleIter = scriptModules.begin();
	for (; moduleIter != scriptModules.end(); ++moduleIter)
	{
		s << moduleIter->get()->getUType();
		s << moduleIter->get()->getName();
	}

	sendStream(&s, updateType_);

	// 改变为更新实体
	updateType_ = 1;

	lastUpdateVersion_ = 0;
}
Esempio n. 12
0
int
streamFile(shout_t *shout, const char *fileName)
{
	FILE		*filepstream = NULL;
	int		 popenFlag = 0;
	char		*songLenStr = NULL;
	int		 isStdin = 0;
	int		 ret, retval = 0;
	long		 songLen;
	metadata_t	*mdata;
	struct timeval	 startTime;

	if ((filepstream = openResource(shout, fileName, &popenFlag,
					&mdata, &isStdin, &songLen))
	    == NULL) {
		if (++resource_errors > 100) {
			printf("%s: Too many errors -- giving up.\n", __progname);
			return (0);
		}
		/* Continue with next resource on failure: */
		return (1);
	}
	resource_errors = 0;

	if (mdata != NULL) {
		char	*tmp, *metaData;

		tmp = metadata_assemble_string(mdata);
		if ((metaData = UTF8toCHAR(tmp, ICONV_REPLACE)) == NULL)
			metaData = xstrdup("(unknown title)");
		xfree(tmp);
		printf("%s: Streaming ``%s''", __progname, metaData);
		if (vFlag)
			printf(" (file: %s)\n", fileName);
		else
			printf("\n");
		xfree(metaData);

		/* MP3 streams are special, so set the metadata explicitly: */
		if (strcmp(pezConfig->format, MP3_FORMAT) == 0)
			setMetadata(shout, mdata, NULL);

		metadata_free(&mdata);
	} else if (isStdin)
		printf("%s: Streaming from standard input\n", __progname);

	if (songLen > 0)
		songLenStr = xstrdup(getTimeString(songLen));
	ez_gettimeofday((void *)&startTime);
	do {
		ret = sendStream(shout, filepstream, fileName, isStdin,
				 songLenStr, &startTime);
		if (quit)
			break;
		if (ret != STREAM_DONE) {
			if ((skipTrack && rereadPlaylist) ||
			    (skipTrack && queryMetadata)) {
				skipTrack = 0;
				ret = STREAM_CONT;
			}
			if (queryMetadata && rereadPlaylist) {
				queryMetadata = 0;
				ret = STREAM_CONT;
			}
			if (ret == STREAM_SKIP || skipTrack) {
				skipTrack = 0;
				if (!isStdin && vFlag)
					printf("%s: SIGUSR1 signal received, skipping current track\n",
					       __progname);
				retval = 1;
				ret = STREAM_DONE;
			}
			if (ret == STREAM_UPDMDATA || queryMetadata) {
				queryMetadata = 0;
				if (mFlag)
					continue;
				if (metadataFromProgram) {
					char		*mdataStr = NULL;
					metadata_t	*prog_mdata;

					if (vFlag > 1)
						printf("%s: Querying '%s' for fresh metadata\n",
						       __progname, pezConfig->metadataProgram);
					if ((prog_mdata = getMetadata(pezConfig->metadataProgram)) == NULL) {
						retval = 0;
						ret = STREAM_DONE;
						continue;
					}
					if (setMetadata(shout, prog_mdata, &mdataStr) != SHOUTERR_SUCCESS) {
						retval = 0;
						ret = STREAM_DONE;
						continue;
					}
					metadata_free(&prog_mdata);
					if (vFlag > 1)
						printf("%s: New metadata: ``%s''\n",
						       __progname, mdataStr);
					xfree(mdataStr);
				}
			}
			if (ret == STREAM_SERVERR) {
				retval = 0;
				ret = STREAM_DONE;
			}
		} else
			retval = 1;
	} while (ret != STREAM_DONE);

	if (popenFlag)
		pclose(filepstream);
	else if (!isStdin)
		fclose(filepstream);

	if (songLenStr != NULL)
		xfree(songLenStr);

	return (retval);
}
Esempio n. 13
0
//-------------------------------------------------------------------------------------
void SpaceViewer::updateClient()
{
	if (spaceID_ == 0)
		return;

	Space* space = Spaces::findSpace(spaceID_);
	if (space == NULL || !space->isGood())
	{
		return;
	}

	// 最多每次更新500个实体
	const int MAX_UPDATE_COUNT = 100;
	int updateCount = 0;

	// 获取本次与上次结果的差值,将差值放入stream中更新到客户端
	// 差值包括新增的实体,以及已经有的实体的位置变化
	MemoryStream s;

	Entities<Entity>* pEntities = Cellapp::getSingleton().pEntities();
	Entities<Entity>::ENTITYS_MAP& entitiesMap = pEntities->getEntities();

	// 先检查已经监视的实体,对于版本号较低的优先更新
	if (updateCount < MAX_UPDATE_COUNT)
	{
		std::map< ENTITY_ID, ViewEntity >::iterator viewerIter = viewedEntities.begin();
		for (; viewerIter != viewedEntities.end(); )
		{
			if (updateCount >= MAX_UPDATE_COUNT)
				break;

			ViewEntity& viewEntity = viewerIter->second;
			if (viewEntity.updateVersion > lastUpdateVersion_)
				continue;

			Entities<Entity>::ENTITYS_MAP::iterator iter = entitiesMap.find(viewerIter->first);

			// 找不到实体, 说明已经销毁或者跑到其他进程了
			// 如果在其他进程, 其他进程会将其更新到客户端
			if (iter == entitiesMap.end())
			{
				s << viewerIter->first;
				s << false; // true为更新, false为销毁

				// 将其从viewedEntities删除
				viewedEntities.erase(viewerIter++);
			}
			else
			{
				Entity* pEntity = static_cast<Entity*>(iter->second.get());
				if (pEntity->spaceID() != spaceID_)
				{
					// 将其从viewedEntities删除
					viewedEntities.erase(viewerIter++);
					continue;
				}

				/*
				if (pEntity->cellID() != cellID_)
				{
					// 将其从viewedEntities删除
					viewedEntities.erase(viewerIter++);
					continue;
				}
				*/

				// 有新增的实体或者已经观察到的实体,检查位置变化
				// 如果没有变化则pass
				if ((viewEntity.position - pEntity->position()).length() <= 0.0004f &&
					(viewEntity.direction.dir - pEntity->direction().dir).length() <= 0.0004f)
				{
					++viewerIter;
					continue;
				}

				viewEntity.entityID = pEntity->id();
				viewEntity.position = pEntity->position();
				viewEntity.direction = pEntity->direction();
				++viewEntity.updateVersion;

				s << viewEntity.entityID;
				s << true; // true为更新, false为销毁
				s << pEntity->pScriptModule()->getUType();
				s << viewEntity.position.x << viewEntity.position.y << viewEntity.position.z;
				s << viewEntity.direction.roll() << viewEntity.direction.pitch() << viewEntity.direction.yaw();

				++updateCount;
				++viewerIter;
			}
		}
	}

	// 再检查是否有新增的实体
	if (updateCount < MAX_UPDATE_COUNT)
	{
		Entities<Entity>::ENTITYS_MAP::iterator iter = entitiesMap.begin();

		for (; iter != entitiesMap.end(); ++iter)
		{
			if (updateCount >= MAX_UPDATE_COUNT)
				break;

			Entity* pEntity = static_cast<Entity*>(iter->second.get());
			if (pEntity->spaceID() != spaceID_)
				continue;

			/*
			if (pEntity->cellID() != cellID_)
				continue;
			*/

			std::map< ENTITY_ID, ViewEntity >::iterator findIter = viewedEntities.find(pEntity->id());
			ViewEntity& viewEntity = viewedEntities[pEntity->id()];

			if (findIter != viewedEntities.end())
				continue;

			viewEntity.entityID = pEntity->id();
			viewEntity.position = pEntity->position();
			viewEntity.direction = pEntity->direction();
			viewEntity.updateVersion = lastUpdateVersion_ + 1;

			++updateCount;

			s << viewEntity.entityID;
			s << true; // true为更新, false为销毁
			s << pEntity->pScriptModule()->getUType();
			s << viewEntity.position.x << viewEntity.position.y << viewEntity.position.z;
			s << viewEntity.direction.roll() << viewEntity.direction.pitch() << viewEntity.direction.yaw();
		}
	}

	sendStream(&s, updateType_);

	// 如果全部更新完毕,更换版本号
	if (updateCount < MAX_UPDATE_COUNT)
		++lastUpdateVersion_;
}
void AbstractOutputStream::send(const QString& streamName, const DataBlob* dataBlob)
{
    verbose( QString("sending stream \"") + streamName + "\"");
    sendStream(streamName, dataBlob );
}