├── .gitignore ├── LICENSE ├── README.md └── src ├── impl ├── http_client.cpp ├── rqlite_impl.cpp └── rqlite_impl.hpp ├── rqlite.hpp └── rqlite_factory.hpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 rqlite 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rqlite-cpp 2 | C++ client for rqlite. 3 | -------------------------------------------------------------------------------- /src/impl/http_client.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class HTTPClient { 5 | 6 | public: 7 | HTTPClient() : 8 | socket_(io_service_), 9 | resolver_(io_service_) 10 | {}; 11 | 12 | void Get() {}; 13 | void Post() {}; 14 | 15 | private: 16 | boost::asio::io_service io_service_; 17 | boost::asio::ip::tcp::resolver resolver_; 18 | boost::asio::ip::tcp::socket socket_; 19 | 20 | void request() { 21 | boost::asio::ip::tcp::resolver::query query(boost::asio::ip::tcp::v4(), argv[1], argv[2]); 22 | boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver_.resolve(query); 23 | boost::asio::connect(socket, endpoint_iterator); 24 | 25 | // Form the request. We specify the "Connection: close" header so that the 26 | // server will close the socket after transmitting the response. This will 27 | // allow us to treat all data up until the EOF as the content. 28 | boost::asio::streambuf request; 29 | std::ostream request_stream(&request); 30 | request_stream << "GET " << argv[3] << " HTTP/1.0\r\n"; 31 | request_stream << "Host: " << argv[1] << "\r\n"; 32 | request_stream << "Accept: */*\r\n"; 33 | request_stream << "Connection: close\r\n\r\n"; 34 | 35 | // Send the request. 36 | boost::asio::write(socket, request); 37 | } 38 | 39 | }; 40 | -------------------------------------------------------------------------------- /src/impl/rqlite_impl.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "rqlite_impl.hpp" 3 | 4 | const std::string DefaultProto = "http"; 5 | const std::string DefaultHost = "localhost"; 6 | const int DefaultPort = 4001; 7 | 8 | RqliteImpl::RqliteImpl() { 9 | this->proto = DefaultProto; 10 | this->host = DefaultHost; 11 | this->port = DefaultPort; 12 | } 13 | 14 | RqliteImpl::RqliteImpl(std::string proto, std::string host, int port) { 15 | this->proto = proto; 16 | this->host = host; 17 | this->port = port; 18 | } 19 | 20 | void RqliteImpl::Open() { 21 | } 22 | 23 | void RqliteImpl::Close() { 24 | } 25 | 26 | Pong* RqliteImpl::Ping() { 27 | return NULL; 28 | } 29 | -------------------------------------------------------------------------------- /src/impl/rqlite_impl.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RQLITE_IMPL_HPP 2 | #define RQLITE_HPP 3 | 4 | #include 5 | #include "rqlite.hpp" 6 | 7 | class RqliteImpl : Rqlite { 8 | public: 9 | RqliteImpl(); 10 | RqliteImpl(std::string proto, std::string host, int port); 11 | ~RqliteImpl() {}; 12 | 13 | void Open(); 14 | void Close(); 15 | Pong* Ping(); 16 | 17 | private: 18 | std::string proto; 19 | std::string host; 20 | int port; 21 | }; 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/rqlite.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RQLITE_H 2 | #define RQLITE_H 3 | 4 | #include 5 | 6 | enum ReadConsistencyLevel { 7 | kNone = 0, 8 | kWeak, 9 | kStrong 10 | }; 11 | 12 | class Pong { 13 | public: 14 | std::string version; 15 | 16 | Pong() { 17 | this->version = "unknown"; 18 | } 19 | 20 | Pong(std::string version) { 21 | this->version = version; 22 | } 23 | }; 24 | 25 | class Rqlite { 26 | public: 27 | // Open opens a connection to the node. 28 | virtual void Open() = 0; 29 | 30 | // Close closes the connection to the node. 31 | virtual void Close() = 0; 32 | 33 | // Ping checks communication with the rqlite node. */ 34 | virtual Pong* Ping() = 0; 35 | }; 36 | 37 | #endif // RQLITE_H 38 | -------------------------------------------------------------------------------- /src/rqlite_factory.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RQLITE_FACTORY_HPP 2 | #define RQLITE_FACTORY_HPP 3 | 4 | #include 5 | #include "rqlite.hpp" 6 | #include "impl/rqliteImpl.hpp" 7 | 8 | class RqliteFactory { 9 | public: 10 | static Rqlite Connect(string proto, string host, int port) { 11 | return new RqliteImpl(proto,host, port); 12 | } 13 | }; 14 | 15 | #endif // RQLITE_FACTORY_HPP 16 | --------------------------------------------------------------------------------