fae33e9235
This replaces grid hub usage in the material editor. It allows material editor and other tools to intercommunicate on the local host. This will allow enforcing that there is only one instance of the material editor running. Opening a second instance will forward command line options to the first instance running a local server. https://jira.agscollab.com/browse/ATOM-15439 https://jira.agscollab.com/browse/ATOM-13742
87 lines
2.7 KiB
C++
87 lines
2.7 KiB
C++
/*
|
|
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
* its licensors.
|
|
*
|
|
* For complete copyright and license terms please see the LICENSE at the root of this
|
|
* distribution (the "License"). All use of this software is governed by the License,
|
|
* or, if provided, by the license below or the license accompanying this file. Do not
|
|
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
*
|
|
*/
|
|
|
|
#include <AtomToolsFramework/Communication/LocalSocket.h>
|
|
#include <AzCore/Debug/Trace.h>
|
|
#include <QByteArray>
|
|
#include <QString>
|
|
|
|
namespace AtomToolsFramework
|
|
{
|
|
LocalSocket::LocalSocket()
|
|
{
|
|
}
|
|
|
|
LocalSocket::~LocalSocket()
|
|
{
|
|
Disconnect();
|
|
}
|
|
|
|
bool LocalSocket::Connect(const QString& serverName)
|
|
{
|
|
Disconnect();
|
|
|
|
m_serverName = serverName;
|
|
|
|
AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Connecting to: %s\n", m_serverName.toUtf8().constData());
|
|
m_socket.connectToServer(m_serverName);
|
|
|
|
if (IsConnected())
|
|
{
|
|
AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Waiting for connection to: %s\n", m_serverName.toUtf8().constData());
|
|
if (m_socket.waitForConnected())
|
|
{
|
|
AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Connected to: %s\n", m_serverName.toUtf8().constData());
|
|
return true;
|
|
}
|
|
}
|
|
|
|
AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Connecting failed: %s\n", m_serverName.toUtf8().constData());
|
|
Disconnect();
|
|
return false;
|
|
}
|
|
|
|
void LocalSocket::Disconnect()
|
|
{
|
|
if (IsConnected())
|
|
{
|
|
AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Disconnecting from: %s\n", m_serverName.toUtf8().constData());
|
|
m_socket.disconnectFromServer();
|
|
m_socket.waitForDisconnected();
|
|
|
|
AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Closing socket\n");
|
|
m_socket.close();
|
|
}
|
|
}
|
|
|
|
bool LocalSocket::IsConnected() const
|
|
{
|
|
return m_socket.isOpen();
|
|
}
|
|
|
|
bool LocalSocket::Send(const QByteArray& buffer)
|
|
{
|
|
if (IsConnected())
|
|
{
|
|
AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Sending data to: %s\n", m_serverName.toUtf8().constData());
|
|
m_socket.write(buffer);
|
|
|
|
AZ_TracePrintf("AtomToolsFramework::LocalSocket", "Waiting for write to: %s\n", m_serverName.toUtf8().constData());
|
|
m_socket.waitForBytesWritten();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
} // namespace AtomToolsFramework
|
|
|
|
#include <AtomToolsFramework/Communication/moc_LocalSocket.cpp>
|