Commit 7c8ae93f authored by hkrishna's avatar hkrishna

simple refactor of Socket serialization

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@25389 18c085ea-50e0-402c-830e-de6fd14e8384
parent baba8212
......@@ -37,6 +37,7 @@
*****************************************************************************/
#include <SocketConnection.h>
#include <AttributeSubject.h>
#include <AttributeSubjectSerialize.h>
#include <visit-config.h>
#if defined(_WIN32)
......@@ -890,3 +891,33 @@ SocketConnection::NeedsRead(bool blocking) const
return true;
#endif
}
std::string
AttributeSubjectSocketConnection::serializeMetaData(AttributeSubject *subject)
{
JSONNode meta;
JSONNode node;
subject->WriteAPI(meta);
node["id"] = subject->GetGuido();
node["typename"] = subject->TypeName();
node["api"] = meta; //.ToJSONNode(false,false);
return node.ToString();
}
std::string
AttributeSubjectSocketConnection::serializeAttributeSubject(AttributeSubject *subject) {
JSONNode child, metadata;
JSONNode node;
subject->Write(child);
subject->WriteMetaData(metadata);
node["id"] = subject->GetGuido();
node["typename"] = subject->TypeName();
node["contents"] = child; //.ToJSONNode(false,true);
node["metadata"] = metadata;
return node.ToString();
}
......@@ -110,7 +110,10 @@ public:
AttributeSubjectSocketConnection(DESCRIPTOR descriptor_): SocketConnection(descriptor_) {}
virtual ~AttributeSubjectSocketConnection() {}
virtual void Flush(AttributeSubject*) = 0;
virtual void FlushAttr(AttributeSubject*) = 0;
virtual int Fill() = 0;
std::string serializeMetaData(AttributeSubject*);
std::string serializeAttributeSubject(AttributeSubject*);
};
#endif
......@@ -203,45 +203,9 @@ AttributeSubjectSerialize::Flush(AttributeSubject *subject)
AttributeSubjectSocketConnection* ascomm = dynamic_cast<AttributeSubjectSocketConnection*>(conn);
if(ascomm) {
ascomm->Flush(subject);
ascomm->FlushAttr(subject);
}
else {
/*
if(subject->GetSendMetaInformation())
{
JSONNode meta;
JSONNode node;
subject->WriteAPI(meta);
node["id"] = subject->GetGuido();
node["typename"] = subject->TypeName();
node["api"] = meta;
const std::string& output = node.ToString().c_str();
conn->Append((const unsigned char *)output.c_str(), output.size());
conn->Flush();
}
JSONNode child, metadata;
JSONNode node;
subject->Write(child);
subject->WriteMetaData(metadata);
node["id"] = subject->GetGuido();
node["typename"] = subject->TypeName();
node["contents"] = child; //.ToJSONNode(false);
node["metadata"] = metadata; //.ToJSONNode(false);
const std::string& output = node.ToString();
conn->Append((const unsigned char *)output.c_str(), output.size());
conn->Flush();
*/
// std::cout << subject->TypeName() << " "
// << subject->CalculateMessageSize(*this)
// << std::endl;
if(subject->GetSendMetaInformation())
{
......@@ -277,6 +241,7 @@ AttributeSubjectSerialize::Flush(AttributeSubject *subject)
node["contents"] = child; //.ToJSONNode(false);
node["metadata"] = metadata; //.ToJSONNode(false);
const std::string& output = node.ToString().c_str();
#if defined(_WIN32)
send(conn->GetDescriptor(), (const char FAR *)output.c_str(), output.size(), 0);
#else
......
......@@ -1111,7 +1111,7 @@ WebSocketConnection::Fill()
//
// ****************************************************************************
void
WebSocketConnection::Flush(AttributeSubject *subject)
WebSocketConnection::FlushAttr(AttributeSubject *subject)
{
// std::cout << subject->TypeName() << " "
// << subject->CalculateMessageSize(*this)
......@@ -1123,37 +1123,39 @@ WebSocketConnection::Flush(AttributeSubject *subject)
try{
if(subject->GetSendMetaInformation())
{
JSONNode meta;
JSONNode node;
// JSONNode meta;
// JSONNode node;
subject->WriteAPI(meta);
// subject->WriteAPI(meta);
node["id"] = subject->GetGuido();
node["typename"] = subject->TypeName();
node["api"] = meta; //.ToJSONNode(false,false);
// node["id"] = subject->GetGuido();
// node["typename"] = subject->TypeName();
// node["api"] = meta; //.ToJSONNode(false,false);
std::string output = node.ToString();
// std::string output = node.ToString();
QString qoutput = output.c_str();
// QString qoutput = output.c_str();
QString qoutput = serializeMetaData(subject).c_str();
socket->write(qoutput);
if(socket->internalSocket()->state() != QAbstractSocket::UnconnectedState)
socket->internalSocket()->waitForBytesWritten();
}
JSONNode child, metadata;
JSONNode node;
// JSONNode child, metadata;
// JSONNode node;
subject->Write(child);
subject->WriteMetaData(metadata);
node["id"] = subject->GetGuido();
node["typename"] = subject->TypeName();
node["contents"] = child; //.ToJSONNode(false,true);
node["metadata"] = metadata;
// subject->Write(child);
// subject->WriteMetaData(metadata);
// node["id"] = subject->GetGuido();
// node["typename"] = subject->TypeName();
// node["contents"] = child; //.ToJSONNode(false,true);
// node["metadata"] = metadata;
std::string output = node.ToString();
// std::string output = node.ToString();
QString qoutput = output.c_str();
// QString qoutput = output.c_str();
QString qoutput = serializeAttributeSubject(subject).c_str();
socket->write(qoutput);
if(socket->internalSocket()->state() != QAbstractSocket::UnconnectedState)
......
......@@ -165,7 +165,7 @@ public:
virtual int Fill();
virtual void Flush();
virtual void Flush(AttributeSubject*);
virtual void FlushAttr(AttributeSubject*);
virtual long Size();
virtual void Write(unsigned char value);
virtual void Read(unsigned char *address);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment