From c4eb0961ac3dd39f56071c07384cfa71df942ca4 Mon Sep 17 00:00:00 2001 From: Hosang Kim Date: Fri, 11 Jun 2021 14:02:14 +0900 Subject: [PATCH 01/16] bootstrap: change size of screenshot. --- org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc index ad199b1..3206029 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc @@ -21,7 +21,7 @@ TakeScreenshotCommand::TakeScreenshotCommand( std::ifstream ifs(path, std::ifstream::binary); ::aurum::RspTakeScreenshot rsp; - int size = 1024 * 1024; + int size = 1920 * 1080; char buf[size]; while (!ifs.eof()) { -- 2.7.4 From 269ed6fa02ea306b10ed73dc08c4b358c03c8dd6 Mon Sep 17 00:00:00 2001 From: Hosang Kim Date: Tue, 8 Jun 2021 17:20:32 +0900 Subject: [PATCH 02/16] aurum: remove ecore_main_loop_thread API Change-Id: I09e7a17fba305d4e427e785193fdaafff0dd01a6 --- libaurum/src/Impl/TizenDeviceImpl.cc | 123 +++++++-------------- .../src/Commands/PreCommand.cc | 27 ++--- 2 files changed, 49 insertions(+), 101 deletions(-) diff --git a/libaurum/src/Impl/TizenDeviceImpl.cc b/libaurum/src/Impl/TizenDeviceImpl.cc index 14f684b..fc81f06 100644 --- a/libaurum/src/Impl/TizenDeviceImpl.cc +++ b/libaurum/src/Impl/TizenDeviceImpl.cc @@ -21,25 +21,19 @@ TizenDeviceImpl::TizenDeviceImpl() loguru::g_stderr_verbosity = loguru::Verbosity_ERROR; LOG_SCOPE_F(INFO, "device implementation init"); - ecore_main_loop_thread_safe_call_sync([](void *data)->void*{ - TizenDeviceImpl *obj = static_cast(data); - obj->mFakeTouchHandle = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN); - obj->mFakeKeyboardHandle = - efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_KEYBOARD); - obj->mFakeWheelHandle = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_POINTER); - return NULL; - }, this); + TizenDeviceImpl *obj = static_cast(this); + obj->mFakeTouchHandle = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN); + obj->mFakeKeyboardHandle = + efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_KEYBOARD); + obj->mFakeWheelHandle = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_POINTER); } TizenDeviceImpl::~TizenDeviceImpl() { - ecore_main_loop_thread_safe_call_sync([](void *data)->void*{ - TizenDeviceImpl *obj = static_cast(data); - efl_util_input_deinitialize_generator(obj->mFakeTouchHandle); - efl_util_input_deinitialize_generator(obj->mFakeKeyboardHandle); - efl_util_input_deinitialize_generator(obj->mFakeWheelHandle); - return NULL; - }, this); + TizenDeviceImpl *obj = static_cast(this); + efl_util_input_deinitialize_generator(obj->mFakeTouchHandle); + efl_util_input_deinitialize_generator(obj->mFakeKeyboardHandle); + efl_util_input_deinitialize_generator(obj->mFakeWheelHandle); } bool TizenDeviceImpl::click(const int x, const int y) @@ -65,20 +59,14 @@ int TizenDeviceImpl::touchDown(const int x, const int y) int seq = grabTouchSeqNumber(); LOG_SCOPE_F(INFO, "touch down %d %d , seq:%d", x, y, seq); if (seq >= 0) { - auto args = std::make_tuple(this, x, y, seq); - long result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{ - TizenDeviceImpl *obj; - int x, y, seq; - std::tie(obj, x, y, seq) = *static_cast*>(data); - return (void*)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_BEGIN, - x, y); - - }, (void*)(&args)); - - if (result != EFL_UTIL_ERROR_NONE) { - releaseTouchSeqNumber(seq); - return -1; - } + TizenDeviceImpl *obj = static_cast(this); + long result = (long)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_BEGIN, + x, y); + + if (result != EFL_UTIL_ERROR_NONE) { + releaseTouchSeqNumber(seq); + return -1; + } } return seq; } @@ -87,33 +75,21 @@ bool TizenDeviceImpl::touchMove(const int x, const int y, const int seq) { LOG_SCOPE_F(INFO, "touch move %d %d, seq:%d", x, y, seq); if (seq >= 0) { - auto args = std::make_tuple(this, x, y, seq); - long result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{ - TizenDeviceImpl *obj; - int x, y, seq; - std::tie(obj, x, y, seq) = *static_cast*>(data); - - return (void*)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_UPDATE, - x, y); - - }, (void*)(&args)); - return result == EFL_UTIL_ERROR_NONE; + TizenDeviceImpl *obj = static_cast(this); + long result = (long)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_UPDATE, + x, y); + return result == EFL_UTIL_ERROR_NONE; } return false; } bool TizenDeviceImpl::touchUp(const int x, const int y, const int seq) { - LOG_SCOPE_F(INFO, "touch up %d %d, seq:%d", x, y, seq); - if (seq >= 0) { - auto args = std::make_tuple(this, x, y, seq); - long result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{ - TizenDeviceImpl *obj; - int x, y, seq; - std::tie(obj, x, y, seq) = *static_cast*>(data); - return (void*)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_END, - x, y); - }, (void*)(&args)); + LOG_SCOPE_F(INFO, "touch up %d %d, seq:%d", x, y, seq); + if (seq >= 0) { + TizenDeviceImpl *obj = static_cast(this); + long result = (long)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_END, + x, y); return releaseTouchSeqNumber(seq) && result == EFL_UTIL_ERROR_NONE; } return false; @@ -122,15 +98,11 @@ bool TizenDeviceImpl::touchUp(const int x, const int y, const int seq) bool TizenDeviceImpl::wheelUp(int amount, const int durationMs) { LOG_SCOPE_F(INFO, "wheel up %d for %d", amount, durationMs); - auto args = std::make_tuple(this); long result = -1; for (int i = 0; i < amount; i++){ - result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{ - TizenDeviceImpl *obj; - std::tie(obj) = *static_cast*>(data); - return (void*)efl_util_input_generate_wheel(obj->mFakeWheelHandle, EFL_UTIL_INPUT_POINTER_WHEEL_HORZ, 1); - }, (void*)(&args)); - usleep(durationMs*MSEC_PER_SEC/amount); + TizenDeviceImpl *obj = static_cast(this); + result = (long)efl_util_input_generate_wheel(obj->mFakeWheelHandle, EFL_UTIL_INPUT_POINTER_WHEEL_HORZ, 1); + usleep(durationMs*MSEC_PER_SEC/amount); } return result == EFL_UTIL_ERROR_NONE; @@ -138,16 +110,11 @@ bool TizenDeviceImpl::wheelUp(int amount, const int durationMs) bool TizenDeviceImpl::wheelDown(int amount, const int durationMs) { - LOG_SCOPE_F(INFO, "wheel down %d for %d", amount, durationMs); - auto args = std::make_tuple(this); - long result = -1; - for (int i = 0; i < amount; i++){ - result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{ - TizenDeviceImpl *obj; - std::tie(obj) = *static_cast*>(data); - return (void*)efl_util_input_generate_wheel(obj->mFakeWheelHandle, EFL_UTIL_INPUT_POINTER_WHEEL_HORZ, -1); - return NULL; - }, (void*)(&args)); + LOG_SCOPE_F(INFO, "wheel down %d for %d", amount, durationMs); + long result = -1; + for (int i = 0; i < amount; i++){ + TizenDeviceImpl *obj = static_cast(this); + result = (long)efl_util_input_generate_wheel(obj->mFakeWheelHandle, EFL_UTIL_INPUT_POINTER_WHEEL_HORZ, -1); usleep(durationMs*MSEC_PER_SEC/amount); } @@ -259,27 +226,15 @@ bool TizenDeviceImpl::strokeKeyCode(std::string keycode, unsigned int intv) bool TizenDeviceImpl::pressKeyCode(std::string keycode) { - auto args = std::make_tuple(this, keycode); - long result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{ - TizenDeviceImpl *obj; - std::string keycode; - std::tie(obj, keycode) = *static_cast*>(data); - return (void*)efl_util_input_generate_key(obj->mFakeKeyboardHandle, keycode.c_str(), 1); - }, (void*)(&args)); - ecore_main_loop_thread_safe_call_sync([](void *data)->void*{return NULL;}, NULL); - return result == EFL_UTIL_ERROR_NONE; + TizenDeviceImpl *obj = static_cast(this); + long result = (long)efl_util_input_generate_key(obj->mFakeKeyboardHandle, keycode.c_str(), 1); + return result == EFL_UTIL_ERROR_NONE; } bool TizenDeviceImpl::releaseKeyCode(std::string keycode) { - auto args = std::make_tuple(this, keycode); - long result = (long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{ - TizenDeviceImpl *obj; - std::string keycode; - std::tie(obj, keycode) = *static_cast*>(data); - return (void*)efl_util_input_generate_key(obj->mFakeKeyboardHandle, keycode.c_str(), 0); - }, (void*)(&args)); - ecore_main_loop_thread_safe_call_sync([](void *data)->void*{return NULL;}, NULL); + TizenDeviceImpl *obj = static_cast(this); + long result = (long)efl_util_input_generate_key(obj->mFakeKeyboardHandle, keycode.c_str(), 0); return result == EFL_UTIL_ERROR_NONE; } diff --git a/org.tizen.aurum-bootstrap/src/Commands/PreCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/PreCommand.cc index b9a72ee..af36b2c 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/PreCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/PreCommand.cc @@ -16,24 +16,17 @@ PreCommand::PreCommand(Command *cmd) : mCommand{cmd} {} ::grpc::Status PreCommand::execute() { { - LOG_SCOPE_F(INFO, "PreCommand --------------- "); - - bool isDisplayOn = DISPLAY_STATE_SCREEN_OFF != (display_state_e)((long)ecore_main_loop_thread_safe_call_sync([](void *data)->void*{ - display_state_e state; - if(device_display_get_state(&state) == DEVICE_ERROR_NONE) { - return (void*)(state); - } + LOG_SCOPE_F(INFO, "PreCommand --------------- "); + display_state_e state; + if (device_display_get_state(&state) != DEVICE_ERROR_NONE) { LOG_F(INFO, "getting display state has failed"); - return NULL; - }, NULL)); - - ecore_main_loop_thread_safe_call_sync([](void *data)->void*{ - if (device_power_wakeup(false) != DEVICE_ERROR_NONE) { - LOG_F(INFO, "turning on display has failed"); - return NULL; - } - return NULL; - }, NULL); + } + + bool isDisplayOn = DISPLAY_STATE_SCREEN_OFF != state; + + if (device_power_wakeup(false) != DEVICE_ERROR_NONE) { + LOG_F(INFO, "turning on display has failed"); + } if (!isDisplayOn) std::this_thread::sleep_for(std::chrono::milliseconds{INTV_TURNON_MARGIN}); -- 2.7.4 From 9b7a2ccc08e373ea6609cb77765749d2d4dbe136 Mon Sep 17 00:00:00 2001 From: Hosang Kim Date: Thu, 24 Jun 2021 19:34:39 +0900 Subject: [PATCH 03/16] libaurum: check invalid accessible object Change-Id: I912df64eae169eb60b57d39d4fdbb7e7f4811360 --- libaurum/src/Accessibility/AccessibleNode.cc | 3 +-- .../src/Impl/Accessibility/AtspiAccessibleWatcher.cc | 17 ++++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libaurum/src/Accessibility/AccessibleNode.cc b/libaurum/src/Accessibility/AccessibleNode.cc index 6e86d51..8e6dbb3 100644 --- a/libaurum/src/Accessibility/AccessibleNode.cc +++ b/libaurum/src/Accessibility/AccessibleNode.cc @@ -66,7 +66,6 @@ std::string AccessibleNode::description() { void AccessibleNode::notify(int type, int type2, void *src) { - LOG_SCOPE_F(INFO, "notified for obj(%p) t1:%d t2:%d src:%p",this, type, type2, src); void *handler = getRawHandler(); if ((EventType)type == EventType::Object && (ObjectEventType)type2 == ObjectEventType::ObjectStateDefunct) { @@ -227,4 +226,4 @@ bool AccessibleNode::isShowing() const bool AccessibleNode::isActive() const { return hasFeatureProperty(NodeFeatureProperties::ACTIVE); -} \ No newline at end of file +} diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc index 23b15b4..46544d7 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc @@ -74,17 +74,15 @@ static gpointer _event_thread_loop (gpointer data) { LOG_F(INFO, "event thread start"); AtspiEventListener * listener = - atspi_event_listener_new(AtspiAccessibleWatcher::onAtspiEvents, NULL, NULL); + atspi_event_listener_new(AtspiAccessibleWatcher::onAtspiEvents, data, NULL); atspi_event_listener_register(listener, "window:", NULL); - atspi_event_listener_register(listener, "object:state-changed:focused", NULL); - atspi_event_listener_register(listener, "object:text-changed:insert", NULL); + atspi_event_listener_register(listener, "object:", NULL); atspi_event_main(); LOG_F(INFO, "event thread end"); - atspi_event_listener_deregister(listener, "object:state-changed:focused", NULL); - atspi_event_listener_deregister(listener, "object:text-changed:insert", NULL); + atspi_event_listener_deregister(listener, "object:", NULL); atspi_event_listener_deregister(listener, "window:", NULL); g_object_unref(listener); @@ -99,7 +97,7 @@ AtspiAccessibleWatcher::AtspiAccessibleWatcher() atspi_set_main_context (g_main_context_default ()); atspi_init(); - mEventThread = g_thread_new("AtspiEventThread", _event_thread_loop, nullptr); + mEventThread = g_thread_new("AtspiEventThread", _event_thread_loop, this); mDbusProxy = g_dbus_proxy_new_for_bus_sync( G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, @@ -148,6 +146,7 @@ void AtspiAccessibleWatcher::onAtspiEvents(AtspiEvent *event, void *user_data) return; } char *name = NULL, *pkg = NULL; + AtspiAccessibleWatcher *instance = (AtspiAccessibleWatcher *)user_data; name = AtspiWrapper::Atspi_accessible_get_name(event->source, NULL); AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(event->source, NULL); @@ -160,6 +159,11 @@ void AtspiAccessibleWatcher::onAtspiEvents(AtspiEvent *event, void *user_data) pkg = strdup(""); mEventQueue.push_back(std::make_shared(std::string(event->type), std::string(name), std::string(pkg))); + + if (!strcmp(event->type, "object:state-changed:defunct")) { + instance->onObjectDefunct( + static_cast(event->source)); + } if (name) free(name); if (pkg) free(pkg); /* char *name = NULL, *pname = NULL; @@ -257,7 +261,6 @@ void AtspiAccessibleWatcher::onObjectDefunct(AtspiAccessible *node) notifyAll((int)EventType::Object, (int)ObjectEventType::ObjectStateDefunct, node); } - int AtspiAccessibleWatcher::getApplicationCount(void) const { AtspiWrapper::lock(); -- 2.7.4 From 8b2e59f496171ad76e67d6a17148dd43ffe2fb81 Mon Sep 17 00:00:00 2001 From: Hosang Kim Date: Fri, 25 Jun 2021 19:26:08 +0900 Subject: [PATCH 04/16] bootstrap: avoid creating duplicate objects Change-Id: Ie289fb4d877636207b0fa8d12b4b20944a9e0623 --- org.tizen.aurum-bootstrap/inc/ObjectMapper.h | 4 +-- .../src/Commands/FindElementCommand.cc | 5 ++- org.tizen.aurum-bootstrap/src/ObjectMapper.cc | 36 ++++++++++++---------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/org.tizen.aurum-bootstrap/inc/ObjectMapper.h b/org.tizen.aurum-bootstrap/inc/ObjectMapper.h index a997f68..7f4f651 100644 --- a/org.tizen.aurum-bootstrap/inc/ObjectMapper.h +++ b/org.tizen.aurum-bootstrap/inc/ObjectMapper.h @@ -8,7 +8,7 @@ class ObjectMapper { private: std::map> mObjectMap; - std::map, std::string> mObjectMapReverse; + std::map mObjectMapReverse; unsigned long long mObjCounter; private: @@ -28,4 +28,4 @@ public: bool removeElement(std::shared_ptr object); void cleanUp(); -}; \ No newline at end of file +}; diff --git a/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc index fb9bd1d..8524db9 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc @@ -67,7 +67,10 @@ std::vector> FindElementCommand::getSelectors(void) if (founds.size() > 0) { for (auto& found : founds) { UiObject* obj = found.get(); - std::string key = mObjMap->addElement(std::move(found)); + std::string key{}; + key = mObjMap->getElement(found); + if (key.length() <= 0) + key = mObjMap->addElement(std::move(found)); LOG_F(INFO, "found object : %s key:%s", obj->getAutomationId().c_str(), key.c_str()); ::aurum::Element* elm = mResponse->add_elements(); diff --git a/org.tizen.aurum-bootstrap/src/ObjectMapper.cc b/org.tizen.aurum-bootstrap/src/ObjectMapper.cc index 645dece..32b97c3 100644 --- a/org.tizen.aurum-bootstrap/src/ObjectMapper.cc +++ b/org.tizen.aurum-bootstrap/src/ObjectMapper.cc @@ -19,8 +19,9 @@ std::string ObjectMapper::addElement(std::shared_ptr object) ++mObjCounter; std::string key = std::to_string(mObjCounter); mObjectMap[key] = object; - mObjectMapReverse[object] = key; - LOG_SCOPE_F(INFO, "addElement %p as key %s", object.get(), key.c_str()); + std::string value = object->getId(); + mObjectMapReverse[value] = key; + LOG_SCOPE_F(INFO, "addElement %p as key %s, id %s", object.get(), key.c_str(), value.c_str()); return key; } @@ -42,9 +43,10 @@ std::shared_ptr ObjectMapper::getElement(std::string key) std::string ObjectMapper::getElement(std::shared_ptr object) { LOG_SCOPE_F(INFO, "getElement for object(%p)", object.get()); - if (object && mObjectMapReverse.count(object)) { + std::string value = object->getId(); + if (mObjectMapReverse.count(value)) { LOG_F(INFO, "succeeded"); - return mObjectMapReverse[object]; + return mObjectMapReverse[value]; } LOG_F(INFO, "failed(object not found)"); return std::string{""}; @@ -55,7 +57,8 @@ bool ObjectMapper::removeElement(const std::string key) LOG_SCOPE_F(INFO, "removeElement for key(%s)", key.c_str()); std::shared_ptr obj = getElement(key); if (obj) { - if (mObjectMap.erase(key) && mObjectMapReverse.erase(obj)) + std::string value = obj->getId(); + if (mObjectMap.erase(key) && mObjectMapReverse.erase(value)) return true; } return false; @@ -74,22 +77,23 @@ void ObjectMapper::cleanUp() std::stringstream ss{}; LOG_SCOPE_F(INFO, "clean up object map"); - ss << "mObjectMap: "; - for(auto iter = mObjectMap.begin(); iter != mObjectMap.end(); ) { - if (!iter->second->isValid()) { - iter = mObjectMap.erase(iter); + ss << "mObjectMapReverse: "; + for(auto iter = mObjectMapReverse.begin(); iter != mObjectMapReverse.end(); ) { + auto obj = mObjectMap[iter->second]; + if (obj && !obj->isValid()) { + iter = mObjectMapReverse.erase(iter); } else { - ss << "(" << iter->first << "," << iter->second.get() << ") "; + ss << "(" << iter->first << "," << iter->second << ") "; ++iter; } } ss << std::endl; - ss << "mObjectMapReverse: "; - for(auto iter = mObjectMapReverse.begin(); iter != mObjectMapReverse.end(); ) { - if (!iter->first->isValid()) { - iter = mObjectMapReverse.erase(iter); + ss << "mObjectMap: "; + for(auto iter = mObjectMap.begin(); iter != mObjectMap.end(); ) { + if (!iter->second->isValid()) { + iter = mObjectMap.erase(iter); } else { - ss << "(" << iter->first.get() << "," << iter->second << ") "; + ss << "(" << iter->first << "," << iter->second.get() << ") "; ++iter; } } @@ -108,4 +112,4 @@ void ObjectMapper::cleanUp() return !pair.second->isValid(); }); } - */ \ No newline at end of file + */ -- 2.7.4 From 2ac92c4c6d5dbbbaf87b45a8ccf640087cb2b99a Mon Sep 17 00:00:00 2001 From: Woochanlee Date: Mon, 21 Jun 2021 19:44:16 +0900 Subject: [PATCH 05/16] aurum-bootstrap: Add element infomation Change-Id: I74d727061ae41adf9ba5b360dcac2f4f18db8a4d --- .../src/Commands/FindElementCommand.cc | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc index 8524db9..59ba209 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc @@ -76,6 +76,34 @@ std::vector> FindElementCommand::getSelectors(void) ::aurum::Element* elm = mResponse->add_elements(); elm->set_elementid(key); elm->set_package(obj->getApplicationPackage()); + + ::aurum::Rect *rect = elm->mutable_geometry(); + const Rect &size = obj->getBoundingBox(); + rect->set_x(size.mTopLeft.x); + rect->set_y(size.mTopLeft.y); + rect->set_width(size.width()); + rect->set_height(size.height()); + elm->set_widget_type(obj->getElementType()); + elm->set_widget_style(obj->getElementStyle()); + + elm->set_text(obj->getText()); + elm->set_id(obj->getId()); + elm->set_automationid(obj->getAutomationId()); + elm->set_package(obj->getApplicationPackage()); + elm->set_role(obj->getRole()); + + elm->set_ischecked(obj->isChecked()); + elm->set_ischeckable(obj->isCheckable()); + elm->set_isclickable(obj->isClickable()); + elm->set_isenabled(obj->isEnabled()); + elm->set_isfocused(obj->isFocused()); + elm->set_isfocusable(obj->isFocusable()); + elm->set_isscrollable(obj->isScrollable()); + elm->set_isselected(obj->isSelected()); + elm->set_isshowing(obj->isShowing()); + elm->set_isactive(obj->isActive()); + elm->set_isvisible(obj->isVisible()); + elm->set_isselectable(obj->isSelectable()); } mResponse->set_status(::aurum::RspStatus::OK); } -- 2.7.4 From 087624826e1642249cc28368c4dd763b0da0e51d Mon Sep 17 00:00:00 2001 From: Woochanlee Date: Wed, 30 Jun 2021 15:11:21 +0900 Subject: [PATCH 06/16] libaurum: Print dlog instead of file write(loguru) Change-Id: I634bf285fa4551166c9afdd9a1e3c93fd6052df7 --- libaurum/inc/A11yEvent.h | 1 - libaurum/inc/Aurum.h | 16 ++++++ libaurum/meson.build | 1 + libaurum/src/A11yEvent.cc | 1 + .../src/Accessibility/AccessibleApplication.cc | 4 +- libaurum/src/Accessibility/AccessibleNode.cc | 9 ++-- libaurum/src/Accessibility/AccessibleUtils.cc | 8 +-- libaurum/src/Accessibility/AccessibleWatcher.cc | 14 +++--- libaurum/src/Accessibility/AccessibleWindow.cc | 3 +- libaurum/src/Comparer.cc | 13 ++--- .../Accessibility/AtspiAccessibleApplication.cc | 2 - .../src/Impl/Accessibility/AtspiAccessibleNode.cc | 11 ++-- .../Impl/Accessibility/AtspiAccessibleWatcher.cc | 58 +++++++++++----------- .../Accessibility/MockAccessibleApplication.cc | 2 - libaurum/src/Impl/MockDeviceImpl.cc | 1 - libaurum/src/PartialMatch.cc | 6 +-- libaurum/src/Runnable/SendKeyRunnable.cc | 7 +-- libaurum/src/Sel.cc | 2 +- libaurum/src/UiDevice.cc | 7 +-- libaurum/src/UiObject.cc | 9 ++-- libaurum/src/UiScrollable.cc | 2 +- libaurum/src/UiSelector.cc | 2 +- libaurum/src/Until.cc | 11 ++-- libaurum/src/Waiter.cc | 10 ++-- packaging/aurum.spec | 1 + 25 files changed, 92 insertions(+), 109 deletions(-) diff --git a/libaurum/inc/A11yEvent.h b/libaurum/inc/A11yEvent.h index 43da498..28ab8a4 100644 --- a/libaurum/inc/A11yEvent.h +++ b/libaurum/inc/A11yEvent.h @@ -1,6 +1,5 @@ #pragma once #include "bitmask.h" - #include enum class A11yEvent { diff --git a/libaurum/inc/Aurum.h b/libaurum/inc/Aurum.h index 801d2dd..2f46351 100644 --- a/libaurum/inc/Aurum.h +++ b/libaurum/inc/Aurum.h @@ -1,3 +1,13 @@ +#ifndef _AURUM_H_ +#define _AURUM_H_ + +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "AURUM" + #include "UiDevice.h" #include "UiObject.h" #include "UiSelector.h" @@ -15,3 +25,9 @@ #include "IEventSource.h" #include "Point2D.h" #include "Rect.h" +#include "PartialMatch.h" +#include "Comparer.h" +#include "A11yEvent.h" +#include "Runnables.h" + +#endif /* _AURUM_H_ */ diff --git a/libaurum/meson.build b/libaurum/meson.build index 85afdb3..257e6f4 100644 --- a/libaurum/meson.build +++ b/libaurum/meson.build @@ -49,6 +49,7 @@ if get_option('tizen') == true libaurum_dep += [ dependency('capi-system-info'), dependency('capi-ui-efl-util'), + dependency('dlog'), dependency('elementary'), dependency('libtdm'), ] diff --git a/libaurum/src/A11yEvent.cc b/libaurum/src/A11yEvent.cc index 325d6fb..996fb33 100644 --- a/libaurum/src/A11yEvent.cc +++ b/libaurum/src/A11yEvent.cc @@ -1,5 +1,6 @@ #include "A11yEvent.h" +#include "Aurum.h" #include A11yEventInfo::A11yEventInfo() : A11yEventInfo(A11yEvent::EVENT_NONE, nullptr, nullptr) {} diff --git a/libaurum/src/Accessibility/AccessibleApplication.cc b/libaurum/src/Accessibility/AccessibleApplication.cc index 6fe51d6..fdbb013 100644 --- a/libaurum/src/Accessibility/AccessibleApplication.cc +++ b/libaurum/src/Accessibility/AccessibleApplication.cc @@ -1,8 +1,6 @@ -#include "AccessibleApplication.h" -#include "AccessibleWatcher.h" +#include "Aurum.h" #include -#include AccessibleApplication::AccessibleApplication(std::shared_ptr node) : mNode{node} diff --git a/libaurum/src/Accessibility/AccessibleNode.cc b/libaurum/src/Accessibility/AccessibleNode.cc index 8e6dbb3..db1c386 100644 --- a/libaurum/src/Accessibility/AccessibleNode.cc +++ b/libaurum/src/Accessibility/AccessibleNode.cc @@ -1,13 +1,12 @@ -#include "AccessibleNode.h" +#include "Aurum.h" + #include #include #include -#include #include "config.h" #include - AccessibleNode::~AccessibleNode() { } @@ -76,7 +75,7 @@ void AccessibleNode::notify(int type, int type2, void *src) void AccessibleNode::invalidate() { std::unique_lock lock(mLock); - LOG_F(INFO, "object %p is now invalid", this); + dlog_print(DLOG_INFO, LOG_TAG, "object %p is now invalid", this); mValid = false; } @@ -101,7 +100,7 @@ void AccessibleNode::print(int depth, int maxDepth) void AccessibleNode::print(int d) { this->refresh(); - LOG_F(INFO, "%s%s",std::string(d, ' ').c_str(), description().c_str()); + dlog_print(DLOG_INFO, LOG_TAG, "%s %s",std::string(d, ' ').c_str(), description().c_str()); } bool AccessibleNode::isSupporting(AccessibleNodeInterface thisIface) const diff --git a/libaurum/src/Accessibility/AccessibleUtils.cc b/libaurum/src/Accessibility/AccessibleUtils.cc index 98b2082..76e0792 100644 --- a/libaurum/src/Accessibility/AccessibleUtils.cc +++ b/libaurum/src/Accessibility/AccessibleUtils.cc @@ -1,5 +1,5 @@ -#include "AccessibleUtils.h" -#include +#include "Aurum.h" + #include char* state_to_char(AtspiStateType state) @@ -108,11 +108,11 @@ static void _print_stateset_debug( AtspiStateSet *stateSet) char *state_name = NULL; AtspiStateType stat; - LOG_F(INFO, "check ss:%p s:%p, len:%d", stateSet, states, states->len); + dlog_print(DLOG_INFO, LOG_TAG, "check ss:%p s:%p, len:%d", stateSet, states, states->len); for (int i = 0; states && (i < states->len); ++i) { stat = g_array_index(states, AtspiStateType, i); state_name = state_to_char(stat); - LOG_SCOPE_F(INFO, "state: %s", state_name); + dlog_print(DLOG_INFO, LOG_TAG, "state: %s", state_name); free(state_name); } g_array_free(states, 1); diff --git a/libaurum/src/Accessibility/AccessibleWatcher.cc b/libaurum/src/Accessibility/AccessibleWatcher.cc index 3073482..f9636e7 100644 --- a/libaurum/src/Accessibility/AccessibleWatcher.cc +++ b/libaurum/src/Accessibility/AccessibleWatcher.cc @@ -1,16 +1,14 @@ -#include "AccessibleWatcher.h" +#include "Aurum.h" #ifdef TIZEN #include "AtspiAccessibleWatcher.h" #endif - #include "MockAccessibleWatcher.h" #include #include #include #include -#include AccessibleWatcher::AccessibleWatcher() :mSources{}, mLock{} @@ -59,17 +57,17 @@ AccessibleWatcher *AccessibleWatcher::getInstance(AccessibleWatcher *watcherImpl std::vector> AccessibleWatcher::getActiveApplications(void) const { - LOG_SCOPE_F(INFO, "getActiveApplications for this(%p)", this); + dlog_print(DLOG_INFO, LOG_TAG, "getActiveApplications for this(%p)", this); std::vector> ret{}; auto apps = this->getApplications(); - LOG_F(INFO, "apps size %d", apps.size()); + dlog_print(DLOG_INFO, LOG_TAG, "apps size %d", apps.size()); apps.erase(std::remove_if(apps.begin(), apps.end(), [](auto app){ return !app->isActive(); }), apps.end()); - LOG_F(INFO, "active apps size %d", apps.size()); + dlog_print(DLOG_INFO, LOG_TAG, "active apps size %d", apps.size()); return apps; } @@ -77,7 +75,7 @@ std::vector> AccessibleWatcher::getActive void AccessibleWatcher::attach(std::shared_ptr source) { std::unique_lock lock(mLock); - LOG_F(INFO, "source attached %p", source.get()); + dlog_print(DLOG_INFO, LOG_TAG, "source attached %p", source.get()); if (source) { mSources.insert(source); } @@ -86,7 +84,7 @@ void AccessibleWatcher::attach(std::shared_ptr source) void AccessibleWatcher::detach(std::shared_ptr source) { std::unique_lock lock(mLock); - LOG_F(INFO, "source detached %p", source.get()); + dlog_print(DLOG_INFO, LOG_TAG, "source detached %p", source.get()); if (source) { auto iter = mSources.find(source); if (iter != mSources.end()) mSources.erase(iter); diff --git a/libaurum/src/Accessibility/AccessibleWindow.cc b/libaurum/src/Accessibility/AccessibleWindow.cc index 437f141..2818edb 100644 --- a/libaurum/src/Accessibility/AccessibleWindow.cc +++ b/libaurum/src/Accessibility/AccessibleWindow.cc @@ -1,5 +1,4 @@ -#include "AccessibleWindow.h" -#include "AccessibleWatcher.h" +#include "Aurum.h" AccessibleWindow::AccessibleWindow(std::shared_ptr app, std::shared_ptr node) : mApp{app}, mNode{node} diff --git a/libaurum/src/Comparer.cc b/libaurum/src/Comparer.cc index b54298f..e23cf54 100644 --- a/libaurum/src/Comparer.cc +++ b/libaurum/src/Comparer.cc @@ -1,6 +1,4 @@ -#include "Comparer.h" - -#include +#include "Aurum.h" Comparer::Comparer(const std::shared_ptr device, const std::shared_ptr selector, const bool &earlyReturn) @@ -27,7 +25,7 @@ std::vector> Comparer::findObjects(const std::sh { Comparer comparer(device, selector, earlyReturn); - LOG_SCOPE_F(INFO, "findObjects selector(%s) from (type:%s style:%s, role:%s, text:%s) earlyReturn:%d", selector->description().c_str(), root->getType().c_str(), root->getStyle().c_str(), root->getRole().c_str(), root->getText().c_str(), earlyReturn); + dlog_print(DLOG_INFO, LOG_TAG, "findObjects selector(%s) from (type:%s style:%s, role:%s, text:%s) earlyReturn:%d", selector->description().c_str(), root->getType().c_str(), root->getStyle().c_str(), root->getRole().c_str(), root->getText().c_str(), earlyReturn); if (selector->mParent) { auto ret = Comparer::findObjects(device, selector->mParent, root); @@ -47,7 +45,7 @@ std::vector> Comparer::findObjects(const std::sh { std::list> partialList{}; std::vector> ret = findObjects(root, 0, 0, partialList); - LOG_F(INFO, "%d object(s) found", ret.size()); + dlog_print(DLOG_INFO, LOG_TAG, "%d object(s) found", ret.size()); return ret; } @@ -56,7 +54,6 @@ std::vector> Comparer::findObjects( std::list> &partialMatches) { std::vector> ret; - //LOG_SCOPE_F(INFO, "findObjects idx:%d, depth:%d, partialMatches.size:%d", index, depth, partialMatches.size()); root->refresh(); for (auto &match : partialMatches) @@ -79,11 +76,11 @@ std::vector> Comparer::findObjects( if (!ret.empty() && mEarlyReturn) return ret; } } else { - LOG_F(INFO, "Abort searching! No need to search children(maxDepth limit overflow, %d < %d < %d)", mSelector->mMinDepth?*(mSelector->mMinDepth):-1, depth, mSelector->mMaxDepth?*(mSelector->mMaxDepth):9999999); + dlog_print(DLOG_INFO, LOG_TAG, "Abort searching! No need to search children(maxDepth limit overflow, %d < %d < %d)", mSelector->mMinDepth?*(mSelector->mMinDepth):-1, depth, mSelector->mMaxDepth?*(mSelector->mMaxDepth):9999999); } if (currentMatch && currentMatch->finalizeMatch()){ - LOG_F(INFO, "Found matched = %s with criteria %s", root->description().c_str(), currentMatch->debugPrint().c_str()); + dlog_print(DLOG_INFO, LOG_TAG, "Found matched = %s with criteria %s", root->description().c_str(), currentMatch->debugPrint().c_str()); ret.push_back(root); } diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleApplication.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleApplication.cc index 79aec79..c458fa0 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleApplication.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleApplication.cc @@ -5,8 +5,6 @@ #include #include -#include - AtspiAccessibleApplication::AtspiAccessibleApplication(std::shared_ptr node) : AccessibleApplication(node) { diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc index 68239bf..a918fd6 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc @@ -1,11 +1,10 @@ +#include "Aurum.h" + #include "AtspiAccessibleNode.h" -#include "AccessibleWatcher.h" #include "AtspiWrapper.h" #include -#include - //std::map AccessibleNode::mNodeMap{}; AtspiAccessibleNode::AtspiAccessibleNode(AtspiAccessible *node) @@ -70,7 +69,7 @@ AtspiAccessibleNode::AtspiAccessibleNode(AtspiAccessible *node) this->refresh(); } else { - LOG_F(INFO, "AtspiAccessibleNode Ctor : mNode is null"); + dlog_print(DLOG_INFO, LOG_TAG, "AtspiAccessibleNode Ctor : mNode is null"); } } @@ -101,7 +100,7 @@ std::shared_ptr AtspiAccessibleNode::getChildAt(int index) const AtspiWrapper::unlock(); return std::make_shared(nullptr); } - LOG_SCOPE_F(INFO, "getChild @ %d from node(%p)", index, mNode); + dlog_print(DLOG_INFO, LOG_TAG, "getChild @ %d from node(%p)", index, mNode); AtspiAccessible *rawChild = AtspiWrapper::Atspi_accessible_get_child_at_index(mNode, index, NULL); AtspiWrapper::unlock(); return std::make_shared(rawChild); @@ -310,7 +309,7 @@ void AtspiAccessibleNode::setValue(std::string text) } AtspiEditableText *iface = AtspiWrapper::Atspi_accessible_get_editable_text(mNode); - LOG_F(INFO,"set Value iface:%p obj:%p text:%s", iface, mNode, text.c_str() ); + dlog_print(DLOG_INFO, LOG_TAG, "set Value iface:%p obj:%p text:%s", iface, mNode, text.c_str() ); if (iface) { int len = getText().length(); AtspiWrapper::Atspi_editable_text_delete_text(iface, 0, len, NULL); diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc index 46544d7..bffa403 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc @@ -1,9 +1,11 @@ -#include "AtspiAccessibleWatcher.h" +#include "Aurum.h" +#include "AtspiAccessibleWatcher.h" #include "AtspiAccessibleApplication.h" #include "AtspiAccessibleWindow.h" #include "AtspiAccessibleNode.h" #include "AtspiWrapper.h" + #include #include #include @@ -20,12 +22,12 @@ static bool iShowingNode(AtspiAccessible *node) if (node) name = AtspiWrapper::Atspi_accessible_get_name(node, NULL); else return false; - LOG_SCOPE_F(INFO, "isShowing %s", name); + dlog_print(DLOG_INFO, LOG_TAG, "isShowing %s", name); auto stateSet = AtspiWrapper::Atspi_accessible_get_state_set(node); if (AtspiWrapper::Atspi_state_set_contains(stateSet, ATSPI_STATE_ACTIVE) && AtspiWrapper::Atspi_state_set_contains(stateSet, ATSPI_STATE_SHOWING)) { - LOG_F(INFO, "active and showing %p %s", node, name); + dlog_print(DLOG_INFO, LOG_TAG, "active and showing %p %s", node, name); free(name); g_object_unref(stateSet); return true; @@ -39,14 +41,14 @@ static std::vector findActiveNode(AtspiAccessible *node, int depth, int max_depth) { - LOG_SCOPE_F(INFO, "findActiveNode %p %d/%d", node, depth, max_depth); + dlog_print(DLOG_INFO, LOG_TAG, "findActiveNode %p %d/%d", node, depth, max_depth); std::vector ret{}; if (iShowingNode(node)) { char *name = AtspiWrapper::Atspi_accessible_get_name(node, NULL); if (name) { - LOG_SCOPE_F(INFO, "%s", name); + dlog_print(DLOG_INFO, LOG_TAG, "%s", name); free(name); } ret.push_back(node); @@ -58,10 +60,10 @@ findActiveNode(AtspiAccessible *node, int depth, int nchild = AtspiWrapper::Atspi_accessible_get_child_count(node, NULL); if (nchild <= 0) return ret; - LOG_F(INFO, "findActiveNode node %p has %d children", node, nchild); + dlog_print(DLOG_INFO, LOG_TAG, "findActiveNode node %p has %d children", node, nchild); for (int i = 0; i < nchild; i++) { AtspiAccessible* child = AtspiWrapper::Atspi_accessible_get_child_at_index(node, i, NULL); - LOG_F(INFO, "a child found @ %d : %p", i, child); + dlog_print(DLOG_INFO, LOG_TAG, "a child found @ %d : %p", i, child); std::vector childRet = findActiveNode(child, depth + 1, max_depth); ret.insert(ret.end(), childRet.begin(), childRet.end()); g_object_unref(child); @@ -72,7 +74,7 @@ findActiveNode(AtspiAccessible *node, int depth, static gpointer _event_thread_loop (gpointer data) { - LOG_F(INFO, "event thread start"); + dlog_print(DLOG_INFO, LOG_TAG, "event thread start"); AtspiEventListener * listener = atspi_event_listener_new(AtspiAccessibleWatcher::onAtspiEvents, data, NULL); @@ -81,7 +83,7 @@ static gpointer _event_thread_loop (gpointer data) atspi_event_main(); - LOG_F(INFO, "event thread end"); + dlog_print(DLOG_INFO, LOG_TAG, "event thread end"); atspi_event_listener_deregister(listener, "object:", NULL); atspi_event_listener_deregister(listener, "window:", NULL); @@ -207,57 +209,57 @@ void AtspiAccessibleWatcher::onAtspiEvents(AtspiEvent *event, void *user_data) void AtspiAccessibleWatcher::print_debug() { - LOG_F(INFO, "activatewindowlist-------------------"); + dlog_print(DLOG_INFO, LOG_TAG, "activatewindowlist-------------------"); std::for_each(mActivatedWindowList.begin(), mActivatedWindowList.end(), [](auto acc){ - LOG_F(INFO, "child:%p", acc); + dlog_print(DLOG_INFO, LOG_TAG, "child:%p", acc); }); - LOG_F(INFO, "mActivatedApplicationList--------------------------"); + dlog_print(DLOG_INFO, LOG_TAG, "mActivatedApplicationList--------------------------"); std::for_each(mActivatedApplicationList.begin(), mActivatedApplicationList.end(), [](auto acc){ - LOG_F(INFO, "child:%p", acc); + dlog_print(DLOG_INFO, LOG_TAG, "child:%p", acc); }); - LOG_F(INFO, "mWindowSet------------------------------"); + dlog_print(DLOG_INFO, LOG_TAG, "mWindowSet------------------------------"); std::for_each(mWindowSet.begin(), mWindowSet.end(), [](auto acc){ - LOG_F(INFO, "child:%p", acc); + dlog_print(DLOG_INFO, LOG_TAG, "child:%p", acc); }); - LOG_F(INFO, "------------------------------"); + dlog_print(DLOG_INFO, LOG_TAG, "------------------------------"); } void AtspiAccessibleWatcher::onWindowActivated(AtspiAccessible *node, WindowActivateInfoType type) { - LOG_SCOPE_F(INFO, "onWindowActivated obj:%p", node); + dlog_print(DLOG_INFO, LOG_TAG, "onWindowActivated obj:%p", node); notifyAll((int)EventType::Window, (int)WindowEventType::WindowActivated, node); } void AtspiAccessibleWatcher::onWindowDeactivated(AtspiAccessible *node) { - LOG_SCOPE_F(INFO, "onWindowDeactivated obj:%p", node); + dlog_print(DLOG_INFO, LOG_TAG, "onWindowDeactivated obj:%p", node); notifyAll((int)EventType::Window, (int)WindowEventType::WindowDeactivated, node); } void AtspiAccessibleWatcher::onWindowCreated(AtspiAccessible *node) { - LOG_SCOPE_F(INFO, "onWindowCreated obj:%p", node); + dlog_print(DLOG_INFO, LOG_TAG, "onWindowCreated obj:%p", node); notifyAll((int)EventType::Window, (int)WindowEventType::WindowCreated, node); } void AtspiAccessibleWatcher::onWindowDestroyed(AtspiAccessible *node) { - LOG_SCOPE_F(INFO, "onWindowDestroyed obj:%p", node); + dlog_print(DLOG_INFO, LOG_TAG, "onWindowDestroyed obj:%p", node); notifyAll((int)EventType::Window, (int)WindowEventType::WindowDestroyed, node); } void AtspiAccessibleWatcher::onVisibilityChanged(AtspiAccessible *node, bool visible) { - LOG_SCOPE_F(INFO, "onVisibilityChanged obj:%p", node); + dlog_print(DLOG_INFO, LOG_TAG, "onVisibilityChanged obj:%p", node); notifyAll((int)EventType::Object, (int)ObjectEventType::ObjectStateVisible, node); } void AtspiAccessibleWatcher::onObjectDefunct(AtspiAccessible *node) { - LOG_SCOPE_F(INFO, "onObjectDefunct obj:%p", node); + dlog_print(DLOG_INFO, LOG_TAG, "onObjectDefunct obj:%p", node); notifyAll((int)EventType::Object, (int)ObjectEventType::ObjectStateDefunct, node); } @@ -288,7 +290,7 @@ std::shared_ptr AtspiAccessibleWatcher::getApplicationAt( std::vector> AtspiAccessibleWatcher::getApplications(void) const { AtspiWrapper::lock(); - LOG_SCOPE_F(INFO, "getApplications for this(%p)", this); + dlog_print(DLOG_INFO, LOG_TAG, "getApplications for this(%p)", this); std::vector> ret{}; AtspiAccessible *root = AtspiWrapper::Atspi_get_desktop(0); int nchild = AtspiWrapper::Atspi_accessible_get_child_count(root, NULL); @@ -335,7 +337,7 @@ bool AtspiAccessibleWatcher::executeAndWaitForEvents(const Runnable *cmd, const for (const auto &event : localEvents) { if (COMPARE(type, event->getEvent())) { - LOG_F(INFO, "type %d == %d name %s pkg %s",static_cast(type), static_cast(event->getEvent()), event->getName().c_str(), event->getPkg().c_str()); + dlog_print(DLOG_INFO, LOG_TAG, "type %d == %d name %s pkg %s",static_cast(type), static_cast(event->getEvent()), event->getName().c_str(), event->getPkg().c_str()); return true; } } @@ -352,11 +354,11 @@ bool AtspiAccessibleWatcher::executeAndWaitForEvents(const Runnable *cmd, const bool AtspiAccessibleWatcher::removeFromActivatedList(AtspiAccessible *node) { - LOG_SCOPE_F(INFO,"remove from activelist node %p", node); + dlog_print(DLOG_INFO, LOG_TAG, "remove from activelist node %p", node); mActivatedWindowList.remove_if([&](auto &n) { return n == node; }); AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(node, NULL); - LOG_F(INFO, "node:%p, app:%p", node, app); + dlog_print(DLOG_INFO, LOG_TAG, "node:%p, app:%p", node, app); if (app) { mActivatedApplicationList.remove_if([&](auto &n) { return n == app; }); g_object_unref(app); @@ -366,7 +368,7 @@ bool AtspiAccessibleWatcher::removeFromActivatedList(AtspiAccessible *node) bool AtspiAccessibleWatcher::addToActivatedList(AtspiAccessible *node) { - LOG_SCOPE_F(INFO,"add to activelist node %p", node); + dlog_print(DLOG_INFO, LOG_TAG, "add to activelist node %p", node); mActivatedWindowList.remove_if([&](auto &n) { return n == node; }); mActivatedWindowList.push_front(node); @@ -374,7 +376,7 @@ bool AtspiAccessibleWatcher::addToActivatedList(AtspiAccessible *node) if ( iter == mWindowSet.end()) mWindowSet.insert(node); AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(node, NULL); - LOG_F(INFO, "node:%p, app:%p", node, app); + dlog_print(DLOG_INFO, LOG_TAG, "node:%p, app:%p", node, app); if (app) { mActivatedApplicationList.remove_if([&](auto &n) { if(n == app) { g_object_unref(app); return true;} else return false; }); mActivatedApplicationList.push_front(app); diff --git a/libaurum/src/Impl/Accessibility/MockAccessibleApplication.cc b/libaurum/src/Impl/Accessibility/MockAccessibleApplication.cc index e4f0f34..ed89a5a 100644 --- a/libaurum/src/Impl/Accessibility/MockAccessibleApplication.cc +++ b/libaurum/src/Impl/Accessibility/MockAccessibleApplication.cc @@ -4,8 +4,6 @@ #include -#include - MockAccessibleApplication::MockAccessibleApplication(std::shared_ptr node) : AccessibleApplication(node), mWindowList{} { diff --git a/libaurum/src/Impl/MockDeviceImpl.cc b/libaurum/src/Impl/MockDeviceImpl.cc index 486c32e..0184b44 100644 --- a/libaurum/src/Impl/MockDeviceImpl.cc +++ b/libaurum/src/Impl/MockDeviceImpl.cc @@ -1,5 +1,4 @@ #include "MockDeviceImpl.h" -#include #include #include diff --git a/libaurum/src/PartialMatch.cc b/libaurum/src/PartialMatch.cc index 3abc783..bfce60b 100644 --- a/libaurum/src/PartialMatch.cc +++ b/libaurum/src/PartialMatch.cc @@ -1,13 +1,10 @@ -#include "PartialMatch.h" +#include "Aurum.h" #include #include #include #include -#include - - bool PartialMatch::checkCriteria(const std::string *textA, const std::string textB, const bool *match) { if (!textA || !match) return false; @@ -80,7 +77,6 @@ std::shared_ptr PartialMatch::accept(const std::shared_ptrmMinDepth?*(selector->mMinDepth):-1, relativeDepth, selector->mMaxDepth?*(selector->mMaxDepth):9999999); PartialMatch *match = nullptr; if ((selector->mMinDepth && (relativeDepth < *(selector->mMinDepth))) || diff --git a/libaurum/src/Runnable/SendKeyRunnable.cc b/libaurum/src/Runnable/SendKeyRunnable.cc index 88e1fef..fc1f54c 100644 --- a/libaurum/src/Runnable/SendKeyRunnable.cc +++ b/libaurum/src/Runnable/SendKeyRunnable.cc @@ -1,7 +1,4 @@ -#include "SendKeyRunnable.h" - -#include -#include +#include "Aurum.h" SendKeyRunnable::SendKeyRunnable(std::string keycode) : mKeycode{keycode} @@ -10,7 +7,7 @@ SendKeyRunnable::SendKeyRunnable(std::string keycode) void SendKeyRunnable::run() const { - LOG_F(INFO, "sendKey %s",mKeycode.c_str()); + dlog_print(DLOG_INFO, LOG_TAG, "sendKey %s",mKeycode.c_str()); std::shared_ptr mDevice = UiDevice::getInstance(); mDevice->pressKeyCode(mKeycode.c_str(), KeyRequestType::PRESS); mDevice->pressKeyCode(mKeycode.c_str(), KeyRequestType::RELEASE); diff --git a/libaurum/src/Sel.cc b/libaurum/src/Sel.cc index 1897870..bf92244 100644 --- a/libaurum/src/Sel.cc +++ b/libaurum/src/Sel.cc @@ -1,4 +1,4 @@ -#include "Sel.h" +#include "Aurum.h" #include std::shared_ptr Sel::text(std::string text) diff --git a/libaurum/src/UiDevice.cc b/libaurum/src/UiDevice.cc index b9b5ab4..3250661 100644 --- a/libaurum/src/UiDevice.cc +++ b/libaurum/src/UiDevice.cc @@ -1,14 +1,10 @@ -#include "UiDevice.h" -#include "AccessibleWatcher.h" -#include "Comparer.h" +#include "Aurum.h" #ifdef TIZEN #include "TizenDeviceImpl.h" #endif #include "MockDeviceImpl.h" -#include "Runnables.h" - #include #include #include @@ -17,7 +13,6 @@ #include #include -#include UiDevice::UiDevice() : UiDevice(nullptr) {} UiDevice::UiDevice(IDevice *impl) diff --git a/libaurum/src/UiObject.cc b/libaurum/src/UiObject.cc index e363c7e..1095669 100644 --- a/libaurum/src/UiObject.cc +++ b/libaurum/src/UiObject.cc @@ -1,14 +1,11 @@ -#include "UiObject.h" -#include "Comparer.h" -#include "Sel.h" +#include "Aurum.h" #include #include -#include - #include #include + UiObject::UiObject() : UiObject(nullptr, nullptr, nullptr) {} UiObject::~UiObject() @@ -89,7 +86,7 @@ std::vector> UiObject::findObjects( auto nodes = Comparer::findObjects(mDevice, selector, getAccessibleNode()); for ( auto& node : nodes) { if (!node) { - LOG_F(INFO, "Skipped! (node == nullptr)"); + dlog_print(DLOG_INFO, LOG_TAG, "Skipped! (node == nullptr)"); continue; } result.push_back(std::make_shared(mDevice, selector, std::move(node))); diff --git a/libaurum/src/UiScrollable.cc b/libaurum/src/UiScrollable.cc index a051210..7c4ca8a 100644 --- a/libaurum/src/UiScrollable.cc +++ b/libaurum/src/UiScrollable.cc @@ -1,4 +1,4 @@ -#include "UiScrollable.h" +#include "Aurum.h" UiScrollable::UiScrollable(std::shared_ptr selector) : mSelector{selector}, mMaxSearchSwipe{100}, mScrollStep{50} diff --git a/libaurum/src/UiSelector.cc b/libaurum/src/UiSelector.cc index ae14799..5caad3d 100644 --- a/libaurum/src/UiSelector.cc +++ b/libaurum/src/UiSelector.cc @@ -1,4 +1,4 @@ -#include "UiSelector.h" +#include "Aurum.h" #include #include diff --git a/libaurum/src/Until.cc b/libaurum/src/Until.cc index c243fca..324635b 100644 --- a/libaurum/src/Until.cc +++ b/libaurum/src/Until.cc @@ -1,13 +1,10 @@ -#include - -#include -#include +#include "Aurum.h" std::function Until::hasObject( const std::shared_ptr selector) { return [=](const ISearchable *searchable) -> bool { - LOG_SCOPE_F(INFO, "Until::hasObject search:%p", searchable); + dlog_print(DLOG_INFO, LOG_TAG, "Until::hasObject search:%p", searchable); std::shared_ptr obj = searchable->findObject(selector); return obj.get() != nullptr; }; @@ -17,7 +14,7 @@ std::function(const ISearchable *)> Until::findObject( const std::shared_ptr selector) { return [=](const ISearchable *searchable) -> std::shared_ptr { - LOG_SCOPE_F(INFO, "Until::findObject search:%p", searchable); + dlog_print(DLOG_INFO, LOG_TAG, "Until::findObject search:%p", searchable); std::shared_ptr obj = searchable->findObject(selector); return obj; }; @@ -26,7 +23,7 @@ std::function(const ISearchable *)> Until::findObject( std::function Until::checkable(const bool isCheckable) { return [=](const UiObject *object) -> bool { - LOG_SCOPE_F(INFO, "Until::checkable checkable:%d for obj %p", isCheckable, object); + dlog_print(DLOG_INFO, LOG_TAG, "Until::checkable checkable:%d for obj %p", isCheckable, object); return object->isClickable() == isCheckable; }; } diff --git a/libaurum/src/Waiter.cc b/libaurum/src/Waiter.cc index bdee46a..dfb2ae8 100644 --- a/libaurum/src/Waiter.cc +++ b/libaurum/src/Waiter.cc @@ -1,12 +1,8 @@ -#include "Waiter.h" +#include "Aurum.h" #include #include #include -#include "ISearchable.h" -#include "UiObject.h" -#include - Waiter::Waiter() : Waiter(nullptr) {} Waiter::~Waiter() {} @@ -32,7 +28,7 @@ template bool Waiter::waitFor( template R Waiter::waitFor(const std::function condition) const { - LOG_SCOPE_F(INFO, "Waiter::waitFor ISearchable"); + dlog_print(DLOG_INFO, LOG_TAG, "Waiter::waitFor ISearchable"); // startTime = currentTime(); std::chrono::system_clock::time_point start = std::chrono::system_clock::now(); @@ -51,7 +47,7 @@ R Waiter::waitFor(const std::function condition) const template R Waiter::waitFor(const std::function condition) const { - LOG_SCOPE_F(INFO, "Waiter::waitFor UiObject"); + dlog_print(DLOG_INFO, LOG_TAG, "Waiter::waitFor UiObject"); if (mUiObject) { std::chrono::system_clock::time_point start = std::chrono::system_clock::now(); diff --git a/packaging/aurum.spec b/packaging/aurum.spec index 065d7b6..7e14f5d 100644 --- a/packaging/aurum.spec +++ b/packaging/aurum.spec @@ -24,6 +24,7 @@ BuildRequires: pkgconfig(capi-appfw-package-manager) BuildRequires: pkgconfig(capi-appfw-app-control) BuildRequires: pkgconfig(capi-appfw-app-manager) BuildRequires: pkgconfig(capi-appfw-service-application) +BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(capi-system-device) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(capi-system-system-settings) -- 2.7.4 From e75c780e049122fb50d74c2f67c93270e2480a9b Mon Sep 17 00:00:00 2001 From: Hosang Kim Date: Tue, 29 Jun 2021 19:47:07 +0900 Subject: [PATCH 07/16] libaurum: apply cache clear when element is updated. Change-Id: Iac3a6c2811ac36237456b55792e634103f4f9b8d --- libaurum/inc/Impl/Accessibility/AtspiWrapper.h | 3 ++- libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc | 3 +++ libaurum/src/Impl/Accessibility/AtspiWrapper.cc | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libaurum/inc/Impl/Accessibility/AtspiWrapper.h b/libaurum/inc/Impl/Accessibility/AtspiWrapper.h index beac01a..0bebabc 100644 --- a/libaurum/inc/Impl/Accessibility/AtspiWrapper.h +++ b/libaurum/inc/Impl/Accessibility/AtspiWrapper.h @@ -26,10 +26,11 @@ public: static gboolean Atspi_editable_text_delete_text(AtspiEditableText*, int start, int end, GError **error); static gboolean Atspi_editable_text_insert_text(AtspiEditableText*, int pos, const gchar *text, int len, GError **error); static AtspiAccessible* Atspi_accessible_get_application (AtspiAccessible *node, GError **error); + static void Atspi_accessible_clear_cache (AtspiAccessible *node); static void lock(); static void unlock(); private: static std::recursive_mutex mMutex; //static std::unique_lock mLock; -}; \ No newline at end of file +}; diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc index a918fd6..c9d7259 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc @@ -155,6 +155,9 @@ void* AtspiAccessibleNode::getRawHandler(void) const void AtspiAccessibleNode::refresh() { AtspiWrapper::lock(); + + AtspiWrapper::Atspi_accessible_clear_cache(mNode); + if (isValid()) { gchar *rolename = AtspiWrapper::Atspi_accessible_get_role_name(mNode, NULL); if (rolename) { diff --git a/libaurum/src/Impl/Accessibility/AtspiWrapper.cc b/libaurum/src/Impl/Accessibility/AtspiWrapper.cc index 308b9af..69e47c6 100644 --- a/libaurum/src/Impl/Accessibility/AtspiWrapper.cc +++ b/libaurum/src/Impl/Accessibility/AtspiWrapper.cc @@ -135,6 +135,11 @@ AtspiAccessible* AtspiWrapper::Atspi_accessible_get_application (AtspiAccessible return atspi_accessible_get_application(node, error); } +void AtspiWrapper::Atspi_accessible_clear_cache (AtspiAccessible *node) +{ + std::unique_lock lock(mMutex); + return atspi_accessible_clear_cache(node); +} void AtspiWrapper::lock() { mMutex.lock(); -- 2.7.4 From 76c509a3846b5a377ac24e7d0a3ff79d10e81bb1 Mon Sep 17 00:00:00 2001 From: Hosang Kim Date: Wed, 30 Jun 2021 19:09:57 +0900 Subject: [PATCH 08/16] aurum: add package name for findElement API Change-Id: Ia5f3c24d40b5e64ebb0ca65d6553119f9a175608 --- org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc | 1 + protocol/aurum.proto | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc index 59ba209..590806f 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc @@ -47,6 +47,7 @@ std::vector> FindElementCommand::getSelectors(void) if(mRequest->_isactive_case()) sel->isActive(mRequest->isactive()); if(mRequest->_mindepth_case()) sel->minDepth(mRequest->mindepth()); if(mRequest->_maxdepth_case()) sel->maxDepth(mRequest->maxdepth()); + if(mRequest->_packagename_case()) sel->pkg(mRequest->packagename()); return std::vector>{sel}; } diff --git a/protocol/aurum.proto b/protocol/aurum.proto index a93de34..23f6f67 100644 --- a/protocol/aurum.proto +++ b/protocol/aurum.proto @@ -157,7 +157,11 @@ message ReqFindElement { int32 maxDepth = 17; } - repeated ReqFindElement children = 18; + oneof _packagename { + string packageName = 18; + } + + repeated ReqFindElement children = 19; } message RspFindElement { RspStatus status = 1; -- 2.7.4 From e47acb6523dad2056cb03789caad98df6323ab24 Mon Sep 17 00:00:00 2001 From: Woochanlee Date: Wed, 30 Jun 2021 19:57:36 +0900 Subject: [PATCH 09/16] libaurum: Re-arrange headers Divide interface, Combine Accessble, Move header to proper location etc... Change-Id: I6c27896543ceca46cf61c57a746f2060e16ac4b5 --- libaurum/inc/Accessibility/Accessible.h | 12 ++++++++++++ libaurum/inc/Accessibility/AccessibleWatcher.h | 1 - libaurum/inc/Aurum.h | 8 +------- libaurum/inc/{ => Interface}/IDevice.h | 0 libaurum/inc/{ => Interface}/ISearchable.h | 0 libaurum/inc/{ => Misc}/bitmask.h | 0 libaurum/meson.build | 18 ++++++------------ libaurum/src/A11yEvent.cc | 3 +-- 8 files changed, 20 insertions(+), 22 deletions(-) create mode 100644 libaurum/inc/Accessibility/Accessible.h rename libaurum/inc/{ => Interface}/IDevice.h (100%) rename libaurum/inc/{ => Interface}/ISearchable.h (100%) rename libaurum/inc/{ => Misc}/bitmask.h (100%) diff --git a/libaurum/inc/Accessibility/Accessible.h b/libaurum/inc/Accessibility/Accessible.h new file mode 100644 index 0000000..3292ad8 --- /dev/null +++ b/libaurum/inc/Accessibility/Accessible.h @@ -0,0 +1,12 @@ +#ifndef _ACCESSIBLE_H_ +#define _ACCESSIBLE_H_ + +#include "AccessibleNode.h" +#include "AccessibleUtils.h" +#include "AccessibleWatcher.h" +#include "AccessibleApplication.h" +#include "AccessibleWindow.h" +#include "IEventConsumer.h" +#include "IEventSource.h" + +#endif /* _ACCESSIBLE_H_ */ diff --git a/libaurum/inc/Accessibility/AccessibleWatcher.h b/libaurum/inc/Accessibility/AccessibleWatcher.h index e695057..d9869cd 100644 --- a/libaurum/inc/Accessibility/AccessibleWatcher.h +++ b/libaurum/inc/Accessibility/AccessibleWatcher.h @@ -1,6 +1,5 @@ #pragma once - #include "AccessibleApplication.h" #include "AccessibleWindow.h" #include "AccessibleNode.h" diff --git a/libaurum/inc/Aurum.h b/libaurum/inc/Aurum.h index 2f46351..76e7405 100644 --- a/libaurum/inc/Aurum.h +++ b/libaurum/inc/Aurum.h @@ -16,13 +16,7 @@ #include "Waiter.h" #include "ISearchable.h" #include "IDevice.h" -#include "AccessibleNode.h" -#include "AccessibleUtils.h" -#include "AccessibleWatcher.h" -#include "AccessibleApplication.h" -#include "AccessibleWindow.h" -#include "IEventConsumer.h" -#include "IEventSource.h" +#include "Accessible.h" #include "Point2D.h" #include "Rect.h" #include "PartialMatch.h" diff --git a/libaurum/inc/IDevice.h b/libaurum/inc/Interface/IDevice.h similarity index 100% rename from libaurum/inc/IDevice.h rename to libaurum/inc/Interface/IDevice.h diff --git a/libaurum/inc/ISearchable.h b/libaurum/inc/Interface/ISearchable.h similarity index 100% rename from libaurum/inc/ISearchable.h rename to libaurum/inc/Interface/ISearchable.h diff --git a/libaurum/inc/bitmask.h b/libaurum/inc/Misc/bitmask.h similarity index 100% rename from libaurum/inc/bitmask.h rename to libaurum/inc/Misc/bitmask.h diff --git a/libaurum/meson.build b/libaurum/meson.build index 257e6f4..24d3c3b 100644 --- a/libaurum/meson.build +++ b/libaurum/meson.build @@ -7,18 +7,12 @@ libaurum_install_inc = [ './inc/Sel.h', './inc/Until.h', './inc/Waiter.h', - './inc/ISearchable.h', - './inc/IDevice.h', + './inc/Interface/ISearchable.h', + './inc/Interface/IDevice.h', './inc/A11yEvent.h', - './inc/bitmask.h', - './inc/Accessibility/AccessibleNode.h', - './inc/Accessibility/AccessibleUtils.h', - './inc/Accessibility/AccessibleWatcher.h', - './inc/Accessibility/AccessibleApplication.h', - './inc/Accessibility/AccessibleWindow.h', - './inc/Accessibility/IEventConsumer.h', - './inc/Accessibility/IEventSource.h', + './inc/Accessibility/Accessible.h', './inc/Runnable/Runnable.h', + './inc/Misc/bitmask.h', './inc/Misc/Point2D.h', './inc/Misc/Rect.h', './inc/Aurum.h', @@ -30,7 +24,8 @@ libaurum_inc = [ include_directories('./inc/Impl'), include_directories('./inc/Impl/Accessibility'), include_directories('./inc/Misc'), - include_directories('./inc/Runnable/'), + include_directories('./inc/Runnable'), + include_directories('./inc/Interface'), root_inc, loguru_inc, ] @@ -77,4 +72,3 @@ libaurum = declare_dependency(link_with: libaurum_lib, install_headers(libaurum_install_inc, ) - diff --git a/libaurum/src/A11yEvent.cc b/libaurum/src/A11yEvent.cc index 996fb33..d4d0bed 100644 --- a/libaurum/src/A11yEvent.cc +++ b/libaurum/src/A11yEvent.cc @@ -1,6 +1,5 @@ -#include "A11yEvent.h" - #include "Aurum.h" + #include A11yEventInfo::A11yEventInfo() : A11yEventInfo(A11yEvent::EVENT_NONE, nullptr, nullptr) {} -- 2.7.4 From 7386c192cdcbea8c831ab7abc0e48a52873f7fed Mon Sep 17 00:00:00 2001 From: Woochanlee Date: Thu, 1 Jul 2021 16:40:30 +0900 Subject: [PATCH 10/16] libaurum: Sync connect mouse device when wheel needed and code clean up File log update Change-Id: I0c8bd1a9bc44e286cf5389aa5a50540bfa487e69 --- libaurum/src/Impl/TizenDeviceImpl.cc | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/libaurum/src/Impl/TizenDeviceImpl.cc b/libaurum/src/Impl/TizenDeviceImpl.cc index fc81f06..82fc926 100644 --- a/libaurum/src/Impl/TizenDeviceImpl.cc +++ b/libaurum/src/Impl/TizenDeviceImpl.cc @@ -1,5 +1,6 @@ +#include "Aurum.h" + #include "TizenDeviceImpl.h" -#include #include #include @@ -17,15 +18,11 @@ TizenDeviceImpl::TizenDeviceImpl() : mFakeTouchHandle{0}, mFakeKeyboardHandle{0}, mFakeWheelHandle{0}, tStart{}, isTimerStarted{false}, mTouchSeq{} { - loguru::add_file("/tmp/aurum.log", loguru::Append, loguru::Verbosity_MAX); - loguru::g_stderr_verbosity = loguru::Verbosity_ERROR; - - LOG_SCOPE_F(INFO, "device implementation init"); + dlog_print(DLOG_INFO, LOG_TAG, "device implementation init"); TizenDeviceImpl *obj = static_cast(this); obj->mFakeTouchHandle = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN); obj->mFakeKeyboardHandle = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_KEYBOARD); - obj->mFakeWheelHandle = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_POINTER); } TizenDeviceImpl::~TizenDeviceImpl() @@ -33,7 +30,6 @@ TizenDeviceImpl::~TizenDeviceImpl() TizenDeviceImpl *obj = static_cast(this); efl_util_input_deinitialize_generator(obj->mFakeTouchHandle); efl_util_input_deinitialize_generator(obj->mFakeKeyboardHandle); - efl_util_input_deinitialize_generator(obj->mFakeWheelHandle); } bool TizenDeviceImpl::click(const int x, const int y) @@ -43,7 +39,7 @@ bool TizenDeviceImpl::click(const int x, const int y) bool TizenDeviceImpl::click(const int x, const int y, const unsigned int intv) { - LOG_SCOPE_F(INFO, "click %d %d , intv:%d", x, y, intv); + dlog_print(DLOG_INFO, LOG_TAG, "click %d %d , intv:%d", x, y, intv); int seq = touchDown(x, y); if (seq < 0) return false; @@ -57,7 +53,7 @@ bool TizenDeviceImpl::click(const int x, const int y, const unsigned int intv) int TizenDeviceImpl::touchDown(const int x, const int y) { int seq = grabTouchSeqNumber(); - LOG_SCOPE_F(INFO, "touch down %d %d , seq:%d", x, y, seq); + dlog_print(DLOG_INFO, LOG_TAG, "touch down %d %d , seq:%d", x, y, seq); if (seq >= 0) { TizenDeviceImpl *obj = static_cast(this); long result = (long)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_BEGIN, @@ -73,7 +69,7 @@ int TizenDeviceImpl::touchDown(const int x, const int y) bool TizenDeviceImpl::touchMove(const int x, const int y, const int seq) { - LOG_SCOPE_F(INFO, "touch move %d %d, seq:%d", x, y, seq); + dlog_print(DLOG_INFO, LOG_TAG, "touch move %d %d, seq:%d", x, y, seq); if (seq >= 0) { TizenDeviceImpl *obj = static_cast(this); long result = (long)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_UPDATE, @@ -85,7 +81,7 @@ bool TizenDeviceImpl::touchMove(const int x, const int y, const int seq) bool TizenDeviceImpl::touchUp(const int x, const int y, const int seq) { - LOG_SCOPE_F(INFO, "touch up %d %d, seq:%d", x, y, seq); + dlog_print(DLOG_INFO, LOG_TAG, "touch up %d %d, seq:%d", x, y, seq); if (seq >= 0) { TizenDeviceImpl *obj = static_cast(this); long result = (long)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_END, @@ -97,26 +93,32 @@ bool TizenDeviceImpl::touchUp(const int x, const int y, const int seq) bool TizenDeviceImpl::wheelUp(int amount, const int durationMs) { - LOG_SCOPE_F(INFO, "wheel up %d for %d", amount, durationMs); + dlog_print(DLOG_INFO, LOG_TAG, "wheel up %d for %d", amount, durationMs); long result = -1; + TizenDeviceImpl *obj = static_cast(this); + obj->mFakeWheelHandle = efl_util_input_initialize_generator_with_sync(EFL_UTIL_INPUT_DEVTYPE_POINTER, NULL); for (int i = 0; i < amount; i++){ TizenDeviceImpl *obj = static_cast(this); result = (long)efl_util_input_generate_wheel(obj->mFakeWheelHandle, EFL_UTIL_INPUT_POINTER_WHEEL_HORZ, 1); usleep(durationMs*MSEC_PER_SEC/amount); } + efl_util_input_deinitialize_generator(obj->mFakeWheelHandle); return result == EFL_UTIL_ERROR_NONE; } bool TizenDeviceImpl::wheelDown(int amount, const int durationMs) { - LOG_SCOPE_F(INFO, "wheel down %d for %d", amount, durationMs); - long result = -1; - for (int i = 0; i < amount; i++){ + dlog_print(DLOG_INFO, LOG_TAG, "wheel down %d for %d", amount, durationMs); + long result = -1; + TizenDeviceImpl *obj = static_cast(this); + obj->mFakeWheelHandle = efl_util_input_initialize_generator_with_sync(EFL_UTIL_INPUT_DEVTYPE_POINTER, NULL); + for (int i = 0; i < amount; i++){ TizenDeviceImpl *obj = static_cast(this); result = (long)efl_util_input_generate_wheel(obj->mFakeWheelHandle, EFL_UTIL_INPUT_POINTER_WHEEL_HORZ, -1); usleep(durationMs*MSEC_PER_SEC/amount); } + efl_util_input_deinitialize_generator(obj->mFakeWheelHandle); return result == EFL_UTIL_ERROR_NONE; } @@ -154,7 +156,7 @@ bool TizenDeviceImpl::drag(const int sx, const int sy, const int ex, const int e _steps = (int)(_durationUs / (INTV_MINIMUM_DRAG_MS * MSEC_PER_SEC)) - 1; _stepUs = (INTV_MINIMUM_DRAG_MS * MSEC_PER_SEC); } - LOG_SCOPE_F(INFO, "flicking (%d, %d) -> (%d, %d) for (%d ms)", sx, sy, ex, ey, durationMs); + dlog_print(DLOG_INFO, LOG_TAG, "flicking (%d, %d) -> (%d, %d) for (%d ms)", sx, sy, ex, ey, durationMs); startTimer(); int seq = touchDown(sx, sy); if (seq < 0) return false; -- 2.7.4 From 8376a89e1f81b1f3e7ce53ea3b63f4a0a36842ee Mon Sep 17 00:00:00 2001 From: Woochanlee Date: Tue, 6 Jul 2021 18:03:35 +0900 Subject: [PATCH 11/16] libaurum, bootstrap: change log system to dlog instead of loguru Change-Id: Ib2af00fb9cc14555e869e1fd4c568680a7695eca --- libaurum/inc/Aurum.h | 23 ++++- libaurum/src/Accessibility/AccessibleNode.cc | 4 +- libaurum/src/Accessibility/AccessibleUtils.cc | 4 +- libaurum/src/Accessibility/AccessibleWatcher.cc | 8 +- libaurum/src/Comparer.cc | 13 ++- .../src/Impl/Accessibility/AtspiAccessibleNode.cc | 66 +------------ .../Impl/Accessibility/AtspiAccessibleWatcher.cc | 103 +++++++-------------- libaurum/src/Impl/TizenDeviceImpl.cc | 21 +++-- libaurum/src/Runnable/SendKeyRunnable.cc | 8 +- libaurum/src/UiObject.cc | 2 +- libaurum/src/Until.cc | 6 +- libaurum/src/Waiter.cc | 5 +- org.tizen.aurum-bootstrap/inc/bootstrap.h | 30 ++++++ org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc | 1 - org.tizen.aurum-bootstrap/src/BootstrapServer.cc | 31 +++---- .../src/Commands/ClearCommand.cc | 5 +- .../src/Commands/ClickCommand.cc | 10 +- .../src/Commands/CloseAppCommand.cc | 12 +-- org.tizen.aurum-bootstrap/src/Commands/Command.cc | 1 - .../src/Commands/DumpObjectTreeCommand.cc | 16 ++-- .../src/Commands/FindElementCommand.cc | 15 ++- .../src/Commands/FlickCommand.cc | 7 +- .../src/Commands/GetAppInfoCommand.cc | 4 +- .../src/Commands/GetAttributeCommand.cc | 9 +- .../src/Commands/GetDeviceTimeCommand.cc | 8 +- .../src/Commands/GetLocationCommand.cc | 4 +- .../src/Commands/GetSizeCommand.cc | 7 +- .../src/Commands/GetValueCommand.cc | 7 +- .../src/Commands/InstallAppCommand.cc | 6 +- .../src/Commands/KillServerCommand.cc | 4 +- .../src/Commands/LaunchAppCommand.cc | 12 +-- .../src/Commands/LongClickCommand.cc | 9 +- .../src/Commands/PostCommand.cc | 4 +- .../src/Commands/PreCommand.cc | 14 +-- .../src/Commands/RemoveAppCommand.cc | 8 +- .../src/Commands/SendKeyCommand.cc | 7 +- .../src/Commands/SetValueCommand.cc | 4 +- .../src/Commands/TakeScreenshotCommand.cc | 6 +- .../src/Commands/TouchDownCommand.cc | 6 +- .../src/Commands/TouchMoveCommand.cc | 6 +- .../src/Commands/TouchUpCommand.cc | 6 +- org.tizen.aurum-bootstrap/src/ObjectMapper.cc | 24 ++--- 42 files changed, 238 insertions(+), 308 deletions(-) create mode 100644 org.tizen.aurum-bootstrap/inc/bootstrap.h diff --git a/libaurum/inc/Aurum.h b/libaurum/inc/Aurum.h index 76e7405..63f6fcd 100644 --- a/libaurum/inc/Aurum.h +++ b/libaurum/inc/Aurum.h @@ -3,11 +3,30 @@ #include -#ifdef LOG_TAG -#undef LOG_TAG +#ifdef LOG_TAG +#undef LOG_TAG #endif #define LOG_TAG "AURUM" +#ifndef LOGI +#define LOGI(fmt, arg...) \ + ({ do { \ + dlog_print(DLOG_INFO, LOG_TAG, \ + "%s: %s(%d) > " fmt, __FILE__, __func__, __LINE__, ##arg); \ + } while (0); }) +#endif + +#ifndef LOGE +#define FONT_RED "\033[31m" +#define FONT_RESET "\033[0m" +#define LOGI_RED(fmt, arg...) \ + ({ do { \ + dlog_print(DLOG_ERROR, LOG_TAG, \ + FONT_RED "%s: %s(%d) > " fmt FONT_RESET, \ + __FILE__, __func__, __LINE__, ##arg); \ + } while (0); }) +#endif + #include "UiDevice.h" #include "UiObject.h" #include "UiSelector.h" diff --git a/libaurum/src/Accessibility/AccessibleNode.cc b/libaurum/src/Accessibility/AccessibleNode.cc index db1c386..070d97c 100644 --- a/libaurum/src/Accessibility/AccessibleNode.cc +++ b/libaurum/src/Accessibility/AccessibleNode.cc @@ -75,7 +75,7 @@ void AccessibleNode::notify(int type, int type2, void *src) void AccessibleNode::invalidate() { std::unique_lock lock(mLock); - dlog_print(DLOG_INFO, LOG_TAG, "object %p is now invalid", this); + LOGI("object %p is now invalid", this); mValid = false; } @@ -100,7 +100,7 @@ void AccessibleNode::print(int depth, int maxDepth) void AccessibleNode::print(int d) { this->refresh(); - dlog_print(DLOG_INFO, LOG_TAG, "%s %s",std::string(d, ' ').c_str(), description().c_str()); + LOGI("%s %s",std::string(d, ' ').c_str(), description().c_str()); } bool AccessibleNode::isSupporting(AccessibleNodeInterface thisIface) const diff --git a/libaurum/src/Accessibility/AccessibleUtils.cc b/libaurum/src/Accessibility/AccessibleUtils.cc index 76e0792..b126880 100644 --- a/libaurum/src/Accessibility/AccessibleUtils.cc +++ b/libaurum/src/Accessibility/AccessibleUtils.cc @@ -108,11 +108,11 @@ static void _print_stateset_debug( AtspiStateSet *stateSet) char *state_name = NULL; AtspiStateType stat; - dlog_print(DLOG_INFO, LOG_TAG, "check ss:%p s:%p, len:%d", stateSet, states, states->len); + LOGI("check ss:%p s:%p, len:%d", stateSet, states, states->len); for (int i = 0; states && (i < states->len); ++i) { stat = g_array_index(states, AtspiStateType, i); state_name = state_to_char(stat); - dlog_print(DLOG_INFO, LOG_TAG, "state: %s", state_name); + LOGI("state: %s", state_name); free(state_name); } g_array_free(states, 1); diff --git a/libaurum/src/Accessibility/AccessibleWatcher.cc b/libaurum/src/Accessibility/AccessibleWatcher.cc index f9636e7..4ff9548 100644 --- a/libaurum/src/Accessibility/AccessibleWatcher.cc +++ b/libaurum/src/Accessibility/AccessibleWatcher.cc @@ -57,17 +57,17 @@ AccessibleWatcher *AccessibleWatcher::getInstance(AccessibleWatcher *watcherImpl std::vector> AccessibleWatcher::getActiveApplications(void) const { - dlog_print(DLOG_INFO, LOG_TAG, "getActiveApplications for this(%p)", this); + LOGI("getActiveApplications for this(%p)", this); std::vector> ret{}; auto apps = this->getApplications(); - dlog_print(DLOG_INFO, LOG_TAG, "apps size %d", apps.size()); + LOGI("apps size %d", apps.size()); apps.erase(std::remove_if(apps.begin(), apps.end(), [](auto app){ return !app->isActive(); }), apps.end()); - dlog_print(DLOG_INFO, LOG_TAG, "active apps size %d", apps.size()); + LOGI("active apps size %d", apps.size()); return apps; } @@ -75,7 +75,6 @@ std::vector> AccessibleWatcher::getActive void AccessibleWatcher::attach(std::shared_ptr source) { std::unique_lock lock(mLock); - dlog_print(DLOG_INFO, LOG_TAG, "source attached %p", source.get()); if (source) { mSources.insert(source); } @@ -84,7 +83,6 @@ void AccessibleWatcher::attach(std::shared_ptr source) void AccessibleWatcher::detach(std::shared_ptr source) { std::unique_lock lock(mLock); - dlog_print(DLOG_INFO, LOG_TAG, "source detached %p", source.get()); if (source) { auto iter = mSources.find(source); if (iter != mSources.end()) mSources.erase(iter); diff --git a/libaurum/src/Comparer.cc b/libaurum/src/Comparer.cc index e23cf54..37ee045 100644 --- a/libaurum/src/Comparer.cc +++ b/libaurum/src/Comparer.cc @@ -25,7 +25,7 @@ std::vector> Comparer::findObjects(const std::sh { Comparer comparer(device, selector, earlyReturn); - dlog_print(DLOG_INFO, LOG_TAG, "findObjects selector(%s) from (type:%s style:%s, role:%s, text:%s) earlyReturn:%d", selector->description().c_str(), root->getType().c_str(), root->getStyle().c_str(), root->getRole().c_str(), root->getText().c_str(), earlyReturn); + LOGI("findObjects selector(%s) from (type:%s style:%s, role:%s, text:%s) earlyReturn:%d", selector->description().c_str(), root->getType().c_str(), root->getStyle().c_str(), root->getRole().c_str(), root->getText().c_str(), earlyReturn); if (selector->mParent) { auto ret = Comparer::findObjects(device, selector->mParent, root); @@ -45,7 +45,7 @@ std::vector> Comparer::findObjects(const std::sh { std::list> partialList{}; std::vector> ret = findObjects(root, 0, 0, partialList); - dlog_print(DLOG_INFO, LOG_TAG, "%d object(s) found", ret.size()); + LOGI("%d object(s) found", ret.size()); return ret; } @@ -73,14 +73,17 @@ std::vector> Comparer::findObjects( findObjects(childNode, i, depth + 1, partialMatches); std::move(std::begin(childret), std::end(childret), std::back_inserter(ret)); - if (!ret.empty() && mEarlyReturn) return ret; + if (!ret.empty() && mEarlyReturn) { + LOGI("Object found and earlyReturn"); + return ret; + } } } else { - dlog_print(DLOG_INFO, LOG_TAG, "Abort searching! No need to search children(maxDepth limit overflow, %d < %d < %d)", mSelector->mMinDepth?*(mSelector->mMinDepth):-1, depth, mSelector->mMaxDepth?*(mSelector->mMaxDepth):9999999); + LOGI("Abort searching! No need to search children(maxDepth limit overflow, %d < %d < %d)", mSelector->mMinDepth?*(mSelector->mMinDepth):-1, depth, mSelector->mMaxDepth?*(mSelector->mMaxDepth):9999999); } if (currentMatch && currentMatch->finalizeMatch()){ - dlog_print(DLOG_INFO, LOG_TAG, "Found matched = %s with criteria %s", root->description().c_str(), currentMatch->debugPrint().c_str()); + LOGI("Found matched = %s with criteria %s", root->description().c_str(), currentMatch->debugPrint().c_str()); ret.push_back(root); } diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc index c9d7259..2b165d2 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc @@ -15,61 +15,9 @@ AtspiAccessibleNode::AtspiAccessibleNode(AtspiAccessible *node) watcher->attach(shared_from_this()); if (mNode) { - /* - GArray *ifaces = AtspiWrapper::Atspi_accessible_get_interfaces(mNode); - if (ifaces) { - for (unsigned int i = 0; i < ifaces->len; i++) { - char *iface = g_array_index(ifaces, char *, i); - if (!strcmp(iface, "Action")) - mSupportingIfaces |= - static_cast(AccessibleNodeInterface::ACTION); - else if (!strcmp(iface, "Collection")) - mSupportingIfaces |= - static_cast(AccessibleNodeInterface::COLLECTION); - else if (!strcmp(iface, "Component")) - mSupportingIfaces |= - static_cast(AccessibleNodeInterface::COMPONENT); - else if (!strcmp(iface, "Document")) - mSupportingIfaces |= - static_cast(AccessibleNodeInterface::DOCUMENT); - else if (!strcmp(iface, "EditableText")) - mSupportingIfaces |= - static_cast(AccessibleNodeInterface::EDITABLETEXT); - else if (!strcmp(iface, "Hypertext")) - mSupportingIfaces |= - static_cast(AccessibleNodeInterface::HYPERTEXT); - else if (!strcmp(iface, "Image")) - mSupportingIfaces |= - static_cast(AccessibleNodeInterface::IMAGE); - else if (!strcmp(iface, "Selection")) - mSupportingIfaces |= - static_cast(AccessibleNodeInterface::SELECTION); - else if (!strcmp(iface, "Text")) - mSupportingIfaces |= - static_cast(AccessibleNodeInterface::TEXT); - else if (!strcmp(iface, "Value")) - mSupportingIfaces |= - static_cast(AccessibleNodeInterface::VALUE); - else if (!strcmp(iface, "Accessible")) - mSupportingIfaces |= - static_cast(AccessibleNodeInterface::ACCESSIBLE); - else if (!strcmp(iface, "Table")) - mSupportingIfaces |= - static_cast(AccessibleNodeInterface::TABLE); - else if (!strcmp(iface, "TableCell")) - mSupportingIfaces |= - static_cast(AccessibleNodeInterface::TABLECELL); - else - LOG_F(WARNING, "Not Supported interface found %s", iface); - - g_free(iface); - } - g_array_free(ifaces, FALSE); - }*/ - this->refresh(); } else { - dlog_print(DLOG_INFO, LOG_TAG, "AtspiAccessibleNode Ctor : mNode is null"); + LOGI("AtspiAccessibleNode Ctor : mNode is null"); } } @@ -100,7 +48,6 @@ std::shared_ptr AtspiAccessibleNode::getChildAt(int index) const AtspiWrapper::unlock(); return std::make_shared(nullptr); } - dlog_print(DLOG_INFO, LOG_TAG, "getChild @ %d from node(%p)", index, mNode); AtspiAccessible *rawChild = AtspiWrapper::Atspi_accessible_get_child_at_index(mNode, index, NULL); AtspiWrapper::unlock(); return std::make_shared(rawChild); @@ -127,10 +74,8 @@ std::shared_ptr AtspiAccessibleNode::getParent() const AtspiAccessible *rawParent = AtspiWrapper::Atspi_accessible_get_parent(mNode, NULL); AtspiWrapper::unlock(); return std::make_shared(rawParent); -/* auto node = AccessibleNode::get(parent); - if (parent) g_object_unref(parent); - return node; */ } + bool AtspiAccessibleNode::isValid() const { if(!AccessibleNode::isValid()) return false; @@ -146,7 +91,6 @@ bool AtspiAccessibleNode::isValid() const return true; } - void* AtspiAccessibleNode::getRawHandler(void) const { return static_cast(mNode); @@ -312,7 +256,7 @@ void AtspiAccessibleNode::setValue(std::string text) } AtspiEditableText *iface = AtspiWrapper::Atspi_accessible_get_editable_text(mNode); - dlog_print(DLOG_INFO, LOG_TAG, "set Value iface:%p obj:%p text:%s", iface, mNode, text.c_str() ); + LOGI("set Value iface:%p obj:%p text:%s", iface, mNode, text.c_str() ); if (iface) { int len = getText().length(); AtspiWrapper::Atspi_editable_text_delete_text(iface, 0, len, NULL); @@ -324,10 +268,6 @@ void AtspiAccessibleNode::setValue(std::string text) void AtspiAccessibleNode::setFeatureProperty(AtspiStateType type) { -/* - LONGCLICKABLE = 0X0040, - SCROLLABLE = 0X0080, -*/ switch(type) { case ATSPI_STATE_CHECKED: setFeatureProperty(NodeFeatureProperties::CHECKED, true); diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc index bffa403..b15e440 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc @@ -22,12 +22,12 @@ static bool iShowingNode(AtspiAccessible *node) if (node) name = AtspiWrapper::Atspi_accessible_get_name(node, NULL); else return false; - dlog_print(DLOG_INFO, LOG_TAG, "isShowing %s", name); + LOGI("isShowing %s", name); auto stateSet = AtspiWrapper::Atspi_accessible_get_state_set(node); if (AtspiWrapper::Atspi_state_set_contains(stateSet, ATSPI_STATE_ACTIVE) && AtspiWrapper::Atspi_state_set_contains(stateSet, ATSPI_STATE_SHOWING)) { - dlog_print(DLOG_INFO, LOG_TAG, "active and showing %p %s", node, name); + LOGI("active and showing %p %s", node, name); free(name); g_object_unref(stateSet); return true; @@ -41,14 +41,14 @@ static std::vector findActiveNode(AtspiAccessible *node, int depth, int max_depth) { - dlog_print(DLOG_INFO, LOG_TAG, "findActiveNode %p %d/%d", node, depth, max_depth); + LOGI("findActiveNode %p %d/%d", node, depth, max_depth); std::vector ret{}; if (iShowingNode(node)) { char *name = AtspiWrapper::Atspi_accessible_get_name(node, NULL); if (name) { - dlog_print(DLOG_INFO, LOG_TAG, "%s", name); + LOGI("%s", name); free(name); } ret.push_back(node); @@ -60,10 +60,10 @@ findActiveNode(AtspiAccessible *node, int depth, int nchild = AtspiWrapper::Atspi_accessible_get_child_count(node, NULL); if (nchild <= 0) return ret; - dlog_print(DLOG_INFO, LOG_TAG, "findActiveNode node %p has %d children", node, nchild); + LOGI("findActiveNode node %p has %d children", node, nchild); for (int i = 0; i < nchild; i++) { AtspiAccessible* child = AtspiWrapper::Atspi_accessible_get_child_at_index(node, i, NULL); - dlog_print(DLOG_INFO, LOG_TAG, "a child found @ %d : %p", i, child); + LOGI("a child found @ %d : %p", i, child); std::vector childRet = findActiveNode(child, depth + 1, max_depth); ret.insert(ret.end(), childRet.begin(), childRet.end()); g_object_unref(child); @@ -74,7 +74,7 @@ findActiveNode(AtspiAccessible *node, int depth, static gpointer _event_thread_loop (gpointer data) { - dlog_print(DLOG_INFO, LOG_TAG, "event thread start"); + LOGI("event thread start"); AtspiEventListener * listener = atspi_event_listener_new(AtspiAccessibleWatcher::onAtspiEvents, data, NULL); @@ -83,7 +83,7 @@ static gpointer _event_thread_loop (gpointer data) atspi_event_main(); - dlog_print(DLOG_INFO, LOG_TAG, "event thread end"); + LOGI("event thread end"); atspi_event_listener_deregister(listener, "object:", NULL); atspi_event_listener_deregister(listener, "window:", NULL); @@ -168,98 +168,63 @@ void AtspiAccessibleWatcher::onAtspiEvents(AtspiEvent *event, void *user_data) } if (name) free(name); if (pkg) free(pkg); -/* char *name = NULL, *pname = NULL; - AtspiAccessibleWatcher *instance = (AtspiAccessibleWatcher *)user_data; - if (!event->source) - { - LOG_F(INFO, "event->source is NULL. Skip event handling"); - return; - } - - name = AtspiWrapper::Atspi_accessible_get_name(event->source, NULL); - AtspiAccessible *parent = AtspiWrapper::Atspi_accessible_get_parent(event->source, NULL); - if (parent) { - pname = AtspiWrapper::Atspi_accessible_get_name(parent, NULL); - g_object_unref(parent); - } - - if (!strcmp(event->type, "window:activate")) { - instance->onWindowActivated( - static_cast(event->source), - static_cast(event->detail1)); - } else if (!strcmp(event->type, "window:deactivate")) { - instance->onWindowDeactivated(static_cast(event->source)); - } else if (!strcmp(event->type, "window:create")) { - instance->onWindowCreated(static_cast(event->source)); - } else if (!strcmp(event->type, "window:destroy")) { - instance->onWindowDestroyed(static_cast(event->source)); - } else if (!strcmp(event->type, "object:state-changed:visible")) { - instance->onVisibilityChanged( - static_cast(event->source), - (event->detail1 != 0)); - } else if (!strcmp(event->type, "object:state-changed:defunct")) { - instance->onObjectDefunct( - static_cast(event->source)); - } - if (name) free(name); - if (pname) free(pname);*/ AtspiWrapper::unlock(); } void AtspiAccessibleWatcher::print_debug() { - dlog_print(DLOG_INFO, LOG_TAG, "activatewindowlist-------------------"); + LOGI("activatewindowlist-------------------"); std::for_each(mActivatedWindowList.begin(), mActivatedWindowList.end(), [](auto acc){ - dlog_print(DLOG_INFO, LOG_TAG, "child:%p", acc); + LOGI("child:%p", acc); }); - dlog_print(DLOG_INFO, LOG_TAG, "mActivatedApplicationList--------------------------"); + LOGI("mActivatedApplicationList--------------------------"); std::for_each(mActivatedApplicationList.begin(), mActivatedApplicationList.end(), [](auto acc){ - dlog_print(DLOG_INFO, LOG_TAG, "child:%p", acc); + LOGI("child:%p", acc); }); - dlog_print(DLOG_INFO, LOG_TAG, "mWindowSet------------------------------"); + LOGI("mWindowSet------------------------------"); std::for_each(mWindowSet.begin(), mWindowSet.end(), [](auto acc){ - dlog_print(DLOG_INFO, LOG_TAG, "child:%p", acc); + LOGI("child:%p", acc); }); - dlog_print(DLOG_INFO, LOG_TAG, "------------------------------"); + LOGI("------------------------------"); } void AtspiAccessibleWatcher::onWindowActivated(AtspiAccessible *node, WindowActivateInfoType type) { - dlog_print(DLOG_INFO, LOG_TAG, "onWindowActivated obj:%p", node); + LOGI("onWindowActivated obj:%p", node); notifyAll((int)EventType::Window, (int)WindowEventType::WindowActivated, node); } void AtspiAccessibleWatcher::onWindowDeactivated(AtspiAccessible *node) { - dlog_print(DLOG_INFO, LOG_TAG, "onWindowDeactivated obj:%p", node); + LOGI("onWindowDeactivated obj:%p", node); notifyAll((int)EventType::Window, (int)WindowEventType::WindowDeactivated, node); } void AtspiAccessibleWatcher::onWindowCreated(AtspiAccessible *node) { - dlog_print(DLOG_INFO, LOG_TAG, "onWindowCreated obj:%p", node); + LOGI("onWindowCreated obj:%p", node); notifyAll((int)EventType::Window, (int)WindowEventType::WindowCreated, node); } void AtspiAccessibleWatcher::onWindowDestroyed(AtspiAccessible *node) { - dlog_print(DLOG_INFO, LOG_TAG, "onWindowDestroyed obj:%p", node); + LOGI("onWindowDestroyed obj:%p", node); notifyAll((int)EventType::Window, (int)WindowEventType::WindowDestroyed, node); } void AtspiAccessibleWatcher::onVisibilityChanged(AtspiAccessible *node, bool visible) { - dlog_print(DLOG_INFO, LOG_TAG, "onVisibilityChanged obj:%p", node); + LOGI("onVisibilityChanged obj:%p", node); notifyAll((int)EventType::Object, (int)ObjectEventType::ObjectStateVisible, node); } void AtspiAccessibleWatcher::onObjectDefunct(AtspiAccessible *node) { - dlog_print(DLOG_INFO, LOG_TAG, "onObjectDefunct obj:%p", node); + LOGI("onObjectDefunct obj:%p", node); notifyAll((int)EventType::Object, (int)ObjectEventType::ObjectStateDefunct, node); } @@ -290,7 +255,7 @@ std::shared_ptr AtspiAccessibleWatcher::getApplicationAt( std::vector> AtspiAccessibleWatcher::getApplications(void) const { AtspiWrapper::lock(); - dlog_print(DLOG_INFO, LOG_TAG, "getApplications for this(%p)", this); + LOGI("getApplications for this(%p)", this); std::vector> ret{}; AtspiAccessible *root = AtspiWrapper::Atspi_get_desktop(0); int nchild = AtspiWrapper::Atspi_accessible_get_child_count(root, NULL); @@ -332,16 +297,16 @@ bool AtspiAccessibleWatcher::executeAndWaitForEvents(const Runnable *cmd, const mEventQueue.clear(); AtspiWrapper::unlock(); - if (!localEvents.empty()) - { + if (!localEvents.empty()) + { for (const auto &event : localEvents) { if (COMPARE(type, event->getEvent())) - { - dlog_print(DLOG_INFO, LOG_TAG, "type %d == %d name %s pkg %s",static_cast(type), static_cast(event->getEvent()), event->getName().c_str(), event->getPkg().c_str()); - return true; - } - } - } + { + LOGI("type %d == %d name %s pkg %s",static_cast(type), static_cast(event->getEvent()), event->getName().c_str(), event->getPkg().c_str()); + return true; + } + } + } if ((std::chrono::system_clock::now() - start) > std::chrono::milliseconds{timeout}) break; @@ -354,11 +319,11 @@ bool AtspiAccessibleWatcher::executeAndWaitForEvents(const Runnable *cmd, const bool AtspiAccessibleWatcher::removeFromActivatedList(AtspiAccessible *node) { - dlog_print(DLOG_INFO, LOG_TAG, "remove from activelist node %p", node); + LOGI("remove from activelist node %p", node); mActivatedWindowList.remove_if([&](auto &n) { return n == node; }); AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(node, NULL); - dlog_print(DLOG_INFO, LOG_TAG, "node:%p, app:%p", node, app); + LOGI("node:%p, app:%p", node, app); if (app) { mActivatedApplicationList.remove_if([&](auto &n) { return n == app; }); g_object_unref(app); @@ -368,7 +333,7 @@ bool AtspiAccessibleWatcher::removeFromActivatedList(AtspiAccessible *node) bool AtspiAccessibleWatcher::addToActivatedList(AtspiAccessible *node) { - dlog_print(DLOG_INFO, LOG_TAG, "add to activelist node %p", node); + LOGI("add to activelist node %p", node); mActivatedWindowList.remove_if([&](auto &n) { return n == node; }); mActivatedWindowList.push_front(node); @@ -376,7 +341,7 @@ bool AtspiAccessibleWatcher::addToActivatedList(AtspiAccessible *node) if ( iter == mWindowSet.end()) mWindowSet.insert(node); AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(node, NULL); - dlog_print(DLOG_INFO, LOG_TAG, "node:%p, app:%p", node, app); + LOGI("node:%p, app:%p", node, app); if (app) { mActivatedApplicationList.remove_if([&](auto &n) { if(n == app) { g_object_unref(app); return true;} else return false; }); mActivatedApplicationList.push_front(app); diff --git a/libaurum/src/Impl/TizenDeviceImpl.cc b/libaurum/src/Impl/TizenDeviceImpl.cc index 82fc926..446d041 100644 --- a/libaurum/src/Impl/TizenDeviceImpl.cc +++ b/libaurum/src/Impl/TizenDeviceImpl.cc @@ -15,10 +15,13 @@ #include #include +#define NANO_SEC 1000000000.0 +#define MICRO_SEC 1000000 + TizenDeviceImpl::TizenDeviceImpl() : mFakeTouchHandle{0}, mFakeKeyboardHandle{0}, mFakeWheelHandle{0}, tStart{}, isTimerStarted{false}, mTouchSeq{} { - dlog_print(DLOG_INFO, LOG_TAG, "device implementation init"); + LOGI("device implementation init"); TizenDeviceImpl *obj = static_cast(this); obj->mFakeTouchHandle = efl_util_input_initialize_generator(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN); obj->mFakeKeyboardHandle = @@ -39,7 +42,7 @@ bool TizenDeviceImpl::click(const int x, const int y) bool TizenDeviceImpl::click(const int x, const int y, const unsigned int intv) { - dlog_print(DLOG_INFO, LOG_TAG, "click %d %d , intv:%d", x, y, intv); + LOGI("click %d %d , intv:%d", x, y, intv); int seq = touchDown(x, y); if (seq < 0) return false; @@ -53,7 +56,7 @@ bool TizenDeviceImpl::click(const int x, const int y, const unsigned int intv) int TizenDeviceImpl::touchDown(const int x, const int y) { int seq = grabTouchSeqNumber(); - dlog_print(DLOG_INFO, LOG_TAG, "touch down %d %d , seq:%d", x, y, seq); + LOGI("touch down %d %d , seq:%d", x, y, seq); if (seq >= 0) { TizenDeviceImpl *obj = static_cast(this); long result = (long)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_BEGIN, @@ -69,7 +72,7 @@ int TizenDeviceImpl::touchDown(const int x, const int y) bool TizenDeviceImpl::touchMove(const int x, const int y, const int seq) { - dlog_print(DLOG_INFO, LOG_TAG, "touch move %d %d, seq:%d", x, y, seq); + LOGI("touch move %d %d, seq:%d", x, y, seq); if (seq >= 0) { TizenDeviceImpl *obj = static_cast(this); long result = (long)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_UPDATE, @@ -81,7 +84,7 @@ bool TizenDeviceImpl::touchMove(const int x, const int y, const int seq) bool TizenDeviceImpl::touchUp(const int x, const int y, const int seq) { - dlog_print(DLOG_INFO, LOG_TAG, "touch up %d %d, seq:%d", x, y, seq); + LOGI("touch up %d %d, seq:%d", x, y, seq); if (seq >= 0) { TizenDeviceImpl *obj = static_cast(this); long result = (long)efl_util_input_generate_touch(obj->mFakeTouchHandle, seq, EFL_UTIL_INPUT_TOUCH_END, @@ -93,7 +96,7 @@ bool TizenDeviceImpl::touchUp(const int x, const int y, const int seq) bool TizenDeviceImpl::wheelUp(int amount, const int durationMs) { - dlog_print(DLOG_INFO, LOG_TAG, "wheel up %d for %d", amount, durationMs); + LOGI("wheel up %d for %d", amount, durationMs); long result = -1; TizenDeviceImpl *obj = static_cast(this); obj->mFakeWheelHandle = efl_util_input_initialize_generator_with_sync(EFL_UTIL_INPUT_DEVTYPE_POINTER, NULL); @@ -109,7 +112,7 @@ bool TizenDeviceImpl::wheelUp(int amount, const int durationMs) bool TizenDeviceImpl::wheelDown(int amount, const int durationMs) { - dlog_print(DLOG_INFO, LOG_TAG, "wheel down %d for %d", amount, durationMs); + LOGI("wheel down %d for %d", amount, durationMs); long result = -1; TizenDeviceImpl *obj = static_cast(this); obj->mFakeWheelHandle = efl_util_input_initialize_generator_with_sync(EFL_UTIL_INPUT_DEVTYPE_POINTER, NULL); @@ -134,7 +137,7 @@ int TizenDeviceImpl::stopTimer(void) if (!isTimerStarted) return 0; isTimerStarted = false; clock_gettime(CLOCK_MONOTONIC, &tEnd); - return ((tEnd.tv_sec + tEnd.tv_nsec/1000000000.0) - (tStart.tv_sec + tStart.tv_nsec/1000000000.0)) * 1000000; + return ((tEnd.tv_sec + tEnd.tv_nsec/NANO_SEC) - (tStart.tv_sec + tStart.tv_nsec/NANO_SEC)) * MICRO_SEC; } bool TizenDeviceImpl::drag(const int sx, const int sy, const int ex, const int ey, @@ -156,7 +159,7 @@ bool TizenDeviceImpl::drag(const int sx, const int sy, const int ex, const int e _steps = (int)(_durationUs / (INTV_MINIMUM_DRAG_MS * MSEC_PER_SEC)) - 1; _stepUs = (INTV_MINIMUM_DRAG_MS * MSEC_PER_SEC); } - dlog_print(DLOG_INFO, LOG_TAG, "flicking (%d, %d) -> (%d, %d) for (%d ms)", sx, sy, ex, ey, durationMs); + LOGI("flicking (%d, %d) -> (%d, %d) for (%d ms)", sx, sy, ex, ey, durationMs); startTimer(); int seq = touchDown(sx, sy); if (seq < 0) return false; diff --git a/libaurum/src/Runnable/SendKeyRunnable.cc b/libaurum/src/Runnable/SendKeyRunnable.cc index fc1f54c..61d3138 100644 --- a/libaurum/src/Runnable/SendKeyRunnable.cc +++ b/libaurum/src/Runnable/SendKeyRunnable.cc @@ -7,9 +7,9 @@ SendKeyRunnable::SendKeyRunnable(std::string keycode) void SendKeyRunnable::run() const { - dlog_print(DLOG_INFO, LOG_TAG, "sendKey %s",mKeycode.c_str()); - std::shared_ptr mDevice = UiDevice::getInstance(); - mDevice->pressKeyCode(mKeycode.c_str(), KeyRequestType::PRESS); - mDevice->pressKeyCode(mKeycode.c_str(), KeyRequestType::RELEASE); + LOGI("sendKey %s",mKeycode.c_str()); + std::shared_ptr mDevice = UiDevice::getInstance(); + mDevice->pressKeyCode(mKeycode.c_str(), KeyRequestType::PRESS); + mDevice->pressKeyCode(mKeycode.c_str(), KeyRequestType::RELEASE); } diff --git a/libaurum/src/UiObject.cc b/libaurum/src/UiObject.cc index 1095669..db48098 100644 --- a/libaurum/src/UiObject.cc +++ b/libaurum/src/UiObject.cc @@ -86,7 +86,7 @@ std::vector> UiObject::findObjects( auto nodes = Comparer::findObjects(mDevice, selector, getAccessibleNode()); for ( auto& node : nodes) { if (!node) { - dlog_print(DLOG_INFO, LOG_TAG, "Skipped! (node == nullptr)"); + LOGI("Skipped! (node == nullptr)"); continue; } result.push_back(std::make_shared(mDevice, selector, std::move(node))); diff --git a/libaurum/src/Until.cc b/libaurum/src/Until.cc index 324635b..987627a 100644 --- a/libaurum/src/Until.cc +++ b/libaurum/src/Until.cc @@ -4,7 +4,7 @@ std::function Until::hasObject( const std::shared_ptr selector) { return [=](const ISearchable *searchable) -> bool { - dlog_print(DLOG_INFO, LOG_TAG, "Until::hasObject search:%p", searchable); + LOGI("Until::hasObject search:%p", searchable); std::shared_ptr obj = searchable->findObject(selector); return obj.get() != nullptr; }; @@ -14,7 +14,7 @@ std::function(const ISearchable *)> Until::findObject( const std::shared_ptr selector) { return [=](const ISearchable *searchable) -> std::shared_ptr { - dlog_print(DLOG_INFO, LOG_TAG, "Until::findObject search:%p", searchable); + LOGI("Until::findObject search:%p", searchable); std::shared_ptr obj = searchable->findObject(selector); return obj; }; @@ -23,7 +23,7 @@ std::function(const ISearchable *)> Until::findObject( std::function Until::checkable(const bool isCheckable) { return [=](const UiObject *object) -> bool { - dlog_print(DLOG_INFO, LOG_TAG, "Until::checkable checkable:%d for obj %p", isCheckable, object); + LOGI("Until::checkable checkable:%d for obj %p", isCheckable, object); return object->isClickable() == isCheckable; }; } diff --git a/libaurum/src/Waiter.cc b/libaurum/src/Waiter.cc index dfb2ae8..05b4f63 100644 --- a/libaurum/src/Waiter.cc +++ b/libaurum/src/Waiter.cc @@ -28,8 +28,7 @@ template bool Waiter::waitFor( template R Waiter::waitFor(const std::function condition) const { - dlog_print(DLOG_INFO, LOG_TAG, "Waiter::waitFor ISearchable"); - // startTime = currentTime(); + LOGI("Waiter::waitFor ISearchable"); std::chrono::system_clock::time_point start = std::chrono::system_clock::now(); R result = condition(mSearchableObject); @@ -47,7 +46,7 @@ R Waiter::waitFor(const std::function condition) const template R Waiter::waitFor(const std::function condition) const { - dlog_print(DLOG_INFO, LOG_TAG, "Waiter::waitFor UiObject"); + LOGI("Waiter::waitFor UiObject"); if (mUiObject) { std::chrono::system_clock::time_point start = std::chrono::system_clock::now(); diff --git a/org.tizen.aurum-bootstrap/inc/bootstrap.h b/org.tizen.aurum-bootstrap/inc/bootstrap.h new file mode 100644 index 0000000..429e4e5 --- /dev/null +++ b/org.tizen.aurum-bootstrap/inc/bootstrap.h @@ -0,0 +1,30 @@ +#ifndef _BOOTSTRAP_H_ +#define _BOOTSTRAP_H_ + +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "AURUM-BOOTSTRAP" + +#ifndef LOGI +#define LOGI(fmt, arg...) \ + ({ do { \ + dlog_print(DLOG_INFO, LOG_TAG, \ + "%s: %s(%d) > " fmt, __FILE__, __func__, __LINE__, ##arg); \ + } while (0); }) +#endif + +#ifndef LOGE +#define FONT_RED "\033[31m" +#define FONT_RESET "\033[0m" +#define LOGI_RED(fmt, arg...) \ + ({ do { \ + dlog_print(DLOG_ERROR, LOG_TAG, \ + FONT_RED "%s: %s(%d) > " fmt FONT_RESET, \ + __FILE__, __func__, __LINE__, ##arg); \ + } while (0); }) +#endif + +#endif \ No newline at end of file diff --git a/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc b/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc index 8cf4527..e733b23 100644 --- a/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc +++ b/org.tizen.aurum-bootstrap/src/AurumServiceImpl.cc @@ -6,7 +6,6 @@ #include "Commands/PreCommand.h" #include "config.h" -#include using namespace grpc; using namespace aurum; diff --git a/org.tizen.aurum-bootstrap/src/BootstrapServer.cc b/org.tizen.aurum-bootstrap/src/BootstrapServer.cc index aa70fd3..827fcee 100644 --- a/org.tizen.aurum-bootstrap/src/BootstrapServer.cc +++ b/org.tizen.aurum-bootstrap/src/BootstrapServer.cc @@ -1,5 +1,6 @@ #include #include +#include "bootstrap.h" #include #include @@ -10,7 +11,6 @@ #include "AurumServiceImpl.h" #include "config.h" -#include #define PRIV_MEDIASTORAGE "http://tizen.org/privilege/mediastorage" #define PRIV_LOCATION "http://tizen.org/privilege/location" @@ -31,10 +31,9 @@ _grpc_thread_func (gpointer data) aurumServiceImpl service; ServerBuilder builder; - LOG_F(INFO, "[T] Server Listening on %s", binding.c_str()); + LOGI("[T] Server Listening on %s", binding.c_str()); builder.AddListeningPort(binding, grpc::InsecureServerCredentials()); builder.RegisterService(&service); - //std::unique_ptr server(builder.BuildAndStart()); ctx->server = std::move(builder.BuildAndStart()); ctx->server->Wait(); @@ -46,22 +45,22 @@ reponse_cb(ppm_call_cause_e cause, ppm_request_result_e result, const char *privilege, void *user_data) { if (cause == PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR) { - LOG_F(INFO, "PPM Error PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR"); + LOGI("PPM Error PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR"); return; } switch (result) { case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER: - LOG_F(INFO, "priv:%s PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER", privilege); + LOGI("priv:%s PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER", privilege); break; case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_FOREVER: - LOG_F(INFO, "priv:%s PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER", privilege); + LOGI("priv:%s PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER", privilege); break; case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_ONCE: - LOG_F(INFO, "priv:%s PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER", privilege); + LOGI("priv:%s PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER", privilege); break; default: - LOG_F(INFO, "priv:%s default", privilege); + LOGI("priv:%s default", privilege); break; } } @@ -71,7 +70,7 @@ check_permission(char *path_privilege) { ppm_check_result_e result; int ret; - LOG_F(INFO, "path_privilege = %s",path_privilege); + LOGI("path_privilege = %s",path_privilege); ret = ppm_check_permission(path_privilege, &result); if (ret == PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE) { @@ -80,12 +79,12 @@ check_permission(char *path_privilege) break; case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY: - LOG_F(INFO, "PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY"); + LOGI("PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY"); ; break; case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK: - LOG_F(INFO, "PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK"); + LOGI("PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK"); ppm_request_permission(path_privilege, reponse_cb, NULL); break; @@ -93,7 +92,7 @@ check_permission(char *path_privilege) break; } } else { - LOG_F(INFO, "Error to check permission[0x%x]", ret); + LOGI("Error to check permission[0x%x]", ret); } } @@ -101,12 +100,6 @@ check_permission(char *path_privilege) static bool _service_app_create(void *data) { ServiceContext *ctx = (ServiceContext*)data; - const char *logPath = "/tmp/ua.log"; - - - loguru::g_preamble = false; - loguru::add_file(logPath, loguru::Append, loguru::Verbosity_MAX); - LOG_SCOPE_F(INFO, "Log : %s", logPath); ctx->loop = g_main_loop_new ( NULL , FALSE ); ctx->thread = g_thread_new("grpc_thread", _grpc_thread_func, ctx); @@ -149,7 +142,7 @@ int main(int argc, char **argv) try { result = service_app_main(argc, argv, &event_callback, &ctx); } catch (const std::exception& e) { - LOG_F(INFO, "service_app_main exception: %s", e.what()); + LOGI("service_app_main exception: %s", e.what()); } return result; diff --git a/org.tizen.aurum-bootstrap/src/Commands/ClearCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/ClearCommand.cc index 352c537..3b80401 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/ClearCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/ClearCommand.cc @@ -1,6 +1,5 @@ +#include "bootstrap.h" #include "ClearCommand.h" -#include -#include #include ClearCommand::ClearCommand(const ::aurum::ReqClear* request, @@ -25,7 +24,7 @@ bool ClearCommand::hasHintText(std::shared_ptr obj) ::grpc::Status ClearCommand::execute() { - LOG_SCOPE_F(INFO, "Clear --------------- "); + LOGI("Clear --------------- "); ObjectMapper* mObjMap = ObjectMapper::getInstance(); std::shared_ptr obj = mObjMap->getElement(mRequest->elementid()); diff --git a/org.tizen.aurum-bootstrap/src/Commands/ClickCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/ClickCommand.cc index 8340168..0b74527 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/ClickCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/ClickCommand.cc @@ -1,10 +1,8 @@ +#include "bootstrap.h" #include "ClickCommand.h" - #include "UiObject.h" #include "UiDevice.h" -#include - ClickCommand::ClickCommand(const ::aurum::ReqClick* request, ::aurum::RspClick* response) : mRequest{request}, mResponse{response} @@ -34,7 +32,7 @@ std::unique_ptr ClickCommand::createCommand(const ::aurum::ReqClic { ObjectMapper* mObjMap = ObjectMapper::getInstance(); std::shared_ptr obj = mObjMap->getElement(mRequest->elementid()); - LOG_SCOPE_F(INFO, "ClickElementCommand execute %p", obj); + LOGI("ClickElementCommand execute %p", obj.get()); if (obj) { obj->click(); @@ -49,7 +47,7 @@ std::unique_ptr ClickCommand::createCommand(const ::aurum::ReqClic { std::shared_ptr obj = UiDevice::getInstance(); const ::aurum::Point& point = mRequest->coordination(); - LOG_SCOPE_F(INFO, "ClickCoordCommand execute %p @ (%d, %d)", obj.get(), point.x(), point.y()); + LOGI("ClickCoordCommand execute %p @ (%d, %d)", obj.get(), point.x(), point.y()); obj->click(point.x(), point.y()); mResponse->set_status(::aurum::RspStatus::OK); return grpc::Status::OK; @@ -60,7 +58,7 @@ std::unique_ptr ClickCommand::createCommand(const ::aurum::ReqClic ObjectMapper* mObjMap = ObjectMapper::getInstance(); std::shared_ptr obj = mObjMap->getElement(mRequest->elementid()); - LOG_SCOPE_F(INFO, "ClickAtspiCommand execute %p", obj); + LOGI("ClickAtspiCommand execute %p", obj.get()); if (obj) { if (obj->DoAtspiActivate()) mResponse->set_status(::aurum::RspStatus::OK); diff --git a/org.tizen.aurum-bootstrap/src/Commands/CloseAppCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/CloseAppCommand.cc index 3221d36..f40f7cb 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/CloseAppCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/CloseAppCommand.cc @@ -1,5 +1,5 @@ +#include "bootstrap.h" #include "CloseAppCommand.h" -#include #include #include #ifdef GBSBUILD @@ -14,22 +14,22 @@ CloseAppCommand::CloseAppCommand(const ::aurum::ReqCloseApp* request, ::grpc::Status CloseAppCommand::execute() { - LOG_SCOPE_F(INFO, "CloseApp --------------- "); + LOGI("CloseApp --------------- "); #ifdef GBSBUILD std::string packageName = mRequest->packagename(); app_context_h app_context = NULL; - LOG_F(INFO, "close req : %s", packageName.c_str()); + LOGI("close req : %s", packageName.c_str()); int ret = app_manager_get_app_context(packageName.c_str(), &app_context); if (ret) { - LOG_SCOPE_F(INFO, "Terminate Failed(1/2) Err Code : %d", ret); + LOGI("Terminate Failed(1/2) Err Code : %d", ret); mResponse->set_status(::aurum::RspStatus::ERROR); return grpc::Status::OK; } ret = app_manager_terminate_app(app_context); if (ret) { - LOG_SCOPE_F(INFO, "Terminate Failed(2/2) Err Code : %d", ret); + LOGI("Terminate Failed(2/2) Err Code : %d", ret); mResponse->set_status(::aurum::RspStatus::ERROR); return grpc::Status::OK; } @@ -39,7 +39,7 @@ CloseAppCommand::CloseAppCommand(const ::aurum::ReqCloseApp* request, ::grpc::Status CloseAppCommand::executePost() { - LOG_SCOPE_F(INFO, "CloseAppCommand::executePost"); + LOGI("CloseAppCommand::executePost"); std::this_thread::sleep_for(std::chrono::milliseconds{1500}); return grpc::Status::OK; } \ No newline at end of file diff --git a/org.tizen.aurum-bootstrap/src/Commands/Command.cc b/org.tizen.aurum-bootstrap/src/Commands/Command.cc index 71a6eb7..8988bf7 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/Command.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/Command.cc @@ -1,5 +1,4 @@ #include "Command.h" -#include ::grpc::Status Command::executePost() { diff --git a/org.tizen.aurum-bootstrap/src/Commands/DumpObjectTreeCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/DumpObjectTreeCommand.cc index c7c0e4a..b8b7c71 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/DumpObjectTreeCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/DumpObjectTreeCommand.cc @@ -1,14 +1,10 @@ +#include "bootstrap.h" #include "DumpObjectTreeCommand.h" - -#include "ISearchable.h" - -#include "Sel.h" -#include "UiDevice.h" #include "UiObject.h" +#include "UiDevice.h" #include "UiSelector.h" - -#include - +#include "Sel.h" +#include "ISearchable.h" DumpObjectTreeCommand::DumpObjectTreeCommand(const ::aurum::ReqDumpObjectTree* request, ::aurum::RspDumpObjectTree* response) @@ -66,8 +62,8 @@ void DumpObjectTreeCommand::traverse(::aurum::Element *root, std::shared_ptrelementid().c_str()); + LOGI("DumpObjectTree --------------- "); + LOGI("elementid : %s", mRequest->elementid().c_str()); if (mRequest->elementid().length()) { auto obj = mObjMap->getElement(mRequest->elementid()); if (!obj) return grpc::Status::OK;; diff --git a/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc index 590806f..1238b8b 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/FindElementCommand.cc @@ -1,13 +1,10 @@ +#include "bootstrap.h" #include "FindElementCommand.h" - -#include "ISearchable.h" - -#include "Sel.h" -#include "UiDevice.h" #include "UiObject.h" +#include "UiDevice.h" #include "UiSelector.h" - -#include +#include "Sel.h" +#include "ISearchable.h" FindElementCommand::FindElementCommand(const ::aurum::ReqFindElement* request, ::aurum::RspFindElement* response) @@ -54,7 +51,7 @@ std::vector> FindElementCommand::getSelectors(void) ::grpc::Status FindElementCommand::execute() { - LOG_SCOPE_F(INFO, "findElement --------------- "); + LOGI("findElement --------------- "); auto searchableObj = getSearchableTop(); auto selectors = getSelectors(); @@ -72,7 +69,7 @@ std::vector> FindElementCommand::getSelectors(void) key = mObjMap->getElement(found); if (key.length() <= 0) key = mObjMap->addElement(std::move(found)); - LOG_F(INFO, "found object : %s key:%s", + LOGI("found object : %s key:%s", obj->getAutomationId().c_str(), key.c_str()); ::aurum::Element* elm = mResponse->add_elements(); elm->set_elementid(key); diff --git a/org.tizen.aurum-bootstrap/src/Commands/FlickCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/FlickCommand.cc index b468e43..d1703be 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/FlickCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/FlickCommand.cc @@ -1,7 +1,6 @@ +#include "bootstrap.h" #include "FlickCommand.h" -#include - -#include +#include "UiDevice.h" FlickCommand::FlickCommand(const ::aurum::ReqFlick *request, ::aurum::RspFlick * response) @@ -11,7 +10,7 @@ FlickCommand::FlickCommand(const ::aurum::ReqFlick *request, ::grpc::Status FlickCommand::execute() { - LOG_SCOPE_F(INFO, "Flick --------------- "); + LOGI("Flick --------------- "); const ::aurum::Point &startPoint = mRequest->startpoint(); const ::aurum::Point &endPoint = mRequest->endpoint(); diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetAppInfoCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetAppInfoCommand.cc index b4c5ff7..6ecb115 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/GetAppInfoCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/GetAppInfoCommand.cc @@ -1,5 +1,5 @@ +#include "bootstrap.h" #include "GetAppInfoCommand.h" -#include #ifdef GBSBUILD #include #include @@ -13,7 +13,7 @@ GetAppInfoCommand::GetAppInfoCommand(const ::aurum::ReqGetAppInfo* request, ::grpc::Status GetAppInfoCommand::execute() { - LOG_SCOPE_F(INFO, "GetAppInfo --------------- "); + LOGI("GetAppInfo --------------- "); #ifdef GBSBUILD std::string packageName = mRequest->packagename(); diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetAttributeCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetAttributeCommand.cc index 5b0ced7..38a3686 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/GetAttributeCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/GetAttributeCommand.cc @@ -1,8 +1,7 @@ +#include "bootstrap.h" #include "GetAttributeCommand.h" -#include - -#include -#include +#include "UiObject.h" +#include "UiDevice.h" GetAttributeCommand::GetAttributeCommand( const ::aurum::ReqGetAttribute* request, ::aurum::RspGetAttribute* response) @@ -20,7 +19,7 @@ std::unique_ptr GetAttributeCommand::createCommand(const :: { ::aurum::ReqGetAttribute_RequestType type = request->attribute(); - LOG_SCOPE_F(INFO, "type : %d", type); + LOGI("type : %d", type); if (type == ::aurum::ReqGetAttribute_RequestType::ReqGetAttribute_RequestType_VISIBLE) return std::make_unique(request, response); diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetDeviceTimeCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetDeviceTimeCommand.cc index 0119a20..8403dc8 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/GetDeviceTimeCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/GetDeviceTimeCommand.cc @@ -1,12 +1,10 @@ +#include "bootstrap.h" #include "GetDeviceTimeCommand.h" #include #include - -#include - -#include "UiDevice.h" #include +#include "UiDevice.h" #define BUFSIZE 64 @@ -88,7 +86,7 @@ public: ::grpc::Status GetDeviceTimeCommand::execute() { - LOG_SCOPE_F(INFO, "GetDeviceTime --------------- "); + LOGI("GetDeviceTime --------------- "); std::shared_ptr obj = UiDevice::getInstance(); ::aurum::ReqGetDeviceTime_TimeType type = mRequest->type(); diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetLocationCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetLocationCommand.cc index b92ff80..9110cb5 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/GetLocationCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/GetLocationCommand.cc @@ -1,5 +1,5 @@ +#include "bootstrap.h" #include "GetLocationCommand.h" -#include GetLocationCommand::GetLocationCommand(const ::aurum::ReqGetLocation* request, ::aurum::RspGetLocation* response) @@ -9,7 +9,7 @@ GetLocationCommand::GetLocationCommand(const ::aurum::ReqGetLocation* request, ::grpc::Status GetLocationCommand::execute() { - LOG_SCOPE_F(INFO, "CliGetLocation --------------- "); + LOGI("CliGetLocation --------------- "); // ObjectMapper *mObjMap = ObjectMapper::getInstance(); mResponse->set_alt(-1); diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetSizeCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetSizeCommand.cc index 919c196..88c7b00 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/GetSizeCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/GetSizeCommand.cc @@ -1,7 +1,6 @@ +#include "bootstrap.h" #include "GetSizeCommand.h" -#include - -#include +#include "UiObject.h" GetSizeCommand::GetSizeCommand(const ::aurum::ReqGetSize* request, ::aurum::RspGetSize* response) @@ -11,7 +10,7 @@ GetSizeCommand::GetSizeCommand(const ::aurum::ReqGetSize* request, ::grpc::Status GetSizeCommand::execute() { - LOG_SCOPE_F(INFO, "GetSize --------------- "); + LOGI("GetSize --------------- "); ObjectMapper *mObjMap = ObjectMapper::getInstance(); std::shared_ptr obj = mObjMap->getElement(mRequest->elementid()); if (obj) { diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetValueCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetValueCommand.cc index ebe9c93..410af95 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/GetValueCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/GetValueCommand.cc @@ -1,7 +1,6 @@ +#include "bootstrap.h" #include "GetValueCommand.h" -#include - -#include +#include "UiObject.h" GetValueCommand::GetValueCommand(const ::aurum::ReqGetValue* request, ::aurum::RspGetValue* response) @@ -11,7 +10,7 @@ GetValueCommand::GetValueCommand(const ::aurum::ReqGetValue* request, ::grpc::Status GetValueCommand::execute() { - LOG_SCOPE_F(INFO, "GetValue --------------- "); + LOGI("GetValue --------------- "); ObjectMapper* mObjMap = ObjectMapper::getInstance(); std::shared_ptr obj = mObjMap->getElement(mRequest->elementid()); diff --git a/org.tizen.aurum-bootstrap/src/Commands/InstallAppCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/InstallAppCommand.cc index 58c369f..f475da2 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/InstallAppCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/InstallAppCommand.cc @@ -1,8 +1,8 @@ +#include "bootstrap.h" #include "InstallAppCommand.h" #include #include #include -#include #ifdef GBSBUILD #include #endif @@ -16,7 +16,7 @@ InstallAppCommand::InstallAppCommand( ::grpc::Status InstallAppCommand::execute() { - LOG_SCOPE_F(INFO, "InstallApp --------------- "); + LOGI("InstallApp --------------- "); #ifdef GBSBUILD ::aurum::ReqInstallApp chunk; @@ -40,7 +40,7 @@ InstallAppCommand::InstallAppCommand( ::grpc::Status InstallAppCommand::executePost() { - LOG_SCOPE_F(INFO, "InstallAppCommand::executePost"); + LOGI("InstallAppCommand::executePost"); std::this_thread::sleep_for(std::chrono::milliseconds{5000}); return grpc::Status::OK; } \ No newline at end of file diff --git a/org.tizen.aurum-bootstrap/src/Commands/KillServerCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/KillServerCommand.cc index 2e51682..8a8641f 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/KillServerCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/KillServerCommand.cc @@ -1,5 +1,5 @@ +#include "bootstrap.h" #include "KillServerCommand.h" -#include KillServerCommand::KillServerCommand(const ::aurum::ReqEmpty* request, ::aurum::RspEmpty* response) @@ -9,7 +9,7 @@ KillServerCommand::KillServerCommand(const ::aurum::ReqEmpty* request, ::grpc::Status KillServerCommand::execute() { - LOG_SCOPE_F(INFO, "Kill Server "); + LOGI("Kill Server "); exit(1); diff --git a/org.tizen.aurum-bootstrap/src/Commands/LaunchAppCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/LaunchAppCommand.cc index f611eb5..b2a01c3 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/LaunchAppCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/LaunchAppCommand.cc @@ -1,5 +1,5 @@ +#include "bootstrap.h" #include "LaunchAppCommand.h" -#include #include #include @@ -15,7 +15,7 @@ LaunchAppCommand::LaunchAppCommand(const ::aurum::ReqLaunchApp* request, ::grpc::Status LaunchAppCommand::execute() { - LOG_SCOPE_F(INFO, "LaunchApp --------------- "); + LOGI("LaunchApp --------------- "); #ifdef GBSBUILD app_control_h appControl; std::string packageName = mRequest->packagename(); @@ -25,14 +25,14 @@ LaunchAppCommand::LaunchAppCommand(const ::aurum::ReqLaunchApp* request, ret = app_control_create(&appControl); if (ret) { - LOG_SCOPE_F(INFO, "Launch Failed(1/3) Err Code : %ull", ret); + LOGI("Launch Failed(1/3) Err Code : %ull", ret); mResponse->set_status(::aurum::RspStatus::ERROR); return grpc::Status::OK; } ret = app_control_set_app_id(appControl, packageName.c_str()); if (ret) { - LOG_SCOPE_F(INFO, "Launch Failed(2/3) Err Code : %ull", ret); + LOGI("Launch Failed(2/3) Err Code : %ull", ret); mResponse->set_status(::aurum::RspStatus::ERROR); app_control_destroy(appControl); return grpc::Status::OK; @@ -40,7 +40,7 @@ LaunchAppCommand::LaunchAppCommand(const ::aurum::ReqLaunchApp* request, ret = app_control_send_launch_request(appControl, NULL, NULL); if (ret) { - LOG_SCOPE_F(INFO, "Launch Failed(3/3) Err Code : %ull", ret); + LOGI("Launch Failed(3/3) Err Code : %ull", ret); mResponse->set_status(::aurum::RspStatus::ERROR); app_control_destroy(appControl); return grpc::Status::OK; @@ -52,7 +52,7 @@ LaunchAppCommand::LaunchAppCommand(const ::aurum::ReqLaunchApp* request, } ::grpc::Status LaunchAppCommand::executePost() { - LOG_SCOPE_F(INFO, "LaunchAppCommand::executePost"); + LOGI("LaunchAppCommand::executePost"); std::this_thread::sleep_for(std::chrono::milliseconds{2500}); return grpc::Status::OK; } diff --git a/org.tizen.aurum-bootstrap/src/Commands/LongClickCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/LongClickCommand.cc index 6360c12..22148b5 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/LongClickCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/LongClickCommand.cc @@ -1,8 +1,7 @@ +#include "bootstrap.h" #include "LongClickCommand.h" -#include - -#include -#include +#include "UiObject.h" +#include "UiDevice.h" LongClickCommand::LongClickCommand(const ::aurum::ReqClick* request, ::aurum::RspClick* response) @@ -12,7 +11,7 @@ LongClickCommand::LongClickCommand(const ::aurum::ReqClick* request, ::grpc::Status LongClickCommand::execute() { - LOG_SCOPE_F(INFO, "LongClick --------------- "); + LOGI("LongClick --------------- "); ObjectMapper* mObjMap = ObjectMapper::getInstance(); ::aurum::ReqClick_RequestType type = mRequest->type(); diff --git a/org.tizen.aurum-bootstrap/src/Commands/PostCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/PostCommand.cc index d6664cc..2a2a5e1 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/PostCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/PostCommand.cc @@ -1,6 +1,6 @@ +#include "bootstrap.h" #include "PostCommand.h" #include -#include PostCommand::PostCommand() : PostCommand(nullptr) {} PostCommand::PostCommand(Command *cmd) : mCommand{cmd} {} @@ -8,7 +8,7 @@ PostCommand::PostCommand(Command *cmd) : mCommand{cmd} {} ::grpc::Status PostCommand::execute() { ::grpc::Status rst = mCommand->execute(); - LOG_SCOPE_F(INFO, "PostCommand --------------- "); + LOGI("PostCommand --------------- "); mCommand->executePost(); // do post-command diff --git a/org.tizen.aurum-bootstrap/src/Commands/PreCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/PreCommand.cc index af36b2c..b291289 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/PreCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/PreCommand.cc @@ -1,6 +1,6 @@ +#include "bootstrap.h" #include "PreCommand.h" #include -#include #include #include @@ -16,16 +16,16 @@ PreCommand::PreCommand(Command *cmd) : mCommand{cmd} {} ::grpc::Status PreCommand::execute() { { - LOG_SCOPE_F(INFO, "PreCommand --------------- "); - display_state_e state; - if (device_display_get_state(&state) != DEVICE_ERROR_NONE) { - LOG_F(INFO, "getting display state has failed"); - } + LOGI("PreCommand --------------- "); + display_state_e state; + if (device_display_get_state(&state) != DEVICE_ERROR_NONE) { + LOGI("getting display state has failed"); + } bool isDisplayOn = DISPLAY_STATE_SCREEN_OFF != state; if (device_power_wakeup(false) != DEVICE_ERROR_NONE) { - LOG_F(INFO, "turning on display has failed"); + LOGI("turning on display has failed"); } if (!isDisplayOn) diff --git a/org.tizen.aurum-bootstrap/src/Commands/RemoveAppCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/RemoveAppCommand.cc index 07c0738..218e3d5 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/RemoveAppCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/RemoveAppCommand.cc @@ -1,5 +1,5 @@ +#include "bootstrap.h" #include "RemoveAppCommand.h" -#include #include #include #ifdef GBSBUILD @@ -14,13 +14,13 @@ RemoveAppCommand::RemoveAppCommand(const ::aurum::ReqRemoveApp* request, ::grpc::Status RemoveAppCommand::execute() { - LOG_SCOPE_F(INFO, "RemoveAppCommand::execute"); + LOGI("RemoveAppCommand::execute"); #ifdef GBSBUILD package_manager_request_h pkgRequest; std::string name = mRequest->packagename(); int id; - LOG_F(INFO, "package name :%s", name.c_str()); + LOGI("package name :%s", name.c_str()); if (package_manager_request_create(&pkgRequest) == PACKAGE_MANAGER_ERROR_NONE) { if (package_manager_request_uninstall(pkgRequest, name.c_str(), &id) == PACKAGE_MANAGER_ERROR_NONE) { @@ -33,7 +33,7 @@ RemoveAppCommand::RemoveAppCommand(const ::aurum::ReqRemoveApp* request, ::grpc::Status RemoveAppCommand::executePost() { - LOG_SCOPE_F(INFO, "RemoveAppCommand::executePost"); + LOGI("RemoveAppCommand::executePost"); std::this_thread::sleep_for(std::chrono::milliseconds{5000}); return grpc::Status::OK; } diff --git a/org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc index 6008d44..52e137f 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/SendKeyCommand.cc @@ -1,7 +1,6 @@ +#include "bootstrap.h" #include "SendKeyCommand.h" -#include - -#include +#include "UiDevice.h" SendKeyCommand::SendKeyCommand(const ::aurum::ReqKey* request, ::aurum::RspKey* response) @@ -11,7 +10,7 @@ SendKeyCommand::SendKeyCommand(const ::aurum::ReqKey* request, ::grpc::Status SendKeyCommand::execute() { - LOG_SCOPE_F(INFO, "SendKey --------------- "); + LOGI("SendKey --------------- "); std::shared_ptr mDevice = UiDevice::getInstance(); ::aurum::ReqKey_KeyType type = mRequest->type(); ::aurum::ReqKey_KeyActionType action_type = mRequest->actiontype(); diff --git a/org.tizen.aurum-bootstrap/src/Commands/SetValueCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/SetValueCommand.cc index 32cd476..8e4e4ac 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/SetValueCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/SetValueCommand.cc @@ -1,5 +1,5 @@ +#include "bootstrap.h" #include "SetValueCommand.h" -#include SetValueCommand::SetValueCommand(const ::aurum::ReqSetValue* request, ::aurum::RspSetValue* response) @@ -9,7 +9,7 @@ SetValueCommand::SetValueCommand(const ::aurum::ReqSetValue* request, ::grpc::Status SetValueCommand::execute() { - LOG_SCOPE_F(INFO, "SetValue (text:%s) --------------- ", mRequest->stringvalue().c_str()); + LOGI("SetValue (text:%s) --------------- ", mRequest->stringvalue().c_str()); ObjectMapper* mObjMap = ObjectMapper::getInstance(); std::shared_ptr obj = mObjMap->getElement(mRequest->elementid()); if (obj) obj->setText(const_cast(mRequest->stringvalue())); diff --git a/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc index 3206029..6d0177c 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/TakeScreenshotCommand.cc @@ -1,8 +1,8 @@ +#include "bootstrap.h" #include "TakeScreenshotCommand.h" -#include +#include #include "UiObject.h" #include "UiDevice.h" -#include TakeScreenshotCommand::TakeScreenshotCommand( const ::aurum::ReqTakeScreenshot* request, @@ -13,7 +13,7 @@ TakeScreenshotCommand::TakeScreenshotCommand( ::grpc::Status TakeScreenshotCommand::execute() { - LOG_SCOPE_F(INFO, "TakeScreenshot --------------- "); + LOGI("TakeScreenshot --------------- "); std::string path = "/tmp/screenshot.png"; std::shared_ptr mDevice = UiDevice::getInstance(); diff --git a/org.tizen.aurum-bootstrap/src/Commands/TouchDownCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/TouchDownCommand.cc index 533f520..c148b8a 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/TouchDownCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/TouchDownCommand.cc @@ -1,6 +1,6 @@ +#include "bootstrap.h" #include "TouchDownCommand.h" -#include -#include +#include "UiDevice.h" TouchDownCommand::TouchDownCommand(const ::aurum::ReqTouchDown* request, ::aurum::RspTouchDown* response) @@ -10,7 +10,7 @@ TouchDownCommand::TouchDownCommand(const ::aurum::ReqTouchDown* request, ::grpc::Status TouchDownCommand::execute() { - LOG_SCOPE_F(INFO, "TouchDown --------------- "); + LOGI("TouchDown --------------- "); const aurum::Point& point_ = mRequest->coordination(); int seq = UiDevice::getInstance() ->touchDown(point_.x(), point_.y()); diff --git a/org.tizen.aurum-bootstrap/src/Commands/TouchMoveCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/TouchMoveCommand.cc index d31c771..2bb0423 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/TouchMoveCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/TouchMoveCommand.cc @@ -1,6 +1,6 @@ +#include "bootstrap.h" #include "TouchMoveCommand.h" -#include -#include +#include "UiDevice.h" TouchMoveCommand::TouchMoveCommand(const ::aurum::ReqTouchMove* request, ::aurum::RspTouchMove* response) @@ -10,7 +10,7 @@ TouchMoveCommand::TouchMoveCommand(const ::aurum::ReqTouchMove* request, ::grpc::Status TouchMoveCommand::execute() { - LOG_SCOPE_F(INFO, "TouchMove --------------- "); + LOGI("TouchMove --------------- "); const aurum::Point& point = mRequest->coordination(); int seq = mRequest->seqid(); UiDevice::getInstance()->touchMove(point.x(), point.y(), seq); diff --git a/org.tizen.aurum-bootstrap/src/Commands/TouchUpCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/TouchUpCommand.cc index 354ccad..4fd946b 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/TouchUpCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/TouchUpCommand.cc @@ -1,6 +1,6 @@ +#include "bootstrap.h" #include "TouchUpCommand.h" -#include -#include +#include "UiDevice.h" TouchUpCommand::TouchUpCommand(const ::aurum::ReqTouchUp* request, ::aurum::RspTouchUp* response) @@ -10,7 +10,7 @@ TouchUpCommand::TouchUpCommand(const ::aurum::ReqTouchUp* request, ::grpc::Status TouchUpCommand::execute() { - LOG_SCOPE_F(INFO, "TouchUp --------------- "); + LOGI("TouchUp --------------- "); const aurum::Point& point = mRequest->coordination(); int seq = mRequest->seqid(); UiDevice::getInstance()->touchUp(point.x(), point.y(), seq); diff --git a/org.tizen.aurum-bootstrap/src/ObjectMapper.cc b/org.tizen.aurum-bootstrap/src/ObjectMapper.cc index 32b97c3..aa07fb5 100644 --- a/org.tizen.aurum-bootstrap/src/ObjectMapper.cc +++ b/org.tizen.aurum-bootstrap/src/ObjectMapper.cc @@ -1,6 +1,6 @@ #include "ObjectMapper.h" #include -#include +#include "bootstrap.h" #include #include @@ -21,40 +21,40 @@ std::string ObjectMapper::addElement(std::shared_ptr object) mObjectMap[key] = object; std::string value = object->getId(); mObjectMapReverse[value] = key; - LOG_SCOPE_F(INFO, "addElement %p as key %s, id %s", object.get(), key.c_str(), value.c_str()); + LOGI("addElement %p as key %s, id %s", object.get(), key.c_str(), value.c_str()); return key; } std::shared_ptr ObjectMapper::getElement(std::string key) { - LOG_SCOPE_F(INFO, "getElement for key(%s)", key.c_str()); + LOGI("getElement for key(%s)", key.c_str()); unsigned long long keyCnt = (unsigned long long)std::stoll(key); // this key is a result of calling std:to_string(mObjCounter) if (keyCnt <= 0 || keyCnt > mObjCounter) return nullptr; if (mObjectMap.count(key)) { std::shared_ptr obj = mObjectMap[key]; obj->refresh(); - LOG_F(INFO, "succeeded"); + LOGI("succeeded"); return obj; } - LOG_F(INFO, "failed(object not found)"); + LOGI("failed(object not found)"); return nullptr; } std::string ObjectMapper::getElement(std::shared_ptr object) { - LOG_SCOPE_F(INFO, "getElement for object(%p)", object.get()); + LOGI("getElement for object(%p)", object.get()); std::string value = object->getId(); if (mObjectMapReverse.count(value)) { - LOG_F(INFO, "succeeded"); + LOGI("succeeded"); return mObjectMapReverse[value]; } - LOG_F(INFO, "failed(object not found)"); + LOGI("failed(object not found)"); return std::string{""}; } bool ObjectMapper::removeElement(const std::string key) { - LOG_SCOPE_F(INFO, "removeElement for key(%s)", key.c_str()); + LOGI("removeElement for key(%s)", key.c_str()); std::shared_ptr obj = getElement(key); if (obj) { std::string value = obj->getId(); @@ -66,7 +66,7 @@ bool ObjectMapper::removeElement(const std::string key) bool ObjectMapper::removeElement(std::shared_ptr object) { - LOG_SCOPE_F(INFO, "removeElement for object(%p)", object.get()); + LOGI("removeElement for object(%p)", object.get()); std::string key = getElement(object); if (key.empty()) return false; return removeElement(key); @@ -76,7 +76,7 @@ void ObjectMapper::cleanUp() { std::stringstream ss{}; - LOG_SCOPE_F(INFO, "clean up object map"); + LOGI("clean up object map"); ss << "mObjectMapReverse: "; for(auto iter = mObjectMapReverse.begin(); iter != mObjectMapReverse.end(); ) { auto obj = mObjectMap[iter->second]; @@ -98,7 +98,7 @@ void ObjectMapper::cleanUp() } } ss << std::endl; - LOG_F(INFO, "%s", ss.str().c_str()); + LOGI("%s", ss.str().c_str()); } // std::remove_if(mObjectMapReverse.begin(), mObjectMapReverse.end(), [](auto& pair){return !pair.first->isValid();}); -- 2.7.4 From b1791c3078b6a3dac2e393ab57c5460d9893f295 Mon Sep 17 00:00:00 2001 From: Woochanlee Date: Wed, 7 Jul 2021 16:04:31 +0900 Subject: [PATCH 12/16] Aurum: Delete libloguru dependency Change-Id: I92b583cc4383093b63dac1ed99468ece395e6082 --- libaurum/meson.build | 3 - .../Impl/Accessibility/AtspiAccessibleWatcher.cc | 2 - libloguru/inc/loguru.hpp | 1335 --------------- libloguru/meson.build | 20 - libloguru/src/loguru.cpp | 1795 -------------------- meson.build | 1 - org.tizen.aurum-bootstrap/meson.build | 3 - tests/Test_Misc.cc | 3 - tests/Test_Sel.cc | 4 - tests/Test_UiDevice.cc | 7 +- tests/Test_UiObject.cc | 4 +- tests/Test_UiSelector.cc | 2 - 12 files changed, 2 insertions(+), 3177 deletions(-) delete mode 100644 libloguru/inc/loguru.hpp delete mode 100644 libloguru/meson.build delete mode 100644 libloguru/src/loguru.cpp diff --git a/libaurum/meson.build b/libaurum/meson.build index 24d3c3b..d55c9ee 100644 --- a/libaurum/meson.build +++ b/libaurum/meson.build @@ -27,7 +27,6 @@ libaurum_inc = [ include_directories('./inc/Runnable'), include_directories('./inc/Interface'), root_inc, - loguru_inc, ] libaurum_src = [] @@ -37,7 +36,6 @@ libaurum_dep = [ dependency('atspi-2'), dependency('gio-2.0'), dependency('threads'), - loguru_deps, ] if get_option('tizen') == true @@ -53,7 +51,6 @@ endif libaurum_lib = library('aurum', libaurum_src, dependencies: libaurum_dep, include_directories: libaurum_inc, - link_with: libloguru, install: true, version: meson.project_version(), ) diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc index b15e440..a2aaa49 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleWatcher.cc @@ -11,8 +11,6 @@ #include #include -#include - std::vector> AtspiAccessibleWatcher::mEventQueue; GThread *AtspiAccessibleWatcher::mEventThread = nullptr; diff --git a/libloguru/inc/loguru.hpp b/libloguru/inc/loguru.hpp deleted file mode 100644 index 24eca7a..0000000 --- a/libloguru/inc/loguru.hpp +++ /dev/null @@ -1,1335 +0,0 @@ -/* -Loguru logging library for C++, by Emil Ernerfeldt. -www.github.com/emilk/loguru -If you find Loguru useful, please let me know on twitter or in a mail! -Twitter: @ernerfeldt -Mail: emil.ernerfeldt@gmail.com -Website: www.ilikebigbits.com - -# License - This software is in the public domain. Where that dedication is not - recognized, you are granted a perpetual, irrevocable license to - copy, modify and distribute it as you see fit. - -# Inspiration - Much of Loguru was inspired by GLOG, https://code.google.com/p/google-glog/. - The choice of public domain is fully due Sean T. Barrett - and his wonderful stb libraries at https://github.com/nothings/stb. - -# Version history - * Version 0.1.0 - 2015-03-22 - Works great on Mac. - * Version 0.2.0 - 2015-09-17 - Removed the only dependency. - * Version 0.3.0 - 2015-10-02 - Drop-in replacement for most of GLOG - * Version 0.4.0 - 2015-10-07 - Single-file! - * Version 0.5.0 - 2015-10-17 - Improved file logging - * Version 0.6.0 - 2015-10-24 - Add stack traces - * Version 0.7.0 - 2015-10-27 - Signals - * Version 0.8.0 - 2015-10-30 - Color logging. - * Version 0.9.0 - 2015-11-26 - ABORT_S and proper handling of FATAL - * Version 1.0.0 - 2016-02-14 - ERROR_CONTEXT - * Version 1.1.0 - 2016-02-19 - -v OFF, -v INFO etc - * Version 1.1.1 - 2016-02-20 - textprintf vs strprintf - * Version 1.1.2 - 2016-02-22 - Remove g_alsologtostderr - * Version 1.1.3 - 2016-02-29 - ERROR_CONTEXT as linked list - * Version 1.2.0 - 2016-03-19 - Add get_thread_name() - * Version 1.2.1 - 2016-03-20 - Minor fixes - * Version 1.2.2 - 2016-03-29 - Fix issues with set_fatal_handler throwing an exception - * Version 1.2.3 - 2016-05-16 - Log current working directory in loguru::init(). - * Version 1.2.4 - 2016-05-18 - Custom replacement for -v in loguru::init() by bjoernpollex - * Version 1.2.5 - 2016-05-18 - Add ability to print ERROR_CONTEXT of parent thread. - * Version 1.2.6 - 2016-05-19 - Bug fix regarding VLOG verbosity argument lacking (). - * Version 1.2.7 - 2016-05-23 - Fix PATH_MAX problem. - * Version 1.2.8 - 2016-05-26 - Add shutdown() and remove_all_callbacks() - * Version 1.2.9 - 2016-06-09 - Use a monotonic clock for uptime. - * Version 1.3.0 - 2016-07-20 - Fix issues with callback flush/close not being called. - * Version 1.3.1 - 2016-07-20 - Add LOGURU_UNSAFE_SIGNAL_HANDLER to toggle stacktrace on signals. - * Version 1.3.2 - 2016-07-20 - Add loguru::arguments() - * Version 1.4.0 - 2016-09-15 - Semantic versioning + add loguru::create_directories - * Version 1.4.1 - 2016-09-29 - Customize formating with LOGURU_FILENAME_WIDTH - * Version 1.5.0 - 2016-12-22 - LOGURU_USE_FMTLIB by kolis and LOGURU_WITH_FILEABS by scinart - * Version 1.5.1 - 2017-08-08 - Terminal colors on Windows 10 thanks to looki - * Version 1.6.0 - 2018-01-03 - Add LOGURU_RTTI and LOGURU_STACKTRACES settings - * Version 1.7.0 - 2018-01-03 - Add ability to turn off the preamble with loguru::g_preamble - * Version 1.7.1 - 2018-04-05 - Add function get_fatal_handler - * Version 1.7.2 - 2018-04-22 - Fix a bug where large file names could cause stack corruption (thanks @ccamporesi) - * Version 1.8.0 - 2018-04-23 - Shorten long file names to keep preamble fixed width - * Version 1.9.0 - 2018-09-22 - Adjust terminal colors, add LOGURU_VERBOSE_SCOPE_ENDINGS, add LOGURU_SCOPE_TIME_PRECISION, add named log levels - * Version 2.0.0 - 2018-09-22 - Split loguru.hpp into loguru.hpp and loguru.cpp - -# Compiling - Just include where you want to use Loguru. - Then, in one .cpp file #include - Make sure you compile with -std=c++11 -lstdc++ -lpthread -ldl - -# Usage - For details, please see the official documentation at emilk.github.io/loguru - - #include - - int main(int argc, char* argv[]) { - loguru::init(argc, argv); - - // Put every log message in "everything.log": - loguru::add_file("everything.log", loguru::Append, loguru::Verbosity_MAX); - - LOG_F(INFO, "The magic number is %d", 42); - } - -*/ - -#if defined(LOGURU_IMPLEMENTATION) - #warning "You are defining LOGURU_IMPLEMENTATION. This is for older versions of Loguru. You should now instead include loguru.cpp (or build it and link with it)" -#endif - -// Disable all warnings from gcc/clang: -#if defined(__clang__) - #pragma clang system_header -#elif defined(__GNUC__) - #pragma GCC system_header -#endif - -#ifndef LOGURU_HAS_DECLARED_FORMAT_HEADER -#define LOGURU_HAS_DECLARED_FORMAT_HEADER - -// Semantic versioning. Loguru version can be printed with printf("%d.%d.%d", LOGURU_VERSION_MAJOR, LOGURU_VERSION_MINOR, LOGURU_VERSION_PATCH); -#define LOGURU_VERSION_MAJOR 2 -#define LOGURU_VERSION_MINOR 0 -#define LOGURU_VERSION_PATCH 0 - -#if defined(_MSC_VER) -#include // Needed for _In_z_ etc annotations -#endif - -// ---------------------------------------------------------------------------- - -#ifndef LOGURU_EXPORT - // Define to your project's export declaration if needed for use in a shared library. - #define LOGURU_EXPORT -#endif - -#ifndef LOGURU_SCOPE_TEXT_SIZE - // Maximum length of text that can be printed by a LOG_SCOPE. - // This should be long enough to get most things, but short enough not to clutter the stack. - #define LOGURU_SCOPE_TEXT_SIZE 196 -#endif - -#ifndef LOGURU_FILENAME_WIDTH - // Width of the column containing the file name - #define LOGURU_FILENAME_WIDTH 23 -#endif - -#ifndef LOGURU_THREADNAME_WIDTH - // Width of the column containing the thread name - #define LOGURU_THREADNAME_WIDTH 16 -#endif - -#ifndef LOGURU_SCOPE_TIME_PRECISION - // Resolution of scope timers. 3=ms, 6=us, 9=ns - #define LOGURU_SCOPE_TIME_PRECISION 3 -#endif - -#ifndef LOGURU_CATCH_SIGABRT - // Should Loguru catch SIGABRT to print stack trace etc? - #define LOGURU_CATCH_SIGABRT 1 -#endif - -#ifndef LOGURU_VERBOSE_SCOPE_ENDINGS - // Show milliseconds and scope name at end of scope. - #define LOGURU_VERBOSE_SCOPE_ENDINGS 1 -#endif - -#ifndef LOGURU_REDEFINE_ASSERT - #define LOGURU_REDEFINE_ASSERT 0 -#endif - -#ifndef LOGURU_WITH_STREAMS - #define LOGURU_WITH_STREAMS 0 -#endif - -#ifndef LOGURU_REPLACE_GLOG - #define LOGURU_REPLACE_GLOG 0 -#endif - -#if LOGURU_REPLACE_GLOG - #undef LOGURU_WITH_STREAMS - #define LOGURU_WITH_STREAMS 1 -#endif - -#ifndef LOGURU_UNSAFE_SIGNAL_HANDLER - #define LOGURU_UNSAFE_SIGNAL_HANDLER 1 -#endif - -#if LOGURU_IMPLEMENTATION - #undef LOGURU_WITH_STREAMS - #define LOGURU_WITH_STREAMS 1 -#endif - -#ifndef LOGURU_USE_FMTLIB - #define LOGURU_USE_FMTLIB 0 -#endif - -#ifndef LOGURU_WITH_FILEABS - #define LOGURU_WITH_FILEABS 0 -#endif - -#ifndef LOGURU_RTTI -#if defined(__clang__) - #if __has_feature(cxx_rtti) - #define LOGURU_RTTI 1 - #endif -#elif defined(__GNUG__) - #if defined(__GXX_RTTI) - #define LOGURU_RTTI 1 - #endif -#elif defined(_MSC_VER) - #if defined(_CPPRTTI) - #define LOGURU_RTTI 1 - #endif -#endif -#endif - -// -------------------------------------------------------------------- -// Utility macros - -#define LOGURU_CONCATENATE_IMPL(s1, s2) s1 ## s2 -#define LOGURU_CONCATENATE(s1, s2) LOGURU_CONCATENATE_IMPL(s1, s2) - -#ifdef __COUNTER__ -# define LOGURU_ANONYMOUS_VARIABLE(str) LOGURU_CONCATENATE(str, __COUNTER__) -#else -# define LOGURU_ANONYMOUS_VARIABLE(str) LOGURU_CONCATENATE(str, __LINE__) -#endif - -#if defined(__clang__) || defined(__GNUC__) - // Helper macro for declaring functions as having similar signature to printf. - // This allows the compiler to catch format errors at compile-time. - #define LOGURU_PRINTF_LIKE(fmtarg, firstvararg) __attribute__((__format__ (__printf__, fmtarg, firstvararg))) - #define LOGURU_FORMAT_STRING_TYPE const char* -#elif defined(_MSC_VER) - #define LOGURU_PRINTF_LIKE(fmtarg, firstvararg) - #define LOGURU_FORMAT_STRING_TYPE _In_z_ _Printf_format_string_ const char* -#else - #define LOGURU_PRINTF_LIKE(fmtarg, firstvararg) - #define LOGURU_FORMAT_STRING_TYPE const char* -#endif - -// Used to mark log_and_abort for the benefit of the static analyzer and optimizer. -#if defined(_MSC_VER) -#define LOGURU_NORETURN __declspec(noreturn) -#else -#define LOGURU_NORETURN __attribute__((noreturn)) -#endif - -#if defined(_MSC_VER) -#define LOGURU_PREDICT_FALSE(x) (x) -#define LOGURU_PREDICT_TRUE(x) (x) -#else -#define LOGURU_PREDICT_FALSE(x) (__builtin_expect(x, 0)) -#define LOGURU_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) -#endif - -#if LOGURU_USE_FMTLIB - #include -#endif - -#ifdef _WIN32 - #define STRDUP(str) _strdup(str) -#else - #define STRDUP(str) strdup(str) -#endif - -// -------------------------------------------------------------------- - -namespace loguru -{ - // Simple RAII ownership of a char*. - class LOGURU_EXPORT Text - { - public: - explicit Text(char* owned_str) : _str(owned_str) {} - ~Text(); - Text(Text&& t) - { - _str = t._str; - t._str = nullptr; - } - Text(Text& t) = delete; - Text& operator=(Text& t) = delete; - void operator=(Text&& t) = delete; - - const char* c_str() const { return _str; } - bool empty() const { return _str == nullptr || *_str == '\0'; } - - char* release() - { - auto result = _str; - _str = nullptr; - return result; - } - - private: - char* _str; - }; - - // Like printf, but returns the formated text. - LOGURU_EXPORT - Text textprintf(LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(1, 2); - - // Overloaded for variadic template matching. - LOGURU_EXPORT - Text textprintf(); - - using Verbosity = int; - -#undef FATAL -#undef ERROR -#undef WARNING -#undef INFO -#undef MAX - - enum NamedVerbosity : Verbosity - { - // Used to mark an invalid verbosity. Do not log to this level. - Verbosity_INVALID = -10, // Never do LOG_F(INVALID) - - // You may use Verbosity_OFF on g_stderr_verbosity, but for nothing else! - Verbosity_OFF = -9, // Never do LOG_F(OFF) - - // Prefer to use ABORT_F or ABORT_S over LOG_F(FATAL) or LOG_S(FATAL). - Verbosity_FATAL = -3, - Verbosity_ERROR = -2, - Verbosity_WARNING = -1, - - // Normal messages. By default written to stderr. - Verbosity_INFO = 0, - - // Same as Verbosity_INFO in every way. - Verbosity_0 = 0, - - // Verbosity levels 1-9 are generally not written to stderr, but are written to file. - Verbosity_1 = +1, - Verbosity_2 = +2, - Verbosity_3 = +3, - Verbosity_4 = +4, - Verbosity_5 = +5, - Verbosity_6 = +6, - Verbosity_7 = +7, - Verbosity_8 = +8, - Verbosity_9 = +9, - - // Don not use higher verbosity levels, as that will make grepping log files harder. - Verbosity_MAX = +9, - }; - - struct Message - { - // You would generally print a Message by just concating the buffers without spacing. - // Optionally, ignore preamble and indentation. - Verbosity verbosity; // Already part of preamble - const char* filename; // Already part of preamble - unsigned line; // Already part of preamble - const char* preamble; // Date, time, uptime, thread, file:line, verbosity. - const char* indentation; // Just a bunch of spacing. - const char* prefix; // Assertion failure info goes here (or ""). - const char* message; // User message goes here. - }; - - /* Everything with a verbosity equal or greater than g_stderr_verbosity will be - written to stderr. You can set this in code or via the -v argument. - Set to loguru::Verbosity_OFF to write nothing to stderr. - Default is 0, i.e. only log ERROR, WARNING and INFO are written to stderr. - */ - LOGURU_EXPORT extern Verbosity g_stderr_verbosity; - LOGURU_EXPORT extern bool g_colorlogtostderr; // True by default. - LOGURU_EXPORT extern unsigned g_flush_interval_ms; // 0 (unbuffered) by default. - LOGURU_EXPORT extern bool g_preamble; // Prefix each log line with date, time etc? True by default. - - /* Specify the verbosity used by loguru to log its info messages including the header - logged when logged::init() is called or on exit. Default is 0 (INFO). - */ - LOGURU_EXPORT extern Verbosity g_internal_verbosity; - - // Turn off individual parts of the preamble - LOGURU_EXPORT extern bool g_preamble_date; // The date field - LOGURU_EXPORT extern bool g_preamble_time; // The time of the current day - LOGURU_EXPORT extern bool g_preamble_uptime; // The time since init call - LOGURU_EXPORT extern bool g_preamble_thread; // The logging thread - LOGURU_EXPORT extern bool g_preamble_file; // The file from which the log originates from - LOGURU_EXPORT extern bool g_preamble_verbose; // The verbosity field - LOGURU_EXPORT extern bool g_preamble_pipe; // The pipe symbol right before the message - - // May not throw! - typedef void (*log_handler_t)(void* user_data, const Message& message); - typedef void (*close_handler_t)(void* user_data); - typedef void (*flush_handler_t)(void* user_data); - - // May throw if that's how you'd like to handle your errors. - typedef void (*fatal_handler_t)(const Message& message); - - // Given a verbosity level, return the level's name or nullptr. - typedef const char* (*verbosity_to_name_t)(Verbosity verbosity); - - // Given a verbosity level name, return the verbosity level or - // Verbosity_INVALID if name is not recognized. - typedef Verbosity (*name_to_verbosity_t)(const char* name); - - /* Should be called from the main thread. - You don't *need* to call this, but if you do you get: - * Signal handlers installed - * Program arguments logged - * Working dir logged - * Optional -v verbosity flag parsed - * Main thread name set to "main thread" - * Explanation of the preamble (date, threanmae etc) logged - - loguru::init() will look for arguments meant for loguru and remove them. - Arguments meant for loguru are: - -v n Set loguru::g_stderr_verbosity level. Examples: - -v 3 Show verbosity level 3 and lower. - -v 0 Only show INFO, WARNING, ERROR, FATAL (default). - -v INFO Only show INFO, WARNING, ERROR, FATAL (default). - -v WARNING Only show WARNING, ERROR, FATAL. - -v ERROR Only show ERROR, FATAL. - -v FATAL Only show FATAL. - -v OFF Turn off logging to stderr. - - Tip: You can set g_stderr_verbosity before calling loguru::init. - That way you can set the default but have the user override it with the -v flag. - Note that -v does not affect file logging (see loguru::add_file). - - You can use something else instead of "-v" via verbosity_flag. - You can also set verbosity_flag to nullptr. - */ - LOGURU_EXPORT - void init(int& argc, char* argv[], const char* verbosity_flag = "-v"); - - // Will call remove_all_callbacks(). After calling this, logging will still go to stderr. - // You generally don't need to call this. - LOGURU_EXPORT - void shutdown(); - - // What ~ will be replaced with, e.g. "/home/your_user_name/" - LOGURU_EXPORT - const char* home_dir(); - - /* Returns the name of the app as given in argv[0] but without leading path. - That is, if argv[0] is "../foo/app" this will return "app". - */ - LOGURU_EXPORT - const char* argv0_filename(); - - // Returns all arguments given to loguru::init(), but escaped with a single space as separator. - LOGURU_EXPORT - const char* arguments(); - - // Returns the path to the current working dir when loguru::init() was called. - LOGURU_EXPORT - const char* current_dir(); - - // Returns the part of the path after the last / or \ (if any). - LOGURU_EXPORT - const char* filename(const char* path); - - // e.g. "foo/bar/baz.ext" will create the directories "foo/" and "foo/bar/" - LOGURU_EXPORT - bool create_directories(const char* file_path_const); - - // Writes date and time with millisecond precision, e.g. "20151017_161503.123" - LOGURU_EXPORT - void write_date_time(char* buff, unsigned buff_size); - - // Helper: thread-safe version strerror - LOGURU_EXPORT - Text errno_as_text(); - - /* Given a prefix of e.g. "~/loguru/" this might return - "/home/your_username/loguru/app_name/20151017_161503.123.log" - - where "app_name" is a sanitized version of argv[0]. - */ - LOGURU_EXPORT - void suggest_log_path(const char* prefix, char* buff, unsigned buff_size); - - enum FileMode { Truncate, Append }; - - /* Will log to a file at the given path. - Any logging message with a verbosity lower or equal to - the given verbosity will be included. - The function will create all directories in 'path' if needed. - If path starts with a ~, it will be replaced with loguru::home_dir() - To stop the file logging, just call loguru::remove_callback(path) with the same path. - */ - LOGURU_EXPORT - bool add_file(const char* path, FileMode mode, Verbosity verbosity); - - /* Will be called right before abort(). - You can for instance use this to print custom error messages, or throw an exception. - Feel free to call LOG:ing function from this, but not FATAL ones! */ - LOGURU_EXPORT - void set_fatal_handler(fatal_handler_t handler); - - // Get the current fatal handler, if any. Default value is nullptr. - LOGURU_EXPORT - fatal_handler_t get_fatal_handler(); - - /* Will be called on each log messages with a verbosity less or equal to the given one. - Useful for displaying messages on-screen in a game, for example. - The given on_close is also expected to flush (if desired). - */ - LOGURU_EXPORT - void add_callback( - const char* id, - log_handler_t callback, - void* user_data, - Verbosity verbosity, - close_handler_t on_close = nullptr, - flush_handler_t on_flush = nullptr); - - /* Set a callback that returns custom verbosity level names. If callback - is nullptr or returns nullptr, default log names will be used. - */ - LOGURU_EXPORT - void set_verbosity_to_name_callback(verbosity_to_name_t callback); - - /* Set a callback that returns the verbosity level matching a name. The - callback should return Verbosity_INVALID if the name is not - recognized. - */ - LOGURU_EXPORT - void set_name_to_verbosity_callback(name_to_verbosity_t callback); - - /* Get a custom name for a specific verbosity, if one exists, or nullptr. */ - LOGURU_EXPORT - const char* get_verbosity_name(Verbosity verbosity); - - /* Get the verbosity enum value from a custom 4-character level name, if one exists. - If the name does not match a custom level name, Verbosity_INVALID is returned. - */ - LOGURU_EXPORT - Verbosity get_verbosity_from_name(const char* name); - - // Returns true iff the callback was found (and removed). - LOGURU_EXPORT - bool remove_callback(const char* id); - - // Shut down all file logging and any other callback hooks installed. - LOGURU_EXPORT - void remove_all_callbacks(); - - // Returns the maximum of g_stderr_verbosity and all file/custom outputs. - LOGURU_EXPORT - Verbosity current_verbosity_cutoff(); - -#if LOGURU_USE_FMTLIB - // Actual logging function. Use the LOG macro instead of calling this directly. - LOGURU_EXPORT - void log(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, fmt::ArgList args); - FMT_VARIADIC(void, log, Verbosity, const char*, unsigned, LOGURU_FORMAT_STRING_TYPE) - - // Log without any preamble or indentation. - LOGURU_EXPORT - void raw_log(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, fmt::ArgList args); - FMT_VARIADIC(void, raw_log, Verbosity, const char*, unsigned, LOGURU_FORMAT_STRING_TYPE) -#else // LOGURU_USE_FMTLIB? - // Actual logging function. Use the LOG macro instead of calling this directly. - LOGURU_EXPORT - void log(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(4, 5); - - // Log without any preamble or indentation. - LOGURU_EXPORT - void raw_log(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(4, 5); -#endif // !LOGURU_USE_FMTLIB - - // Helper class for LOG_SCOPE_F - class LOGURU_EXPORT LogScopeRAII - { - public: - LogScopeRAII() : _file(nullptr) {} // No logging - LogScopeRAII(Verbosity verbosity, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(5, 6); - ~LogScopeRAII(); - -#if defined(_MSC_VER) && _MSC_VER > 1800 - // older MSVC default move ctors close the scope on move. See - // issue #43 - LogScopeRAII(LogScopeRAII&& other) - : _verbosity(other._verbosity) - , _file(other._file) - , _line(other._line) - , _indent_stderr(other._indent_stderr) - , _start_time_ns(other._start_time_ns) - { - // Make sure the tmp object's destruction doesn't close the scope: - other._file = nullptr; - - for (unsigned int i = 0; i < LOGURU_SCOPE_TEXT_SIZE; ++i) { - _name[i] = other._name[i]; - } - } -#else - LogScopeRAII(LogScopeRAII&&) = default; -#endif - - private: - LogScopeRAII(const LogScopeRAII&) = delete; - LogScopeRAII& operator=(const LogScopeRAII&) = delete; - void operator=(LogScopeRAII&&) = delete; - - Verbosity _verbosity; - const char* _file; // Set to null if we are disabled due to verbosity - unsigned _line; - bool _indent_stderr; // Did we? - long long _start_time_ns; - char _name[LOGURU_SCOPE_TEXT_SIZE]; - }; - - // Marked as 'noreturn' for the benefit of the static analyzer and optimizer. - // stack_trace_skip is the number of extrace stack frames to skip above log_and_abort. - LOGURU_EXPORT - LOGURU_NORETURN void log_and_abort(int stack_trace_skip, const char* expr, const char* file, unsigned line, LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(5, 6); - LOGURU_EXPORT - LOGURU_NORETURN void log_and_abort(int stack_trace_skip, const char* expr, const char* file, unsigned line); - - // Flush output to stderr and files. - // If g_flush_interval_ms is set to non-zero, this will be called automatically this often. - // If not set, you do not need to call this at all. - LOGURU_EXPORT - void flush(); - - template inline Text format_value(const T&) { return textprintf("N/A"); } - template<> inline Text format_value(const char& v) { return textprintf("%c", v); } - template<> inline Text format_value(const int& v) { return textprintf("%d", v); } - template<> inline Text format_value(const unsigned int& v) { return textprintf("%u", v); } - template<> inline Text format_value(const long& v) { return textprintf("%lu", v); } - template<> inline Text format_value(const unsigned long& v) { return textprintf("%ld", v); } - template<> inline Text format_value(const long long& v) { return textprintf("%llu", v); } - template<> inline Text format_value(const unsigned long long& v) { return textprintf("%lld", v); } - template<> inline Text format_value(const float& v) { return textprintf("%f", v); } - template<> inline Text format_value(const double& v) { return textprintf("%f", v); } - - /* Thread names can be set for the benefit of readable logs. - If you do not set the thread name, a hex id will be shown instead. - These thread names may or may not be the same as the system thread names, - depending on the system. - Try to limit the thread name to 15 characters or less. */ - LOGURU_EXPORT - void set_thread_name(const char* name); - - /* Returns the thread name for this thread. - On OSX this will return the system thread name (settable from both within and without Loguru). - On other systems it will return whatever you set in set_thread_name(); - If no thread name is set, this will return a hexadecimal thread id. - length should be the number of bytes available in the buffer. - 17 is a good number for length. - right_align_hext_id means any hexadecimal thread id will be written to the end of buffer. - */ - LOGURU_EXPORT - void get_thread_name(char* buffer, unsigned long long length, bool right_align_hext_id); - - /* Generates a readable stacktrace as a string. - 'skip' specifies how many stack frames to skip. - For instance, the default skip (1) means: - don't include the call to loguru::stacktrace in the stack trace. */ - LOGURU_EXPORT - Text stacktrace(int skip = 1); - - /* Add a string to be replaced with something else in the stack output. - - For instance, instead of having a stack trace look like this: - 0x41f541 some_function(std::basic_ofstream >&) - You can clean it up with: - auto verbose_type_name = loguru::demangle(typeid(std::ofstream).name()); - loguru::add_stack_cleanup(verbose_type_name.c_str(); "std::ofstream"); - So the next time you will instead see: - 0x41f541 some_function(std::ofstream&) - - `replace_with_this` must be shorter than `find_this`. - */ - LOGURU_EXPORT - void add_stack_cleanup(const char* find_this, const char* replace_with_this); - - // Example: demangle(typeid(std::ofstream).name()) -> "std::basic_ofstream >" - LOGURU_EXPORT - Text demangle(const char* name); - - // ------------------------------------------------------------------------ - /* - Not all terminals support colors, but if they do, and g_colorlogtostderr - is set, Loguru will write them to stderr to make errors in red, etc. - - You also have the option to manually use them, via the function below. - - Note, however, that if you do, the color codes could end up in your logfile! - - This means if you intend to use them functions you should either: - * Use them on the stderr/stdout directly (bypass Loguru). - * Don't add file outputs to Loguru. - * Expect some \e[1m things in your logfile. - - Usage: - printf("%sRed%sGreen%sBold green%sClear again\n", - loguru::terminal_red(), loguru::terminal_green(), - loguru::terminal_bold(), loguru::terminal_reset()); - - If the terminal at hand does not support colors the above output - will just not have funky \e[1m things showing. - */ - - // Do the output terminal support colors? - LOGURU_EXPORT - bool terminal_has_color(); - - // Colors - LOGURU_EXPORT const char* terminal_black(); - LOGURU_EXPORT const char* terminal_red(); - LOGURU_EXPORT const char* terminal_green(); - LOGURU_EXPORT const char* terminal_yellow(); - LOGURU_EXPORT const char* terminal_blue(); - LOGURU_EXPORT const char* terminal_purple(); - LOGURU_EXPORT const char* terminal_cyan(); - LOGURU_EXPORT const char* terminal_light_gray(); - LOGURU_EXPORT const char* terminal_light_red(); - LOGURU_EXPORT const char* terminal_white(); - - // Formating - LOGURU_EXPORT const char* terminal_bold(); - LOGURU_EXPORT const char* terminal_underline(); - - // You should end each line with this! - LOGURU_EXPORT const char* terminal_reset(); - - // -------------------------------------------------------------------- - // Error context related: - - struct StringStream; - - // Use this in your EcEntryBase::print_value overload. - LOGURU_EXPORT - void stream_print(StringStream& out_string_stream, const char* text); - - class LOGURU_EXPORT EcEntryBase - { - public: - EcEntryBase(const char* file, unsigned line, const char* descr); - ~EcEntryBase(); - EcEntryBase(const EcEntryBase&) = delete; - EcEntryBase(EcEntryBase&&) = delete; - EcEntryBase& operator=(const EcEntryBase&) = delete; - EcEntryBase& operator=(EcEntryBase&&) = delete; - - virtual void print_value(StringStream& out_string_stream) const = 0; - - EcEntryBase* previous() const { return _previous; } - - // private: - const char* _file; - unsigned _line; - const char* _descr; - EcEntryBase* _previous; - }; - - template - class EcEntryData : public EcEntryBase - { - public: - using Printer = Text(*)(T data); - - EcEntryData(const char* file, unsigned line, const char* descr, T data, Printer&& printer) - : EcEntryBase(file, line, descr), _data(data), _printer(printer) {} - - virtual void print_value(StringStream& out_string_stream) const override - { - const auto str = _printer(_data); - stream_print(out_string_stream, str.c_str()); - } - - private: - T _data; - Printer _printer; - }; - - // template - // class EcEntryLambda : public EcEntryBase - // { - // public: - // EcEntryLambda(const char* file, unsigned line, const char* descr, Printer&& printer) - // : EcEntryBase(file, line, descr), _printer(std::move(printer)) {} - - // virtual void print_value(StringStream& out_string_stream) const override - // { - // const auto str = _printer(); - // stream_print(out_string_stream, str.c_str()); - // } - - // private: - // Printer _printer; - // }; - - // template - // EcEntryLambda make_ec_entry_lambda(const char* file, unsigned line, const char* descr, Printer&& printer) - // { - // return {file, line, descr, std::move(printer)}; - // } - - template - struct decay_char_array { using type = T; }; - - template - struct decay_char_array { using type = const char*; }; - - template - struct make_const_ptr { using type = T; }; - - template - struct make_const_ptr { using type = const T*; }; - - template - struct make_ec_type { using type = typename make_const_ptr::type>::type; }; - - /* A stack trace gives you the names of the function at the point of a crash. - With ERROR_CONTEXT, you can also get the values of select local variables. - Usage: - - void process_customers(const std::string& filename) - { - ERROR_CONTEXT("Processing file", filename.c_str()); - for (int customer_index : ...) - { - ERROR_CONTEXT("Customer index", customer_index); - ... - } - } - - The context is in effect during the scope of the ERROR_CONTEXT. - Use loguru::get_error_context() to get the contents of the active error contexts. - - Example result: - - ------------------------------------------------ - [ErrorContext] main.cpp:416 Processing file: "customers.json" - [ErrorContext] main.cpp:417 Customer index: 42 - ------------------------------------------------ - - Error contexts are printed automatically on crashes, and only on crashes. - This makes them much faster than logging the value of a variable. - */ - #define ERROR_CONTEXT(descr, data) \ - const loguru::EcEntryData::type> \ - LOGURU_ANONYMOUS_VARIABLE(error_context_scope_)( \ - __FILE__, __LINE__, descr, data, \ - static_cast::type>::Printer>(loguru::ec_to_text) ) // For better error messages - -/* - #define ERROR_CONTEXT(descr, data) \ - const auto LOGURU_ANONYMOUS_VARIABLE(error_context_scope_)( \ - loguru::make_ec_entry_lambda(__FILE__, __LINE__, descr, \ - [=](){ return loguru::ec_to_text(data); })) -*/ - - using EcHandle = const EcEntryBase*; - - /* - Get a light-weight handle to the error context stack on this thread. - The handle is valid as long as the current thread has no changes to its error context stack. - You can pass the handle to loguru::get_error_context on another thread. - This can be very useful for when you have a parent thread spawning several working threads, - and you want the error context of the parent thread to get printed (too) when there is an - error on the child thread. You can accomplish this thusly: - - void foo(const char* parameter) - { - ERROR_CONTEXT("parameter", parameter) - const auto parent_ec_handle = loguru::get_thread_ec_handle(); - - std::thread([=]{ - loguru::set_thread_name("child thread"); - ERROR_CONTEXT("parent context", parent_ec_handle); - dangerous_code(); - }.join(); - } - - */ - LOGURU_EXPORT - EcHandle get_thread_ec_handle(); - - // Get a string describing the current stack of error context. Empty string if there is none. - LOGURU_EXPORT - Text get_error_context(); - - // Get a string describing the error context of the given thread handle. - LOGURU_EXPORT - Text get_error_context_for(EcHandle ec_handle); - - // ------------------------------------------------------------------------ - - LOGURU_EXPORT Text ec_to_text(const char* data); - LOGURU_EXPORT Text ec_to_text(char data); - LOGURU_EXPORT Text ec_to_text(int data); - LOGURU_EXPORT Text ec_to_text(unsigned int data); - LOGURU_EXPORT Text ec_to_text(long data); - LOGURU_EXPORT Text ec_to_text(unsigned long data); - LOGURU_EXPORT Text ec_to_text(long long data); - LOGURU_EXPORT Text ec_to_text(unsigned long long data); - LOGURU_EXPORT Text ec_to_text(float data); - LOGURU_EXPORT Text ec_to_text(double data); - LOGURU_EXPORT Text ec_to_text(long double data); - LOGURU_EXPORT Text ec_to_text(EcHandle); - - /* - You can add ERROR_CONTEXT support for your own types by overloading ec_to_text. Here's how: - - some.hpp: - namespace loguru { - Text ec_to_text(MySmallType data) - Text ec_to_text(const MyBigType* data) - } // namespace loguru - - some.cpp: - namespace loguru { - Text ec_to_text(MySmallType small_value) - { - // Called only when needed, i.e. on a crash. - std::string str = small_value.as_string(); // Format 'small_value' here somehow. - return Text{STRDUP(str.c_str())}; - } - - Text ec_to_text(const MyBigType* big_value) - { - // Called only when needed, i.e. on a crash. - std::string str = big_value->as_string(); // Format 'big_value' here somehow. - return Text{STRDUP(str.c_str())}; - } - } // namespace loguru - - Any file that include some.hpp: - void foo(MySmallType small, const MyBigType& big) - { - ERROR_CONTEXT("Small", small); // Copy ´small` by value. - ERROR_CONTEXT("Big", &big); // `big` should not change during this scope! - .... - } - */ -} // namespace loguru - -// -------------------------------------------------------------------- -// Logging macros - -// LOG_F(2, "Only logged if verbosity is 2 or higher: %d", some_number); -#define VLOG_F(verbosity, ...) \ - ((verbosity) > loguru::current_verbosity_cutoff()) ? (void)0 \ - : loguru::log(verbosity, __FILE__, __LINE__, __VA_ARGS__) - -// LOG_F(INFO, "Foo: %d", some_number); -#define LOG_F(verbosity_name, ...) VLOG_F(loguru::Verbosity_ ## verbosity_name, __VA_ARGS__) - -#define VLOG_IF_F(verbosity, cond, ...) \ - ((verbosity) > loguru::current_verbosity_cutoff() || (cond) == false) \ - ? (void)0 \ - : loguru::log(verbosity, __FILE__, __LINE__, __VA_ARGS__) - -#define LOG_IF_F(verbosity_name, cond, ...) \ - VLOG_IF_F(loguru::Verbosity_ ## verbosity_name, cond, __VA_ARGS__) - -#define VLOG_SCOPE_F(verbosity, ...) \ - loguru::LogScopeRAII LOGURU_ANONYMOUS_VARIABLE(error_context_RAII_) = \ - ((verbosity) > loguru::current_verbosity_cutoff()) ? loguru::LogScopeRAII() : \ - loguru::LogScopeRAII(verbosity, __FILE__, __LINE__, __VA_ARGS__) - -// Raw logging - no preamble, no indentation. Slightly faster than full logging. -#define RAW_VLOG_F(verbosity, ...) \ - ((verbosity) > loguru::current_verbosity_cutoff()) ? (void)0 \ - : loguru::raw_log(verbosity, __FILE__, __LINE__, __VA_ARGS__) - -#define RAW_LOG_F(verbosity_name, ...) RAW_VLOG_F(loguru::Verbosity_ ## verbosity_name, __VA_ARGS__) - -// Use to book-end a scope. Affects logging on all threads. -#define LOG_SCOPE_F(verbosity_name, ...) \ - VLOG_SCOPE_F(loguru::Verbosity_ ## verbosity_name, __VA_ARGS__) - -#define LOG_SCOPE_FUNCTION(verbosity_name) LOG_SCOPE_F(verbosity_name, __func__) - -// ----------------------------------------------- -// ABORT_F macro. Usage: ABORT_F("Cause of error: %s", error_str); - -// Message is optional -#define ABORT_F(...) loguru::log_and_abort(0, "ABORT: ", __FILE__, __LINE__, __VA_ARGS__) - -// -------------------------------------------------------------------- -// CHECK_F macros: - -#define CHECK_WITH_INFO_F(test, info, ...) \ - LOGURU_PREDICT_TRUE((test) == true) ? (void)0 : loguru::log_and_abort(0, "CHECK FAILED: " info " ", __FILE__, \ - __LINE__, ##__VA_ARGS__) - -/* Checked at runtime too. Will print error, then call fatal_handler (if any), then 'abort'. - Note that the test must be boolean. - CHECK_F(ptr); will not compile, but CHECK_F(ptr != nullptr); will. */ -#define CHECK_F(test, ...) CHECK_WITH_INFO_F(test, #test, ##__VA_ARGS__) - -#define CHECK_NOTNULL_F(x, ...) CHECK_WITH_INFO_F((x) != nullptr, #x " != nullptr", ##__VA_ARGS__) - -#define CHECK_OP_F(expr_left, expr_right, op, ...) \ - do \ - { \ - auto val_left = expr_left; \ - auto val_right = expr_right; \ - if (! LOGURU_PREDICT_TRUE(val_left op val_right)) \ - { \ - auto str_left = loguru::format_value(val_left); \ - auto str_right = loguru::format_value(val_right); \ - auto fail_info = loguru::textprintf("CHECK FAILED: %s %s %s (%s %s %s) ", \ - #expr_left, #op, #expr_right, str_left.c_str(), #op, str_right.c_str()); \ - auto user_msg = loguru::textprintf(__VA_ARGS__); \ - loguru::log_and_abort(0, fail_info.c_str(), __FILE__, __LINE__, \ - "%s", user_msg.c_str()); \ - } \ - } while (false) - -#ifndef LOGURU_DEBUG_LOGGING - #ifndef NDEBUG - #define LOGURU_DEBUG_LOGGING 1 - #else - #define LOGURU_DEBUG_LOGGING 0 - #endif -#endif - -#if LOGURU_DEBUG_LOGGING - // Debug logging enabled: - #define DLOG_F(verbosity_name, ...) LOG_F(verbosity_name, __VA_ARGS__) - #define DVLOG_F(verbosity, ...) VLOG_F(verbosity, __VA_ARGS__) - #define DLOG_IF_F(verbosity_name, ...) LOG_IF_F(verbosity_name, __VA_ARGS__) - #define DVLOG_IF_F(verbosity, ...) VLOG_IF_F(verbosity, __VA_ARGS__) - #define DRAW_LOG_F(verbosity_name, ...) RAW_LOG_F(verbosity_name, __VA_ARGS__) - #define DRAW_VLOG_F(verbosity, ...) RAW_VLOG_F(verbosity, __VA_ARGS__) -#else - // Debug logging disabled: - #define DLOG_F(verbosity_name, ...) - #define DVLOG_F(verbosity, ...) - #define DLOG_IF_F(verbosity_name, ...) - #define DVLOG_IF_F(verbosity, ...) - #define DRAW_LOG_F(verbosity_name, ...) - #define DRAW_VLOG_F(verbosity, ...) -#endif - -#define CHECK_EQ_F(a, b, ...) CHECK_OP_F(a, b, ==, ##__VA_ARGS__) -#define CHECK_NE_F(a, b, ...) CHECK_OP_F(a, b, !=, ##__VA_ARGS__) -#define CHECK_LT_F(a, b, ...) CHECK_OP_F(a, b, < , ##__VA_ARGS__) -#define CHECK_GT_F(a, b, ...) CHECK_OP_F(a, b, > , ##__VA_ARGS__) -#define CHECK_LE_F(a, b, ...) CHECK_OP_F(a, b, <=, ##__VA_ARGS__) -#define CHECK_GE_F(a, b, ...) CHECK_OP_F(a, b, >=, ##__VA_ARGS__) - -#ifndef LOGURU_DEBUG_CHECKS - #ifndef NDEBUG - #define LOGURU_DEBUG_CHECKS 1 - #else - #define LOGURU_DEBUG_CHECKS 0 - #endif -#endif - -#if LOGURU_DEBUG_CHECKS - // Debug checks enabled: - #define DCHECK_F(test, ...) CHECK_F(test, ##__VA_ARGS__) - #define DCHECK_NOTNULL_F(x, ...) CHECK_NOTNULL_F(x, ##__VA_ARGS__) - #define DCHECK_EQ_F(a, b, ...) CHECK_EQ_F(a, b, ##__VA_ARGS__) - #define DCHECK_NE_F(a, b, ...) CHECK_NE_F(a, b, ##__VA_ARGS__) - #define DCHECK_LT_F(a, b, ...) CHECK_LT_F(a, b, ##__VA_ARGS__) - #define DCHECK_LE_F(a, b, ...) CHECK_LE_F(a, b, ##__VA_ARGS__) - #define DCHECK_GT_F(a, b, ...) CHECK_GT_F(a, b, ##__VA_ARGS__) - #define DCHECK_GE_F(a, b, ...) CHECK_GE_F(a, b, ##__VA_ARGS__) -#else - // Debug checks disabled: - #define DCHECK_F(test, ...) - #define DCHECK_NOTNULL_F(x, ...) - #define DCHECK_EQ_F(a, b, ...) - #define DCHECK_NE_F(a, b, ...) - #define DCHECK_LT_F(a, b, ...) - #define DCHECK_LE_F(a, b, ...) - #define DCHECK_GT_F(a, b, ...) - #define DCHECK_GE_F(a, b, ...) -#endif // NDEBUG - - -#if LOGURU_REDEFINE_ASSERT - #undef assert - #ifndef NDEBUG - // Debug: - #define assert(test) CHECK_WITH_INFO_F(!!(test), #test) // HACK - #else - #define assert(test) - #endif -#endif // LOGURU_REDEFINE_ASSERT - -#endif // LOGURU_HAS_DECLARED_FORMAT_HEADER - -// ---------------------------------------------------------------------------- -// .dP"Y8 888888 88""Yb 888888 db 8b d8 .dP"Y8 -// `Ybo." 88 88__dP 88__ dPYb 88b d88 `Ybo." -// o.`Y8b 88 88"Yb 88"" dP__Yb 88YbdP88 o.`Y8b -// 8bodP' 88 88 Yb 888888 dP""""Yb 88 YY 88 8bodP' - -#if LOGURU_WITH_STREAMS -#ifndef LOGURU_HAS_DECLARED_STREAMS_HEADER -#define LOGURU_HAS_DECLARED_STREAMS_HEADER - -/* This file extends loguru to enable std::stream-style logging, a la Glog. - It's an optional feature behind the LOGURU_WITH_STREAMS settings - because including it everywhere will slow down compilation times. -*/ - -#include -#include // Adds about 38 kLoC on clang. -#include - -namespace loguru -{ - // Like sprintf, but returns the formated text. - LOGURU_EXPORT - std::string strprintf(LOGURU_FORMAT_STRING_TYPE format, ...) LOGURU_PRINTF_LIKE(1, 2); - - // Like vsprintf, but returns the formated text. - LOGURU_EXPORT - std::string vstrprintf(LOGURU_FORMAT_STRING_TYPE format, va_list) LOGURU_PRINTF_LIKE(1, 0); - - class LOGURU_EXPORT StreamLogger - { - public: - StreamLogger(Verbosity verbosity, const char* file, unsigned line) : _verbosity(verbosity), _file(file), _line(line) {} - ~StreamLogger() noexcept(false); - - template - StreamLogger& operator<<(const T& t) - { - _ss << t; - return *this; - } - - // std::endl and other iomanip:s. - StreamLogger& operator<<(std::ostream&(*f)(std::ostream&)) - { - f(_ss); - return *this; - } - - private: - Verbosity _verbosity; - const char* _file; - unsigned _line; - std::ostringstream _ss; - }; - - class LOGURU_EXPORT AbortLogger - { - public: - AbortLogger(const char* expr, const char* file, unsigned line) : _expr(expr), _file(file), _line(line) { } - LOGURU_NORETURN ~AbortLogger() noexcept(false); - - template - AbortLogger& operator<<(const T& t) - { - _ss << t; - return *this; - } - - // std::endl and other iomanip:s. - AbortLogger& operator<<(std::ostream&(*f)(std::ostream&)) - { - f(_ss); - return *this; - } - - private: - const char* _expr; - const char* _file; - unsigned _line; - std::ostringstream _ss; - }; - - class LOGURU_EXPORT Voidify - { - public: - Voidify() {} - // This has to be an operator with a precedence lower than << but higher than ?: - void operator&(const StreamLogger&) { } - void operator&(const AbortLogger&) { } - }; - - /* Helper functions for CHECK_OP_S macro. - GLOG trick: The (int, int) specialization works around the issue that the compiler - will not instantiate the template version of the function on values of unnamed enum type. */ - #define DEFINE_CHECK_OP_IMPL(name, op) \ - template \ - inline std::string* name(const char* expr, const T1& v1, const char* op_str, const T2& v2) \ - { \ - if (LOGURU_PREDICT_TRUE(v1 op v2)) { return NULL; } \ - std::ostringstream ss; \ - ss << "CHECK FAILED: " << expr << " (" << v1 << " " << op_str << " " << v2 << ") "; \ - return new std::string(ss.str()); \ - } \ - inline std::string* name(const char* expr, int v1, const char* op_str, int v2) \ - { \ - return name(expr, v1, op_str, v2); \ - } - - DEFINE_CHECK_OP_IMPL(check_EQ_impl, ==) - DEFINE_CHECK_OP_IMPL(check_NE_impl, !=) - DEFINE_CHECK_OP_IMPL(check_LE_impl, <=) - DEFINE_CHECK_OP_IMPL(check_LT_impl, < ) - DEFINE_CHECK_OP_IMPL(check_GE_impl, >=) - DEFINE_CHECK_OP_IMPL(check_GT_impl, > ) - #undef DEFINE_CHECK_OP_IMPL - - /* GLOG trick: Function is overloaded for integral types to allow static const integrals - declared in classes and not defined to be used as arguments to CHECK* macros. */ - template - inline const T& referenceable_value(const T& t) { return t; } - inline char referenceable_value(char t) { return t; } - inline unsigned char referenceable_value(unsigned char t) { return t; } - inline signed char referenceable_value(signed char t) { return t; } - inline short referenceable_value(short t) { return t; } - inline unsigned short referenceable_value(unsigned short t) { return t; } - inline int referenceable_value(int t) { return t; } - inline unsigned int referenceable_value(unsigned int t) { return t; } - inline long referenceable_value(long t) { return t; } - inline unsigned long referenceable_value(unsigned long t) { return t; } - inline long long referenceable_value(long long t) { return t; } - inline unsigned long long referenceable_value(unsigned long long t) { return t; } -} // namespace loguru - -// ----------------------------------------------- -// Logging macros: - -// usage: LOG_STREAM(INFO) << "Foo " << std::setprecision(10) << some_value; -#define VLOG_IF_S(verbosity, cond) \ - ((verbosity) > loguru::current_verbosity_cutoff() || (cond) == false) \ - ? (void)0 \ - : loguru::Voidify() & loguru::StreamLogger(verbosity, __FILE__, __LINE__) -#define LOG_IF_S(verbosity_name, cond) VLOG_IF_S(loguru::Verbosity_ ## verbosity_name, cond) -#define VLOG_S(verbosity) VLOG_IF_S(verbosity, true) -#define LOG_S(verbosity_name) VLOG_S(loguru::Verbosity_ ## verbosity_name) - -// ----------------------------------------------- -// ABORT_S macro. Usage: ABORT_S() << "Causo of error: " << details; - -#define ABORT_S() loguru::Voidify() & loguru::AbortLogger("ABORT: ", __FILE__, __LINE__) - -// ----------------------------------------------- -// CHECK_S macros: - -#define CHECK_WITH_INFO_S(cond, info) \ - LOGURU_PREDICT_TRUE((cond) == true) \ - ? (void)0 \ - : loguru::Voidify() & loguru::AbortLogger("CHECK FAILED: " info " ", __FILE__, __LINE__) - -#define CHECK_S(cond) CHECK_WITH_INFO_S(cond, #cond) -#define CHECK_NOTNULL_S(x) CHECK_WITH_INFO_S((x) != nullptr, #x " != nullptr") - -#define CHECK_OP_S(function_name, expr1, op, expr2) \ - while (auto error_string = loguru::function_name(#expr1 " " #op " " #expr2, \ - loguru::referenceable_value(expr1), #op, \ - loguru::referenceable_value(expr2))) \ - loguru::AbortLogger(error_string->c_str(), __FILE__, __LINE__) - -#define CHECK_EQ_S(expr1, expr2) CHECK_OP_S(check_EQ_impl, expr1, ==, expr2) -#define CHECK_NE_S(expr1, expr2) CHECK_OP_S(check_NE_impl, expr1, !=, expr2) -#define CHECK_LE_S(expr1, expr2) CHECK_OP_S(check_LE_impl, expr1, <=, expr2) -#define CHECK_LT_S(expr1, expr2) CHECK_OP_S(check_LT_impl, expr1, < , expr2) -#define CHECK_GE_S(expr1, expr2) CHECK_OP_S(check_GE_impl, expr1, >=, expr2) -#define CHECK_GT_S(expr1, expr2) CHECK_OP_S(check_GT_impl, expr1, > , expr2) - -#if LOGURU_DEBUG_LOGGING - // Debug logging enabled: - #define DVLOG_IF_S(verbosity, cond) VLOG_IF_S(verbosity, cond) - #define DLOG_IF_S(verbosity_name, cond) LOG_IF_S(verbosity_name, cond) - #define DVLOG_S(verbosity) VLOG_S(verbosity) - #define DLOG_S(verbosity_name) LOG_S(verbosity_name) -#else - // Debug logging disabled: - #define DVLOG_IF_S(verbosity, cond) \ - (true || (verbosity) > loguru::current_verbosity_cutoff() || (cond) == false) \ - ? (void)0 \ - : loguru::Voidify() & loguru::StreamLogger(verbosity, __FILE__, __LINE__) - - #define DLOG_IF_S(verbosity_name, cond) DVLOG_IF_S(loguru::Verbosity_ ## verbosity_name, cond) - #define DVLOG_S(verbosity) DVLOG_IF_S(verbosity, true) - #define DLOG_S(verbosity_name) DVLOG_S(loguru::Verbosity_ ## verbosity_name) -#endif - -#if LOGURU_DEBUG_CHECKS - // Debug checks enabled: - #define DCHECK_S(cond) CHECK_S(cond) - #define DCHECK_NOTNULL_S(x) CHECK_NOTNULL_S(x) - #define DCHECK_EQ_S(a, b) CHECK_EQ_S(a, b) - #define DCHECK_NE_S(a, b) CHECK_NE_S(a, b) - #define DCHECK_LT_S(a, b) CHECK_LT_S(a, b) - #define DCHECK_LE_S(a, b) CHECK_LE_S(a, b) - #define DCHECK_GT_S(a, b) CHECK_GT_S(a, b) - #define DCHECK_GE_S(a, b) CHECK_GE_S(a, b) -#else -// Debug checks disabled: - #define DCHECK_S(cond) CHECK_S(true || (cond)) - #define DCHECK_NOTNULL_S(x) CHECK_S(true || (x) != nullptr) - #define DCHECK_EQ_S(a, b) CHECK_S(true || (a) == (b)) - #define DCHECK_NE_S(a, b) CHECK_S(true || (a) != (b)) - #define DCHECK_LT_S(a, b) CHECK_S(true || (a) < (b)) - #define DCHECK_LE_S(a, b) CHECK_S(true || (a) <= (b)) - #define DCHECK_GT_S(a, b) CHECK_S(true || (a) > (b)) - #define DCHECK_GE_S(a, b) CHECK_S(true || (a) >= (b)) -#endif - -#if LOGURU_REPLACE_GLOG - #undef LOG - #undef VLOG - #undef LOG_IF - #undef VLOG_IF - #undef CHECK - #undef CHECK_NOTNULL - #undef CHECK_EQ - #undef CHECK_NE - #undef CHECK_LT - #undef CHECK_LE - #undef CHECK_GT - #undef CHECK_GE - #undef DLOG - #undef DVLOG - #undef DLOG_IF - #undef DVLOG_IF - #undef DCHECK - #undef DCHECK_NOTNULL - #undef DCHECK_EQ - #undef DCHECK_NE - #undef DCHECK_LT - #undef DCHECK_LE - #undef DCHECK_GT - #undef DCHECK_GE - #undef VLOG_IS_ON - - #define LOG LOG_S - #define VLOG VLOG_S - #define LOG_IF LOG_IF_S - #define VLOG_IF VLOG_IF_S - #define CHECK(cond) CHECK_S(!!(cond)) - #define CHECK_NOTNULL CHECK_NOTNULL_S - #define CHECK_EQ CHECK_EQ_S - #define CHECK_NE CHECK_NE_S - #define CHECK_LT CHECK_LT_S - #define CHECK_LE CHECK_LE_S - #define CHECK_GT CHECK_GT_S - #define CHECK_GE CHECK_GE_S - #define DLOG DLOG_S - #define DVLOG DVLOG_S - #define DLOG_IF DLOG_IF_S - #define DVLOG_IF DVLOG_IF_S - #define DCHECK DCHECK_S - #define DCHECK_NOTNULL DCHECK_NOTNULL_S - #define DCHECK_EQ DCHECK_EQ_S - #define DCHECK_NE DCHECK_NE_S - #define DCHECK_LT DCHECK_LT_S - #define DCHECK_LE DCHECK_LE_S - #define DCHECK_GT DCHECK_GT_S - #define DCHECK_GE DCHECK_GE_S - #define VLOG_IS_ON(verbosity) ((verbosity) <= loguru::current_verbosity_cutoff()) - -#endif // LOGURU_REPLACE_GLOG - -#endif // LOGURU_WITH_STREAMS - -#endif // LOGURU_HAS_DECLARED_STREAMS_HEADER \ No newline at end of file diff --git a/libloguru/meson.build b/libloguru/meson.build deleted file mode 100644 index 6c01d58..0000000 --- a/libloguru/meson.build +++ /dev/null @@ -1,20 +0,0 @@ -loguru_inc = [ - include_directories('inc'), -] - -loguru_src = [ - files('src/loguru.cpp'), -] - -loguru_deps = [ - dependency('threads'), - meson.get_compiler('cpp').find_library('dl', required : true), -] - -libloguru = static_library( - 'libloguru', - loguru_src, - dependencies: loguru_deps, - include_directories: loguru_inc, - install:false -) \ No newline at end of file diff --git a/libloguru/src/loguru.cpp b/libloguru/src/loguru.cpp deleted file mode 100644 index 0042789..0000000 --- a/libloguru/src/loguru.cpp +++ /dev/null @@ -1,1795 +0,0 @@ -#ifndef _WIN32 -// Disable all warnings from gcc/clang: -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpragmas" - -#pragma GCC diagnostic ignored "-Wc++98-compat" -#pragma GCC diagnostic ignored "-Wc++98-compat-pedantic" -#pragma GCC diagnostic ignored "-Wexit-time-destructors" -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#pragma GCC diagnostic ignored "-Wglobal-constructors" -#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" -#pragma GCC diagnostic ignored "-Wmissing-prototypes" -#pragma GCC diagnostic ignored "-Wpadded" -#pragma GCC diagnostic ignored "-Wsign-compare" -#pragma GCC diagnostic ignored "-Wsign-conversion" -#pragma GCC diagnostic ignored "-Wunknown-pragmas" -#pragma GCC diagnostic ignored "-Wunused-macros" -#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" -#endif - -#include - -#ifndef LOGURU_HAS_BEEN_IMPLEMENTED -#define LOGURU_HAS_BEEN_IMPLEMENTED - -#define LOGURU_PREAMBLE_WIDTH (53 + LOGURU_THREADNAME_WIDTH + LOGURU_FILENAME_WIDTH) - -#undef min -#undef max - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 - #include - - #define localtime_r(a, b) localtime_s(b, a) // No localtime_r with MSVC, but arguments are swapped for localtime_s -#else - #include - #include // mkdir - #include // STDERR_FILENO -#endif - -#ifdef __linux__ - #include // PATH_MAX -#elif !defined(_WIN32) - #include // PATH_MAX -#endif - -#ifndef PATH_MAX - #define PATH_MAX 1024 -#endif - -#ifdef __APPLE__ - #include "TargetConditionals.h" -#endif - -// TODO: use defined(_POSIX_VERSION) for some of these things? - -#if defined(_WIN32) || defined(__CYGWIN__) - #define LOGURU_PTHREADS 0 - #define LOGURU_WINTHREADS 1 - #ifndef LOGURU_STACKTRACES - #define LOGURU_STACKTRACES 0 - #endif -#elif defined(__rtems__) || defined(__ANDROID__) - #define LOGURU_PTHREADS 1 - #define LOGURU_WINTHREADS 0 - #ifndef LOGURU_STACKTRACES - #define LOGURU_STACKTRACES 0 - #endif -#else - #define LOGURU_PTHREADS 1 - #define LOGURU_WINTHREADS 0 - #ifndef LOGURU_STACKTRACES - #define LOGURU_STACKTRACES 1 - #endif -#endif - -#if LOGURU_STACKTRACES - #include // for __cxa_demangle - #include // for dladdr - #include // for backtrace -#endif // LOGURU_STACKTRACES - -#if LOGURU_PTHREADS - #include - #if defined(__FreeBSD__) - #include - #include - #elif defined(__OpenBSD__) - #include - #endif - - #ifdef __linux__ - /* On Linux, the default thread name is the same as the name of the binary. - Additionally, all new threads inherit the name of the thread it got forked from. - For this reason, Loguru use the pthread Thread Local Storage - for storing thread names on Linux. */ - #define LOGURU_PTLS_NAMES 1 - #endif -#endif - -#if LOGURU_WINTHREADS - #ifndef _WIN32_WINNT - #define _WIN32_WINNT 0x0502 - #endif - #define WIN32_LEAN_AND_MEAN - #define NOMINMAX - #include -#endif - -#ifndef LOGURU_PTLS_NAMES - #define LOGURU_PTLS_NAMES 0 -#endif - -namespace loguru -{ - using namespace std::chrono; - -#if LOGURU_WITH_FILEABS - struct FileAbs - { - char path[PATH_MAX]; - char mode_str[4]; - Verbosity verbosity; - struct stat st; - FILE* fp; - bool is_reopening = false; // to prevent recursive call in file_reopen. - decltype(steady_clock::now()) last_check_time = steady_clock::now(); - }; -#else - typedef FILE* FileAbs; -#endif - - struct Callback - { - std::string id; - log_handler_t callback; - void* user_data; - Verbosity verbosity; // Does not change! - close_handler_t close; - flush_handler_t flush; - unsigned indentation; - }; - - using CallbackVec = std::vector; - - using StringPair = std::pair; - using StringPairList = std::vector; - - const auto s_start_time = steady_clock::now(); - - Verbosity g_stderr_verbosity = Verbosity_0; - bool g_colorlogtostderr = true; - unsigned g_flush_interval_ms = 0; - bool g_preamble = true; - - Verbosity g_internal_verbosity = Verbosity_0; - - // Preamble details - bool g_preamble_date = true; - bool g_preamble_time = true; - bool g_preamble_uptime = true; - bool g_preamble_thread = true; - bool g_preamble_file = true; - bool g_preamble_verbose = true; - bool g_preamble_pipe = true; - - static std::recursive_mutex s_mutex; - static Verbosity s_max_out_verbosity = Verbosity_OFF; - static std::string s_argv0_filename; - static std::string s_arguments; - static char s_current_dir[PATH_MAX]; - static CallbackVec s_callbacks; - static fatal_handler_t s_fatal_handler = nullptr; - static verbosity_to_name_t s_verbosity_to_name_callback = nullptr; - static name_to_verbosity_t s_name_to_verbosity_callback = nullptr; - static StringPairList s_user_stack_cleanups; - static bool s_strip_file_path = true; - static std::atomic s_stderr_indentation { 0 }; - - // For periodic flushing: - static std::thread* s_flush_thread = nullptr; - static bool s_needs_flushing = false; - - static const bool s_terminal_has_color = [](){ - #ifdef _WIN32 - #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING - #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 - #endif - - HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); - if (hOut != INVALID_HANDLE_VALUE) { - DWORD dwMode = 0; - GetConsoleMode(hOut, &dwMode); - dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; - return SetConsoleMode(hOut, dwMode) != 0; - } - return false; - #else - if (const char* term = getenv("TERM")) { - return 0 == strcmp(term, "cygwin") - || 0 == strcmp(term, "linux") - || 0 == strcmp(term, "rxvt-unicode-256color") - || 0 == strcmp(term, "screen") - || 0 == strcmp(term, "screen-256color") - || 0 == strcmp(term, "screen.xterm-256color") - || 0 == strcmp(term, "tmux-256color") - || 0 == strcmp(term, "xterm") - || 0 == strcmp(term, "xterm-256color") - || 0 == strcmp(term, "xterm-termite") - || 0 == strcmp(term, "xterm-color"); - } else { - return false; - } - #endif - }(); - - static void print_preamble_header(char* out_buff, size_t out_buff_size); - - #if LOGURU_PTLS_NAMES - static pthread_once_t s_pthread_key_once = PTHREAD_ONCE_INIT; - static pthread_key_t s_pthread_key_name; - - void make_pthread_key_name() - { - (void)pthread_key_create(&s_pthread_key_name, free); - } - #endif - - // ------------------------------------------------------------------------------ - // Colors - - bool terminal_has_color() { return s_terminal_has_color; } - - // Colors - -#ifdef _WIN32 -#define VTSEQ(ID) ("\x1b[1;" #ID "m") -#else -#define VTSEQ(ID) ("\x1b[" #ID "m") -#endif - - const char* terminal_black() { return s_terminal_has_color ? VTSEQ(30) : ""; } - const char* terminal_red() { return s_terminal_has_color ? VTSEQ(31) : ""; } - const char* terminal_green() { return s_terminal_has_color ? VTSEQ(32) : ""; } - const char* terminal_yellow() { return s_terminal_has_color ? VTSEQ(33) : ""; } - const char* terminal_blue() { return s_terminal_has_color ? VTSEQ(34) : ""; } - const char* terminal_purple() { return s_terminal_has_color ? VTSEQ(35) : ""; } - const char* terminal_cyan() { return s_terminal_has_color ? VTSEQ(36) : ""; } - const char* terminal_light_gray() { return s_terminal_has_color ? VTSEQ(37) : ""; } - const char* terminal_white() { return s_terminal_has_color ? VTSEQ(37) : ""; } - const char* terminal_light_red() { return s_terminal_has_color ? VTSEQ(91) : ""; } - const char* terminal_dim() { return s_terminal_has_color ? VTSEQ(2) : ""; } - - // Formating - const char* terminal_bold() { return s_terminal_has_color ? VTSEQ(1) : ""; } - const char* terminal_underline() { return s_terminal_has_color ? VTSEQ(4) : ""; } - - // You should end each line with this! - const char* terminal_reset() { return s_terminal_has_color ? VTSEQ(0) : ""; } - - // ------------------------------------------------------------------------------ -#if LOGURU_WITH_FILEABS - void file_reopen(void* user_data); - inline FILE* to_file(void* user_data) { return reinterpret_cast(user_data)->fp; } -#else - inline FILE* to_file(void* user_data) { return reinterpret_cast(user_data); } -#endif - - void file_log(void* user_data, const Message& message) - { -#if LOGURU_WITH_FILEABS - FileAbs* file_abs = reinterpret_cast(user_data); - if (file_abs->is_reopening) { - return; - } - // It is better checking file change every minute/hour/day, - // instead of doing this every time we log. - // Here check_interval is set to zero to enable checking every time; - const auto check_interval = seconds(0); - if (duration_cast(steady_clock::now() - file_abs->last_check_time) > check_interval) { - file_abs->last_check_time = steady_clock::now(); - file_reopen(user_data); - } - FILE* file = to_file(user_data); - if (!file) { - return; - } -#else - FILE* file = to_file(user_data); -#endif - fprintf(file, "%s%s%s%s\n", - message.preamble, message.indentation, message.prefix, message.message); - if (g_flush_interval_ms == 0) { - fflush(file); - } - } - - void file_close(void* user_data) - { - FILE* file = to_file(user_data); - if (file) { - fclose(file); - } -#if LOGURU_WITH_FILEABS - delete reinterpret_cast(user_data); -#endif - } - - void file_flush(void* user_data) - { - FILE* file = to_file(user_data); - fflush(file); - } - -#if LOGURU_WITH_FILEABS - void file_reopen(void* user_data) - { - FileAbs * file_abs = reinterpret_cast(user_data); - struct stat st; - int ret; - if (!file_abs->fp || (ret = stat(file_abs->path, &st)) == -1 || (st.st_ino != file_abs->st.st_ino)) { - file_abs->is_reopening = true; - if (file_abs->fp) { - fclose(file_abs->fp); - } - if (!file_abs->fp) { - VLOG_F(g_internal_verbosity, "Reopening file '%s' due to previous error", file_abs->path); - } - else if (ret < 0) { - const auto why = errno_as_text(); - VLOG_F(g_internal_verbosity, "Reopening file '%s' due to '%s'", file_abs->path, why.c_str()); - } else { - VLOG_F(g_internal_verbosity, "Reopening file '%s' due to file changed", file_abs->path); - } - // try reopen current file. - if (!create_directories(file_abs->path)) { - LOG_F(ERROR, "Failed to create directories to '%s'", file_abs->path); - } - file_abs->fp = fopen(file_abs->path, file_abs->mode_str); - if (!file_abs->fp) { - LOG_F(ERROR, "Failed to open '%s'", file_abs->path); - } else { - stat(file_abs->path, &file_abs->st); - } - file_abs->is_reopening = false; - } - } -#endif - // ------------------------------------------------------------------------------ - - // Helpers: - - Text::~Text() { free(_str); } - - LOGURU_PRINTF_LIKE(1, 0) - static Text vtextprintf(const char* format, va_list vlist) - { -#ifdef _WIN32 - int bytes_needed = _vscprintf(format, vlist); - CHECK_F(bytes_needed >= 0, "Bad string format: '%s'", format); - char* buff = (char*)malloc(bytes_needed+1); - vsnprintf(buff, bytes_needed+1, format, vlist); - return Text(buff); -#else - char* buff = nullptr; - int result = vasprintf(&buff, format, vlist); - CHECK_F(result >= 0, "Bad string format: '%s'", format); - return Text(buff); -#endif - } - - Text textprintf(const char* format, ...) - { - va_list vlist; - va_start(vlist, format); - auto result = vtextprintf(format, vlist); - va_end(vlist); - return result; - } - - // Overloaded for variadic template matching. - Text textprintf() - { - return Text(static_cast(calloc(1, 1))); - } - - static const char* indentation(unsigned depth) - { - static const char buff[] = - ". . . . . . . . . . " ". . . . . . . . . . " - ". . . . . . . . . . " ". . . . . . . . . . " - ". . . . . . . . . . " ". . . . . . . . . . " - ". . . . . . . . . . " ". . . . . . . . . . " - ". . . . . . . . . . " ". . . . . . . . . . "; - static const size_t INDENTATION_WIDTH = 4; - static const size_t NUM_INDENTATIONS = (sizeof(buff) - 1) / INDENTATION_WIDTH; - depth = std::min(depth, NUM_INDENTATIONS); - return buff + INDENTATION_WIDTH * (NUM_INDENTATIONS - depth); - } - - static void parse_args(int& argc, char* argv[], const char* verbosity_flag) - { - int arg_dest = 1; - int out_argc = argc; - - for (int arg_it = 1; arg_it < argc; ++arg_it) { - auto cmd = argv[arg_it]; - auto arg_len = strlen(verbosity_flag); - if (strncmp(cmd, verbosity_flag, arg_len) == 0 && !std::isalpha(cmd[arg_len], std::locale(""))) { - out_argc -= 1; - auto value_str = cmd + arg_len; - if (value_str[0] == '\0') { - // Value in separate argument - arg_it += 1; - CHECK_LT_F(arg_it, argc, "Missing verbosiy level after %s", verbosity_flag); - value_str = argv[arg_it]; - out_argc -= 1; - } - if (*value_str == '=') { value_str += 1; } - - auto req_verbosity = get_verbosity_from_name(value_str); - if (req_verbosity != Verbosity_INVALID) { - g_stderr_verbosity = req_verbosity; - } else { - char* end = 0; - g_stderr_verbosity = static_cast(strtol(value_str, &end, 10)); - CHECK_F(end && *end == '\0', - "Invalid verbosity. Expected integer, INFO, WARNING, ERROR or OFF, got '%s'", value_str); - } - } else { - argv[arg_dest++] = argv[arg_it]; - } - } - - argc = out_argc; - argv[argc] = nullptr; - } - - static long long now_ns() - { - return duration_cast(high_resolution_clock::now().time_since_epoch()).count(); - } - - // Returns the part of the path after the last / or \ (if any). - const char* filename(const char* path) - { - for (auto ptr = path; *ptr; ++ptr) { - if (*ptr == '/' || *ptr == '\\') { - path = ptr + 1; - } - } - return path; - } - - // ------------------------------------------------------------------------------ - - static void on_atexit() - { - VLOG_F(g_internal_verbosity, "atexit"); - flush(); - } - - static void install_signal_handlers(); - - static void write_hex_digit(std::string& out, unsigned num) - { - DCHECK_LT_F(num, 16u); - if (num < 10u) { out.push_back(char('0' + num)); } - else { out.push_back(char('A' + num - 10)); } - } - - static void write_hex_byte(std::string& out, uint8_t n) - { - write_hex_digit(out, n >> 4u); - write_hex_digit(out, n & 0x0f); - } - - static void escape(std::string& out, const std::string& str) - { - for (char c : str) { - /**/ if (c == '\a') { out += "\\a"; } - else if (c == '\b') { out += "\\b"; } - else if (c == '\f') { out += "\\f"; } - else if (c == '\n') { out += "\\n"; } - else if (c == '\r') { out += "\\r"; } - else if (c == '\t') { out += "\\t"; } - else if (c == '\v') { out += "\\v"; } - else if (c == '\\') { out += "\\\\"; } - else if (c == '\'') { out += "\\\'"; } - else if (c == '\"') { out += "\\\""; } - else if (c == ' ') { out += "\\ "; } - else if (0 <= c && c < 0x20) { // ASCI control character: - // else if (c < 0x20 || c != (c & 127)) { // ASCII control character or UTF-8: - out += "\\x"; - write_hex_byte(out, static_cast(c)); - } else { out += c; } - } - } - - Text errno_as_text() - { - char buff[256]; - #if defined(__GLIBC__) && defined(_GNU_SOURCE) - // GNU Version - return Text(STRDUP(strerror_r(errno, buff, sizeof(buff)))); - #elif defined(__APPLE__) || _POSIX_C_SOURCE >= 200112L - // XSI Version - strerror_r(errno, buff, sizeof(buff)); - return Text(strdup(buff)); - #elif defined(_WIN32) - strerror_s(buff, sizeof(buff), errno); - return Text(STRDUP(buff)); - #else - // Not thread-safe. - return Text(STRDUP(strerror(errno))); - #endif - } - - void init(int& argc, char* argv[], const char* verbosity_flag) - { - CHECK_GT_F(argc, 0, "Expected proper argc/argv"); - CHECK_EQ_F(argv[argc], nullptr, "Expected proper argc/argv"); - - s_argv0_filename = filename(argv[0]); - - #ifdef _WIN32 - #define getcwd _getcwd - #endif - - if (!getcwd(s_current_dir, sizeof(s_current_dir))) - { - const auto error_text = errno_as_text(); - LOG_F(WARNING, "Failed to get current working directory: %s", error_text.c_str()); - } - - s_arguments = ""; - for (int i = 0; i < argc; ++i) { - escape(s_arguments, argv[i]); - if (i + 1 < argc) { - s_arguments += " "; - } - } - - if (verbosity_flag) { - parse_args(argc, argv, verbosity_flag); - } - - #if LOGURU_PTLS_NAMES || LOGURU_WINTHREADS - set_thread_name("main thread"); - #elif LOGURU_PTHREADS - char old_thread_name[16] = {0}; - auto this_thread = pthread_self(); - #if defined(__APPLE__) || defined(__linux__) - pthread_getname_np(this_thread, old_thread_name, sizeof(old_thread_name)); - #endif - if (old_thread_name[0] == 0) { - #ifdef __APPLE__ - pthread_setname_np("main thread"); - #elif defined(__FreeBSD__) || defined(__OpenBSD__) - pthread_set_name_np(this_thread, "main thread"); - #elif defined(__linux__) - pthread_setname_np(this_thread, "main thread"); - #endif - } - #endif // LOGURU_PTHREADS - - if (g_stderr_verbosity >= Verbosity_INFO) { - if (g_preamble) { - char preamble_explain[LOGURU_PREAMBLE_WIDTH]; - print_preamble_header(preamble_explain, sizeof(preamble_explain)); - if (g_colorlogtostderr && s_terminal_has_color) { - fprintf(stderr, "%s%s%s\n", terminal_reset(), terminal_dim(), preamble_explain); - } else { - fprintf(stderr, "%s\n", preamble_explain); - } - } - fflush(stderr); - } - VLOG_F(g_internal_verbosity, "arguments: %s", s_arguments.c_str()); - if (strlen(s_current_dir) != 0) - { - VLOG_F(g_internal_verbosity, "Current dir: %s", s_current_dir); - } - VLOG_F(g_internal_verbosity, "stderr verbosity: %d", g_stderr_verbosity); - VLOG_F(g_internal_verbosity, "-----------------------------------"); - - install_signal_handlers(); - - atexit(on_atexit); - } - - void shutdown() - { - VLOG_F(g_internal_verbosity, "loguru::shutdown()"); - remove_all_callbacks(); - set_fatal_handler(nullptr); - set_verbosity_to_name_callback(nullptr); - set_name_to_verbosity_callback(nullptr); - } - - void write_date_time(char* buff, size_t buff_size) - { - auto now = system_clock::now(); - long long ms_since_epoch = duration_cast(now.time_since_epoch()).count(); - time_t sec_since_epoch = time_t(ms_since_epoch / 1000); - tm time_info; - localtime_r(&sec_since_epoch, &time_info); - snprintf(buff, buff_size, "%04d%02d%02d_%02d%02d%02d.%03lld", - 1900 + time_info.tm_year, 1 + time_info.tm_mon, time_info.tm_mday, - time_info.tm_hour, time_info.tm_min, time_info.tm_sec, ms_since_epoch % 1000); - } - - const char* argv0_filename() - { - return s_argv0_filename.c_str(); - } - - const char* arguments() - { - return s_arguments.c_str(); - } - - const char* current_dir() - { - return s_current_dir; - } - - const char* home_dir() - { - #ifdef _WIN32 - auto user_profile = getenv("USERPROFILE"); - CHECK_F(user_profile != nullptr, "Missing USERPROFILE"); - return user_profile; - #else // _WIN32 - auto home = getenv("HOME"); - CHECK_F(home != nullptr, "Missing HOME"); - return home; - #endif // _WIN32 - } - - void suggest_log_path(const char* prefix, char* buff, unsigned buff_size) - { - if (prefix[0] == '~') { - snprintf(buff, buff_size - 1, "%s%s", home_dir(), prefix + 1); - } else { - snprintf(buff, buff_size - 1, "%s", prefix); - } - - // Check for terminating / - size_t n = strlen(buff); - if (n != 0) { - if (buff[n - 1] != '/') { - CHECK_F(n + 2 < buff_size, "Filename buffer too small"); - buff[n] = '/'; - buff[n + 1] = '\0'; - } - } - - strncat(buff, s_argv0_filename.c_str(), buff_size - strlen(buff) - 1); - strncat(buff, "/", buff_size - strlen(buff) - 1); - write_date_time(buff + strlen(buff), buff_size - strlen(buff)); - strncat(buff, ".log", buff_size - strlen(buff) - 1); - } - - bool create_directories(const char* file_path_const) - { - CHECK_F(file_path_const && *file_path_const); - char* file_path = STRDUP(file_path_const); - for (char* p = strchr(file_path + 1, '/'); p; p = strchr(p + 1, '/')) { - *p = '\0'; - - #ifdef _WIN32 - if (_mkdir(file_path) == -1) { - #else - if (mkdir(file_path, 0755) == -1) { - #endif - if (errno != EEXIST) { - LOG_F(ERROR, "Failed to create directory '%s'", file_path); - LOG_IF_F(ERROR, errno == EACCES, "EACCES"); - LOG_IF_F(ERROR, errno == ENAMETOOLONG, "ENAMETOOLONG"); - LOG_IF_F(ERROR, errno == ENOENT, "ENOENT"); - LOG_IF_F(ERROR, errno == ENOTDIR, "ENOTDIR"); - LOG_IF_F(ERROR, errno == ELOOP, "ELOOP"); - - *p = '/'; - free(file_path); - return false; - } - } - *p = '/'; - } - free(file_path); - return true; - } - bool add_file(const char* path_in, FileMode mode, Verbosity verbosity) - { - char path[PATH_MAX]; - if (path_in[0] == '~') { - snprintf(path, sizeof(path) - 1, "%s%s", home_dir(), path_in + 1); - } else { - snprintf(path, sizeof(path) - 1, "%s", path_in); - } - - if (!create_directories(path)) { - LOG_F(ERROR, "Failed to create directories to '%s'", path); - } - - const char* mode_str = (mode == FileMode::Truncate ? "w" : "a"); - auto file = fopen(path, mode_str); - if (!file) { - LOG_F(ERROR, "Failed to open '%s'", path); - return false; - } -#if LOGURU_WITH_FILEABS - FileAbs* file_abs = new FileAbs(); // this is deleted in file_close; - snprintf(file_abs->path, sizeof(file_abs->path) - 1, "%s", path); - snprintf(file_abs->mode_str, sizeof(file_abs->mode_str) - 1, "%s", mode_str); - stat(file_abs->path, &file_abs->st); - file_abs->fp = file; - file_abs->verbosity = verbosity; - add_callback(path_in, file_log, file_abs, verbosity, file_close, file_flush); -#else - add_callback(path_in, file_log, file, verbosity, file_close, file_flush); -#endif - - if (mode == FileMode::Append) { - fprintf(file, "\n\n\n\n\n"); - } - if (!s_arguments.empty()) { - fprintf(file, "arguments: %s\n", s_arguments.c_str()); - } - if (strlen(s_current_dir) != 0) { - fprintf(file, "Current dir: %s\n", s_current_dir); - } - fprintf(file, "File verbosity level: %d\n", verbosity); - if (g_preamble) { - char preamble_explain[LOGURU_PREAMBLE_WIDTH]; - print_preamble_header(preamble_explain, sizeof(preamble_explain)); - fprintf(file, "%s\n", preamble_explain); - } - fflush(file); - - VLOG_F(g_internal_verbosity, "Logging to '%s', mode: '%s', verbosity: %d", path, mode_str, verbosity); - return true; - } - - // Will be called right before abort(). - void set_fatal_handler(fatal_handler_t handler) - { - s_fatal_handler = handler; - } - - fatal_handler_t get_fatal_handler() - { - return s_fatal_handler; - } - - void set_verbosity_to_name_callback(verbosity_to_name_t callback) - { - s_verbosity_to_name_callback = callback; - } - - void set_name_to_verbosity_callback(name_to_verbosity_t callback) - { - s_name_to_verbosity_callback = callback; - } - - void add_stack_cleanup(const char* find_this, const char* replace_with_this) - { - if (strlen(find_this) <= strlen(replace_with_this)) { - LOG_F(WARNING, "add_stack_cleanup: the replacement should be shorter than the pattern!"); - return; - } - - s_user_stack_cleanups.push_back(StringPair(find_this, replace_with_this)); - } - - static void on_callback_change() - { - s_max_out_verbosity = Verbosity_OFF; - for (const auto& callback : s_callbacks) { - s_max_out_verbosity = std::max(s_max_out_verbosity, callback.verbosity); - } - } - - void add_callback( - const char* id, - log_handler_t callback, - void* user_data, - Verbosity verbosity, - close_handler_t on_close, - flush_handler_t on_flush) - { - std::lock_guard lock(s_mutex); - s_callbacks.push_back(Callback{id, callback, user_data, verbosity, on_close, on_flush, 0}); - on_callback_change(); - } - - // Returns a custom verbosity name if one is available, or nullptr. - // See also set_verbosity_to_name_callback. - const char* get_verbosity_name(Verbosity verbosity) - { - auto name = s_verbosity_to_name_callback - ? (*s_verbosity_to_name_callback)(verbosity) - : nullptr; - - // Use standard replacements if callback fails: - if (!name) - { - if (verbosity <= Verbosity_FATAL) { - name = "FATL"; - } else if (verbosity == Verbosity_ERROR) { - name = "ERR"; - } else if (verbosity == Verbosity_WARNING) { - name = "WARN"; - } else if (verbosity == Verbosity_INFO) { - name = "INFO"; - } - } - - return name; - } - - // Returns Verbosity_INVALID if the name is not found. - // See also set_name_to_verbosity_callback. - Verbosity get_verbosity_from_name(const char* name) - { - auto verbosity = s_name_to_verbosity_callback - ? (*s_name_to_verbosity_callback)(name) - : Verbosity_INVALID; - - // Use standard replacements if callback fails: - if (verbosity == Verbosity_INVALID) { - if (strcmp(name, "OFF") == 0) { - verbosity = Verbosity_OFF; - } else if (strcmp(name, "INFO") == 0) { - verbosity = Verbosity_INFO; - } else if (strcmp(name, "WARNING") == 0) { - verbosity = Verbosity_WARNING; - } else if (strcmp(name, "ERROR") == 0) { - verbosity = Verbosity_ERROR; - } else if (strcmp(name, "FATAL") == 0) { - verbosity = Verbosity_FATAL; - } - } - - return verbosity; - } - - bool remove_callback(const char* id) - { - std::lock_guard lock(s_mutex); - auto it = std::find_if(begin(s_callbacks), end(s_callbacks), [&](const Callback& c) { return c.id == id; }); - if (it != s_callbacks.end()) { - if (it->close) { it->close(it->user_data); } - s_callbacks.erase(it); - on_callback_change(); - return true; - } else { - LOG_F(ERROR, "Failed to locate callback with id '%s'", id); - return false; - } - } - - void remove_all_callbacks() - { - std::lock_guard lock(s_mutex); - for (auto& callback : s_callbacks) { - if (callback.close) { - callback.close(callback.user_data); - } - } - s_callbacks.clear(); - on_callback_change(); - } - - // Returns the maximum of g_stderr_verbosity and all file/custom outputs. - Verbosity current_verbosity_cutoff() - { - return g_stderr_verbosity > s_max_out_verbosity ? - g_stderr_verbosity : s_max_out_verbosity; - } - -#if LOGURU_WINTHREADS - char* get_thread_name_win32() - { - __declspec( thread ) static char thread_name[LOGURU_THREADNAME_WIDTH + 1] = {0}; - return &thread_name[0]; - } -#endif // LOGURU_WINTHREADS - - void set_thread_name(const char* name) - { - #if LOGURU_PTLS_NAMES - (void)pthread_once(&s_pthread_key_once, make_pthread_key_name); - (void)pthread_setspecific(s_pthread_key_name, STRDUP(name)); - - #elif LOGURU_PTHREADS - #ifdef __APPLE__ - pthread_setname_np(name); - #elif defined(__FreeBSD__) || defined(__OpenBSD__) - pthread_set_name_np(pthread_self(), name); - #elif defined(__linux__) - pthread_setname_np(pthread_self(), name); - #endif - #elif LOGURU_WINTHREADS - strncpy_s(get_thread_name_win32(), LOGURU_THREADNAME_WIDTH + 1, name, _TRUNCATE); - #else // LOGURU_PTHREADS - (void)name; - #endif // LOGURU_PTHREADS - } - -#if LOGURU_PTLS_NAMES - const char* get_thread_name_ptls() - { - (void)pthread_once(&s_pthread_key_once, make_pthread_key_name); - return static_cast(pthread_getspecific(s_pthread_key_name)); - } -#endif // LOGURU_PTLS_NAMES - - void get_thread_name(char* buffer, unsigned long long length, bool right_align_hext_id) - { -#ifdef _WIN32 - (void)right_align_hext_id; -#endif - CHECK_NE_F(length, 0u, "Zero length buffer in get_thread_name"); - CHECK_NOTNULL_F(buffer, "nullptr in get_thread_name"); -#if LOGURU_PTHREADS - auto thread = pthread_self(); - #if LOGURU_PTLS_NAMES - if (const char* name = get_thread_name_ptls()) { - snprintf(buffer, length, "%s", name); - } else { - buffer[0] = 0; - } - #elif defined(__APPLE__) || defined(__linux__) - pthread_getname_np(thread, buffer, length); - #else - buffer[0] = 0; - #endif - - if (buffer[0] == 0) { - #ifdef __APPLE__ - uint64_t thread_id; - pthread_threadid_np(thread, &thread_id); - #elif defined(__FreeBSD__) - long thread_id; - (void)thr_self(&thread_id); - #elif defined(__OpenBSD__) - unsigned thread_id = -1; - #else - uint64_t thread_id = thread; - #endif - if (right_align_hext_id) { - snprintf(buffer, length, "%*X", static_cast(length - 1), static_cast(thread_id)); - } else { - snprintf(buffer, length, "%X", static_cast(thread_id)); - } - } -#elif LOGURU_WINTHREADS - if (const char* name = get_thread_name_win32()) { - snprintf(buffer, (size_t)length, "%s", name); - } else { - buffer[0] = 0; - } -#else // !LOGURU_WINTHREADS && !LOGURU_WINTHREADS - buffer[0] = 0; -#endif - - } - - // ------------------------------------------------------------------------ - // Stack traces - -#if LOGURU_STACKTRACES - Text demangle(const char* name) - { - int status = -1; - char* demangled = abi::__cxa_demangle(name, 0, 0, &status); - Text result{status == 0 ? demangled : STRDUP(name)}; - return result; - } - - #if LOGURU_RTTI - template - std::string type_name() - { - auto demangled = demangle(typeid(T).name()); - return demangled.c_str(); - } - #endif // LOGURU_RTTI - - static const StringPairList REPLACE_LIST = { - #if LOGURU_RTTI - { type_name(), "std::string" }, - { type_name(), "std::wstring" }, - { type_name(), "std::u16string" }, - { type_name(), "std::u32string" }, - #endif // LOGURU_RTTI - { "std::__1::", "std::" }, - { "__thiscall ", "" }, - { "__cdecl ", "" }, - }; - - void do_replacements(const StringPairList& replacements, std::string& str) - { - for (auto&& p : replacements) { - if (p.first.size() <= p.second.size()) { - // On gcc, "type_name()" is "std::string" - continue; - } - - size_t it; - while ((it=str.find(p.first)) != std::string::npos) { - str.replace(it, p.first.size(), p.second); - } - } - } - - std::string prettify_stacktrace(const std::string& input) - { - std::string output = input; - - do_replacements(s_user_stack_cleanups, output); - do_replacements(REPLACE_LIST, output); - - try { - std::regex std_allocator_re(R"(,\s*std::allocator<[^<>]+>)"); - output = std::regex_replace(output, std_allocator_re, std::string("")); - - std::regex template_spaces_re(R"(<\s*([^<> ]+)\s*>)"); - output = std::regex_replace(output, template_spaces_re, std::string("<$1>")); - } catch (std::regex_error&) { - // Probably old GCC. - } - - return output; - } - - std::string stacktrace_as_stdstring(int skip) - { - // From https://gist.github.com/fmela/591333 - void* callstack[128] = {0}; - const auto max_frames = sizeof(callstack) / sizeof(callstack[0]); - int num_frames = backtrace(callstack, max_frames); - char** symbols = backtrace_symbols(callstack, num_frames); - - std::string result; - // Print stack traces so the most relevant ones are written last - // Rationale: http://yellerapp.com/posts/2015-01-22-upside-down-stacktraces.html - for (int i = num_frames - 1; i >= skip; --i) { - char buf[1024]; - Dl_info info; - if (dladdr(callstack[i], &info) && info.dli_sname) { - char* demangled = NULL; - int status = -1; - if (info.dli_sname[0] == '_') { - demangled = abi::__cxa_demangle(info.dli_sname, 0, 0, &status); - } - snprintf(buf, sizeof(buf), "%-3d %*p %s + %zd\n", - i - skip, int(2 + sizeof(void*) * 2), callstack[i], - status == 0 ? demangled : - info.dli_sname == 0 ? symbols[i] : info.dli_sname, - static_cast(callstack[i]) - static_cast(info.dli_saddr)); - free(demangled); - } else { - snprintf(buf, sizeof(buf), "%-3d %*p %s\n", - i - skip, int(2 + sizeof(void*) * 2), callstack[i], symbols[i]); - } - result += buf; - } - free(symbols); - - if (num_frames == max_frames) { - result = "[truncated]\n" + result; - } - - if (!result.empty() && result[result.size() - 1] == '\n') { - result.resize(result.size() - 1); - } - - return prettify_stacktrace(result); - } - -#else // LOGURU_STACKTRACES - Text demangle(const char* name) - { - return Text(STRDUP(name)); - } - - std::string stacktrace_as_stdstring(int) - { - // No stacktraces available on this platform" - return ""; - } - -#endif // LOGURU_STACKTRACES - - Text stacktrace(int skip) - { - auto str = stacktrace_as_stdstring(skip + 1); - return Text(STRDUP(str.c_str())); - } - - // ------------------------------------------------------------------------ - - static void print_preamble_header(char* out_buff, size_t out_buff_size) - { - if (out_buff_size == 0) { return; } - out_buff[0] = '\0'; - long pos = 0; - if (g_preamble_date && pos < out_buff_size) { - pos += snprintf(out_buff + pos, out_buff_size - pos, "date "); - } - if (g_preamble_time && pos < out_buff_size) { - pos += snprintf(out_buff + pos, out_buff_size - pos, "time "); - } - if (g_preamble_uptime && pos < out_buff_size) { - pos += snprintf(out_buff + pos, out_buff_size - pos, "( uptime ) "); - } - if (g_preamble_thread && pos < out_buff_size) { - pos += snprintf(out_buff + pos, out_buff_size - pos, "[%-*s]", LOGURU_THREADNAME_WIDTH, " thread name/id"); - } - if (g_preamble_file && pos < out_buff_size) { - pos += snprintf(out_buff + pos, out_buff_size - pos, "%*s:line ", LOGURU_FILENAME_WIDTH, "file"); - } - if (g_preamble_verbose && pos < out_buff_size) { - pos += snprintf(out_buff + pos, out_buff_size - pos, " v"); - } - if (g_preamble_pipe && pos < out_buff_size) { - pos += snprintf(out_buff + pos, out_buff_size - pos, "| "); - } - } - - static void print_preamble(char* out_buff, size_t out_buff_size, Verbosity verbosity, const char* file, unsigned line) - { - if (out_buff_size == 0) { return; } - out_buff[0] = '\0'; - if (!g_preamble) { return; } - long long ms_since_epoch = duration_cast(system_clock::now().time_since_epoch()).count(); - time_t sec_since_epoch = time_t(ms_since_epoch / 1000); - tm time_info; - localtime_r(&sec_since_epoch, &time_info); - - auto uptime_ms = duration_cast(steady_clock::now() - s_start_time).count(); - auto uptime_sec = uptime_ms / 1000.0; - - char thread_name[LOGURU_THREADNAME_WIDTH + 1] = {0}; - get_thread_name(thread_name, LOGURU_THREADNAME_WIDTH + 1, true); - - if (s_strip_file_path) { - file = filename(file); - } - - char level_buff[6]; - const char* custom_level_name = get_verbosity_name(verbosity); - if (custom_level_name) { - snprintf(level_buff, sizeof(level_buff) - 1, "%s", custom_level_name); - } else { - snprintf(level_buff, sizeof(level_buff) - 1, "% 4d", verbosity); - } - - long pos = 0; - - if (g_preamble_date && pos < out_buff_size) { - pos += snprintf(out_buff + pos, out_buff_size - pos, "%04d-%02d-%02d ", - 1900 + time_info.tm_year, 1 + time_info.tm_mon, time_info.tm_mday); - } - if (g_preamble_time && pos < out_buff_size) { - pos += snprintf(out_buff + pos, out_buff_size - pos, "%02d:%02d:%02d.%03lld ", - time_info.tm_hour, time_info.tm_min, time_info.tm_sec, ms_since_epoch % 1000); - } - if (g_preamble_uptime && pos < out_buff_size) { - pos += snprintf(out_buff + pos, out_buff_size - pos, "(%8.3fs) ", - uptime_sec); - } - if (g_preamble_thread && pos < out_buff_size) { - pos += snprintf(out_buff + pos, out_buff_size - pos, "[%-*s]", - LOGURU_THREADNAME_WIDTH, thread_name); - } - if (g_preamble_file && pos < out_buff_size) { - char shortened_filename[LOGURU_FILENAME_WIDTH + 1]; - snprintf(shortened_filename, LOGURU_FILENAME_WIDTH + 1, "%s", file); - pos += snprintf(out_buff + pos, out_buff_size - pos, "%*s:%-5u ", - LOGURU_FILENAME_WIDTH, shortened_filename, line); - } - if (g_preamble_verbose && pos < out_buff_size) { - pos += snprintf(out_buff + pos, out_buff_size - pos, "%4s", - level_buff); - } - if (g_preamble_pipe && pos < out_buff_size) { - pos += snprintf(out_buff + pos, out_buff_size - pos, "| "); - } - } - - // stack_trace_skip is just if verbosity == FATAL. - static void log_message(int stack_trace_skip, Message& message, bool with_indentation, bool abort_if_fatal) - { - const auto verbosity = message.verbosity; - std::lock_guard lock(s_mutex); - - if (message.verbosity == Verbosity_FATAL) { - auto st = loguru::stacktrace(stack_trace_skip + 2); - if (!st.empty()) { - RAW_LOG_F(ERROR, "Stack trace:\n%s", st.c_str()); - } - - auto ec = loguru::get_error_context(); - if (!ec.empty()) { - RAW_LOG_F(ERROR, "%s", ec.c_str()); - } - } - - if (with_indentation) { - message.indentation = indentation(s_stderr_indentation); - } - - if (verbosity <= g_stderr_verbosity) { - if (g_colorlogtostderr && s_terminal_has_color) { - if (verbosity > Verbosity_WARNING) { - fprintf(stderr, "%s%s%s%s%s%s%s%s\n", - terminal_reset(), - terminal_dim(), - message.preamble, - message.indentation, - verbosity == Verbosity_INFO ? terminal_reset() : "", // un-dim for info - message.prefix, - message.message, - terminal_reset()); - } else { - fprintf(stderr, "%s%s%s%s%s%s%s\n", - terminal_reset(), - verbosity == Verbosity_WARNING ? terminal_yellow() : terminal_red(), - message.preamble, - message.indentation, - message.prefix, - message.message, - terminal_reset()); - } - } else { - fprintf(stderr, "%s%s%s%s\n", - message.preamble, message.indentation, message.prefix, message.message); - } - - if (g_flush_interval_ms == 0) { - fflush(stderr); - } else { - s_needs_flushing = true; - } - } - - for (auto& p : s_callbacks) { - if (verbosity <= p.verbosity) { - if (with_indentation) { - message.indentation = indentation(p.indentation); - } - p.callback(p.user_data, message); - if (g_flush_interval_ms == 0) { - if (p.flush) { p.flush(p.user_data); } - } else { - s_needs_flushing = true; - } - } - } - - if (g_flush_interval_ms > 0 && !s_flush_thread) { - s_flush_thread = new std::thread([](){ - for (;;) { - if (s_needs_flushing) { - flush(); - } - std::this_thread::sleep_for(std::chrono::milliseconds(g_flush_interval_ms)); - } - }); - } - - if (message.verbosity == Verbosity_FATAL) { - flush(); - - if (s_fatal_handler) { - s_fatal_handler(message); - flush(); - } - - if (abort_if_fatal) { -#if LOGURU_CATCH_SIGABRT && !defined(_WIN32) - // Make sure we don't catch our own abort: - signal(SIGABRT, SIG_DFL); -#endif - abort(); - } - } - } - - // stack_trace_skip is just if verbosity == FATAL. - void log_to_everywhere(int stack_trace_skip, Verbosity verbosity, - const char* file, unsigned line, - const char* prefix, const char* buff) - { - char preamble_buff[LOGURU_PREAMBLE_WIDTH]; - print_preamble(preamble_buff, sizeof(preamble_buff), verbosity, file, line); - auto message = Message{verbosity, file, line, preamble_buff, "", prefix, buff}; - log_message(stack_trace_skip + 1, message, true, true); - } - -#if LOGURU_USE_FMTLIB - void log(Verbosity verbosity, const char* file, unsigned line, const char* format, fmt::ArgList args) - { - auto formatted = fmt::format(format, args); - log_to_everywhere(1, verbosity, file, line, "", formatted.c_str()); - } - - void raw_log(Verbosity verbosity, const char* file, unsigned line, const char* format, fmt::ArgList args) - { - auto formatted = fmt::format(format, args); - auto message = Message{verbosity, file, line, "", "", "", formatted.c_str()}; - log_message(1, message, false, true); - } - -#else - void log(Verbosity verbosity, const char* file, unsigned line, const char* format, ...) - { - va_list vlist; - va_start(vlist, format); - auto buff = vtextprintf(format, vlist); - log_to_everywhere(1, verbosity, file, line, "", buff.c_str()); - va_end(vlist); - } - - void raw_log(Verbosity verbosity, const char* file, unsigned line, const char* format, ...) - { - va_list vlist; - va_start(vlist, format); - auto buff = vtextprintf(format, vlist); - auto message = Message{verbosity, file, line, "", "", "", buff.c_str()}; - log_message(1, message, false, true); - va_end(vlist); - } -#endif - - void flush() - { - std::lock_guard lock(s_mutex); - fflush(stderr); - for (const auto& callback : s_callbacks) - { - if (callback.flush) { - callback.flush(callback.user_data); - } - } - s_needs_flushing = false; - } - - LogScopeRAII::LogScopeRAII(Verbosity verbosity, const char* file, unsigned line, const char* format, ...) - : _verbosity(verbosity), _file(file), _line(line) - { - if (verbosity <= current_verbosity_cutoff()) { - std::lock_guard lock(s_mutex); - _indent_stderr = (verbosity <= g_stderr_verbosity); - _start_time_ns = now_ns(); - va_list vlist; - va_start(vlist, format); - vsnprintf(_name, sizeof(_name), format, vlist); - log_to_everywhere(1, _verbosity, file, line, "{ ", _name); - va_end(vlist); - - if (_indent_stderr) { - ++s_stderr_indentation; - } - - for (auto& p : s_callbacks) { - if (verbosity <= p.verbosity) { - ++p.indentation; - } - } - } else { - _file = nullptr; - } - } - - LogScopeRAII::~LogScopeRAII() - { - if (_file) { - std::lock_guard lock(s_mutex); - if (_indent_stderr && s_stderr_indentation > 0) { - --s_stderr_indentation; - } - for (auto& p : s_callbacks) { - // Note: Callback indentation cannot change! - if (_verbosity <= p.verbosity) { - // in unlikely case this callback is new - if (p.indentation > 0) { - --p.indentation; - } - } - } -#if LOGURU_VERBOSE_SCOPE_ENDINGS - auto duration_sec = (now_ns() - _start_time_ns) / 1e9; - auto buff = textprintf("%.*f s: %s", LOGURU_SCOPE_TIME_PRECISION, duration_sec, _name); - log_to_everywhere(1, _verbosity, _file, _line, "} ", buff.c_str()); -#else - log_to_everywhere(1, _verbosity, _file, _line, "}", ""); -#endif - } - } - - void log_and_abort(int stack_trace_skip, const char* expr, const char* file, unsigned line, const char* format, ...) - { - va_list vlist; - va_start(vlist, format); - auto buff = vtextprintf(format, vlist); - log_to_everywhere(stack_trace_skip + 1, Verbosity_FATAL, file, line, expr, buff.c_str()); - va_end(vlist); - abort(); // log_to_everywhere already does this, but this makes the analyzer happy. - } - - void log_and_abort(int stack_trace_skip, const char* expr, const char* file, unsigned line) - { - log_and_abort(stack_trace_skip + 1, expr, file, line, " "); - } - - // ---------------------------------------------------------------------------- - // Streams: - - std::string vstrprintf(const char* format, va_list vlist) - { - auto text = vtextprintf(format, vlist); - std::string result = text.c_str(); - return result; - } - - std::string strprintf(const char* format, ...) - { - va_list vlist; - va_start(vlist, format); - auto result = vstrprintf(format, vlist); - va_end(vlist); - return result; - } - - #if LOGURU_WITH_STREAMS - - StreamLogger::~StreamLogger() noexcept(false) - { - auto message = _ss.str(); - log(_verbosity, _file, _line, "%s", message.c_str()); - } - - AbortLogger::~AbortLogger() noexcept(false) - { - auto message = _ss.str(); - loguru::log_and_abort(1, _expr, _file, _line, "%s", message.c_str()); - } - - #endif // LOGURU_WITH_STREAMS - - // ---------------------------------------------------------------------------- - // 888888 88""Yb 88""Yb dP"Yb 88""Yb dP""b8 dP"Yb 88b 88 888888 888888 Yb dP 888888 - // 88__ 88__dP 88__dP dP Yb 88__dP dP `" dP Yb 88Yb88 88 88__ YbdP 88 - // 88"" 88"Yb 88"Yb Yb dP 88"Yb Yb Yb dP 88 Y88 88 88"" dPYb 88 - // 888888 88 Yb 88 Yb YbodP 88 Yb YboodP YbodP 88 Y8 88 888888 dP Yb 88 - // ---------------------------------------------------------------------------- - - struct StringStream - { - std::string str; - }; - - // Use this in your EcPrinter implementations. - void stream_print(StringStream& out_string_stream, const char* text) - { - out_string_stream.str += text; - } - - // ---------------------------------------------------------------------------- - - using ECPtr = EcEntryBase*; - -#if defined(_WIN32) || (defined(__APPLE__) && !TARGET_OS_IPHONE) - #ifdef __APPLE__ - #define LOGURU_THREAD_LOCAL __thread - #else - #define LOGURU_THREAD_LOCAL thread_local - #endif - static LOGURU_THREAD_LOCAL ECPtr thread_ec_ptr = nullptr; - - ECPtr& get_thread_ec_head_ref() - { - return thread_ec_ptr; - } -#else // !thread_local - static pthread_once_t s_ec_pthread_once = PTHREAD_ONCE_INIT; - static pthread_key_t s_ec_pthread_key; - - void free_ec_head_ref(void* io_error_context) - { - delete reinterpret_cast(io_error_context); - } - - void ec_make_pthread_key() - { - (void)pthread_key_create(&s_ec_pthread_key, free_ec_head_ref); - } - - ECPtr& get_thread_ec_head_ref() - { - (void)pthread_once(&s_ec_pthread_once, ec_make_pthread_key); - auto ec = reinterpret_cast(pthread_getspecific(s_ec_pthread_key)); - if (ec == nullptr) { - ec = new ECPtr(nullptr); - (void)pthread_setspecific(s_ec_pthread_key, ec); - } - return *ec; - } -#endif // !thread_local - - // ---------------------------------------------------------------------------- - - EcHandle get_thread_ec_handle() - { - return get_thread_ec_head_ref(); - } - - Text get_error_context() - { - return get_error_context_for(get_thread_ec_head_ref()); - } - - Text get_error_context_for(const EcEntryBase* ec_head) - { - std::vector stack; - while (ec_head) { - stack.push_back(ec_head); - ec_head = ec_head->_previous; - } - std::reverse(stack.begin(), stack.end()); - - StringStream result; - if (!stack.empty()) { - result.str += "------------------------------------------------\n"; - for (auto entry : stack) { - const auto description = std::string(entry->_descr) + ":"; - auto prefix = textprintf("[ErrorContext] %*s:%-5u %-20s ", - LOGURU_FILENAME_WIDTH, filename(entry->_file), entry->_line, description.c_str()); - result.str += prefix.c_str(); - entry->print_value(result); - result.str += "\n"; - } - result.str += "------------------------------------------------"; - } - return Text(STRDUP(result.str.c_str())); - } - - EcEntryBase::EcEntryBase(const char* file, unsigned line, const char* descr) - : _file(file), _line(line), _descr(descr) - { - EcEntryBase*& ec_head = get_thread_ec_head_ref(); - _previous = ec_head; - ec_head = this; - } - - EcEntryBase::~EcEntryBase() - { - get_thread_ec_head_ref() = _previous; - } - - // ------------------------------------------------------------------------ - - Text ec_to_text(const char* value) - { - // Add quotes around the string to make it obvious where it begin and ends. - // This is great for detecting erroneous leading or trailing spaces in e.g. an identifier. - auto str = "\"" + std::string(value) + "\""; - return Text{STRDUP(str.c_str())}; - } - - Text ec_to_text(char c) - { - // Add quotes around the character to make it obvious where it begin and ends. - std::string str = "'"; - - auto write_hex_digit = [&](unsigned num) - { - if (num < 10u) { str += char('0' + num); } - else { str += char('a' + num - 10); } - }; - - auto write_hex_16 = [&](uint16_t n) - { - write_hex_digit((n >> 12u) & 0x0f); - write_hex_digit((n >> 8u) & 0x0f); - write_hex_digit((n >> 4u) & 0x0f); - write_hex_digit((n >> 0u) & 0x0f); - }; - - if (c == '\\') { str += "\\\\"; } - else if (c == '\"') { str += "\\\""; } - else if (c == '\'') { str += "\\\'"; } - else if (c == '\0') { str += "\\0"; } - else if (c == '\b') { str += "\\b"; } - else if (c == '\f') { str += "\\f"; } - else if (c == '\n') { str += "\\n"; } - else if (c == '\r') { str += "\\r"; } - else if (c == '\t') { str += "\\t"; } - else if (0 <= c && c < 0x20) { - str += "\\u"; - write_hex_16(static_cast(c)); - } else { str += c; } - - str += "'"; - - return Text{STRDUP(str.c_str())}; - } - - #define DEFINE_EC(Type) \ - Text ec_to_text(Type value) \ - { \ - auto str = std::to_string(value); \ - return Text{STRDUP(str.c_str())}; \ - } - - DEFINE_EC(int) - DEFINE_EC(unsigned int) - DEFINE_EC(long) - DEFINE_EC(unsigned long) - DEFINE_EC(long long) - DEFINE_EC(unsigned long long) - DEFINE_EC(float) - DEFINE_EC(double) - DEFINE_EC(long double) - - #undef DEFINE_EC - - Text ec_to_text(EcHandle ec_handle) - { - Text parent_ec = get_error_context_for(ec_handle); - char* with_newline = reinterpret_cast(malloc(strlen(parent_ec.c_str()) + 2)); - with_newline[0] = '\n'; - strcpy(with_newline + 1, parent_ec.c_str()); - return Text(with_newline); - } - - // ---------------------------------------------------------------------------- - -} // namespace loguru - -// ---------------------------------------------------------------------------- -// .dP"Y8 88 dP""b8 88b 88 db 88 .dP"Y8 -// `Ybo." 88 dP `" 88Yb88 dPYb 88 `Ybo." -// o.`Y8b 88 Yb "88 88 Y88 dP__Yb 88 .o o.`Y8b -// 8bodP' 88 YboodP 88 Y8 dP""""Yb 88ood8 8bodP' -// ---------------------------------------------------------------------------- - -#ifdef _WIN32 -namespace loguru { - void install_signal_handlers() - { - #if defined(_MSC_VER) - #pragma message ( "No signal handlers on Win32" ) - #else - #warning "No signal handlers on Win32" - #endif - } -} // namespace loguru - -#else // _WIN32 - -namespace loguru -{ - struct Signal - { - int number; - const char* name; - }; - const Signal ALL_SIGNALS[] = { -#if LOGURU_CATCH_SIGABRT - { SIGABRT, "SIGABRT" }, -#endif - { SIGBUS, "SIGBUS" }, - { SIGFPE, "SIGFPE" }, - { SIGILL, "SIGILL" }, - { SIGINT, "SIGINT" }, - { SIGSEGV, "SIGSEGV" }, - { SIGTERM, "SIGTERM" }, - }; - - void write_to_stderr(const char* data, size_t size) - { - auto result = write(STDERR_FILENO, data, size); - (void)result; // Ignore errors. - } - - void write_to_stderr(const char* data) - { - write_to_stderr(data, strlen(data)); - } - - void call_default_signal_handler(int signal_number) - { - struct sigaction sig_action; - memset(&sig_action, 0, sizeof(sig_action)); - sigemptyset(&sig_action.sa_mask); - sig_action.sa_handler = SIG_DFL; - sigaction(signal_number, &sig_action, NULL); - kill(getpid(), signal_number); - } - - void signal_handler(int signal_number, siginfo_t*, void*) - { - const char* signal_name = "UNKNOWN SIGNAL"; - - for (const auto& s : ALL_SIGNALS) { - if (s.number == signal_number) { - signal_name = s.name; - break; - } - } - - // -------------------------------------------------------------------- - /* There are few things that are safe to do in a signal handler, - but writing to stderr is one of them. - So we first print out what happened to stderr so we're sure that gets out, - then we do the unsafe things, like logging the stack trace. - */ - - if (g_colorlogtostderr && s_terminal_has_color) { - write_to_stderr(terminal_reset()); - write_to_stderr(terminal_bold()); - write_to_stderr(terminal_light_red()); - } - write_to_stderr("\n"); - write_to_stderr("Loguru caught a signal: "); - write_to_stderr(signal_name); - write_to_stderr("\n"); - if (g_colorlogtostderr && s_terminal_has_color) { - write_to_stderr(terminal_reset()); - } - - // -------------------------------------------------------------------- - -#if LOGURU_UNSAFE_SIGNAL_HANDLER - // -------------------------------------------------------------------- - /* Now we do unsafe things. This can for example lead to deadlocks if - the signal was triggered from the system's memory management functions - and the code below tries to do allocations. - */ - - flush(); - char preamble_buff[LOGURU_PREAMBLE_WIDTH]; - print_preamble(preamble_buff, sizeof(preamble_buff), Verbosity_FATAL, "", 0); - auto message = Message{Verbosity_FATAL, "", 0, preamble_buff, "", "Signal: ", signal_name}; - try { - log_message(1, message, false, false); - } catch (...) { - // This can happed due to s_fatal_handler. - write_to_stderr("Exception caught and ignored by Loguru signal handler.\n"); - } - flush(); - - // -------------------------------------------------------------------- -#endif // LOGURU_UNSAFE_SIGNAL_HANDLER - - call_default_signal_handler(signal_number); - } - - void install_signal_handlers() - { - struct sigaction sig_action; - memset(&sig_action, 0, sizeof(sig_action)); - sigemptyset(&sig_action.sa_mask); - sig_action.sa_flags |= SA_SIGINFO; - sig_action.sa_sigaction = &signal_handler; - for (const auto& s : ALL_SIGNALS) { - CHECK_F(sigaction(s.number, &sig_action, NULL) != -1, - "Failed to install handler for %s", s.name); - } - } -} // namespace loguru - -#endif // _WIN32 - -#endif // LOGURU_IMPLEMENTATION diff --git a/meson.build b/meson.build index 8d6ccd1..68d7bd9 100644 --- a/meson.build +++ b/meson.build @@ -22,7 +22,6 @@ endif root_inc = include_directories('./') subdir('protocol') -subdir('libloguru') subdir('libaurum') if get_option('tizen') == true subdir('org.tizen.aurum-bootstrap') diff --git a/org.tizen.aurum-bootstrap/meson.build b/org.tizen.aurum-bootstrap/meson.build index eb6cfd0..d4da42d 100644 --- a/org.tizen.aurum-bootstrap/meson.build +++ b/org.tizen.aurum-bootstrap/meson.build @@ -3,7 +3,6 @@ bootstrap_svr_inc = [ root_inc, include_directories('inc'), include_directories('inc/Commands'), - loguru_inc, ] bootstrap_svr_src = [ @@ -44,7 +43,6 @@ bootstrap_svr_src += [ bootstrap_svr_dep = [ libaurum, grpc_deps, - loguru_deps, ] if get_option('tizen') == true @@ -65,7 +63,6 @@ bootstrap_svr_bin = executable( [bootstrap_svr_src, grpc_src, grpc_pb_src], dependencies: bootstrap_svr_dep, include_directories: bootstrap_svr_inc, - link_with: libloguru, install:true, install_dir: join_paths(get_option('tzapp_path'), 'org.tizen.aurum-bootstrap', 'bin'), pie:true, diff --git a/tests/Test_Misc.cc b/tests/Test_Misc.cc index f5f4a74..d6793f7 100644 --- a/tests/Test_Misc.cc +++ b/tests/Test_Misc.cc @@ -10,9 +10,6 @@ #include #include -#include - - #include "MockAccessibleWatcher.h" #include "MockAccessibleApplication.h" #include "MockAccessibleWindow.h" diff --git a/tests/Test_Sel.cc b/tests/Test_Sel.cc index 6937683..cef1c7f 100644 --- a/tests/Test_Sel.cc +++ b/tests/Test_Sel.cc @@ -10,9 +10,6 @@ #include #include -#include - - #include "MockAccessibleWatcher.h" #include "MockAccessibleApplication.h" #include "MockAccessibleWindow.h" @@ -22,7 +19,6 @@ class AurumTestSel : public ::testing::Test { public: AurumTestSel() : mDevice{nullptr}, mWatcher{nullptr}, mApps{}, mWins{}, mNodes{}{ - //loguru::g_stderr_verbosity = loguru::Verbosity_9; } protected: void SetUp() override { diff --git a/tests/Test_UiDevice.cc b/tests/Test_UiDevice.cc index 2a054cd..b46b312 100644 --- a/tests/Test_UiDevice.cc +++ b/tests/Test_UiDevice.cc @@ -6,7 +6,6 @@ #include #include - #include "MockDeviceImpl.h" #include @@ -14,9 +13,6 @@ #include #include -#include - - #include "MockAccessibleWatcher.h" #include "MockAccessibleApplication.h" #include "MockAccessibleWindow.h" @@ -27,7 +23,6 @@ class AurumTestUiDevice : public ::testing::Test { public: AurumTestUiDevice() : mDevice{nullptr}, mWatcher{nullptr}, mApp{nullptr}, mWin{nullptr}, mNode{nullptr} { - //loguru::g_stderr_verbosity = loguru::Verbosity_9; } void SetUp() override { @@ -319,4 +314,4 @@ TEST_F(AurumTestUiDevice, getSystemTime_P1) clock_gettime(CLOCK_REALTIME, &t); long long t4 = (long long)t.tv_sec * 1000L + (long long)(t.tv_nsec / 1000000); ASSERT_NEAR(t3,t4,100); -} \ No newline at end of file +} diff --git a/tests/Test_UiObject.cc b/tests/Test_UiObject.cc index 8bd2915..a08a8f9 100644 --- a/tests/Test_UiObject.cc +++ b/tests/Test_UiObject.cc @@ -11,7 +11,6 @@ #include #include -#include #include #include @@ -24,7 +23,6 @@ class AurumTestUiObject : public ::testing::Test { public: AurumTestUiObject() : mDevice{nullptr},mWatcher{nullptr}, mApp{nullptr}, mWin{nullptr}, mNode{nullptr} { - //loguru::g_stderr_verbosity = loguru::Verbosity_9; } void SetUp() override { @@ -433,4 +431,4 @@ TEST_F(AurumTestUiObject, DoAtspiActivate_P1) TEST_F(AurumTestUiObject, refresh_P1) { -} \ No newline at end of file +} diff --git a/tests/Test_UiSelector.cc b/tests/Test_UiSelector.cc index c712d91..9f76683 100644 --- a/tests/Test_UiSelector.cc +++ b/tests/Test_UiSelector.cc @@ -10,7 +10,6 @@ #include #include -#include #include "MockAccessibleWatcher.h" @@ -22,7 +21,6 @@ class AurumTestUiSelector : public ::testing::Test { public: AurumTestUiSelector(): mDevice{nullptr}, mWatcher{nullptr}, mApps{}, mWins{}, mNodes{}{ - //loguru::g_stderr_verbosity = loguru::Verbosity_9; } protected: void SetUp() override { -- 2.7.4 From 94eb2b0661b8539ccea217d06f239e6bfde5cd40 Mon Sep 17 00:00:00 2001 From: Woochanlee Date: Wed, 7 Jul 2021 16:18:34 +0900 Subject: [PATCH 13/16] bootstrap: Delete privacy_privilege for location, mediastroge It's not need on current status Change-Id: I122319a2bab50c463a4305f2a72bdadfa29357e7 --- org.tizen.aurum-bootstrap/meson.build | 1 - org.tizen.aurum-bootstrap/src/BootstrapServer.cc | 64 ------------------------ 2 files changed, 65 deletions(-) diff --git a/org.tizen.aurum-bootstrap/meson.build b/org.tizen.aurum-bootstrap/meson.build index d4da42d..41d8472 100644 --- a/org.tizen.aurum-bootstrap/meson.build +++ b/org.tizen.aurum-bootstrap/meson.build @@ -54,7 +54,6 @@ bootstrap_svr_dep += [ dependency('capi-appfw-service-application'), dependency('capi-system-system-settings'), dependency('capi-base-utils-i18n'), - dependency('capi-privacy-privilege-manager'), ] endif diff --git a/org.tizen.aurum-bootstrap/src/BootstrapServer.cc b/org.tizen.aurum-bootstrap/src/BootstrapServer.cc index 827fcee..3415218 100644 --- a/org.tizen.aurum-bootstrap/src/BootstrapServer.cc +++ b/org.tizen.aurum-bootstrap/src/BootstrapServer.cc @@ -3,7 +3,6 @@ #include "bootstrap.h" #include -#include #include #include @@ -12,9 +11,6 @@ #include "AurumServiceImpl.h" #include "config.h" -#define PRIV_MEDIASTORAGE "http://tizen.org/privilege/mediastorage" -#define PRIV_LOCATION "http://tizen.org/privilege/location" - using namespace grpc; typedef struct _ServiceContext { @@ -40,63 +36,6 @@ _grpc_thread_func (gpointer data) return NULL; } -static void -reponse_cb(ppm_call_cause_e cause, ppm_request_result_e result, - const char *privilege, void *user_data) -{ - if (cause == PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR) { - LOGI("PPM Error PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR"); - return; - } - - switch (result) { - case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER: - LOGI("priv:%s PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER", privilege); - break; - case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_FOREVER: - LOGI("priv:%s PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER", privilege); - break; - case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_ONCE: - LOGI("priv:%s PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER", privilege); - break; - default: - LOGI("priv:%s default", privilege); - break; - } -} - -static void -check_permission(char *path_privilege) -{ - ppm_check_result_e result; - int ret; - LOGI("path_privilege = %s",path_privilege); - ret = ppm_check_permission(path_privilege, &result); - - if (ret == PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE) { - switch (result) { - case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ALLOW: - break; - - case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY: - LOGI("PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY"); - ; - break; - - case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK: - LOGI("PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK"); - ppm_request_permission(path_privilege, reponse_cb, NULL); - break; - - default: - break; - } - } else { - LOGI("Error to check permission[0x%x]", ret); - } -} - - static bool _service_app_create(void *data) { ServiceContext *ctx = (ServiceContext*)data; @@ -104,9 +43,6 @@ static bool _service_app_create(void *data) ctx->loop = g_main_loop_new ( NULL , FALSE ); ctx->thread = g_thread_new("grpc_thread", _grpc_thread_func, ctx); - check_permission(PRIV_LOCATION); - check_permission(PRIV_MEDIASTORAGE); - return true; } -- 2.7.4 From baabbdb7f31e8e0f99d04143e6ae195159428112 Mon Sep 17 00:00:00 2001 From: Woochanlee Date: Wed, 7 Jul 2021 16:52:00 +0900 Subject: [PATCH 14/16] Aurum: Remove build warnings Change-Id: Ifcd13621d8559a4d5d33865c39262fca70caad37 --- org.tizen.aurum-bootstrap/org.tizen.aurum-bootstrap.xml | 2 -- org.tizen.aurum-bootstrap/src/BootstrapServer.cc | 3 ++- org.tizen.aurum-bootstrap/src/Commands/GetAppInfoCommand.cc | 1 - packaging/aurum.spec | 3 --- 4 files changed, 2 insertions(+), 7 deletions(-) diff --git a/org.tizen.aurum-bootstrap/org.tizen.aurum-bootstrap.xml b/org.tizen.aurum-bootstrap/org.tizen.aurum-bootstrap.xml index fcac948..fb382b2 100644 --- a/org.tizen.aurum-bootstrap/org.tizen.aurum-bootstrap.xml +++ b/org.tizen.aurum-bootstrap/org.tizen.aurum-bootstrap.xml @@ -10,7 +10,6 @@ http://tizen.org/privilege/datasharing http://tizen.org/privilege/externalstroage - http://tizen.org/privilege/mediastorage http://tizen.org/privilege/application.info http://tizen.org/privilege/application.launch http://tizen.org/privilege/packagemanager.info @@ -21,7 +20,6 @@ http://tizen.org/privilege/appmanager.launch http://tizen.org/privilege/inputgenerator http://tizen.org/privilege/screenshot - http://tizen.org/privilege/location http://tizen.org/privilege/display true diff --git a/org.tizen.aurum-bootstrap/src/BootstrapServer.cc b/org.tizen.aurum-bootstrap/src/BootstrapServer.cc index 3415218..6ef11e2 100644 --- a/org.tizen.aurum-bootstrap/src/BootstrapServer.cc +++ b/org.tizen.aurum-bootstrap/src/BootstrapServer.cc @@ -57,6 +57,8 @@ static void _service_app_terminate(void *data) static void _service_app_control(app_control_h app_control, void *data) { ServiceContext *ctx = (ServiceContext*)data; + if (!ctx) + LOGE("Service context is empty!"); } int main(int argc, char **argv) @@ -66,7 +68,6 @@ int main(int argc, char **argv) #endif service_app_lifecycle_callback_s event_callback; - app_event_handler_h handlers[5] = {NULL, }; ServiceContext ctx = {0,}; event_callback.create = _service_app_create; diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetAppInfoCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetAppInfoCommand.cc index 6ecb115..219211d 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/GetAppInfoCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/GetAppInfoCommand.cc @@ -22,7 +22,6 @@ GetAppInfoCommand::GetAppInfoCommand(const ::aurum::ReqGetAppInfo* request, app_state_e appState; char* label = nullptr; - int ret = -1; mResponse->set_status(::aurum::RspStatus::OK); mResponse->set_isinstalled(false); diff --git a/packaging/aurum.spec b/packaging/aurum.spec index 7e14f5d..21e21fc 100644 --- a/packaging/aurum.spec +++ b/packaging/aurum.spec @@ -29,7 +29,6 @@ BuildRequires: pkgconfig(capi-system-device) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(capi-system-system-settings) BuildRequires: pkgconfig(capi-base-utils-i18n) -BuildRequires: pkgconfig(capi-privacy-privilege-manager) %if 0%{?gendoc:1} BuildRequires: doxygen @@ -215,6 +214,4 @@ echo "signing %{TZ_SYS_RO_APP}/org.tizen.aurum-bootstrap" %files gcov %{_datadir}/gcov/obj/* %{_bindir}/test_* -%else -%exclude %{_bindir}/test_* %endif -- 2.7.4 From 118904f09e5b60e5116abca3bd8ff03daebfc62e Mon Sep 17 00:00:00 2001 From: Woochanlee Date: Wed, 7 Jul 2021 18:23:53 +0900 Subject: [PATCH 15/16] bootstrap: Fix typo Change-Id: I3a1864a5c7825f372975adfbe873a646a1169ed9 --- org.tizen.aurum-bootstrap/src/Commands/GetLocationCommand.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetLocationCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetLocationCommand.cc index 9110cb5..dc85706 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/GetLocationCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/GetLocationCommand.cc @@ -9,7 +9,7 @@ GetLocationCommand::GetLocationCommand(const ::aurum::ReqGetLocation* request, ::grpc::Status GetLocationCommand::execute() { - LOGI("CliGetLocation --------------- "); + LOGI("GetLocation --------------- "); // ObjectMapper *mObjMap = ObjectMapper::getInstance(); mResponse->set_alt(-1); -- 2.7.4 From e4640c5cee1cc448de2f7237822639c64115acda Mon Sep 17 00:00:00 2001 From: Woochanlee Date: Wed, 7 Jul 2021 19:06:24 +0900 Subject: [PATCH 16/16] bootstrap: Code and logic clean up when display off state there is no need to call device_power_wakeup(), if display already on Change-Id: Ic42d9625cf04b0a1ffec79652c4c8a5fb0d363e3 --- .../src/Commands/PreCommand.cc | 24 +++++++++++++--------- packaging/aurum.spec | 5 +++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/org.tizen.aurum-bootstrap/src/Commands/PreCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/PreCommand.cc index b291289..82d10d5 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/PreCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/PreCommand.cc @@ -15,22 +15,26 @@ PreCommand::PreCommand(Command *cmd) : mCommand{cmd} {} ::grpc::Status PreCommand::execute() { - { - LOGI("PreCommand --------------- "); - display_state_e state; - if (device_display_get_state(&state) != DEVICE_ERROR_NONE) { - LOGI("getting display state has failed"); - } +#ifndef TIZEN_TV + display_state_e state; + if (device_display_get_state(&state) != DEVICE_ERROR_NONE) { + LOGE("getting display state has failed"); + return grpc::Status::CANCELLED; + } - bool isDisplayOn = DISPLAY_STATE_SCREEN_OFF != state; + bool isDisplayOn = DISPLAY_STATE_SCREEN_OFF != state; + if (!isDisplayOn) { + LOGI("Display off state try to wake up"); if (device_power_wakeup(false) != DEVICE_ERROR_NONE) { - LOGI("turning on display has failed"); + LOGE("turning on display has failed"); + return grpc::Status::CANCELLED; } - if (!isDisplayOn) - std::this_thread::sleep_for(std::chrono::milliseconds{INTV_TURNON_MARGIN}); + std::this_thread::sleep_for(std::chrono::milliseconds{INTV_TURNON_MARGIN}); } +#endif /* TIZEN_TV */ + mCommand->executePre(); return mCommand->execute(); } diff --git a/packaging/aurum.spec b/packaging/aurum.spec index 21e21fc..f002269 100644 --- a/packaging/aurum.spec +++ b/packaging/aurum.spec @@ -131,6 +131,11 @@ meson \ -e 's%^.*: warning: .*$%\x1b[30;43m&\x1b[m%' %build + +%if "%{tizen_profile_name}" == "tv" + CFLAGS+=" -DTIZEN_TV";export CFLAGS +%endif + ninja \ -C gbsbuild \ -j %(echo "`/usr/bin/getconf _NPROCESSORS_ONLN`") \ -- 2.7.4