예제 #1
0
result_t HeapSnapshotProxy::save(const char* fname, AsyncEvent* ac)
{
	class BufferStream : public v8::OutputStream {
	public:
		virtual void EndOfStream()
		{}

		virtual WriteResult WriteAsciiChunk(char* data, int size)
		{
			m_buf.append(data, size);
			return kContinue;
		}

		std::string result()
		{
			return m_buf.str();
		}

	private:
		StringBuffer m_buf;
	};

	BufferStream bs;
	m_snapshot->Serialize(&bs);

	return fs_base::ac_writeFile(fname, bs.result().c_str());
}
예제 #2
0
result_t HeapSnapshot::serialize(std::string& retVal)
{
	class BufferStream : public v8::OutputStream {
	public:
		virtual void EndOfStream()
		{}

		virtual WriteResult WriteAsciiChunk(char* data, int size)
		{
			m_buf.append(data, size);
			return kContinue;
		}

		std::string result()
		{
			return m_buf.str();
		}

	private:
		StringBuffer m_buf;
	};

	BufferStream bs;

	m_snapshot->Serialize(&bs);
	retVal = bs.result();

	return 0;
}
예제 #3
0
void BufferStream::FlushOnReadWrite(StreamDataOperation curOperation)const
{
	if (IsReadWrite() && mPrevOperation != curOperation)
	{
		BufferStream* stream = const_cast<BufferStream*>(this);	//force cast to non-const
		stream->Flush();

		mPrevOperation = curOperation;
	}
}
예제 #4
0
파일: Batch.cpp 프로젝트: SeijiEmery/hifi
void Batch::setInputStream(Slot startChannel, const BufferStream& stream) {
    if (stream.getNumBuffers()) {
        const Buffers& buffers = stream.getBuffers();
        const Offsets& offsets = stream.getOffsets();
        const Offsets& strides = stream.getStrides();
        for (unsigned int i = 0; i < buffers.size(); i++) {
            setInputBuffer(startChannel + i, buffers[i], offsets[i], strides[i]);
        }
    }
}
예제 #5
0
bool LoginConnexion::OnLoginRequest(ThreadPoolLocalStorage *tls, BufferStream msg, u32 bytes)
{
	WARN("LoginConnexion") << _client_addr.IPToString() << ':' << _client_addr.GetPort() << " : Got LoginRequest";

	// Validate name
	char *name = msg.c_str() + 1 + 64;
	int name_len = GetFixedStrLen(name, USER_NAME_MAXLEN);

	if (!ValidLoginServerUserName(name, name_len))
	{
		WriteReliable(STREAM_1, LC_LOGIN_BAD_NAME);
		return true;
	}

	// Validate alias
	char *alias = name + USER_NAME_MAXLEN;
	int alias_len = GetFixedStrLen(alias, USER_NAME_MAXLEN);

	if (!ValidLoginServerUserName(alias, alias_len))
	{
		WriteReliable(STREAM_1, LC_LOGIN_BAD_ALIAS);
		return true;
	}

	// Copy message data into connexion object
	SetFixedStr(_account_name, sizeof(_account_name), name, name_len);
	SetFixedStr(_alias_name, sizeof(_alias_name), alias, alias_len);
	memcpy(_public_key, msg+1, sizeof(_public_key));

	// Expect ban ids next
	_state = SS_LOGIN_BANID_CDROM;
	return true;
}
예제 #6
0
void OutXmlSerializer::pushStructure(const char* name, SerializableStructure* structure, Pointer* ptr)
{
	ZENIC_ASSERT(structure);

	XmlElement* st = new XmlElement;
	st->setValue("struct");

	if (name)
		st->setAttribute("name",name);

	SerializableFactory* factory = structure->factory();
	{
		BufferStream temp;
		temp << hex << setw(8) << setfill('0') << factory->host();
		st->setAttribute("host",temp.string());
	}
	{
		BufferStream temp;
		temp << hex << setw(8) << setfill('0') << factory->type();
		st->setAttribute("type",temp.string());
	}
	{
		BufferStream temp;
		temp << hex << setw(8) << setfill('0') << structure->identifier();
		st->setAttribute("id",temp.string());
	}

	if (ptr->m_allocator && (ptr->m_allocator != &HeapAllocator::allocator()))
	{
		BufferStream temp;
		temp << hex << setfill('0') << setw(8) << ptr->m_allocator->handle();
		st->setAttribute("allocator",temp.string());
	}
	
	{
		BufferStream temp;
		temp << ptr->m_count;
		st->setAttribute("count",temp.string());
	}

	m_stack.pushBack(m_current);
	m_current->addChild(st);
	m_current = st;
}
예제 #7
0
void OutXmlSerializer::process(const char* name, Serializable*& object)
{
	XmlElement* reference = new XmlElement;
	reference->setValue("ref");

	if (name)
		reference->setAttribute("name",name);

	XmlText* text = new XmlText;

	if (object)
	{
		// insert into list if needed

		uint i;

		for (i = 0; i < m_objects.count(); ++i)
		{
			if (m_objects[i] == object)
				break;
		}

		if (i == m_objects.count())
			m_objects.pushBack(object);

		BufferStream temp;
		temp << i;
		text->setValue(temp.string());
	}
	else
		text->setValue("null");

	reference->addChild(text);

	ZENIC_ASSERT(m_current);
	m_current->addChild(reference);
}
예제 #8
0
void OutXmlSerializer::process(const char* name, const char* valueType, BufferStream& value)
{
	XmlElement* variable = zenic_new XmlElement;
	variable->setValue(valueType);

	if (name)
		variable->setAttribute("name",name);

	XmlText* text = zenic_new XmlText;
	text->setValue(value.string());
	variable->addChild(text);

	ZENIC_ASSERT(m_current);
	m_current->addChild(variable);
}
예제 #9
0
void OutXmlSerializer::process(SerializableVersion& version)
{
	if (!m_current)
	{
		ZENIC_ASSERT(version.factory());

		XmlElement* current = zenic_new XmlElement;
		current->setValue("object");
		
		{
			BufferStream temp;
			temp << m_currentIndex;
			current->setAttribute("id",temp.string());
		}

		{
			BufferStream temp;
			temp << hex << setw(8) << setfill('0') << version.factory()->host();
			current->setAttribute("host",temp.string());
		}

		{
			BufferStream temp;
			temp << hex << setw(8) << setfill('0') << version.factory()->type();
			current->setAttribute("type",temp.string());
		}

		m_current = current;
	}

	XmlElement* v = zenic_new XmlElement;
	v->setValue("version");

	XmlText* text = zenic_new XmlText;
	BufferStream temp;
	temp << version.version();
	text->setValue(temp.string());
	v->addChild(text);

	m_current->addChild(v);
}
예제 #10
0
void LoginAdminClient::OnAddPlayer(ThreadPoolLocalStorage *tls, BufferStream msg, u32 bytes)
{
	if (bytes < 1 + 2 + 1)
	{
		WARN("AdminClient") << "Corrupted add player packet";
		on_disconnect();
		return;
	}

	u16 id;
	++msg >> id;

	Player &player = _player_list[id];

	SetFixedStr(player.name, USER_NAME_MAXLEN+1, msg.c_str(), bytes - 3);

	WARN("AdminClient") << "Player joined: " << player.name;

	on_add_player(player.name);
}
예제 #11
0
void LoginAdminClient::OnChat(ThreadPoolLocalStorage *tls, BufferStream msg, u32 bytes)
{
	if (bytes < 1 + 2)
	{
		WARN("AdminClient") << "Corrupted chat packet";
		on_disconnect();
		return;
	}

	u32 msglen = bytes - 3;

	u16 id;
	++msg >> id;

	QString chatline = QString::fromAscii(msg.c_str(), msglen);

	Player &player = _player_list[id];

	WARN("AdminClient") << "<" << player.name << "> " << chatline.toAscii().data();

	on_chat_message(player.name, chatline);
}
예제 #12
0
void OutXmlSerializer::process(const char* name, Pointer* ptr, u32 elementSize)
{
	XmlElement* data = new XmlElement;
	data->setValue("data");

	if (name)
		data->setAttribute("name",name);

	if ((&m_allocation.allocator()) != (&HeapAllocator::allocator()))
	{
		BufferStream temp;
		temp << hex << setfill('0') << setw(8) << ptr->m_allocator->handle();

		data->setAttribute("allocator",temp.string());
	}

	if (m_allocation.alignment() != SerializableAllocation::DefaultAlignment)
	{
		BufferStream temp;
		temp << m_allocation.alignment();
		data->setAttribute("align",temp.string());
	}

	if (ptr->m_count > 0)
	{
		BufferStream temp;
		temp << ptr->m_count;
		data->setAttribute("count",temp.string());
	}

	{
		BufferStream temp;
		temp << elementSize;
		data->setAttribute("size",temp.string());
	}

	{
		BufferStream temp;
		Base64::encode(temp,ptr->m_objects,elementSize * ptr->m_count);

		if (temp.buffer().count() > 0)
		{
			XmlText* text = zenic_new XmlText;
			text->setValue(temp.string());
			data->addChild(text);
		}
	}	

	ZENIC_ASSERT(m_current);
	m_current->addChild(data);

	m_allocation = SerializableAllocation();
}