ScreenAnalyzer: Data Communication Interface (FR10) 52/274452/4
authorWoochanlee <wc0917.lee@samsung.com>
Thu, 28 Apr 2022 10:57:58 +0000 (19:57 +0900)
committerWoochanlee <wc0917.lee@samsung.com>
Wed, 22 Jun 2022 12:24:35 +0000 (21:24 +0900)
Introduce MQTT protocol(mosquitto)

Change-Id: I835779979aaeffb22ea22a5d4dfce8f246cd7b47

libaurum/inc/Aurum.h
libaurum/inc/ScreenAnalyzer/ScreenAnalyzerWatcher.h [new file with mode: 0644]
libaurum/meson.build
libaurum/src/ScreenAnalyzer/ScreenAnalyzerWatcher.cc [new file with mode: 0644]
libaurum/src/ScreenAnalyzer/meson.build [new file with mode: 0644]
libaurum/src/meson.build
packaging/aurum.spec

index 52bb8b2..cdb35dc 100644 (file)
@@ -60,5 +60,7 @@
 #include "Comparer.h"
 #include "A11yEvent.h"
 #include "Runnables.h"
+#include "ScreenAnalyzerWatcher.h"
+
 
 #endif
diff --git a/libaurum/inc/ScreenAnalyzer/ScreenAnalyzerWatcher.h b/libaurum/inc/ScreenAnalyzer/ScreenAnalyzerWatcher.h
new file mode 100644 (file)
index 0000000..d692965
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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.
+ *
+ */
+
+#ifndef _SCREEN_ANALYZER_WATCHER_H_
+#define _SCREEN_ANALYZER_WATCHER_H_
+
+#include <mosquitto.h>
+
+namespace Aurum {
+
+class ScreenAnalyzerWatcher {
+public:
+    ScreenAnalyzerWatcher();
+    ~ScreenAnalyzerWatcher();
+    static void onMessage(struct mosquitto *mosq, void *obj, const struct mosquitto_message *msg);
+    void PublishData(std::string path, const Size2D<int> screenSize);
+
+private:
+    const std::string serverAddress = "10.113.16.21";
+    struct mosquitto *mosq;
+    std::string jsontext;
+    static bool doneLoad;
+};
+
+}
+
+#endif
index 5440ee7..540c967 100644 (file)
@@ -22,6 +22,7 @@ libaurum_install_inc = [
   './inc/Accessibility/IEventConsumer.h',
   './inc/Accessibility/AccessibleApplication.h',
   './inc/Accessibility/Accessible.h',
+  './inc/ScreenAnalyzer/ScreenAnalyzerWatcher.h',
   './inc/Runnable/Runnable.h',
   './inc/Runnable/Runnables.h',
   './inc/Runnable/SendKeyRunnable.h',
@@ -35,6 +36,7 @@ libaurum_install_inc = [
 libaurum_inc = [
   include_directories('./inc'),
   include_directories('./inc/Accessibility'),
+  include_directories('./inc/ScreenAnalyzer'),
   include_directories('./inc/Impl'),
   include_directories('./inc/Impl/Accessibility'),
   include_directories('./inc/Misc'),
@@ -60,6 +62,8 @@ if get_option('tizen') == true
     dependency('dlog'),
     dependency('elementary'),
     dependency('libtdm'),
+    dependency('libmosquitto'),
+    dependency('jsoncpp'),
   ]
 endif
 
diff --git a/libaurum/src/ScreenAnalyzer/ScreenAnalyzerWatcher.cc b/libaurum/src/ScreenAnalyzer/ScreenAnalyzerWatcher.cc
new file mode 100644 (file)
index 0000000..acc24a3
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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.
+ *
+ */
+
+#include "Aurum.h"
+
+#include "ScreenAnalyzerWatcher.h"
+#include <fstream>
+#include <json/json.h>
+#include <sstream>
+#include <time.h>
+#include <thread>
+
+using namespace Aurum;
+
+bool ScreenAnalyzerWatcher::doneLoad;
+
+void onConnect(struct mosquitto *mosq, void *obj, int ret)
+{
+    LOGI("Mosquitto on connected");
+
+    if(ret != 0) {
+        LOGE("Mosquitto  connect error : %d", ret);
+        mosquitto_disconnect(mosq);
+    }
+    int rc;
+    rc = mosquitto_subscribe(mosq, NULL, "screen_analyzer/json", 1);
+    if(rc != MOSQ_ERR_SUCCESS) {
+        LOGE("Mosquitto subscribe fail");
+        mosquitto_disconnect(mosq);
+    }
+}
+
+void onPublish(struct mosquitto *mosq, void *obj, int mid)
+{
+    LOGI("Mosquitto on published");
+}
+
+void onSubscribe(struct mosquitto *mosq, void *obj, int mid, int qos_count, const int *granted_qos)
+{
+    LOGI("Mosquitto on subscribed. qos count : %d", qos_count);
+}
+
+void ScreenAnalyzerWatcher::onMessage(struct mosquitto *mosq, void *obj, const struct mosquitto_message *msg)
+{
+    LOGI("Mosquitto onMessage called");
+    std::string txt((char *)msg->payload);
+
+    LOGI("Mosquitto onMessage finished");
+    doneLoad = true;
+
+}
+
+ScreenAnalyzerWatcher::ScreenAnalyzerWatcher()
+{
+    LOGI("Screen Analyzer Constructor");
+    mosquitto_lib_init();
+    mosq = mosquitto_new(NULL, true, NULL);
+    if(mosq == NULL){
+        LOGE("Mosquitto initialize fail");
+        return;
+    }
+
+    mosquitto_connect_callback_set(mosq, onConnect);
+    mosquitto_publish_callback_set(mosq, onPublish);
+    mosquitto_subscribe_callback_set(mosq, onSubscribe);
+    mosquitto_message_callback_set(mosq, ScreenAnalyzerWatcher::onMessage);
+
+    int rc;
+    rc = mosquitto_connect(mosq, serverAddress.c_str(), 1883, 60);
+    if(rc != MOSQ_ERR_SUCCESS){
+        mosquitto_destroy(mosq);
+        LOGE("Mosquitto connect fail");
+        return;
+    }
+    rc = mosquitto_loop_start(mosq);
+    if(rc != MOSQ_ERR_SUCCESS){
+        mosquitto_destroy(mosq);
+        LOGE("Mosquitto loop start fail");
+        return;
+    }
+}
+
+ScreenAnalyzerWatcher::~ScreenAnalyzerWatcher()
+{
+    LOGI("Screen Analyzer destructor");
+    mosquitto_disconnect(mosq);
+    mosquitto_loop_stop(mosq, false);
+    mosquitto_lib_cleanup();
+}
+
+void ScreenAnalyzerWatcher::PublishData(std::string path, const Size2D<int> screenSize)
+{
+    LOGI("Mosquitto publish data start file path : " path.c_str());
+
+    LOGI("Mosquitto publish data finish");
+}
\ No newline at end of file
diff --git a/libaurum/src/ScreenAnalyzer/meson.build b/libaurum/src/ScreenAnalyzer/meson.build
new file mode 100644 (file)
index 0000000..5047b43
--- /dev/null
@@ -0,0 +1,3 @@
+libaurum_src += [
+    files('ScreenAnalyzerWatcher.cc')
+]
index 11af3ea..ef6b2f4 100644 (file)
@@ -13,5 +13,6 @@ libaurum_src += [
 ]
 
 subdir('Accessibility')
+subdir('ScreenAnalyzer')
 subdir('Impl')
 subdir('Runnable')
index ce0c060..ee859ae 100644 (file)
@@ -30,6 +30,8 @@ BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(capi-system-system-settings)
 BuildRequires: pkgconfig(capi-base-utils-i18n)
 BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(libmosquitto)
+BuildRequires: pkgconfig(jsoncpp)
 
 %if 0%{?gendoc:1}
 BuildRequires:  doxygen