summaryrefslogtreecommitdiffstats
path: root/Source/cmServerConnection.h
diff options
context:
space:
mode:
authorJustin Berger <j.david.berger@gmail.com>2017-03-25 03:38:52 (GMT)
committerJustin Berger <j.david.berger@gmail.com>2017-07-11 00:11:27 (GMT)
commitd4f5d35ca491ede92003b26a7d0eb06aea3a2bbb (patch)
tree90f665b7e1611c47ab8eaa3f069e9572d3df58fb /Source/cmServerConnection.h
parent5acbf08bff643ec6779464c840bfe2f02a4e65ae (diff)
downloadCMake-d4f5d35ca491ede92003b26a7d0eb06aea3a2bbb.zip
CMake-d4f5d35ca491ede92003b26a7d0eb06aea3a2bbb.tar.gz
CMake-d4f5d35ca491ede92003b26a7d0eb06aea3a2bbb.tar.bz2
server: Refactor to make the event loop owned by server object
Diffstat (limited to 'Source/cmServerConnection.h')
-rw-r--r--Source/cmServerConnection.h94
1 files changed, 36 insertions, 58 deletions
diff --git a/Source/cmServerConnection.h b/Source/cmServerConnection.h
index b96bf3c..8865480 100644
--- a/Source/cmServerConnection.h
+++ b/Source/cmServerConnection.h
@@ -2,68 +2,46 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once
-#include "cmConfigure.h"
+#include "cmConnection.h"
+#include "cmPipeConnection.h"
#include "cm_uv.h"
#include <string>
-class cmFileMonitor;
-class cmServer;
+class cmServerBase;
-class cmServerConnection
+/***
+ * This connection buffer strategy accepts messages in the form of
+ * [== "CMake Server" ==[
+{
+ ... some JSON message ...
+}
+]== "CMake Server" ==]
+ * and only passes on the core json; it discards the envelope.
+ */
+class cmServerBufferStrategy : public cmConnectionBufferStrategy
{
- CM_DISABLE_COPY(cmServerConnection)
-
public:
- cmServerConnection();
- virtual ~cmServerConnection();
-
- void SetServer(cmServer* s);
-
- bool ProcessEvents(std::string* errorMessage);
-
- void ReadData(const std::string& data);
- void TriggerShutdown();
- void WriteData(const std::string& data);
- void ProcessNextRequest();
-
- virtual void Connect(uv_stream_t* server) { (void)(server); }
-
- cmFileMonitor* FileMonitor() const { return this->mFileMonitor; }
-
-protected:
- virtual bool DoSetup(std::string* errorMessage) = 0;
- virtual void TearDown() = 0;
-
- void SendGreetings();
-
- uv_loop_t* Loop() const { return mLoop; }
-
-protected:
- std::string RawReadBuffer;
- std::string RequestBuffer;
-
- uv_stream_t* ReadStream = nullptr;
- uv_stream_t* WriteStream = nullptr;
+ std::string BufferMessage(std::string& rawBuffer) override;
private:
- uv_loop_t* mLoop = nullptr;
- cmFileMonitor* mFileMonitor = nullptr;
- cmServer* Server = nullptr;
- uv_signal_t* SIGINTHandler = nullptr;
- uv_signal_t* SIGHUPHandler = nullptr;
-
- friend class LoopGuard;
+ std::string RequestBuffer;
};
-class cmServerStdIoConnection : public cmServerConnection
+/***
+ * Generic connection over std io interfaces -- tty
+ */
+class cmStdIoConnection : public cmConnection
{
public:
- cmServerStdIoConnection();
- bool DoSetup(std::string* errorMessage) override;
+ cmStdIoConnection(cmConnectionBufferStrategy* bufferStrategy);
+
+ void SetServer(cmServerBase* s) override;
+
+ bool OnServerShuttingDown() override;
- void TearDown() override;
+ bool OnServeStart(std::string* pString) override;
private:
typedef union
@@ -78,18 +56,18 @@ private:
InOutUnion Output;
};
-class cmServerPipeConnection : public cmServerConnection
+/***
+ * These specific connections use the cmake server
+ * buffering strategy.
+ */
+class cmServerStdIoConnection : public cmStdIoConnection
{
public:
- cmServerPipeConnection(const std::string& name);
- bool DoSetup(std::string* errorMessage) override;
-
- void TearDown() override;
-
- void Connect(uv_stream_t* server) override;
+ cmServerStdIoConnection();
+};
-private:
- const std::string PipeName;
- uv_pipe_t* ServerPipe = nullptr;
- uv_pipe_t* ClientPipe = nullptr;
+class cmServerPipeConnection : public cmPipeConnection
+{
+public:
+ cmServerPipeConnection(const std::string& name);
};