diff --git a/examples/pub/CMakeLists.txt b/examples/pub/CMakeLists.txt
index 0e3c279..d26ac52 100644
--- a/examples/pub/CMakeLists.txt
+++ b/examples/pub/CMakeLists.txt
@@ -5,7 +5,7 @@ include(projectheader)
project_header(test_mqtt_pub)
include_directories( SYSTEM
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../include
)
include(compiler)
@@ -21,7 +21,7 @@ add_executable( ${PROJECT_NAME}
target_link_libraries(
${PROJECT_NAME}
- mqtt
+ mqtt-cpp
)
set_target_properties( ${PROJECT_NAME} PROPERTIES
diff --git a/examples/pub/main.cpp b/examples/pub/main.cpp
index dd85a8e..9c181de 100644
--- a/examples/pub/main.cpp
+++ b/examples/pub/main.cpp
@@ -78,7 +78,7 @@ int main( int argc, char* argv[] )
{
std::cout << "{OK}" << std::endl;
std::cout << "Connecting to the broker : ";
- pPublisher->connect( "localhost", 1883, "", "" );
+ pPublisher->connect( "office.osdev.nl", 1883, "", "" );
// Assume we are connected now, start publishing.
while( 1 )
@@ -86,7 +86,7 @@ int main( int argc, char* argv[] )
std::string payload = "" ;
pPublisher->publish( std::string( "test/publisher/TestPublisher" ), payload );
- sleepcp( 1, T_SECONDS );
+ sleepcp( 1, T_MICRO );
if( messageNumber > 2000000000 )
messageNumber = -1;
diff --git a/examples/pub/publisher.cpp b/examples/pub/publisher.cpp
index f41785b..07c0ee0 100644
--- a/examples/pub/publisher.cpp
+++ b/examples/pub/publisher.cpp
@@ -21,7 +21,7 @@
* ***************************************************************************/
// osdev::components::mqtt
-#include "token.h"
+// #include "token.h"
// mqtt_tests
#include "publisher.h"
diff --git a/examples/sub/CMakeLists.txt b/examples/sub/CMakeLists.txt
index f118452..281089e 100644
--- a/examples/sub/CMakeLists.txt
+++ b/examples/sub/CMakeLists.txt
@@ -5,7 +5,7 @@ include(projectheader)
project_header(test_mqtt_sub)
include_directories( SYSTEM
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../include
)
include(compiler)
@@ -21,7 +21,7 @@ add_executable( ${PROJECT_NAME}
target_link_libraries(
${PROJECT_NAME}
- mqtt
+ mqtt-cpp
)
set_target_properties( ${PROJECT_NAME} PROPERTIES
diff --git a/examples/sub/main.cpp b/examples/sub/main.cpp
index 8288545..57e365c 100644
--- a/examples/sub/main.cpp
+++ b/examples/sub/main.cpp
@@ -71,12 +71,12 @@ int main( int argc, char* argv[] )
std::cout << "Creating the subscriber : ";
// Create the subscriber
- Subscriber *pSubscriber = new Subscriber();
+ Subscriber *pSubscriber = new Subscriber( "Test_Subscriber" );
if( pSubscriber != nullptr )
{
std::cout << "[OK]" << std::endl;
std::cout << "Connecting to the test-broker : " << std::endl;
- pSubscriber->connect( "localhost", 1883, "", "" );
+ pSubscriber->connect( "office.osdev.nl", 1883, "", "" );
std::cout << "Subscribing to the test-topic....." << std::endl;
pSubscriber->subscribe( "test/publisher/TestPublisher" );
diff --git a/examples/sub/subscriber.cpp b/examples/sub/subscriber.cpp
index 61d0d5e..8354dd6 100644
--- a/examples/sub/subscriber.cpp
+++ b/examples/sub/subscriber.cpp
@@ -20,27 +20,13 @@
* DEALINGS IN THE SOFTWARE. *
* ***************************************************************************/
#include "subscriber.h"
-#include "mqttmessage.h"
-#include "credentials.h"
-Subscriber::Subscriber()
- : m_mqtt_client( "TestSubscriber" )
-{
-
-}
+#include
-void Subscriber::connect( const std::string &hostname, int portnumber, const std::string &username, const std::string &password )
+Subscriber::Subscriber( const std::string &client_id )
+ : MqttSubscriberBase( client_id )
{
- m_mqtt_client.connect( hostname, portnumber, osdev::components::mqtt::Credentials( username, password ) );
- std::cout << "Client state : " << m_mqtt_client.state() << std::endl;
-}
-void Subscriber::subscribe( const std::string &message_topic )
-{
- m_mqtt_client.subscribe( message_topic, 1, [this](const osdev::components::mqtt::MqttMessage &message)
- {
- this->receive_data(message.topic(), message.payload() );
- });
}
void Subscriber::receive_data( const std::string &message_topic, const std::string &message_payload )
diff --git a/examples/sub/subscriber.h b/examples/sub/subscriber.h
index a24fcca..8c67ef4 100644
--- a/examples/sub/subscriber.h
+++ b/examples/sub/subscriber.h
@@ -22,27 +22,19 @@
#pragma once
// std
-#include
#include
-// osdev::components::mqtt
-#include "mqttclient.h"
-#include "compat-c++14.h"
+// mqtt-cpp
+#include "mqttsubscriberbase.h"
-class Subscriber
+class Subscriber : public MqttSubscriberBase
{
public:
- Subscriber();
+ Subscriber( const std::string &client_id );
virtual ~Subscriber() {}
- void connect( const std::string &hostname, int portnumber, const std::string &username, const std::string &password );
-
- void subscribe( const std::string &message_topic );
-
-private:
+protected:
void receive_data( const std::string &message_topic, const std::string &message_payload );
-private:
- osdev::components::mqtt::MqttClient m_mqtt_client;
};
diff --git a/include/mqttsubscriberbase.h b/include/mqttsubscriberbase.h
index e69de29..956a8f5 100644
--- a/include/mqttsubscriberbase.h
+++ b/include/mqttsubscriberbase.h
@@ -0,0 +1,81 @@
+/* ****************************************************************************
+ * Copyright 2019 Open Systems Development BV *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the "Software"), *
+ * to deal in the Software without restriction, including without limitation *
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
+ * and/or sell copies of the Software, and to permit persons to whom the *
+ * Software is furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included in *
+ * all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
+ * DEALINGS IN THE SOFTWARE. *
+ * ***************************************************************************/
+#pragma once
+
+// std
+#include
+#include
+
+#include "mqttclient.h"
+
+
+class MqttSubscriberBase
+{
+public:
+ /*!
+ * \brief SubscriberBase
+ */
+ MqttSubscriberBase( const std::string &client_id );
+
+ /*!
+ * \brief ~SubscriberBase
+ */
+ virtual ~MqttSubscriberBase() {}
+
+ /*!
+ * \brief getClientId
+ * \return
+ */
+ std::string getClientId() const;
+
+ /*!
+ * \brief connect
+ * \param hostname
+ * \param portnumber
+ * \param username
+ * \param password
+ */
+ void connect( const std::string &hostname, int portnumber, const std::string &username, const std::string &password );
+
+ /*!
+ * \brief subscribe
+ * \param message_topic
+ */
+ void subscribe( const std::string &message_topic );
+
+ /*!
+ * \brief disconnect
+ */
+ void disconnect();
+
+protected:
+ /*!
+ * \brief receive_data
+ * \param message_topic
+ * \param message_payload
+ */
+ virtual void receive_data( const std::string &message_topic, const std::string &message_payload ) = 0;
+
+private:
+ osdev::components::mqtt::MqttClient m_mqtt_client;
+
+};
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 34432bc..e4f8c37 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -23,15 +23,14 @@ endif()
# ==============================================================================
include(projectheader)
-project_header(mqtt)
+project_header(mqtt-cpp)
find_package( Boost REQUIRED COMPONENTS regex )
include(compiler)
include_directories(
- ${CMAKE_CURRENT_SOURCE_DIR}/../logutils
- ${CMAKE_CURRENT_SOURCE_DIR}/../include
+ ${CMAKE_SOURCE_DIR}/include
)
set(SRC_LIST
@@ -40,8 +39,6 @@ set(SRC_LIST
${CMAKE_CURRENT_SOURCE_DIR}/clientpaho.cpp
${CMAKE_CURRENT_SOURCE_DIR}/commondefs.cpp
${CMAKE_CURRENT_SOURCE_DIR}/connectionstatus.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/compiletimedigits.h
- ${CMAKE_CURRENT_SOURCE_DIR}/compiletimestring.h
${CMAKE_CURRENT_SOURCE_DIR}/credentials.cpp
${CMAKE_CURRENT_SOURCE_DIR}/errorcode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/token.cpp
@@ -63,23 +60,23 @@ set(SRC_LIST
${CMAKE_CURRENT_SOURCE_DIR}/stringutils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/uriparser.cpp
# Helper files ( Utillities )
- ${CMAKE_CURRENT_SOURCE_DIR}/bimap.h
- ${CMAKE_CURRENT_SOURCE_DIR}/compat-c++14.h
- ${CMAKE_CURRENT_SOURCE_DIR}/compat-chrono.h
- ${CMAKE_CURRENT_SOURCE_DIR}/histogram.h
- ${CMAKE_CURRENT_SOURCE_DIR}/histogramprovider.h
- ${CMAKE_CURRENT_SOURCE_DIR}/imqttclient.h
- ${CMAKE_CURRENT_SOURCE_DIR}/imqttclientimpl.h
- ${CMAKE_CURRENT_SOURCE_DIR}/lockguard.h
- ${CMAKE_CURRENT_SOURCE_DIR}/macrodefs.h
- ${CMAKE_CURRENT_SOURCE_DIR}/measure.h
- ${CMAKE_CURRENT_SOURCE_DIR}/metaprogrammingdefs.h
- ${CMAKE_CURRENT_SOURCE_DIR}/mqttstream.h
- ${CMAKE_CURRENT_SOURCE_DIR}/stringify.h
- ${CMAKE_CURRENT_SOURCE_DIR}/stringutils.h
- ${CMAKE_CURRENT_SOURCE_DIR}/synchronizedqueue.h
- ${CMAKE_CURRENT_SOURCE_DIR}/utils.h
- ${CMAKE_CURRENT_SOURCE_DIR}/uriutils.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/bimap.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/compat-c++14.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/compat-chrono.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/histogram.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/histogramprovider.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/imqttclient.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/imqttclientimpl.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/lockguard.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/macrodefs.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/measure.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/metaprogrammingdefs.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/mqttstream.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/stringify.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/stringutils.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/synchronizedqueue.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/utils.h
+ # ${CMAKE_CURRENT_SOURCE_DIR}/uriutils.h
)
include(library)
diff --git a/src/bimap.h b/src/bimap.h
deleted file mode 100644
index e862792..0000000
--- a/src/bimap.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* ****************************************************************************
- * Copyright 2019 Open Systems Development BV *
- * *
- * Permission is hereby granted, free of charge, to any person obtaining a *
- * copy of this software and associated documentation files (the "Software"), *
- * to deal in the Software without restriction, including without limitation *
- * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
- * and/or sell copies of the Software, and to permit persons to whom the *
- * Software is furnished to do so, subject to the following conditions: *
- * *
- * The above copyright notice and this permission notice shall be included in *
- * all copies or substantial portions of the Software. *
- * *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
- * DEALINGS IN THE SOFTWARE. *
- * ***************************************************************************/
-#ifndef OSDEV_COMPONENTS_MQTT_BIMAP_H
-#define OSDEV_COMPONENTS_MQTT_BIMAP_H
-
-// boost
-#include
-
-namespace osdev {
-namespace components {
-namespace mqtt {
-
-/**
- * @brief Factory function to create boost::bimap from an initializer list
- *
- * Usage:
- * @code
- * auto myBimap = makeBimap( { { 1, 2 }, { 2, 3 } } );
- * @endcode
- */
-template
-boost::bimap makeBimap(std::initializer_list::value_type> list)
-{
- return boost::bimap(list.begin(), list.end());
-}
-
-} // End namespace mqtt
-} // End namespace components
-} // End namespace osdev
-
-#endif // OSDEV_COMPONENTS_MQTT_BIMAP_H
diff --git a/src/clientpaho.h b/src/clientpaho.h
deleted file mode 100644
index 2fc83b5..0000000
--- a/src/clientpaho.h
+++ /dev/null
@@ -1,355 +0,0 @@
-/* ****************************************************************************
- * Copyright 2019 Open Systems Development BV *
- * *
- * Permission is hereby granted, free of charge, to any person obtaining a *
- * copy of this software and associated documentation files (the "Software"), *
- * to deal in the Software without restriction, including without limitation *
- * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
- * and/or sell copies of the Software, and to permit persons to whom the *
- * Software is furnished to do so, subject to the following conditions: *
- * *
- * The above copyright notice and this permission notice shall be included in *
- * all copies or substantial portions of the Software. *
- * *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
- * DEALINGS IN THE SOFTWARE. *
- * ***************************************************************************/
-#ifndef OSDEV_COMPONENTS_MQTT_CLIENTPAHO_H
-#define OSDEV_COMPONENTS_MQTT_CLIENTPAHO_H
-
-// std
-#include
-#include
-#include
-#include
-#include
-#include