diff --git a/README.md b/README.md index dff9819..5201ca2 100644 --- a/README.md +++ b/README.md @@ -1 +1,26 @@ -# jus \ No newline at end of file +jus +=== + +`jus` is a Json ยต-service + +Instructions +============ + +TODO ... + +License (APACHE v2.0) +===================== +Copyright jus Edouard DUPIN + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + diff --git a/jus/Client.cpp b/jus/Client.cpp new file mode 100644 index 0000000..2120581 --- /dev/null +++ b/jus/Client.cpp @@ -0,0 +1,7 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ + + diff --git a/jus/Client.h b/jus/Client.h new file mode 100644 index 0000000..530ac1e --- /dev/null +++ b/jus/Client.h @@ -0,0 +1,19 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ +#pragma once + +#include + +namespace jus { + class Client { + private: + jus::TcpString m_interfaceClient; + public: + Client() {} + virtual ~Client() {} + }; +} + diff --git a/jus/GateWay.cpp b/jus/GateWay.cpp new file mode 100644 index 0000000..738a17b --- /dev/null +++ b/jus/GateWay.cpp @@ -0,0 +1,62 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ + +#include +#include + + + +jus::GateWay::GateWay() : + propertyClientIp(this, "client-ip", "127.0.0.1", "Ip to listen client", &jus::GateWay::onPropertyChangeClientIp), + propertyClientPort(this, "client-port", 1983, "Port to listen client", &jus::GateWay::onPropertyChangeClientPort), + propertyClientMax(this, "client-max", 80, "Maximum of client at the same time", &jus::GateWay::onPropertyChangeClientMax), + propertyServiceIp(this, "service-ip", "127.0.0.1", "Ip to listen client", &jus::GateWay::onPropertyChangeServiceIp), + propertyServicePort(this, "service-port", 1982, "Port to listen client", &jus::GateWay::onPropertyChangeServicePort), + propertyServiceMax(this, "service-max", 80, "Maximum of client at the same time", &jus::GateWay::onPropertyChangeServiceMax) { + +} + +jus::GateWay::~GateWay() { + +} + +void jus::GateWay::start() { + m_clientWaiting = std::make_shared(); + m_clientConnected = m_clientWaiting->signalIsConnected.connect(this, &jus::GateWay::onClientConnect); + m_clientWaiting->start(*propertyClientIp, *propertyClientPort); +} + +void jus::GateWay::stop() { + +} + +void jus::GateWay::onClientConnect(const bool& _value) { + JUS_TODO("lklklk: " << _value); +} + +void jus::GateWay::onPropertyChangeClientIp() { + +} + +void jus::GateWay::onPropertyChangeClientPort() { + +} + +void jus::GateWay::onPropertyChangeClientMax() { + +} + +void jus::GateWay::onPropertyChangeServiceIp() { + +} + +void jus::GateWay::onPropertyChangeServicePort() { + +} + +void jus::GateWay::onPropertyChangeServiceMax() { + +} diff --git a/jus/GateWay.h b/jus/GateWay.h new file mode 100644 index 0000000..5bd7140 --- /dev/null +++ b/jus/GateWay.h @@ -0,0 +1,40 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ +#pragma once +#include +#include + +namespace jus { + class GateWay : public eproperty::Interface { + private: + std::vector> m_serviceList; //!< List of all service availlable with their specific connection interface + std::vector> m_clientList; //!< List of all Client interface with their own connection + //TODO: std::vector m_ServerList; //!< List of all Server connected to this gateway + ememory::SharedPtr m_clientWaiting; + esignal::Connection m_clientConnected; + public: + eproperty::Value propertyClientIp; + eproperty::Value propertyClientPort; + eproperty::Value propertyClientMax; + eproperty::Value propertyServiceIp; + eproperty::Value propertyServicePort; + eproperty::Value propertyServiceMax; + public: + GateWay(); + virtual ~GateWay(); + void start(); + void stop(); + private: + void onPropertyChangeClientIp(); + void onPropertyChangeClientPort(); + void onPropertyChangeClientMax(); + void onPropertyChangeServiceIp(); + void onPropertyChangeServicePort(); + void onPropertyChangeServiceMax(); + void onClientConnect(const bool& _value); + }; +} + diff --git a/jus/GateWayClient.cpp b/jus/GateWayClient.cpp new file mode 100644 index 0000000..84c2606 --- /dev/null +++ b/jus/GateWayClient.cpp @@ -0,0 +1,26 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ + +#include + +jus::GateWayClient::GateWayClient() { + +} + +jus::GateWayClient::~GateWayClient() { + +} + +void jus::GateWayClient::start(const std::string& _ip, uint16_t _port) { + m_interfaceClient.propertyIp.set(_ip); + m_interfaceClient.propertyPort.set(_port); + +} + +void jus::GateWayClient::stop() { + +} + diff --git a/jus/GateWayClient.h b/jus/GateWayClient.h new file mode 100644 index 0000000..2385450 --- /dev/null +++ b/jus/GateWayClient.h @@ -0,0 +1,24 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ +#pragma once + +#include +#include +#include + +namespace jus { + class GateWayClient { + public: + jus::TcpString m_interfaceClient; + esignal::Signal signalIsConnected; + public: + GateWayClient(); + virtual ~GateWayClient(); + void start(const std::string& _ip, uint16_t _port); + void stop(); + }; +} + diff --git a/jus/GateWayService.cpp b/jus/GateWayService.cpp new file mode 100644 index 0000000..e69de29 diff --git a/jus/GateWayService.h b/jus/GateWayService.h new file mode 100644 index 0000000..62c0569 --- /dev/null +++ b/jus/GateWayService.h @@ -0,0 +1,21 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ +#pragma once + +#include +#include + +namespace jus { + class GateWayService { + public: + ememory::SharedPtr m_interfaceService; + std::string m_name; + public: + GateWayService(const ememory::SharedPtr& _interface); + virtual ~GateWayService(); + }; +} + diff --git a/jus/Service.cpp b/jus/Service.cpp new file mode 100644 index 0000000..2120581 --- /dev/null +++ b/jus/Service.cpp @@ -0,0 +1,7 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ + + diff --git a/jus/Service.h b/jus/Service.h new file mode 100644 index 0000000..16b2d7a --- /dev/null +++ b/jus/Service.h @@ -0,0 +1,21 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ +#pragma once + + +namespace jus { + class Service { + public: + //eproperty::Value propertyServiceName; + public: + Service(); + virtual ~Service(); + private: + // TODO: ... + void bind(const std::string& _functionName) {} + }; +} + diff --git a/jus/TcpString.cpp b/jus/TcpString.cpp new file mode 100644 index 0000000..5e61f7f --- /dev/null +++ b/jus/TcpString.cpp @@ -0,0 +1,70 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ +#include +#include + +jus::TcpString::TcpString() : + propertyIp(this, "ip", "127.0.0.1", "ip to open or connect server", &jus::TcpString::onPropertyChangeIp), + propertyPort(this, "port", 1983, "Connection port of the server", &jus::TcpString::onPropertyChangePort), + propertyServer(this, "server", false, "is a server or not", &jus::TcpString::onPropertyChangeServer) { + m_connection.setHostNane(*propertyIp); + m_connection.setPort(*propertyPort); + m_connection.setServer(*propertyServer); +} + +jus::TcpString::~TcpString() { + +} + +void jus::TcpString::connect(){ + if (m_connection.link() == false) { + JUS_ERROR("can not connect to the socket..."); + } +} + +void jus::TcpString::disconnect(){ + if (m_connection.unlink() == false) { + JUS_ERROR("can not disconnect to the socket..."); + } +} + +int32_t jus::TcpString::write(const std::string& _data) { + if (_data.size() == 0) { + return 0; + } + uint32_t size = _data.size(); + m_connection.write(&size, 4); + return m_connection.write(_data.c_str(), _data.size()); +} + +std::string jus::TcpString::read() { + std::string out; + uint32_t size = 0; + int32_t len = m_connection.read(&size, 4); + if (len != 4) { + JUS_ERROR("Protocol error occured ..."); + } else { + out.resize(size); + len = m_connection.read(&out[0], size); + if (len != 4) { + JUS_ERROR("Protocol error occured .2."); + } + } + return out; +} + +void jus::TcpString::onPropertyChangeIp() { + m_connection.setHostNane(*propertyIp); +} + +void jus::TcpString::onPropertyChangePort() { + m_connection.setPort(*propertyPort); +} + +void jus::TcpString::onPropertyChangeServer() { + m_connection.setServer(*propertyServer); +} + diff --git a/jus/TcpString.h b/jus/TcpString.h new file mode 100644 index 0000000..bfa35a1 --- /dev/null +++ b/jus/TcpString.h @@ -0,0 +1,34 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ +#pragma once +#include +#include +#include +#include + +namespace jus { + class TcpString : public eproperty::Interface { + private: + enet::Tcp m_connection; + std::unique_ptr m_receiveThread; + public: + eproperty::Value propertyIp; + eproperty::Value propertyPort; + eproperty::Value propertyServer; + public: + TcpString(); + virtual ~TcpString(); + void connect(); + void disconnect(); + int32_t write(const std::string& _data); + std::string read(); + private: + void onPropertyChangeIp(); + void onPropertyChangePort(); + void onPropertyChangeServer(); + }; +} + diff --git a/jus/debug.cpp b/jus/debug.cpp new file mode 100644 index 0000000..18ea08a --- /dev/null +++ b/jus/debug.cpp @@ -0,0 +1,12 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2014, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ + +#include + +int32_t jus::getLogId() { + static int32_t g_val = elog::registerInstance("jus"); + return g_val; +} diff --git a/jus/debug.h b/jus/debug.h new file mode 100644 index 0000000..fa8ca1a --- /dev/null +++ b/jus/debug.h @@ -0,0 +1,39 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2014, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ +#pragma once + +#include + +namespace jus { + int32_t getLogId(); +}; + +#define JUS_BASE(info,data) ELOG_BASE(jus::getLogId(),info,data) + +#define JUS_CRITICAL(data) JUS_BASE(1, data) +#define JUS_ERROR(data) JUS_BASE(2, data) +#define JUS_WARNING(data) JUS_BASE(3, data) +#ifdef DEBUG + #define JUS_INFO(data) JUS_BASE(4, data) + #define JUS_DEBUG(data) JUS_BASE(5, data) + #define JUS_VERBOSE(data) JUS_BASE(6, data) + #define JUS_TODO(data) JUS_BASE(4, "TODO : " << data) +#else + #define JUS_INFO(data) do { } while(false) + #define JUS_DEBUG(data) do { } while(false) + #define JUS_VERBOSE(data) do { } while(false) + #define JUS_TODO(data) do { } while(false) +#endif + +#define JUS_ASSERT(cond,data) \ + do { \ + if (!(cond)) { \ + JUS_CRITICAL(data); \ + assert(!#cond); \ + } \ + } while (0) + + diff --git a/lutinParseSubFolders.txt b/lutinParseSubFolders.txt new file mode 100644 index 0000000..3f09102 --- /dev/null +++ b/lutinParseSubFolders.txt @@ -0,0 +1 @@ +tools/gateway \ No newline at end of file diff --git a/lutin_jus.py b/lutin_jus.py new file mode 100644 index 0000000..0f52403 --- /dev/null +++ b/lutin_jus.py @@ -0,0 +1,58 @@ +#!/usr/bin/python +import lutin.module as module +import lutin.tools as tools + + +def get_type(): + return "LIBRARY" + +def get_desc(): + return "Json micro-service" + +def get_licence(): + return "APACHE-2" + +def get_compagny_type(): + return "com" + +def get_compagny_name(): + return "atria-soft" + +def get_maintainer(): + return ["Mr DUPIN Edouard "] + +def get_version(): + return [0,1,"dev"] + +def create(target, module_name): + my_module = module.Module(__file__, module_name, get_type()) + my_module.add_module_depend(['etk', 'enet', 'ememory', 'eproperty', 'esignal']) + my_module.add_src_file([ + 'jus/debug.cpp' + ]) + my_module.add_path(tools.get_current_path(__file__)) + my_module.add_src_file([ + 'jus/Client.cpp', + 'jus/GateWay.cpp', + 'jus/GateWayService.cpp', + 'jus/GateWayClient.cpp', + 'jus/Service.cpp', + 'jus/TcpString.cpp', + ]) + my_module.add_header_file([ + 'jus/debug.h', + 'jus/Client.h', + 'jus/GateWay.h', + 'jus/GateWayService.h', + 'jus/GateWayClient.h', + 'jus/Service.h', + 'jus/TcpString.h', + ]) + return my_module + + + + + + + diff --git a/tools/gateway/__pycache__/lutin_jus-gateway.cpython-35.pyc b/tools/gateway/__pycache__/lutin_jus-gateway.cpython-35.pyc new file mode 100644 index 0000000..cbf4774 Binary files /dev/null and b/tools/gateway/__pycache__/lutin_jus-gateway.cpython-35.pyc differ diff --git a/tools/gateway/appl/debug.cpp b/tools/gateway/appl/debug.cpp new file mode 100644 index 0000000..c035407 --- /dev/null +++ b/tools/gateway/appl/debug.cpp @@ -0,0 +1,12 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ + +#include + +int32_t appl::getLogId() { + static int32_t g_val = elog::registerInstance("jus-gateway"); + return g_val; +} diff --git a/tools/gateway/appl/debug.h b/tools/gateway/appl/debug.h new file mode 100644 index 0000000..d422118 --- /dev/null +++ b/tools/gateway/appl/debug.h @@ -0,0 +1,40 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2016, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ +#pragma once + +#include + +namespace appl { + int32_t getLogId(); +}; + +#define APPL_BASE(info,data) ELOG_BASE(appl::getLogId(),info,data) + +#define APPL_PRINT(data) APPL_BASE(-1, data) +#define APPL_CRITICAL(data) APPL_BASE(1, data) +#define APPL_ERROR(data) APPL_BASE(2, data) +#define APPL_WARNING(data) APPL_BASE(3, data) +#ifdef DEBUG + #define APPL_INFO(data) APPL_BASE(4, data) + #define APPL_DEBUG(data) APPL_BASE(5, data) + #define APPL_VERBOSE(data) APPL_BASE(6, data) + #define APPL_TODO(data) APPL_BASE(4, "TODO : " << data) +#else + #define APPL_INFO(data) do { } while(false) + #define APPL_DEBUG(data) do { } while(false) + #define APPL_VERBOSE(data) do { } while(false) + #define APPL_TODO(data) do { } while(false) +#endif + +#define APPL_ASSERT(cond,data) \ + do { \ + if (!(cond)) { \ + APPL_CRITICAL(data); \ + assert(!#cond); \ + } \ + } while (0) + + diff --git a/tools/gateway/appl/main.cpp b/tools/gateway/appl/main.cpp new file mode 100644 index 0000000..4a512d3 --- /dev/null +++ b/tools/gateway/appl/main.cpp @@ -0,0 +1,55 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2014, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ + +#include +#include +#include +#include + +#include + +int main(int _argc, const char *_argv[]) { + etk::init(_argc, _argv); + jus::GateWay basicGateway; + for (int32_t iii=0; iii<_argc ; ++iii) { + std::string data = _argv[iii]; + if (etk::start_with(data, "--client-ip=") == true) { + basicGateway.propertyClientIp.set(std::string(&data[12])); + } else if (etk::start_with(data, "--client-port=") == true) { + basicGateway.propertyClientPort.set(etk::string_to_uint16_t(std::string(&data[14]))); + } else if (etk::start_with(data, "--client-max=") == true) { + basicGateway.propertyClientMax.set(etk::string_to_uint16_t(std::string(&data[13]))); + } else if (etk::start_with(data, "--service-ip=") == true) { + basicGateway.propertyServiceIp.set(std::string(&data[13])); + } else if (etk::start_with(data, "--service-port=") == true) { + basicGateway.propertyServicePort.set(etk::string_to_uint16_t(std::string(&data[15]))); + } else if (etk::start_with(data, "--service-max=") == true) { + basicGateway.propertyServiceMax.set(etk::string_to_uint16_t(std::string(&data[14]))); + } else if ( data == "-h" + || data == "--help") { + APPL_PRINT(etk::getApplicationName() << " - help : "); + APPL_PRINT(" " << _argv[0] << " [options]"); + APPL_PRINT(" --client-ip=XXX Client connection IP (default: 1.7.0.0.1)"); + APPL_PRINT(" --client-port=XXX Client connection PORT (default: 1983)"); + APPL_PRINT(" --client-max=XXX Clainet Maximum parallele connection (default: 80)"); + APPL_PRINT(" --service-ip=XXX Service connection IP (default: 1.7.0.0.1)"); + APPL_PRINT(" --service-port=XXX Service connection PORT (default: 1984)"); + APPL_PRINT(" --service-max=XXX Service Maximum IO (default: 15)"); + return -1; + } + } + APPL_INFO("=================================="); + APPL_INFO("== JUS gateway start =="); + APPL_INFO("=================================="); + basicGateway.start(); + while (true) { + usleep(200000); + } + APPL_INFO("=================================="); + APPL_INFO("== JUS gateway stop =="); + APPL_INFO("=================================="); + return 0; +} diff --git a/tools/gateway/lutin_jus-gateway.py b/tools/gateway/lutin_jus-gateway.py new file mode 100644 index 0000000..680aa78 --- /dev/null +++ b/tools/gateway/lutin_jus-gateway.py @@ -0,0 +1,38 @@ +#!/usr/bin/python +import lutin.module as module +import lutin.tools as tools + + +def get_type(): + return "BINARY" + +def get_sub_type(): + return "TOOLS" + +def get_desc(): + return "JUS generic gateway" + +def get_licence(): + return "APACHE-2" + +def get_compagny_type(): + return "com" + +def get_compagny_name(): + return "atria-soft" + +def get_maintainer(): + return ["Mr DUPIN Edouard "] + +def create(target, module_name): + my_module = module.Module(__file__, module_name, get_type()) + my_module.add_export_path(tools.get_current_path(__file__)) + my_module.add_module_depend(['jus']) + my_module.add_src_file([ + 'appl/debug.cpp', + 'appl/main.cpp' + ]) + return my_module + + +