1 #ifndef DALI_INTERNAL_ATSPI_ACCESSIBILITY_COMMON_H
2 #define DALI_INTERNAL_ATSPI_ACCESSIBILITY_COMMON_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/integration-api/debug.h>
28 #include <dali/public-api/dali-adaptor-common.h>
29 #include <dali/devel-api/adaptor-framework/accessibility-impl.h>
30 #include <dali/internal/accessibility/bridge/dbus.h>
31 #include <dali/internal/accessibility/bridge/dbus-locators.h>
33 #define A11yDbusName "org.a11y.Bus"
34 #define A11yDbusPath "/org/a11y/bus"
35 #define A11yDbusStatusInterface "org.a11y.Status"
36 #define AtspiDbusNameRegistry "org.a11y.atspi.Registry"
37 #define AtspiDbusPathRoot "/org/a11y/atspi/accessible/root"
38 #define AtspiDbusInterfaceSocket "org.a11y.atspi.Socket"
39 #define AtspiPath "/org/a11y/atspi/accessible"
40 #define AtspiDbusInterfaceAccessible "org.a11y.atspi.Accessible"
41 #define AtspiDbusInterfaceAction "org.a11y.atspi.Action"
42 #define AtspiDbusInterfaceApplication "org.a11y.atspi.Application"
43 #define AtspiDbusInterfaceCollection "org.a11y.atspi.Collection"
44 #define AtspiDbusInterfaceComponent "org.a11y.atspi.Component"
45 #define AtspiDbusInterfaceDocument "org.a11y.atspi.Document"
46 #define AtspiDbusInterfaceEditableText "org.a11y.atspi.EditableText"
47 #define AtspiDbusInterfaceEventKeyboard "org.a11y.atspi.Event.Keyboard"
48 #define AtspiDbusInterfaceEventMouse "org.a11y.atspi.Event.Mouse"
49 #define AtspiDbusInterfaceEventObject "org.a11y.atspi.Event.Object"
50 #define AtspiDbusInterfaceHyperlink "org.a11y.atspi.Hyperlink"
51 #define AtspiDbusInterfaceHypertext "org.a11y.atspi.Hypertext"
52 #define AtspiDbusInterfaceImage "org.a11y.atspi.Image"
53 #define AtspiDbusInterfaceSelection "org.a11y.atspi.Selection"
54 #define AtspiDbusInterfaceTable "org.a11y.atspi.Table"
55 #define AtspiDbusInterfaceTableCell "org.a11y.atspi.TableCell"
56 #define AtspiDbusInterfaceText "org.a11y.atspi.Text"
57 #define AtspiDbusInterfaceValue "org.a11y.atspi.Value"
58 #define AtspiDbusInterfaceSocket "org.a11y.atspi.Socket"
59 #define AtspiDbusInterfaceEventWindow "org.a11y.atspi.Event.Window"
61 #define AtspiDbusPathDec "/org/a11y/atspi/registry/deviceeventcontroller"
62 #define AtspiDbusInterfaceDec "org.a11y.atspi.DeviceEventController"
63 #define AtspiDbusInterfaceDeviceEventListener "org.a11y.atspi.DeviceEventListener"
65 #define DirectReadingDBusName "org.tizen.ScreenReader"
66 #define DirectReadingDBusPath "/org/tizen/DirectReading"
67 #define DirectReadingDBusInterface "org.tizen.DirectReading"
72 * @brief Enumeration used for quering Accessibility objects
74 enum class MatchType : int32_t
84 * @brief Enumeration used for quering Accessibility objects
85 * SortOrder::Canonical uses breadth-first search and sort objects in order of indexes in parent
86 * SortOrder::ReverseCanonical uses SortOrder::Canonical and reverse collection
87 * The rest of orders is not supported.
89 enum class SortOrder : uint32_t
104 class CurrentBridgePtr
106 static Dali::Accessibility::Bridge*& get()
108 static thread_local Dali::Accessibility::Bridge* b = nullptr;
111 Dali::Accessibility::Bridge* prev;
112 CurrentBridgePtr( const CurrentBridgePtr& ) = delete;
113 CurrentBridgePtr( CurrentBridgePtr&& ) = delete;
114 CurrentBridgePtr& operator=( const CurrentBridgePtr& ) = delete;
115 CurrentBridgePtr& operator=( CurrentBridgePtr&& ) = delete;
118 CurrentBridgePtr( Dali::Accessibility::Bridge* b )
129 static Dali::Accessibility::Bridge* current()
138 template < typename T >
139 struct signature_accessible_impl : signature_helper<signature_accessible_impl<T>>
141 using subtype = std::pair< std::string, ObjectPath >;
143 static constexpr auto name_v = concat("AtspiAccessiblePtr");
144 static constexpr auto sig_v = concat("(so)");
147 * @brief Marshals value v as marshalled type into message
149 static void set( const DBusWrapper::MessageIterPtr& iter, T* t )
153 auto v = t->GetAddress();
154 signature< subtype >::set( iter, { v.GetBus(), ObjectPath{std::string{ ATSPI_PREFIX_PATH } +v.GetPath()} } );
158 signature< subtype >::set( iter, { "", ObjectPath{ ATSPI_NULL_PATH } } );
163 * @brief Marshals value from marshalled type into variable v
165 static bool get( const DBusWrapper::MessageIterPtr& iter, T*& v )
168 if( !signature< subtype >::get( iter, tmp ) )
173 if( tmp.second.value == ATSPI_NULL_PATH )
179 if( tmp.second.value.substr( 0, strlen( ATSPI_PREFIX_PATH ) ) != ATSPI_PREFIX_PATH )
184 auto b = CurrentBridgePtr::current();
185 if( b->GetBusName() != tmp.first )
190 v = b->FindByPath( tmp.second.value.substr( strlen( ATSPI_PREFIX_PATH ) ) );
196 struct signature< Dali::Accessibility::Accessible* > : public signature_accessible_impl< Dali::Accessibility::Accessible >
201 struct signature< Dali::Accessibility::Address > : signature_helper<signature<Dali::Accessibility::Address>>
203 using subtype = std::pair< std::string, ObjectPath >;
205 static constexpr auto name_v = concat("AtspiAccessiblePtr");
206 static constexpr auto sig_v = concat("(so)");
209 * @brief Marshals value v as marshalled type into message
211 static void set( const DBusWrapper::MessageIterPtr& iter, const Dali::Accessibility::Address& v )
215 signature< subtype >::set( iter, { v.GetBus(), ObjectPath{ std::string{ ATSPI_PREFIX_PATH } + v.GetPath() } } );
219 signature< subtype >::set( iter, { v.GetBus(), ObjectPath{ ATSPI_NULL_PATH } } );
224 * @brief Marshals value from marshalled type into variable v
226 static bool get( const DBusWrapper::MessageIterPtr& iter, Dali::Accessibility::Address& v )
229 if( !signature< subtype >::get( iter, tmp ) )
234 if( tmp.second.value == ATSPI_NULL_PATH )
239 if( tmp.second.value.substr( 0, strlen( ATSPI_PREFIX_PATH ) ) != ATSPI_PREFIX_PATH )
244 v = { std::move( tmp.first ), tmp.second.value.substr( strlen( ATSPI_PREFIX_PATH ) ) };
250 struct signature< Dali::Accessibility::States > : signature_helper<signature<Dali::Accessibility::States>>
252 using subtype = std::array<uint32_t, 2>;
254 static constexpr auto name_v = signature<subtype>::name_v;
255 static constexpr auto sig_v = signature<subtype>::sig_v;
258 * @brief Marshals value v as marshalled type into message
260 static void set( const DBusWrapper::MessageIterPtr& iter, const Dali::Accessibility::States& v )
262 signature< subtype >::set( iter, v.GetRawData() );
266 * @brief Marshals value from marshalled type into variable v
268 static bool get( const DBusWrapper::MessageIterPtr& iter, Dali::Accessibility::States& v )
271 if( !signature< subtype >::get( iter, tmp ) )
275 v = Dali::Accessibility::States{ tmp };
286 std::ostringstream tmp;
288 _Logger( const char* f, int l )
294 Dali::Integration::Log::LogMessage( Dali::Integration::Log::DebugInfo, "%s:%d: %s", file, line, tmp.str().c_str() );
297 template < typename T >
298 _Logger& operator<<( T&& t )
300 tmp << std::forward< T >( t );
307 template < typename T >
308 _LoggerEmpty& operator<<( T&& t )
319 _LoggerScope( const char* f, int l )
323 Dali::Integration::Log::LogMessage( Dali::Integration::Log::DebugInfo, "%s:%d: +", file, line );
328 Dali::Integration::Log::LogMessage( Dali::Integration::Log::DebugInfo, "%s:%d: -", file, line );
332 #define LOG() _Logger( __FILE__, __LINE__ )
333 #define SCOPE() _LoggerScope _l##__LINE__( __FILE__, __LINE__ )
335 #endif // DALI_INTERNAL_ATSPI_ACCESSIBILITY_COMMON_H