summaryrefslogtreecommitdiffstats
path: root/examples/activeqt/opengl
diff options
context:
space:
mode:
authorDavid Boddie <dboddie@trolltech.com>2010-05-19 16:58:12 (GMT)
committerDavid Boddie <dboddie@trolltech.com>2010-05-19 16:58:12 (GMT)
commitc2f6ff4d8c2235bfd25407486950e7f8a071a51d (patch)
treebdb6313b0a60cc519916f430070c6512ab396de4 /examples/activeqt/opengl
parentfbacc859b8fa62eb4d42a58924c97949fbc4147b (diff)
downloadQt-c2f6ff4d8c2235bfd25407486950e7f8a071a51d.zip
Qt-c2f6ff4d8c2235bfd25407486950e7f8a071a51d.tar.gz
Qt-c2f6ff4d8c2235bfd25407486950e7f8a071a51d.tar.bz2
Doc: Updated example license to three clause BSD license.
Reviewed-by: Trust Me Requested-by: Legal
Diffstat (limited to 'examples/activeqt/opengl')
-rw-r--r--examples/activeqt/opengl/glbox.cpp57
-rw-r--r--examples/activeqt/opengl/glbox.h57
-rw-r--r--examples/activeqt/opengl/globjwin.cpp53
-rw-r--r--examples/activeqt/opengl/globjwin.h57
-rw-r--r--examples/activeqt/opengl/main.cpp53
5 files changed, 136 insertions, 141 deletions
diff --git a/examples/activeqt/opengl/glbox.cpp b/examples/activeqt/opengl/glbox.cpp
index 3fe4b65..0534cea 100644
--- a/examples/activeqt/opengl/glbox.cpp
+++ b/examples/activeqt/opengl/glbox.cpp
@@ -6,35 +6,34 @@
**
** This file is part of the examples of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/
diff --git a/examples/activeqt/opengl/glbox.h b/examples/activeqt/opengl/glbox.h
index dc054e2..d1c1901 100644
--- a/examples/activeqt/opengl/glbox.h
+++ b/examples/activeqt/opengl/glbox.h
@@ -6,35 +6,34 @@
**
** This file is part of the examples of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/
diff --git a/examples/activeqt/opengl/globjwin.cpp b/examples/activeqt/opengl/globjwin.cpp
index 55fd0b8..ff5b61a 100644
--- a/examples/activeqt/opengl/globjwin.cpp
+++ b/examples/activeqt/opengl/globjwin.cpp
@@ -6,35 +6,34 @@
**
** This file is part of the examples of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/
diff --git a/examples/activeqt/opengl/globjwin.h b/examples/activeqt/opengl/globjwin.h
index e967f3e..a1a3e39 100644
--- a/examples/activeqt/opengl/globjwin.h
+++ b/examples/activeqt/opengl/globjwin.h
@@ -6,35 +6,34 @@
**
** This file is part of the examples of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/
diff --git a/examples/activeqt/opengl/main.cpp b/examples/activeqt/opengl/main.cpp
index f8f0f6b..3b6f067 100644
--- a/examples/activeqt/opengl/main.cpp
+++ b/examples/activeqt/opengl/main.cpp
@@ -6,35 +6,34 @@
**
** This file is part of the examples of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/
n class="hl opt">(request), debug.get()); } else { this->WriteResponse(connection, this->SetProtocolVersion(request), debug.get()); } } void cmServer::RegisterProtocol(cmServerProtocol* protocol) { if (protocol->IsExperimental() && !this->SupportExperimental) { delete protocol; return; } auto version = protocol->ProtocolVersion(); assert(version.first >= 0); assert(version.second >= 0); auto it = std::find_if(this->SupportedProtocols.begin(), this->SupportedProtocols.end(), [version](cmServerProtocol* p) { return p->ProtocolVersion() == version; }); if (it == this->SupportedProtocols.end()) { this->SupportedProtocols.push_back(protocol); } } void cmServer::PrintHello(cmConnection* connection) const { Json::Value hello = Json::objectValue; hello[kTYPE_KEY] = "hello"; Json::Value& protocolVersions = hello[kSUPPORTED_PROTOCOL_VERSIONS] = Json::arrayValue; for (auto const& proto : this->SupportedProtocols) { auto version = proto->ProtocolVersion(); Json::Value tmp = Json::objectValue; tmp[kMAJOR_KEY] = version.first; tmp[kMINOR_KEY] = version.second; if (proto->IsExperimental()) { tmp[kIS_EXPERIMENTAL_KEY] = true; } protocolVersions.append(tmp); } this->WriteJsonObject(connection, hello, nullptr); } void cmServer::reportProgress(const std::string& msg, float progress, const cmServerRequest& request) { if (progress < 0.0f || progress > 1.0f) { request.ReportMessage(msg, ""); } else { request.ReportProgress(0, static_cast<int>(progress * 1000), 1000, msg); } } void cmServer::reportMessage(const std::string& msg, const char* title, const cmServerRequest& request) { std::string titleString; if (title) { titleString = title; } request.ReportMessage(msg, titleString); } cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request) { if (request.Type != kHANDSHAKE_TYPE) { return request.ReportError("Waiting for type \"" + kHANDSHAKE_TYPE + "\"."); } Json::Value requestedProtocolVersion = request.Data[kPROTOCOL_VERSION_KEY]; if (requestedProtocolVersion.isNull()) { return request.ReportError("\"" + kPROTOCOL_VERSION_KEY + "\" is required for \"" + kHANDSHAKE_TYPE + "\"."); } if (!requestedProtocolVersion.isObject()) { return request.ReportError("\"" + kPROTOCOL_VERSION_KEY + "\" must be a JSON object."); } Json::Value majorValue = requestedProtocolVersion[kMAJOR_KEY]; if (!majorValue.isInt()) { return request.ReportError("\"" + kMAJOR_KEY + "\" must be set and an integer."); } Json::Value minorValue = requestedProtocolVersion[kMINOR_KEY]; if (!minorValue.isNull() && !minorValue.isInt()) { return request.ReportError("\"" + kMINOR_KEY + "\" must be unset or an integer."); } const int major = majorValue.asInt(); const int minor = minorValue.isNull() ? -1 : minorValue.asInt(); if (major < 0) { return request.ReportError("\"" + kMAJOR_KEY + "\" must be >= 0."); } if (!minorValue.isNull() && minor < 0) { return request.ReportError("\"" + kMINOR_KEY + "\" must be >= 0 when set."); } this->Protocol = cmServer::FindMatchingProtocol(this->SupportedProtocols, major, minor); if (!this->Protocol) { return request.ReportError("Protocol version not supported."); } std::string errorMessage; if (!this->Protocol->Activate(this, request, &errorMessage)) { this->Protocol = nullptr; return request.ReportError("Failed to activate protocol version: " + errorMessage); } return request.Reply(Json::objectValue); } bool cmServer::Serve(std::string* errorMessage) { if (this->SupportedProtocols.empty()) { *errorMessage = "No protocol versions defined. Maybe you need --experimental?"; return false; } assert(!this->Protocol); return cmServerBase::Serve(errorMessage); } cmFileMonitor* cmServer::FileMonitor() const { return fileMonitor.get(); } void cmServer::WriteJsonObject(const Json::Value& jsonValue, const DebugInfo* debug) const { cm::shared_lock<cm::shared_mutex> lock(ConnectionsMutex); for (auto& connection : this->Connections) { WriteJsonObject(connection.get(), jsonValue, debug); } } void cmServer::WriteJsonObject(cmConnection* connection, const Json::Value& jsonValue, const DebugInfo* debug) const { Json::FastWriter writer; auto beforeJson = uv_hrtime(); std::string result = writer.write(jsonValue); if (debug) { Json::Value copy = jsonValue; if (debug->PrintStatistics) { Json::Value stats = Json::objectValue; auto endTime = uv_hrtime(); stats["jsonSerialization"] = double(endTime - beforeJson) / 1000000.0; stats["totalTime"] = double(endTime - debug->StartTime) / 1000000.0; stats["size"] = static_cast<int>(result.size()); if (!debug->OutputFile.empty()) { stats["dumpFile"] = debug->OutputFile; } copy["zzzDebug"] = stats; result = writer.write(copy); // Update result to include debug info } if (!debug->OutputFile.empty()) { cmsys::ofstream myfile(debug->OutputFile.c_str()); myfile << result; } } connection->WriteData(result); } cmServerProtocol* cmServer::FindMatchingProtocol( const std::vector<cmServerProtocol*>& protocols, int major, int minor) { cmServerProtocol* bestMatch = nullptr; for (auto protocol : protocols) { auto version = protocol->ProtocolVersion(); if (major != version.first) { continue; } if (minor == version.second) { return protocol; } if (!bestMatch || bestMatch->ProtocolVersion().second < version.second) { bestMatch = protocol; } } return minor < 0 ? bestMatch : nullptr; } void cmServer::WriteProgress(const cmServerRequest& request, int min, int current, int max, const std::string& message) const { assert(min <= current && current <= max); assert(message.length() != 0); Json::Value obj = Json::objectValue; obj[kTYPE_KEY] = kPROGRESS_TYPE; obj[kREPLY_TO_KEY] = request.Type; obj[kCOOKIE_KEY] = request.Cookie; obj[kPROGRESS_MESSAGE_KEY] = message; obj[kPROGRESS_MINIMUM_KEY] = min; obj[kPROGRESS_MAXIMUM_KEY] = max; obj[kPROGRESS_CURRENT_KEY] = current; this->WriteJsonObject(request.Connection, obj, nullptr); } void cmServer::WriteMessage(const cmServerRequest& request, const std::string& message, const std::string& title) const { if (message.empty()) { return; } Json::Value obj = Json::objectValue; obj[kTYPE_KEY] = kMESSAGE_TYPE; obj[kREPLY_TO_KEY] = request.Type; obj[kCOOKIE_KEY] = request.Cookie; obj[kMESSAGE_KEY] = message; if (!title.empty()) { obj[kTITLE_KEY] = title; } WriteJsonObject(request.Connection, obj, nullptr); } void cmServer::WriteParseError(cmConnection* connection, const std::string& message) const { Json::Value obj = Json::objectValue; obj[kTYPE_KEY] = kERROR_TYPE; obj[kERROR_MESSAGE_KEY] = message; obj[kREPLY_TO_KEY] = ""; obj[kCOOKIE_KEY] = ""; this->WriteJsonObject(connection, obj, nullptr); } void cmServer::WriteSignal(const std::string& name, const Json::Value& data) const { assert(data.isObject()); Json::Value obj = data; obj[kTYPE_KEY] = kSIGNAL_TYPE; obj[kREPLY_TO_KEY] = ""; obj[kCOOKIE_KEY] = ""; obj[kNAME_KEY] = name; WriteJsonObject(obj, nullptr); } void cmServer::WriteResponse(cmConnection* connection, const cmServerResponse& response, const DebugInfo* debug) const { assert(response.IsComplete()); Json::Value obj = response.Data(); obj[kCOOKIE_KEY] = response.Cookie; obj[kTYPE_KEY] = response.IsError() ? kERROR_TYPE : kREPLY_TYPE; obj[kREPLY_TO_KEY] = response.Type; if (response.IsError()) { obj[kERROR_MESSAGE_KEY] = response.ErrorMessage(); } this->WriteJsonObject(connection, obj, debug); } void cmServer::OnConnected(cmConnection* connection) { PrintHello(connection); } void cmServer::OnServeStart() { cmServerBase::OnServeStart(); fileMonitor = std::make_shared<cmFileMonitor>(GetLoop()); } void cmServer::StartShutDown() { if (fileMonitor) { fileMonitor->StopMonitoring(); fileMonitor.reset(); } cmServerBase::StartShutDown(); } static void __start_thread(void* arg) { auto server = static_cast<cmServerBase*>(arg); std::string error; bool success = server->Serve(&error); if (!success || !error.empty()) { std::cerr << "Error during serve: " << error << std::endl; } } bool cmServerBase::StartServeThread() { ServeThreadRunning = true; uv_thread_create(&ServeThread, __start_thread, this); return true; } static void __shutdownThread(uv_async_t* arg) { auto server = static_cast<cmServerBase*>(arg->data); server->StartShutDown(); } bool cmServerBase::Serve(std::string* errorMessage) { #ifndef NDEBUG uv_thread_t blank_thread_t = {}; assert(uv_thread_equal(&blank_thread_t, &ServeThreadId)); ServeThreadId = uv_thread_self(); #endif errorMessage->clear(); ShutdownSignal.init(Loop, __shutdownThread, this); SIGINTHandler.init(Loop, this); SIGHUPHandler.init(Loop, this); SIGINTHandler.start(&on_signal, SIGINT); SIGHUPHandler.start(&on_signal, SIGHUP); OnServeStart(); { cm::shared_lock<cm::shared_mutex> lock(ConnectionsMutex); for (auto& connection : Connections) { if (!connection->OnServeStart(errorMessage)) { return false; } } } if (uv_run(&Loop, UV_RUN_DEFAULT) != 0) { // It is important we don't ever let the event loop exit with open handles // at best this is a memory leak, but it can also introduce race conditions // which can hang the program. assert(false && "Event loop stopped in unclean state."); *errorMessage = "Internal Error: Event loop stopped in unclean state."; return false; } return true; } void cmServerBase::OnConnected(cmConnection*) { } void cmServerBase::OnServeStart() { } void cmServerBase::StartShutDown() { ShutdownSignal.reset(); SIGINTHandler.reset(); SIGHUPHandler.reset(); { std::unique_lock<cm::shared_mutex> lock(ConnectionsMutex); for (auto& connection : Connections) { connection->OnConnectionShuttingDown(); } Connections.clear(); } uv_walk(&Loop, on_walk_to_shutdown, nullptr); } bool cmServerBase::OnSignal(int signum) { (void)signum; StartShutDown(); return true; } cmServerBase::cmServerBase(cmConnection* connection) { auto err = uv_loop_init(&Loop); (void)err; Loop.data = this; assert(err == 0); AddNewConnection(connection); } void cmServerBase::Close() { if (Loop.data) { if (ServeThreadRunning) { this->ShutdownSignal.send(); uv_thread_join(&ServeThread); } uv_loop_close(&Loop); Loop.data = nullptr; } } cmServerBase::~cmServerBase() { Close(); } void cmServerBase::AddNewConnection(cmConnection* ownedConnection) { { std::unique_lock<cm::shared_mutex> lock(ConnectionsMutex); Connections.emplace_back(ownedConnection); } ownedConnection->SetServer(this); } uv_loop_t* cmServerBase::GetLoop() { return &Loop; } void cmServerBase::OnDisconnect(cmConnection* pConnection) { auto pred = [pConnection](const std::unique_ptr<cmConnection>& m) { return m.get() == pConnection; }; { std::unique_lock<cm::shared_mutex> lock(ConnectionsMutex); Connections.erase( std::remove_if(Connections.begin(), Connections.end(), pred), Connections.end()); } if (Connections.empty()) { this->ShutdownSignal.send(); } }