diff options
author | zheng_wenlong <wenlong_zheng@nexty-ele.com> | 2017-10-23 20:20:23 +0900 |
---|---|---|
committer | zheng_wenlong <wenlong_zheng@nexty-ele.com> | 2017-10-23 20:20:23 +0900 |
commit | a330391a355a9fb00a502fea0cf49d8c38443817 (patch) | |
tree | 39f415b483bbdac59faf9324ffb8daa3ba48dc2e /homescreen | |
parent | 3d836c185f92fb38fed31e373f371187322b2f3f (diff) |
Add debug message control by envirment
Add HMI_DEBUG to print debug message,
It control by USE_HMI_DEBUG envirment.
Signed-off-by: zheng_wenlong <wenlong_zheng@nexty-ele.com>
Diffstat (limited to 'homescreen')
-rw-r--r-- | homescreen/src/applicationlauncher.cpp | 6 | ||||
-rw-r--r-- | homescreen/src/applicationmodel.cpp | 12 | ||||
-rw-r--r-- | homescreen/src/hmi-debug.h | 66 | ||||
-rw-r--r-- | homescreen/src/homescreenhandler.cpp | 9 | ||||
-rw-r--r-- | homescreen/src/layouthandler.cpp | 22 | ||||
-rw-r--r-- | homescreen/src/main.cpp | 3 |
6 files changed, 93 insertions, 25 deletions
diff --git a/homescreen/src/applicationlauncher.cpp b/homescreen/src/applicationlauncher.cpp index 411fb03..7e1cda1 100644 --- a/homescreen/src/applicationlauncher.cpp +++ b/homescreen/src/applicationlauncher.cpp @@ -20,7 +20,7 @@ #include "afm_user_daemon_proxy.h" -#include <QtCore/QDebug> +#include "hmi-debug.h" extern org::AGL::afm::user *afm_user_daemon_proxy; @@ -32,10 +32,10 @@ ApplicationLauncher::ApplicationLauncher(QObject *parent) int ApplicationLauncher::launch(const QString &application) { int result = -1; - qDebug() << "ApplicationLauncher launch" << application; + HMI_DEBUG("HomeScreen","ApplicationLauncher launch %s.", application.toStdString().c_str()); result = afm_user_daemon_proxy->start(application).value().toInt(); - qDebug() << "ApplicationLauncher pid:" << result; + HMI_DEBUG("HomeScreen","ApplicationLauncher pid: %d.", result); if (result > 1) { setCurrent(application); diff --git a/homescreen/src/applicationmodel.cpp b/homescreen/src/applicationmodel.cpp index 08b1a55..f01df06 100644 --- a/homescreen/src/applicationmodel.cpp +++ b/homescreen/src/applicationmodel.cpp @@ -19,7 +19,7 @@ #include "applicationmodel.h" #include "appinfo.h" -#include <QtCore/QDebug> +#include "hmi-debug.h" #include <QtDBus/QDBusInterface> #include <QtDBus/QDBusReply> @@ -63,11 +63,11 @@ ApplicationModel::Private::Private() auto const icon = get_icon_name(jso); // Hide HomeScreen icon itself - if (name != "homescreen-2017") { + if (name != "homescreen-2017" && name != "OnScreenApp") { this->data.append(AppInfo(icon, name, id)); } - qDebug() << "name:" << name << "icon:" << icon << "id:" << id; + HMI_DEBUG("HomeScreen","name: %s icon: %s id: %s.", name.toStdString().c_str(), icon.toStdString().c_str(), id.toStdString().c_str()); } } @@ -138,19 +138,19 @@ void ApplicationModel::move(int from, int to) if (to < 0 || to > rowCount()) return; if (from < to) { if (!beginMoveRows(parent, from, from, parent, to + 1)) { - qDebug() << from << to << false; + HMI_NOTICE("HomeScreen","from : %d, to : %d. false.", from, to); return; } d->data.move(from, to); endMoveRows(); } else if (from > to) { if (!beginMoveRows(parent, from, from, parent, to)) { - qDebug() << from << to << false; + HMI_NOTICE("HomeScreen","from : %d, to : %d. false.", from, to); return; } d->data.move(from, to); endMoveRows(); } else { - qDebug() << from << to << false; + HMI_NOTICE("HomeScreen","from : %d, to : %d. false.", from, to); } } diff --git a/homescreen/src/hmi-debug.h b/homescreen/src/hmi-debug.h new file mode 100644 index 0000000..57b59c7 --- /dev/null +++ b/homescreen/src/hmi-debug.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017 TOYOTA MOTOR CORPORATION + * + * 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 __HMI_DEBUG_H__ +#define __HMI_DEBUG_H__ + +#include <time.h> +#include <stdio.h> +#include <afb/afb-binding.h> + +enum LOG_LEVEL{ + LOG_LEVEL_NONE = 0, + LOG_LEVEL_ERROR, + LOG_LEVEL_WARNING, + LOG_LEVEL_NOTICE, + LOG_LEVEL_INFO, + LOG_LEVEL_DEBUG, + LOG_LEVEL_MAX = LOG_LEVEL_ERROR +}; + +#define HMI_ERROR(prefix, args,...) _HMI_LOG(LOG_LEVEL_ERROR, __FUNCTION__, __LINE__, prefix, args, ##__VA_ARGS__) +#define HMI_WARNING(prefix, args,...) _HMI_LOG(LOG_LEVEL_WARNING, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__) +#define HMI_NOTICE(prefix, args,...) _HMI_LOG(LOG_LEVEL_NOTICE, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__) +#define HMI_INFO(prefix, args,...) _HMI_LOG(LOG_LEVEL_INFO, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__) +#define HMI_DEBUG(prefix, args,...) _HMI_LOG(LOG_LEVEL_DEBUG, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__) + +static char ERROR_FLAG[6][20] = {"NONE", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG"}; + +static void _HMI_LOG(enum LOG_LEVEL level, const char* func, const int line, const char* prefix, const char* log, ...) +{ + const int log_level = (getenv("USE_HMI_DEBUG") == NULL)?0:atoi(getenv("USE_HMI_DEBUG")); + if(log_level < level) + { + return; + } + + char *message; + struct timespec tp; + unsigned int time; + + clock_gettime(CLOCK_REALTIME, &tp); + time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000); + + va_list args; + va_start(args, log); + if (log == NULL || vasprintf(&message, log, args) < 0) + message = NULL; + fprintf(stderr, "[%10.3f] [%s %s] [%s:%d] >>> %s \n", time / 1000.0, prefix, ERROR_FLAG[level], func, line, message); + va_end(args); + free(message); +} + +#endif //__HMI_DEBUG_H__
\ No newline at end of file diff --git a/homescreen/src/homescreenhandler.cpp b/homescreen/src/homescreenhandler.cpp index 5d888ae..6034a5a 100644 --- a/homescreen/src/homescreenhandler.cpp +++ b/homescreen/src/homescreenhandler.cpp @@ -16,6 +16,7 @@ #include "homescreenhandler.h" #include <functional> +#include "hmi-debug.h" void* HomescreenHandler::myThis = 0; @@ -60,7 +61,7 @@ void HomescreenHandler::init(int port, const char *token) void HomescreenHandler::tapShortcut(QString application_name) { - qDebug("tapShortcut %s", qPrintable(application_name)); + HMI_DEBUG("HomeScreen","tapShortcut %s", application_name.toStdString().c_str()); mp_hs->tapShortcut(application_name.toStdString().c_str()); } @@ -77,19 +78,19 @@ void HomescreenHandler::onEv_static(const string& event, struct json_object* eve void HomescreenHandler::onRep(struct json_object* reply_contents) { const char* str = json_object_to_json_string(reply_contents); - qDebug("HomeScreen onReply %s", str); + HMI_DEBUG("HomeScreen","HomeScreen onReply %s", str); } void HomescreenHandler::onEv(const string& event, struct json_object* event_contents) { const char* str = json_object_to_json_string(event_contents); - qDebug("HomeScreen onEv %s, contents: %s", event.c_str(), str); + HMI_DEBUG("HomeScreen","HomeScreen onEv %s, contents: %s", event.c_str(), str); if (event.compare("homescreen/on_screen_message") == 0) { struct json_object *json_data = json_object_object_get(event_contents, "data"); struct json_object *json_display_message = json_object_object_get(json_data, "display_message"); const char* display_message = json_object_get_string(json_display_message); - qDebug("display_message = %s", display_message); + HMI_DEBUG("HomeScreen","display_message = %s", display_message); } } diff --git a/homescreen/src/layouthandler.cpp b/homescreen/src/layouthandler.cpp index 37c1d09..a252e6e 100644 --- a/homescreen/src/layouthandler.cpp +++ b/homescreen/src/layouthandler.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include <QDebug> +#include "hmi-debug.h" #include "layouthandler.h" #define HOMESCREEN "HomeScreen" @@ -44,31 +44,31 @@ void LayoutHandler::init(int port, const char* token) mp_wm->set_event_handler(LibWindowmanager::Event_Active, [this](const char* label) { this->isActived = true; - qDebug("Surface %s got activated!", label); + HMI_DEBUG("HomeScreen","Surface %s got activated!", HOMESCREEN); }); mp_wm->set_event_handler(LibWindowmanager::Event_Inactive, [this](const char* label) { this->isActived = false; - qDebug("Surface %s got deactivated!", label); + HMI_DEBUG("HomeScreen","Surface %s got deactivated!", HOMESCREEN); }); mp_wm->set_event_handler(LibWindowmanager::Event_Visible, [](char const *label) { - qDebug("Surface %s got visibled!", label); + HMI_DEBUG("HomeScreen","Surface %s got visibled!", HOMESCREEN); }); mp_wm->set_event_handler(LibWindowmanager::Event_Invisible, [](char const *label) { - qDebug("Surface %s got invisibled!", label); + HMI_DEBUG("HomeScreen","Surface %s got invisibled!", HOMESCREEN); }); mp_wm->set_event_handler(LibWindowmanager::Event_SyncDraw, [this](const char* label) { - qDebug("Surface %s got syncDraw!", label); - qDebug("Try to endDraw Surface %s Start!", label); + HMI_DEBUG("HomeScreen","Surface %s got syncDraw!", HOMESCREEN); + HMI_DEBUG("HomeScreen","Try to endDraw Surface %s Start!", HOMESCREEN); this->mp_wm->endDraw(HOMESCREEN); - qDebug("Try to endDraw Surface %s End!", label); + HMI_DEBUG("HomeScreen","Try to endDraw Surface %s End!", HOMESCREEN); }); mp_wm->set_event_handler(LibWindowmanager::Event_FlushDraw, [](char const *label) { - qDebug("Surface %s got flushDraw!", label); + HMI_DEBUG("HomeScreen","Surface %s got flushDraw!", HOMESCREEN); }); } @@ -81,12 +81,12 @@ void LayoutHandler::slotActivateSurface() { if(isActived) return; - qDebug(__FUNCTION__); + HMI_DEBUG("HomeScreen","called"); this->activateSurface(); } void LayoutHandler::slotHomeButton() { - qDebug(__FUNCTION__); + HMI_DEBUG("HomeScreen","called"); this->activateSurface(); } diff --git a/homescreen/src/main.cpp b/homescreen/src/main.cpp index 1b42832..45a7c0f 100644 --- a/homescreen/src/main.cpp +++ b/homescreen/src/main.cpp @@ -31,6 +31,7 @@ #include "afm_user_daemon_proxy.h" #include "mastervolume.h" #include "homescreenhandler.h" +#include "hmi-debug.h" // XXX: We want this DBus connection to be shared across the different // QML objects, is there another way to do this, a nice way, perhaps? @@ -83,7 +84,7 @@ int main(int argc, char *argv[]) token = positionalArguments.takeFirst(); } - qDebug("HomeScreen port = %d, token = %s", port, token.toStdString().c_str()); + HMI_DEBUG("HomeScreen","port = %d, token = %s", port, token.toStdString().c_str()); // import C++ class to QML qmlRegisterType<ApplicationLauncher>("HomeScreen", 1, 0, "ApplicationLauncher"); |