Example #1
0
void SharedDaemon::AddNewClient(const std::string &host, const stringVector &args, void *cbdata)
{
    /// Send appropriate message for TCP or WebConnection
    void** data = (void**)cbdata;
    ConnectionType typeOfConnection = *((ConnectionType*)(data[0]));
    QAbstractSocket* socket = static_cast<QAbstractSocket*>(data[1]);
    ViewerState* viewerState = static_cast<ViewerState*>(data[2]);

    JSONNode node;

    QString hostname = typeOfConnection == TcpConnection ? socket->localAddress().toString():
                        dynamic_cast<QWsSocket*>(socket)->internalSocket()->localAddress().toString();

    if(hostMap.contains(hostname)) hostname = hostMap[hostname];

    node["host"] = hostname.toStdString(); //host
    node["port"]  = args[7]; //port
    node["version"] = args[2]; //version
    node["securityKey"] = args[9]; //key
    node["numStates"] = viewerState->GetNumStateObjects(); //number of states

    JSONNode::JSONArray rpc_array = JSONNode::JSONArray();

    for(size_t i = 0; i < ViewerRPC::MaxRPC; ++i) {
        rpc_array.push_back(ViewerRPC::ViewerRPCType_ToString((ViewerRPC::ViewerRPCType)i));
    }
    node["rpc_array"] = rpc_array;

    if(typeOfConnection == TcpConnection)
    {
        QTcpSocket *tsocket = dynamic_cast<QTcpSocket*>(socket);

        std::string message = node.ToString();
        tsocket->write(message.c_str(),message.length());

        if(tsocket->state() != QAbstractSocket::UnconnectedState)
            tsocket->waitForBytesWritten();
        tsocket->disconnectFromHost();
        if(tsocket->state() != QAbstractSocket::UnconnectedState)
            tsocket->waitForDisconnected();
        //HKTODO: Do not delete connection (test fix for ORNL machines)
        //tsocket->deleteLater();
    }
    else
    {
        QWsSocket *wsocket = dynamic_cast<QWsSocket*>(socket);

        wsocket->write(QString(node.ToString().c_str()));
        wsocket->flush();
        if(wsocket->internalSocket()->state() != QAbstractSocket::UnconnectedState)
            wsocket->internalSocket()->waitForBytesWritten();

        wsocket->close("");
        wsocket->internalSocket()->disconnectFromHost();
        if(wsocket->internalSocket()->state() != QAbstractSocket::UnconnectedState)
            wsocket->internalSocket()->waitForDisconnected();
        wsocket->deleteLater();
    }
}
// ****************************************************************************
// Method: SocketConnection::Flush
//
// Purpose: 
//   Writes the entire contents of the connection's buffer onto the
//   socket file descriptor in chunks. It then clears the buffer.
//
//
// Programmer: Brad Whitlock
// Creation:   Tue Aug 29 12:17:37 PDT 2000
//
// Modifications:
//   Brad Whitlock, Tue Mar 26 13:29:20 PST 2002
//   Made it use socket functions so it is more portable.
//
//   Brad Whitlock, Thu Jan 25 18:42:50 PST 2007
//   I made it use MSG_NOSIGNAL so we don't get a signal in the event that
//   we can't write to the socket.
//
//   Eric Brugger, Tue Mar 13 09:18:48 PDT 2007
//   I made the use of MSG_NOSIGNAL conditional on its definition.
//
// ****************************************************************************
void
SocketConnection::Flush(AttributeSubject *subject)
{
    if(destFormat.Format == TypeRepresentation::BINARYFORMAT)
        Connection::Flush(subject);
    else
    {
//        std::cout << subject->TypeName() << " "
//                  << subject->CalculateMessageSize(*this)
//                  << std::endl;

        if(subject->GetSendMetaInformation())
        {
            MapNode meta;
            JSONNode node;

            subject->WriteMeta(meta);

            node["id"] = subject->GetGuido();
            node["typename"] = subject->TypeName();
            node["api"] = meta.ToJSONNode(false,false);

            const std::string& output = node.ToString().c_str();

#if defined(_WIN32)
            send(descriptor, (const char FAR *)output.c_str(), output.size(), 0);
#else
#ifdef MSG_NOSIGNAL
            send(descriptor, (const void *)output.c_str(), output.size(), MSG_NOSIGNAL);
#else
            send(descriptor, (const void *)output.c_str(), output.size(), 0);
#endif
#endif
        }

        MapNode child;
        JSONNode node;

        subject->Write(child);

        node["id"] = subject->GetGuido();
        node["typename"] = subject->TypeName();
        node["contents"] = child.ToJSONNode(false);

        const std::string& output = node.ToString();

#if defined(_WIN32)
            send(descriptor, (const char FAR *)output.c_str(), output.size(), 0);
#else
#ifdef MSG_NOSIGNAL
            send(descriptor, (const void *)output.c_str(), output.size(), MSG_NOSIGNAL);
#else
            send(descriptor, (const void *)output.c_str(), output.size(), 0);
#endif
#endif
        buffer.clear();
    }
}
/// we are always returning true unless the script
/// itself is failing not the inquiry..
bool
avtProgrammableOperation::avtVisItGetVarInfo::func(ProgrammableOpArguments& args, Variant& result)
{
    std::string varName = args.getArg(0).AsString();
    vtkDataSet* dataset = args.GetInputDataSet();
    bool pointData = true;
    vtkDataArray* array = dataset->GetPointData()->GetScalars(varName.c_str());

    if(!array) {
        array = dataset->GetCellData()->GetScalars(varName.c_str());
        pointData = false;
    }

    /// for now just deal with scalars..
    if(array == NULL)
    {
        result = "";
        return true;
    }

    /// now extract information from the array..
    /// through in mesh dimensions to help inquiring class reshape
    /// information correctly..
    JSONNode resultNode;
    resultNode["type"] = pointData ? "pointdata" : "celldata";
    JSONNode::JSONArray dims(3,-1);
    resultNode["dims"] = dims;

    result = resultNode.ToString();

    return true;
}
Example #4
0
void SharedDaemon::AddNewClient(const std::string &host, const stringVector &args, void *cbdata)
{
    /// Send appropriate message for TCP or WebConnection
    void** data = (void**)cbdata;
    ConnectionType typeOfConnection = *((ConnectionType*)(data[0]));
    QAbstractSocket* socket = static_cast<QAbstractSocket*>(data[1]);

    JSONNode node;

    node["host"] = args[5]; //host
    node["port"]  = args[7]; //port
    node["version"] = args[2]; //version
    node["securityKey"] = args[9]; //key

    if(typeOfConnection == TcpConnection)
    {
        QTcpSocket *tsocket = dynamic_cast<QTcpSocket*>(socket);

        std::string message = node.ToString();
        tsocket->write(message.c_str(),message.length());
        tsocket->waitForBytesWritten();
        tsocket->disconnectFromHost();
        tsocket->waitForDisconnected();
        tsocket->deleteLater();
    }
    else
    {
        QWsSocket *wsocket = dynamic_cast<QWsSocket*>(socket);

        wsocket->write(QString(node.ToString().c_str()));
        wsocket->flush();
        wsocket->internalSocket()->waitForBytesWritten();

        wsocket->close();
        wsocket->internalSocket()->disconnectFromHost();
        wsocket->internalSocket()->waitForDisconnected();
        wsocket->deleteLater();
    }
}
bool
avtProgrammableOperation::avtProgrammableOperation::avtVisItGetMeshInfo::func(ProgrammableOpArguments& args, Variant& result)
{
    vtkDataSet *dataset = args.GetInputDataSet();

    vtkRectilinearGrid *rg = vtkRectilinearGrid::SafeDownCast(dataset);
    if (dataset->GetDataObjectType() != VTK_RECTILINEAR_GRID || rg == NULL)
    {
    result = "";
    return true;
    }
    
    JSONNode resultNode;
    resultNode["type"] = "rectilinear_grid";
    JSONNode::JSONArray dims(3, -1);
    int numX = rg->GetDimensions()[0];
    int numY = rg->GetDimensions()[1];
    int numZ = rg->GetDimensions()[2];

    dims[0] = numX;
    dims[1] = numY;
    dims[2] = numZ;

    vtkDataArray *x = rg->GetXCoordinates();
    vtkDataArray *y = rg->GetYCoordinates();
    vtkDataArray *z = rg->GetZCoordinates();

    JSONNode::JSONArray xc(numX, -1);
    JSONNode::JSONArray yc(numY, -1);
    JSONNode::JSONArray zc(numZ, -1);

    for (int i = 0; i < numX; i++)
    xc[i] = x->GetTuple1(i);
    for (int i = 0; i < numY; i++)
    yc[i] = y->GetTuple1(i);
    for (int i = 0; i < numZ; i++)
    zc[i] = z->GetTuple1(i);
    
    resultNode["dims"] = dims;
    resultNode["x_coords"] = xc;
    resultNode["y_coords"] = yc;
    resultNode["z_coords"] = zc;
    result = resultNode.ToString();
    return true;
}