aboutsummaryrefslogtreecommitdiffstats
path: root/src/daemon_clients/clienthandler.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon_clients/clienthandler.h')
-rw-r--r--src/daemon_clients/clienthandler.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/daemon_clients/clienthandler.h b/src/daemon_clients/clienthandler.h
new file mode 100644
index 0000000..1181294
--- /dev/null
+++ b/src/daemon_clients/clienthandler.h
@@ -0,0 +1,64 @@
+/* Copyright (C) 2022 The Qt Company Ltd.
+ *
+ * SPDX-License-Identifier: GPL-3.0-only WITH Qt-GPL-exception-1.0
+*/
+
+#pragma once
+
+#include <iostream>
+#include <string>
+#include "utils.h"
+#include "commonsetup.h"
+#include "licdsetup.h"
+#include "jsonhandler.h"
+
+class ClientHandler
+{
+ public:
+ ClientHandler(const RequestInfo &request, const LicdSetup &settings) :
+ m_request(request),
+ m_settings(settings)
+ { }
+ virtual ~ClientHandler()
+ { }
+ // If this client is using a floating model, it needs to be cached
+ // (Squish, Coco - Socket is alive until client stops working): Set this to true
+
+ std::vector<std::string> params;
+
+ virtual bool isCachedReservationValid(std::string &reply) = 0;
+ virtual bool isLicenseRequestDue() = 0;
+ virtual int parseAndSaveResponse(std::string &response) = 0;
+ virtual void buildRequestJson() = 0;
+
+ bool hasFloatingLicense() { return m_floatingLicense; }
+ void updateLicense(const std::string &responseJson);
+ int parseRequest();
+ RequestInfo getRequest() {return m_request;}
+ int getSocketId() { return m_request.socketId; }
+ RequestType getRequestType() { return m_request.type; }
+ int getClientType() { return (int)m_request.client; }
+ virtual void release() { return; }
+
+ protected:
+ License m_license;
+ RequestInfo m_request;
+ LicdSetup m_settings;;
+ uint64_t m_updateInterval;
+ bool m_floatingLicense = false;
+
+ bool checkLicenseExpiryTime(std::string &reply);
+ bool checkLeewayTime(std::string &reply);
+};
+
+static std::map<RequestReply, std::string> replyString {
+ {e_bad_request, "ERROR Bad request"},
+ {e_license_granted, "License acquired."},
+ {e_license_rejected, "No valid license acquired"},
+ {e_no_conn_leeway, "License granted with warning: No server connection. Leeway time left: "},
+ {e_license_pool_full, "All licenses in use. No more license available on the server."},
+ {e_bad_connection, "No connection to server. Try again later."}
+ };
+
+
+