aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sample/simple-egl/include/hmi-debug.h69
-rw-r--r--sample/simple-egl/src/simple-egl.cpp70
2 files changed, 98 insertions, 41 deletions
diff --git a/sample/simple-egl/include/hmi-debug.h b/sample/simple-egl/include/hmi-debug.h
new file mode 100644
index 0000000..3240171
--- /dev/null
+++ b/sample/simple-egl/include/hmi-debug.h
@@ -0,0 +1,69 @@
+/*
+ * 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 <string.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 __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
+
+#define HMI_ERROR(prefix, args,...) _HMI_LOG(LOG_LEVEL_ERROR, __FILENAME__, __FUNCTION__, __LINE__, prefix, args, ##__VA_ARGS__)
+#define HMI_WARNING(prefix, args,...) _HMI_LOG(LOG_LEVEL_WARNING, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__)
+#define HMI_NOTICE(prefix, args,...) _HMI_LOG(LOG_LEVEL_NOTICE, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__)
+#define HMI_INFO(prefix, args,...) _HMI_LOG(LOG_LEVEL_INFO, __FILENAME__, __FUNCTION__,__LINE__, prefix, args,##__VA_ARGS__)
+#define HMI_DEBUG(prefix, args,...) _HMI_LOG(LOG_LEVEL_DEBUG, __FILENAME__, __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* file, 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, %s(), Line:%d] >>> %s \n", time / 1000.0, prefix, ERROR_FLAG[level], file, func, line, message);
+ va_end(args);
+ free(message);
+}
+
+#endif //__HMI_DEBUG_H__ \ No newline at end of file
diff --git a/sample/simple-egl/src/simple-egl.cpp b/sample/simple-egl/src/simple-egl.cpp
index 822590c..8be9d2e 100644
--- a/sample/simple-egl/src/simple-egl.cpp
+++ b/sample/simple-egl/src/simple-egl.cpp
@@ -51,13 +51,14 @@
#include <libhomescreen.hpp>
#include <ilm/ivi-application-client-protocol.h>
+#include "hmi-debug.h"
+
using namespace std;
uint32_t g_id_ivisurf = 9009;
long port = 1700;
string token = string("wm");
-bool enable_debug = false;
string app_name = string("Navigation");
@@ -169,19 +170,6 @@ static const char *frag_shader_text =
static int running = 1;
-static void debug_out(const char* str, ...)
-{
- if(!enable_debug)
- return;
- char *out;
- va_list arg_ptr;
- va_start(arg_ptr, str);
- vasprintf(&out, str, arg_ptr);
- cout << out;
- va_end(arg_ptr);
- // cout << endl;
-}
-
static void
init_egl(struct display *display, struct window *window)
{
@@ -236,7 +224,7 @@ init_egl(struct display *display, struct window *window)
}
free(configs);
if (display->egl.conf == NULL) {
- debug_out("did not find config with buffer size %d\n",
+ HMI_DEBUG("simple-egl","did not find config with buffer size %d",
window->buffer_size);
exit(EXIT_FAILURE);
}
@@ -256,7 +244,7 @@ init_egl(struct display *display, struct window *window)
eglGetProcAddress("eglSwapBuffersWithDamageEXT");
if (display->swap_buffers_with_damage)
- debug_out("has EGL_EXT_buffer_age and EGL_EXT_swap_buffers_with_damage\n");
+ HMI_DEBUG("simple-egl","has EGL_EXT_buffer_age and EGL_EXT_swap_buffers_with_damage");
}
@@ -284,7 +272,7 @@ create_shader(struct window *window, const char *source, GLenum shader_type)
char log[1000];
GLsizei len;
glGetShaderInfoLog(shader, 1000, &len, log);
- debug_out("Error: compiling %s: %*s\n",
+ HMI_DEBUG("simple-egl","Error: compiling %s: %*s",
shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment",
len, log);
exit(1);
@@ -313,7 +301,7 @@ init_gl(struct window *window)
char log[1000];
GLsizei len;
glGetProgramInfoLog(program, 1000, &len, log);
- debug_out("Error: linking:\n%*s\n", len, log);
+ HMI_DEBUG("simple-egl","Error: linking:%*s", len, log);
exit(1);
}
@@ -339,7 +327,7 @@ create_ivi_surface(struct window *window, struct display *display)
id_ivisurf, window->surface);
if (window->ivi_surface == NULL) {
- debug_out("Failed to create ivi_client_surface\n");
+ HMI_DEBUG("simple-egl","Failed to create ivi_client_surface");
abort();
}
@@ -451,7 +439,7 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)
window->benchmark_time = time;
if (time - window->benchmark_time > (benchmark_interval * 1000)) {
- debug_out("%d frames in %d seconds: %f fps\n",
+ HMI_DEBUG("simple-egl","%d frames in %d seconds: %f fps",
window->frames,
benchmark_interval,
(float) window->frames / benchmark_interval);
@@ -562,42 +550,43 @@ signal_int(int signum)
int
init_wm(LibWindowmanager *wm)
{
+ HMI_DEBUG("simple-egl","called");
char* surfaceIdStr;
if (wm->init(port, token.c_str()) != 0) {
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] wm init failed. \n");
+ HMI_DEBUG("simple-egl","wm init failed. ");
return -1;
}
json_object *obj = json_object_new_object();
json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(app_name.c_str()));
if (wm->requestSurface(obj) != 0) {
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] wm request surface failed \n");
+ HMI_DEBUG("simple-egl","wm request surface failed ");
return -1;
}
wm->set_event_handler(LibWindowmanager::Event_Active, [wm](json_object *object) {
const char *label = json_object_get_string(
json_object_object_get(object, wm->kKeyDrawingName));
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got activated! \n", label);
+ HMI_DEBUG("simple-egl","Surface %s got activated! ", label);
});
wm->set_event_handler(LibWindowmanager::Event_Inactive, [wm](json_object *object) {
const char *label = json_object_get_string(
json_object_object_get(object, wm->kKeyDrawingName));
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got inactivated!\n", label);
+ HMI_DEBUG("simple-egl","Surface %s got inactivated!", label);
});
wm->set_event_handler(LibWindowmanager::Event_Visible, [wm](json_object *object) {
const char *label = json_object_get_string(
json_object_object_get(object, wm->kKeyDrawingName));
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got visibled!\n", label);
+ HMI_DEBUG("simple-egl","Surface %s got visibled!", label);
});
wm->set_event_handler(LibWindowmanager::Event_Invisible, [wm](json_object *object) {
const char *label = json_object_get_string(
json_object_object_get(object, wm->kKeyDrawingName));
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got invisibled!\n", label);
+ HMI_DEBUG("simple-egl","Surface %s got invisibled!", label);
gIsDraw = false;
});
@@ -606,19 +595,22 @@ init_wm(LibWindowmanager *wm)
json_object_object_get(object, wm->kKeyDrawingName));
const char *area = json_object_get_string(
json_object_object_get(object, wm->kKeyDrawingArea));
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got syncdraw!\n", label);
+
+ HMI_DEBUG("simple-egl","Surface %s got syncDraw! Area: %s. ", label, area);
if ((wm->kStrLayoutNormal + "." + wm->kStrAreaFull) == std::string(area)) {
+ HMI_DEBUG("simple-egl","Layout:%s x:%d y:%d w:%d h:%d ", area, 0, 0, 1080, 1488);
wl_egl_window_resize(gWindow->native, 1080, 1488, 0, 0);
gWindow->geometry.width = 1080;
gWindow->geometry.height = 1488;
}
else if ((wm->kStrLayoutSplit + "." + wm->kStrAreaMain) == std::string(area) ||
(wm->kStrLayoutSplit + "." + wm->kStrAreaSub) == std::string(area)) {
+ HMI_DEBUG("simple-egl","Layout:%s x:%d y:%d w:%d h:%d ", area, 0, 0, 1080, 744);
wl_egl_window_resize(gWindow->native, 1080, 744, 0, 0);
gWindow->geometry.width = 1080;
gWindow->geometry.height = 744;
}
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] try to endDraw %s \n", app_name.c_str());
+
if (!gWindow->fullscreen)
gWindow->window_size = gWindow->geometry;
gIsDraw = true;
@@ -631,7 +623,7 @@ init_wm(LibWindowmanager *wm)
wm->set_event_handler(LibWindowmanager::Event_FlushDraw, [wm](json_object *object) {
const char *label = json_object_get_string(
json_object_object_get(object, wm->kKeyDrawingName));
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] Surface %s got flushdraw! \n", label);
+ HMI_DEBUG("simple-egl","Surface %s got flushdraw! ", label);
});
do
@@ -640,7 +632,7 @@ init_wm(LibWindowmanager *wm)
} while (surfaceIdStr == NULL);
g_id_ivisurf = atoi(surfaceIdStr);
- debug_out("************** [SIMPLE EGL] [WM SIMPLE >>>>] IVI_SURFACE_ID: %d \n", g_id_ivisurf);
+ HMI_DEBUG("simple-egl","IVI_SURFACE_ID: %d ", g_id_ivisurf);
return 0;
}
@@ -649,17 +641,17 @@ int
init_hs(LibHomeScreen* hs){
if(hs->init(port, token)!=0)
{
- debug_out("************** [SIMPLE EGL] [HS SIMPLE >>>>] homescreen init failed. \n");
+ HMI_DEBUG("simple-egl","homescreen init failed. ");
return -1;
}
hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [](json_object *object){
const char *application_name = json_object_get_string(
json_object_object_get(object, "application_name"));
- debug_out("************** [SIMPLE EGL] [HS SIMPLE >>>>] Event_TapShortcut application_name = %s \n", application_name);
+ HMI_DEBUG("simple-egl","Event_TapShortcut application_name = %s ", application_name);
if(strcmp(application_name, app_name.c_str()) == 0)
{
- debug_out("************** [SIMPLE EGL] [HS SIMPLE] try to activesurface %s \n", app_name.c_str());
+ HMI_DEBUG("simple-egl","try to activesurface %s ", app_name.c_str());
json_object *obj = json_object_new_object();
json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(app_name.c_str()));
json_object_object_add(obj, wm->kKeyDrawingArea, json_object_new_string("normal.full"));
@@ -671,7 +663,7 @@ init_hs(LibHomeScreen* hs){
hs->set_event_handler(LibHomeScreen::Event_OnScreenMessage, [](json_object *object){
const char *display_message = json_object_get_string(
json_object_object_get(object, "display_message"));
- debug_out("************** [SIMPLE EGL] [HS SIMPLE >>>>] Event_OnScreenMessage display_message = %s \n", display_message);
+ HMI_DEBUG("simple-egl","Event_OnScreenMessage display_message = %s ", display_message);
});
return 0;
@@ -684,11 +676,6 @@ main(int argc, char **argv)
struct window window = { 0 };
struct display display = { 0 };
- if(getenv("ENABLE_DEMO_DEBUG"))
- {
- enable_debug = true;
- }
-
window.display = &display;
display.window = &window;
window.geometry.width = 1080;
@@ -706,7 +693,7 @@ main(int argc, char **argv)
token = argv[2];
}
- debug_out("************** [SIMPLE EGL] [MAIN] app_name: %s, port: %d, token: %s. \n", app_name.c_str(), port, token.c_str());
+ HMI_DEBUG("simple-egl","app_name: %s, port: %d, token: %s. ", app_name.c_str(), port, token.c_str());
display.display = wl_display_connect(NULL);
assert(display.display);
@@ -775,7 +762,8 @@ main(int argc, char **argv)
redraw(&window, NULL, 0);
}
}
- debug_out("************** [SIMPLE EGL] [MAIN] simple-egl exiting! \n");
+
+ HMI_DEBUG("simple-egl","simple-egl exiting! ");
destroy_surface(&window);
fini_egl(&display);