diff options
128 files changed, 27884 insertions, 0 deletions
@@ -0,0 +1,3 @@ +Brian Mattern <rephorm@rephorm.com> +Mathieu Taillefumier <mathieu.taillefumier@free.fr> +Mike Blumenkrantz (zmike/discomfitor) mike@zentific.com @@ -0,0 +1,20 @@ +Copyright (C) 2006 Brian Mattern and various contributors (see AUTHORS) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies of the Software, its documentation and marketing & publicity +materials, and acknowledgment shall be given in the documentation, materials +and software packages that this Software was used. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ChangeLog diff --git a/Doxyfile b/Doxyfile new file mode 100644 index 0000000..3d3346e --- /dev/null +++ b/Doxyfile @@ -0,0 +1,1252 @@ +# Doxyfile 1.4.7 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = e_dbus + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = 0.1.0 + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = doc + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, +# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, +# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, +# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, +# Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). + +USE_WINDOWS_ENCODING = NO + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = YES + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = src/ + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. + +JAVADOC_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = YES + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to +# include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = YES + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = YES + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = NO + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command <command> <input-file>, where <command> is the value of +# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = YES + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = e_dbus_doxy_warnings.txt + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = src/lib + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py + +FILE_PATTERNS = + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = doc/images/ + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command <filter> <input-file>, where <filter> +# is the value of the INPUT_FILTER tag, and <input-file> is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentstion. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = e_ E_ + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = doc/head.html + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = doc/foot.html + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = doc/e.css + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = YES + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = YES + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED =__UNUSED__= + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = YES + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = YES + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a caller dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable caller graphs for selected +# functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that a graph may be further truncated if the graph's +# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH +# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), +# the graph is not depth-constrained. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO @@ -0,0 +1,302 @@ +Installation Instructions +************************* + +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, +2006, 2007, 2008, 2009 Free Software Foundation, Inc. + + This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. + +Basic Installation +================== + + Briefly, the shell commands `./configure; make; make install' should +configure, build, and install this package. The following +more-detailed instructions are generic; see the `README' file for +instructions specific to this package. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. Caching is +disabled by default to prevent problems with accidental use of stale +cache files. + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You need `configure.ac' if +you want to change it or regenerate `configure' using a newer version +of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. + + Running `configure' might take a while. While running, it prints + some messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + + 6. Often, you can also type `make uninstall' to remove the installed + files again. + +Compilers and Options +===================== + + Some systems require unusual options for compilation or linking that +the `configure' script does not know about. Run `./configure --help' +for details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c99 CFLAGS=-g LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + + You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you can use GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + With a non-GNU `make', it is safer to compile the package for one +architecture at a time in the source code directory. After you have +installed the package for one architecture, use `make distclean' before +reconfiguring for another architecture. + + On MacOS X 10.5 and later systems, you can create libraries and +executables that work on multiple system types--known as "fat" or +"universal" binaries--by specifying multiple `-arch' options to the +compiler but only a single `-arch' option to the preprocessor. Like +this: + + ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ + CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ + CPP="gcc -E" CXXCPP="g++ -E" + + This is not guaranteed to produce working output in all cases, you +may have to build one architecture at a time and combine the results +using the `lipo' tool if you have problems. + +Installation Names +================== + + By default, `make install' installs the package's commands under +`/usr/local/bin', include files under `/usr/local/include', etc. You +can specify an installation prefix other than `/usr/local' by giving +`configure' the option `--prefix=PREFIX'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +pass the option `--exec-prefix=PREFIX' to `configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=DIR' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + + Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Particular systems +================== + + On HP-UX, the default C compiler is not ANSI C compatible. If GNU +CC is not installed, it is recommended to use the following options in +order to use an ANSI C compiler: + + ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" + +and if that doesn't work, install pre-built binaries of GCC for HP-UX. + + On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot +parse its `<wchar.h>' header file. The option `-nodtk' can be used as +a workaround. If GNU CC is not installed, it is therefore recommended +to try + + ./configure CC="cc" + +and if that doesn't work, try + + ./configure CC="cc -nodtk" + + On Solaris, don't put `/usr/ucb' early in your `PATH'. This +directory contains several dysfunctional programs; working variants of +these programs are available in `/usr/bin'. So, if you need `/usr/ucb' +in your `PATH', put it _after_ `/usr/bin'. + + On Haiku, software installed for all users goes in `/boot/common', +not `/usr/local'. It is recommended to use the following options: + + ./configure --prefix=/boot/common + +Specifying the System Type +========================== + + There may be some features `configure' cannot figure out +automatically, but needs to determine by the type of machine the package +will run on. Usually, assuming the package is built to be run on the +_same_ architectures, `configure' can figure that out, but if it prints +a message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS + KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option `--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + + If you want to set default values for `configure' scripts to share, +you can create a site shell script called `config.site' that gives +default values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + + Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). + +Unfortunately, this technique does not work for `CONFIG_SHELL' due to +an Autoconf bug. Until the bug is fixed you can use this workaround: + + CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash + +`configure' Invocation +====================== + + `configure' recognizes the following options to control how it +operates. + +`--help' +`-h' + Print a summary of all of the options to `configure', and exit. + +`--help=short' +`--help=recursive' + Print a summary of the options unique to this package's + `configure', and exit. The `short' variant lists options used + only in the top level, while the `recursive' variant lists options + also present in any nested packages. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`--prefix=DIR' + Use DIR as the installation prefix. *Note Installation Names:: + for more details, including other options available for fine-tuning + the installation locations. + +`--no-create' +`-n' + Run the configure checks, but stop before creating any output + files. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..9e69a2c --- /dev/null +++ b/Makefile.am @@ -0,0 +1,31 @@ +ACLOCAL_AMFLAGS = -I m4 + +SUBDIRS = src + +MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess \ + config.log config.sub configure depcomp \ + install-sh ltmain.sh missing compile + +pkgconfigdir = $(libdir)/pkgconfig + +if BUILD_EHAL +EHAL_PC = ehal.pc +endif +if BUILD_ENOTIFY +ENOTIFY_PC = enotify.pc +endif +if BUILD_ECONNMAN +ECONNMAN_PC = econnman.pc +endif +if BUILD_EBLUEZ +EBLUEZ_PC = ebluez.pc +endif +if BUILD_EOFONO +EOFONO_PC = eofono.pc +endif +if BUILD_EUKIT +EUKIT_PC = eukit.pc +endif +pkgconfig_DATA = edbus.pc $(EHAL_PC) $(ENOTIFY_PC) $(ECONNMAN_PC) $(EBLUEZ_PC) $(EOFONO_PC) $(EUKIT_PC) + +EXTRA_DIST = e_dbus.spec @@ -0,0 +1,19 @@ +e_dbus v0.01 + +Requirements: +------------- + +Must: + libc libdbus ecore + +This is the start of some basic convenience wrappers around dbus to ease integrating dbus with EFL based applications. + +When using e_dbus, direct use of the low level dbus api is still heavily required for processing messages. + +A few things to note: + +e_dbus_bus_get() currently creates a new private connection to whichever bus is passed in, and hooks this into the ecore main loop. At some point, we should implement internal refcounting and sharing of these private connections (one for each bus type) so that e.g. multiple modules in an app can reuse the same connection. libdbus implements its own shared connections (available via dbus_bus_get()), but the final reference is always retained by libdbus iteself, causing any cleanup handlers on the connection to only be called at app exit. Thus, if a module hooks a connection in to the mainloop, there is no way to clean up fully before unloading the module, causing issues. + +This code is still in its infancy, and although works, may have some rough edges. The design is not set in stone, so feel free to propose (and implement) changes / improvements. + +Patches can be sent to the enlightenment dev mailing list, or, if you have commit access, feel free to commit. diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..11b419b --- /dev/null +++ b/autogen.sh @@ -0,0 +1,14 @@ +#! /bin/sh + +rm -rf autom4te.cache +rm -f aclocal.m4 ltmain.sh + +echo "Running aclocal..." ; aclocal $ACLOCAL_FLAGS -I m4 || exit 1 +echo "Running autoheader..."; autoheader || exit 1 +echo "Running libtoolize..."; (libtoolize --copy --automake || glibtoolize --automake) || exit 1 +echo "Running automake..."; automake --gnu --add-missing --copy || exit 1 +echo "Running autoconf..."; autoconf || exit 1 + +if [ -z "$NOCONFIGURE" ] ; then + ./configure "$@" +fi diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..f8b33af --- /dev/null +++ b/configure.ac @@ -0,0 +1,213 @@ +# get rid of that stupid cache mechanism +rm -f config.cache + +AC_INIT([e_dbus], [0.5.0.063], [enlightenment-devel@lists.sourceforge.net]) +release="ver-pre-svn-05" +AC_PREREQ([2.52]) +AC_CONFIG_SRCDIR([configure.ac]) +AC_CONFIG_MACRO_DIR([m4]) +AC_CANONICAL_BUILD +AC_CANONICAL_HOST + +AM_INIT_AUTOMAKE([1.6 dist-bzip2]) +AM_CONFIG_HEADER([config.h]) +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) + +AC_PROG_CC +AC_HEADER_STDC +AM_PROG_CC_C_O +AC_C___ATTRIBUTE__ + +AC_LIBTOOL_WIN32_DLL +define([AC_LIBTOOL_LANG_CXX_CONFIG], [:])dnl +define([AC_LIBTOOL_LANG_F77_CONFIG], [:])dnl +AC_PROG_LIBTOOL + +VMAJ=`echo $PACKAGE_VERSION | awk -F. '{printf("%s", $1);}'` +VMIN=`echo $PACKAGE_VERSION | awk -F. '{printf("%s", $2);}'` +VMIC=`echo $PACKAGE_VERSION | awk -F. '{printf("%s", $3);}'` +SNAP=`echo $PACKAGE_VERSION | awk -F. '{printf("%s", $4);}'` +version_info=`expr $VMAJ + $VMIN`":$VMIC:$VMIN" +econnman_release_info="-release $release" +ebluez_release_info="-release $release" +eofono_release_info="-release $release" +edbus_release_info="-release $release" +ehal_release_info="-release $release" +eukit_release_info="-release $release" +enotify_release_info="-release $release" +AC_SUBST(version_info) +AC_SUBST(econnman_release_info) +AC_SUBST(ebluez_release_info) +AC_SUBST(eofono_release_info) +AC_SUBST(edbus_release_info) +AC_SUBST(ehal_release_info) +AC_SUBST(eukit_release_info) +AC_SUBST(enotify_release_info) + +want_ehal="yes" +want_econnman="yes" +want_ebluez="yes" +want_eofono="yes" +want_enotify="yes" +want_eukit="yes" + +case "$host_os" in + mingw*) + want_ehal="no" + want_econnman="no" + want_ebluez="no" + want_eofono="no" + want_enotify="no" + want_eukit="no" + ;; +esac + +dnl Check enabled modules to build +AC_ARG_ENABLE([ehal], + [AC_HELP_STRING([--disable-ehal], [Disable ehal build])], + [enable_ehal=$enableval], + [enable_ehal="${want_ehal}"]) + +AC_ARG_ENABLE([econnman], + [AC_HELP_STRING([--enable-econnman], [Enable econnman build])], + [enable_econnman=$enableval], + [enable_econnman="${want_econnman}"]) + +AC_ARG_ENABLE([ebluez], + [AC_HELP_STRING([--enable-ebluez], [Enable ebluez build])], + [enable_ebluez=$enableval], + [enable_ebluez="${want_ebluez}"]) + +AC_ARG_ENABLE([eofono], + [AC_HELP_STRING([--enable-eofono], [Enable eofono build])], + [enable_eofono=$enableval], + [enable_eofono="${want_eofono}"]) + +AC_ARG_ENABLE([enotify], + [AC_HELP_STRING([--disable-enotify], [Disable enotify build])], + [enable_enotify=$enableval], + [enable_enotify="${want_enotify}"]) + +AC_ARG_ENABLE([eukit], + [AC_HELP_STRING([--disable-eukit], [Disable eukit build])], + [enable_eukit=$enableval], + [enable_eukit="${want_eukit}"]) + +# pkg-config +PKG_PROG_PKG_CONFIG + +# Check whether pkg-config supports Requires.private +if $PKG_CONFIG --atleast-pkgconfig-version 0.22 ; then + pkgconfig_requires_private="Requires.private" +else + pkgconfig_requires_private="Requires" +fi +AC_SUBST(pkgconfig_requires_private) + +PKG_CHECK_MODULES([EINA], [eina-0]) + +PKG_CHECK_MODULES([EDBUS], [ + dbus-1 >= 0.62 + ecore >= 0.9.9 +]) + +##### Find out the version of DBUS we're using +dbus_version=`pkg-config --modversion dbus-1` +DBUS_VERSION_MAJOR=`echo $dbus_version | awk -F. '{print $1}'` +DBUS_VERSION_MINOR=`echo $dbus_version | awk -F. '{print $2}'` +DBUS_VERSION_MICRO=`echo $dbus_version | awk -F. '{print $3}'` + +if test "z$DBUS_VERSION_MAJOR" = "z" ; then + DBUS_VERSION_MAJOR="0" +fi + +if test "z$DBUS_VERSION_MINOR" = "z" ; then + DBUS_VERSION_MINOR="0" +fi + +if test "z$DBUS_VERSION_MICRO" = "z" ; then + DBUS_VERSION_MICRO="0" +fi + +DBUS_VERSION_CFLAGS="$DBUS_VERSION_CFLAGS -DDBUS_VERSION_MAJOR=$DBUS_VERSION_MAJOR" +DBUS_VERSION_CFLAGS="$DBUS_VERSION_CFLAGS -DDBUS_VERSION_MINOR=$DBUS_VERSION_MINOR" +DBUS_VERSION_CFLAGS="$DBUS_VERSION_CFLAGS -DDBUS_VERSION_MICRO=$DBUS_VERSION_MICRO" +AC_SUBST(DBUS_VERSION_CFLAGS) + +AC_FUNC_ALLOCA + +dnl evas +if test "x${enable_enotify}" = "xyes" ; then + PKG_CHECK_MODULES(EVAS, [evas >= 0.9.9], [], [enable_enotify="no"]) +fi + +AM_CONDITIONAL([BUILD_EHAL], [test "x${enable_ehal}" = "xyes"]) +AM_CONDITIONAL([BUILD_EUKIT], [test "x${enable_eukit}" = "xyes"]) +AM_CONDITIONAL([BUILD_ENOTIFY], [test "x${enable_enotify}" = "xyes"]) +AM_CONDITIONAL([BUILD_ECONNMAN], [test "x${enable_econnman}" = "xyes"]) +AM_CONDITIONAL([BUILD_EBLUEZ], [test "x${enable_ebluez}" = "xyes"]) +AM_CONDITIONAL([BUILD_EOFONO], [test "x${enable_eofono}" = "xyes"]) + +EFL_EDBUS_BUILD="" +lt_enable_auto_import="" +case "$host_os" in + mingw*) + EFL_EDBUS_BUILD="-DEFL_EDBUS_BUILD" + lt_enable_auto_import="-Wl,--enable-auto-import" + ;; +esac +AC_SUBST(EFL_EDBUS_BUILD) +AC_SUBST(lt_enable_auto_import) + +AC_OUTPUT([ +e_dbus.spec +Makefile +src/Makefile +src/lib/Makefile +src/lib/dbus/Makefile +src/lib/hal/Makefile +src/lib/ukit/Makefile +src/lib/notification/Makefile +src/lib/connman/Makefile +src/lib/bluez/Makefile +src/lib/ofono/Makefile +src/bin/Makefile +edbus.pc +ehal.pc +eukit.pc +enotify.pc +econnman.pc +ebluez.pc +eofono.pc +]) + + +##################################################################### +## Info + +echo +echo +echo +echo "------------------------------------------------------------------------" +echo "$PACKAGE $VERSION" +echo "------------------------------------------------------------------------" +echo +echo "Configuration Options Summary:" +echo +echo " Modules:" +echo +echo " EHal...............: $enable_ehal" +echo " EUkit..............: $enable_eukit" +echo " EConnman...........: $enable_econnman" +echo " EBluez.............: $enable_ebluez" +echo " EOfono.............: $enable_eofono" +echo " ENotify............: $enable_enotify" +echo +echo "Compilation............: make (or gmake)" +echo " CPPFLAGS.............: $CPPFLAGS" +echo " CFLAGS...............: $CFLAGS" +echo " LDFLAGS..............: $LDFLAGS" +echo +echo "Installation...........: make install (as root if needed, with 'su' or 'sudo')" +echo " prefix...............: $prefix" +echo diff --git a/debian/SVN_REV b/debian/SVN_REV new file mode 100644 index 0000000..94aa019 --- /dev/null +++ b/debian/SVN_REV @@ -0,0 +1,2 @@ +Revision 48959 +Last Changed Rev 48851 diff --git a/debian/_original/changelog b/debian/_original/changelog new file mode 100644 index 0000000..037b44c --- /dev/null +++ b/debian/_original/changelog @@ -0,0 +1,11 @@ +edbus (0.5.0.060+svnYYYYMMDD-1) unstable; urgency=low + + * New version + + -- quaker <quaker66@gmail.com> Thu, 22 Apr 2009 18:13:37 +0100 + +edbus (0.5.0.050+svnYYYYMMDD-1) unstable; urgency=low + + * Clean up changelog + + -- quaker <quaker66@gmail.com> Tue, 21 Apr 2009 19:16:16 +0100 diff --git a/debian/_original/compat b/debian/_original/compat new file mode 100644 index 0000000..1e8b314 --- /dev/null +++ b/debian/_original/compat @@ -0,0 +1 @@ +6 diff --git a/debian/_original/control b/debian/_original/control new file mode 100644 index 0000000..b3c4bd1 --- /dev/null +++ b/debian/_original/control @@ -0,0 +1,31 @@ +Source: edbus +Section: libs +Priority: optional +Maintainer: Debian Pkg-e Team <pkg-e-devel@lists.alioth.debian.org> +Uploaders: Albin Tonnerre <albin.tonnerre@gmail.com>, Niv Sardi <xaiki@debian.org>, + Xavier Oswald <x.oswald@free.fr>, Jan Lübbe <jluebbe@debian.org> +Build-Depends: debhelper (>= 6), cdbs, libecore-dev, libdbus-1-dev, + libevas-dev, libeina-dev (>= 0.0.2.060+svnYYYYMMDD), pkg-config, libtool +Standards-Version: 3.8.1 +Homepage: http://enlightenment.org + +Package: libedbus-dev +Section: libdevel +Architecture: any +Depends: ${misc:Depends}, libedbus-svn-01 (= ${binary:Version}), libdbus-1-dev, + libeina-dev, libecore-dev, libevas-dev +Description: D-Bus and HAL wrapper libraries for use with the EFL - Development files + Wrappers around D-Bus to ease integrating D-Bus with EFL based applications. + . + This packages contains headers and static libraries for libedbus, libehal and + libenotify + +Package: libedbus-svn-01 +Conflicts: libedbus0 +Architecture: any +Depends: ${misc:Depends}, ${shlibs:Depends} +Description: D-Bus and HAL wrapper libraries for use with the EFL + This package contains: + - libedbus0 and libehal0 : D-Bus and HAL-related wrappers to ease integrating + D-Bus and HAL with EFL-based applications + - libenotify0 : provides an EFL-based notification support diff --git a/debian/_original/copyright b/debian/_original/copyright new file mode 100644 index 0000000..7fcb64d --- /dev/null +++ b/debian/_original/copyright @@ -0,0 +1,46 @@ +This package was debianized by Debian Pkg-e Team <pkg-e-devel@lists.alioth.debian.org> +Wed, 27 Feb 2008 23:07:21 +0000 + +It was downloaded from http://download.enlightenment.org/snapshots/LATEST/ + +Upstream Author: Brian Mattern <rephorm@rephorm.com> + +Copyright: + + Copyright (C) 2006 Brian Mattern and various contributors + +License: + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies of the Software and its Copyright notices. In addition publicly + documented acknowledgment must be given that this software has been used if no + source code of this software is made available publicly. This includes + acknowledgments in either Copyright notices, Manuals, Publicity and Marketing + documents or any documentation provided with any product containing this + software. This License does not apply to any software that links to the + libraries provided by this software (statically or dynamically), but only to + the software provided. + + Please see the COPYING.PLAIN for a plain-english explanation of this notice + and it's intent. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +On Debian systems, the complete text of the BSD License can be found +in `/usr/share/common-licenses/BSD'. + +The Debian packaging is: + (C) 2006 2007,Debian Pkg-e Team <pkg-e-devel@lists.alioth.debian.org> +and is licensed under the GPL, see `/usr/share/common-licenses/GPL'. diff --git a/debian/_original/libedbus-dev.install b/debian/_original/libedbus-dev.install new file mode 100644 index 0000000..0f03228 --- /dev/null +++ b/debian/_original/libedbus-dev.install @@ -0,0 +1,13 @@ +debian/tmp/usr/include/E_DBus.h +debian/tmp/usr/include/E_Hal.h +debian/tmp/usr/include/E_Notification_Daemon.h +debian/tmp/usr/include/E_Notify.h +debian/tmp/usr/lib/pkgconfig/edbus.pc +debian/tmp/usr/lib/pkgconfig/ehal.pc +debian/tmp/usr/lib/pkgconfig/enotify.pc +debian/tmp/usr/lib/libedbus.a +debian/tmp/usr/lib/libehal.a +debian/tmp/usr/lib/libenotify.a +debian/tmp/usr/lib/libedbus.so +debian/tmp/usr/lib/libehal.so +debian/tmp/usr/lib/libenotify.so diff --git a/debian/_original/libedbus-svn-01.install b/debian/_original/libedbus-svn-01.install new file mode 100644 index 0000000..8b5e8ed --- /dev/null +++ b/debian/_original/libedbus-svn-01.install @@ -0,0 +1,3 @@ +debian/tmp/usr/lib/libedbus-*.so.* +debian/tmp/usr/lib/libehal-*.so.* +debian/tmp/usr/lib/libenotify-*.so.* diff --git a/debian/_original/libedbus-svn-01.shlibs b/debian/_original/libedbus-svn-01.shlibs new file mode 100644 index 0000000..f9c4d77 --- /dev/null +++ b/debian/_original/libedbus-svn-01.shlibs @@ -0,0 +1,3 @@ +libedbus-ver-pre-svn-01 0 libedbus-svn-01 (>= 0.5.0.060+svnYYYYMMDD) +libehal-ver-pre-svn-01 0 libedbus-svn-01 (>= 0.5.0.060+svnYYYYMMDD) +libenotify-ver-pre-svn-01 0 libedbus-svn-01 (>= 0.5.0.060+svnYYYYMMDD) diff --git a/debian/_original/rules b/debian/_original/rules new file mode 100755 index 0000000..e228d34 --- /dev/null +++ b/debian/_original/rules @@ -0,0 +1,13 @@ +#!/usr/bin/make -f + +include /usr/share/cdbs/1/rules/debhelper.mk +include /usr/share/cdbs/1/class/autotools.mk + +DEB_CONFIGURE_SCRIPT := ./autogen.sh +DEB_MAKE_CLEAN_TARGET := distclean +DEB_CONFIGURE_EXTRA_FLAGS := --disable-rpath +CFLAGS += -fvisibility=hidden +LDFLAGS += -fvisibility=hidden + +clean:: + [ ! -f Makefile ] || make distclean diff --git a/doc/e.css b/doc/e.css new file mode 100644 index 0000000..a9f6f64 --- /dev/null +++ b/doc/e.css @@ -0,0 +1,161 @@ +body { + background: url("images/b.png"); + background-repeat: repeat-x; + background-position: top left; + background-color: #f4f4f4; + text-align: center; + font-family: sans-serif; + padding: 0; + margin: 0; +} + +div.main { + margin: 1em auto; + vertical-align: top; + font-family: "Bitstream Vera", "Vera", "Trebuchet MS", Trebuchet, Tahoma, sans-serif; + color: #444444; + font-size: 0.8em; + text-align: justify; + width: 80%; +} + +td.t { background-image:url("images/t.gif"); } +td.t[class] { background-image:url("images/t.png"); } +td.tl { background-image:url("images/tl.gif"); } +td.tl[class] { background-image:url("images/tl.png"); } + +td.nav, td.lnav, td.rnav { + align: middle; + text-align: center; + vertical-align: middle; + width: 100px; + height: 25px; + font-family: "Bitstream Vera", "Vera", "Trebuchet MS", Trebuchet, Tahoma, sans-serif; + color: #000000; + font-size: 9px; + font-weight: bold; + white-space: no-wrap; +} + +td.lnav[class] { background-image:url("images/n.png"); } +td.lnav[class] { background-image:url("images/n.png"); } +td.rnav { background-image:url("images/n.gif"); } +td.rnav[class] { background-image:url("images/n.png"); } + +hr { + width: 200px; + height: 1px; + background: #dddddd; + border: 0; +} + +p { color: #444444 ;} +p.tiny, small { + color: #888888; + font-size: 0.5em; +} + +h1 { + text-align: center; + font-size: 1.3em; +} + +h2 { font-size: 1.1em; } +h3 { font-size: 0.9em; } + +span.keyword { color: #008000; } +span.keywordtype { color: #604020; } +span.keywordflow { color: #e08000; } +span.comment { color: #800000; } +span.preprocessor { color: #806020; } +span.stringliteral { color: #002080; } +span.charliteral { color: #008080; } + +a:link { + color: #445566; + text-decoration: underline; +} + +a:visited { + color: #667788; + text-decoration: underline; +} + +a:active { + color: #88cccc; + text-decoration: none; +} + +a:hover { + color: #112266; + text-decoration: underline; +} + +a.nav { + text-decoration: none; + display: block; +} + +a.nav:link, a.nav:visited { color: #888888; } +a.nav:active { color: #000000; } +a.nav:hover { color: #444444; } +a.code:link, a.code:visited { text-decoration: none; } + +div.fragment { + font-size: 1em; + border: 1px dotted #cccccc; + background-color: #ffffff; + text-align: left; + vertical-align: middle; + padding: 2px; + margin-left: 25px; + margin-right: 25px; + overflow: auto; +} + +td.indexkey { + font-weight: bold; + padding-left: 10px; + padding-right: 0; + padding-top: 2px; + padding-bottom: 0px; + margin: 0; + margin-top: 2px; + margin-bottom: 2px; + border: 1px dotted #cccccc; + border-right: 0px dotted #cccccc; +} + +td.indexvalue { + font-style: italic; + padding-right: 10px; + padding-left: 0; + padding-top: 2px; + padding-bottom: 2px; + margin: 0; + margin-top: 2px; + margin-bottom: 2px; + border: 1px dotted #cccccc; + border-left: 0px dotted #cccccc; +} + +.mdescRight { font-style: italic; } +.memitem { + padding-left: 2px; + padding-right: 2px; + border: 1px dotted #cccccc; + background-color: #ffffff; +} +.memname { + white-space: nowrap; + font-weight: bold; +} +.paramname { font-weight: normal; } + +div.ah { + border: thin solid #888888; + font-weight: bold; + margin-bottom: 3px; + margin-top: 3px; +} + diff --git a/doc/foot.html b/doc/foot.html new file mode 100644 index 0000000..0d3303d --- /dev/null +++ b/doc/foot.html @@ -0,0 +1,6 @@ + </div> + <hr /> + <p class="tiny">Copyright © Enlightenment.org</p> + <p class="tiny">$projectname Documentation Generated: $datetime</p> + </body> +</html> diff --git a/doc/head.html b/doc/head.html new file mode 100644 index 0000000..1e8e960 --- /dev/null +++ b/doc/head.html @@ -0,0 +1,43 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html> + <head> + <title>$title</title> + <link href="e.css" rel="stylesheet" type="text/css" /> + </head> + +<body> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td class="t" width="50%" valign="top" align="left"> + <table width="100px" height="100px" border="0" cellpadding="0" cellspacing="0"> + <tr><td class="lnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=index">Home</a></td></tr> + <tr><td class="lnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=news">News</a></td></tr> + <tr><td class="lnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=about">About</a></td></tr> + <tr><td class="rnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=download">Download</a></td></tr> + </table> + </td> + <td class="tl" width="612" height="250" valign="bottom" align="center"> + <img src="images/_.gif" width="612" height="1"/> + <table border="0" cellpadding="0" cellspacing="4px"> + <tr> + <td class='nav'><a class='nav' href="index.html">Main Page</a></td> + <td class="nav"><a class="nav" href="annotated.html">Data Structures</a></td> + <td class="nav"><a class="nav" href="classes.html">Index</a></td> + </tr> + </table> + <hr /> + </td> + <td class="t" width="50%" valign="top" align="right"> + <table width="100px" height="100px" border="0" cellpadding="0" cellspacing="0"> + <tr><td class="rnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=support">Support</a></td></tr> + <tr><td class="lnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=contribute">Contribute</a></td></tr> + <tr><td class="lnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=contact">Contact</a></td></tr> + <tr><td class="lnav"><a class="nav" href="http://trac.enlightenment.org/e">Tracker</a></td></tr> + </table> + </td> + </tr> + </table> + + <div class="main"> diff --git a/doc/images/_.gif b/doc/images/_.gif Binary files differnew file mode 100644 index 0000000..60fa7a1 --- /dev/null +++ b/doc/images/_.gif diff --git a/doc/images/b.png b/doc/images/b.png Binary files differnew file mode 100644 index 0000000..6fbfc2b --- /dev/null +++ b/doc/images/b.png diff --git a/doc/images/e.css b/doc/images/e.css new file mode 100644 index 0000000..a9f6f64 --- /dev/null +++ b/doc/images/e.css @@ -0,0 +1,161 @@ +body { + background: url("images/b.png"); + background-repeat: repeat-x; + background-position: top left; + background-color: #f4f4f4; + text-align: center; + font-family: sans-serif; + padding: 0; + margin: 0; +} + +div.main { + margin: 1em auto; + vertical-align: top; + font-family: "Bitstream Vera", "Vera", "Trebuchet MS", Trebuchet, Tahoma, sans-serif; + color: #444444; + font-size: 0.8em; + text-align: justify; + width: 80%; +} + +td.t { background-image:url("images/t.gif"); } +td.t[class] { background-image:url("images/t.png"); } +td.tl { background-image:url("images/tl.gif"); } +td.tl[class] { background-image:url("images/tl.png"); } + +td.nav, td.lnav, td.rnav { + align: middle; + text-align: center; + vertical-align: middle; + width: 100px; + height: 25px; + font-family: "Bitstream Vera", "Vera", "Trebuchet MS", Trebuchet, Tahoma, sans-serif; + color: #000000; + font-size: 9px; + font-weight: bold; + white-space: no-wrap; +} + +td.lnav[class] { background-image:url("images/n.png"); } +td.lnav[class] { background-image:url("images/n.png"); } +td.rnav { background-image:url("images/n.gif"); } +td.rnav[class] { background-image:url("images/n.png"); } + +hr { + width: 200px; + height: 1px; + background: #dddddd; + border: 0; +} + +p { color: #444444 ;} +p.tiny, small { + color: #888888; + font-size: 0.5em; +} + +h1 { + text-align: center; + font-size: 1.3em; +} + +h2 { font-size: 1.1em; } +h3 { font-size: 0.9em; } + +span.keyword { color: #008000; } +span.keywordtype { color: #604020; } +span.keywordflow { color: #e08000; } +span.comment { color: #800000; } +span.preprocessor { color: #806020; } +span.stringliteral { color: #002080; } +span.charliteral { color: #008080; } + +a:link { + color: #445566; + text-decoration: underline; +} + +a:visited { + color: #667788; + text-decoration: underline; +} + +a:active { + color: #88cccc; + text-decoration: none; +} + +a:hover { + color: #112266; + text-decoration: underline; +} + +a.nav { + text-decoration: none; + display: block; +} + +a.nav:link, a.nav:visited { color: #888888; } +a.nav:active { color: #000000; } +a.nav:hover { color: #444444; } +a.code:link, a.code:visited { text-decoration: none; } + +div.fragment { + font-size: 1em; + border: 1px dotted #cccccc; + background-color: #ffffff; + text-align: left; + vertical-align: middle; + padding: 2px; + margin-left: 25px; + margin-right: 25px; + overflow: auto; +} + +td.indexkey { + font-weight: bold; + padding-left: 10px; + padding-right: 0; + padding-top: 2px; + padding-bottom: 0px; + margin: 0; + margin-top: 2px; + margin-bottom: 2px; + border: 1px dotted #cccccc; + border-right: 0px dotted #cccccc; +} + +td.indexvalue { + font-style: italic; + padding-right: 10px; + padding-left: 0; + padding-top: 2px; + padding-bottom: 2px; + margin: 0; + margin-top: 2px; + margin-bottom: 2px; + border: 1px dotted #cccccc; + border-left: 0px dotted #cccccc; +} + +.mdescRight { font-style: italic; } +.memitem { + padding-left: 2px; + padding-right: 2px; + border: 1px dotted #cccccc; + background-color: #ffffff; +} +.memname { + white-space: nowrap; + font-weight: bold; +} +.paramname { font-weight: normal; } + +div.ah { + border: thin solid #888888; + font-weight: bold; + margin-bottom: 3px; + margin-top: 3px; +} + diff --git a/doc/images/foot.html b/doc/images/foot.html new file mode 100644 index 0000000..0d3303d --- /dev/null +++ b/doc/images/foot.html @@ -0,0 +1,6 @@ + </div> + <hr /> + <p class="tiny">Copyright © Enlightenment.org</p> + <p class="tiny">$projectname Documentation Generated: $datetime</p> + </body> +</html> diff --git a/doc/images/head.html b/doc/images/head.html new file mode 100644 index 0000000..1e8e960 --- /dev/null +++ b/doc/images/head.html @@ -0,0 +1,43 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html> + <head> + <title>$title</title> + <link href="e.css" rel="stylesheet" type="text/css" /> + </head> + +<body> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td class="t" width="50%" valign="top" align="left"> + <table width="100px" height="100px" border="0" cellpadding="0" cellspacing="0"> + <tr><td class="lnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=index">Home</a></td></tr> + <tr><td class="lnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=news">News</a></td></tr> + <tr><td class="lnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=about">About</a></td></tr> + <tr><td class="rnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=download">Download</a></td></tr> + </table> + </td> + <td class="tl" width="612" height="250" valign="bottom" align="center"> + <img src="images/_.gif" width="612" height="1"/> + <table border="0" cellpadding="0" cellspacing="4px"> + <tr> + <td class='nav'><a class='nav' href="index.html">Main Page</a></td> + <td class="nav"><a class="nav" href="annotated.html">Data Structures</a></td> + <td class="nav"><a class="nav" href="classes.html">Index</a></td> + </tr> + </table> + <hr /> + </td> + <td class="t" width="50%" valign="top" align="right"> + <table width="100px" height="100px" border="0" cellpadding="0" cellspacing="0"> + <tr><td class="rnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=support">Support</a></td></tr> + <tr><td class="lnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=contribute">Contribute</a></td></tr> + <tr><td class="lnav"><a class="nav" href="http://web.enlightenment.org/p.php?p=contact">Contact</a></td></tr> + <tr><td class="lnav"><a class="nav" href="http://trac.enlightenment.org/e">Tracker</a></td></tr> + </table> + </td> + </tr> + </table> + + <div class="main"> diff --git a/doc/images/n.gif b/doc/images/n.gif Binary files differnew file mode 100644 index 0000000..8c3148f --- /dev/null +++ b/doc/images/n.gif diff --git a/doc/images/n.png b/doc/images/n.png Binary files differnew file mode 100644 index 0000000..6d80004 --- /dev/null +++ b/doc/images/n.png diff --git a/doc/images/t.gif b/doc/images/t.gif Binary files differnew file mode 100644 index 0000000..cff3068 --- /dev/null +++ b/doc/images/t.gif diff --git a/doc/images/t.png b/doc/images/t.png Binary files differnew file mode 100644 index 0000000..5a40479 --- /dev/null +++ b/doc/images/t.png diff --git a/doc/images/tl.gif b/doc/images/tl.gif Binary files differnew file mode 100644 index 0000000..c5e973a --- /dev/null +++ b/doc/images/tl.gif diff --git a/doc/images/tl.png b/doc/images/tl.png Binary files differnew file mode 100644 index 0000000..b14a7f1 --- /dev/null +++ b/doc/images/tl.png diff --git a/e_dbus.spec.in b/e_dbus.spec.in new file mode 100644 index 0000000..354ea68 --- /dev/null +++ b/e_dbus.spec.in @@ -0,0 +1,66 @@ +%define _missing_doc_files_terminate_build 0 + +%{!?_rel:%{expand:%%global _rel 0.r%(svnversion | sed 's/[^0-9].*$//' || echo 0000)}} + +Summary: EFL Wrapper for DBus +Name: @PACKAGE@ +Version: @VERSION@ +Release: %{_rel} +License: BSD +Group: System Environment/Libraries +URL: http://www.enlightenment.org/ +Source: %{name}-%{version}.tar.gz +Packager: %{?_packager:%{_packager}}%{!?_packager:Michael Jennings <mej@eterm.org>} +Vendor: %{?_vendorinfo:%{_vendorinfo}}%{!?_vendorinfo:The Enlightenment Project (http://www.enlightenment.org/)} +Distribution: %{?_distribution:%{_distribution}}%{!?_distribution:%{_vendor}} +Obsoletes: ecore-dbus <= 0.9.9.040 +BuildRoot: %{_tmppath}/%{name}-%{version}-root + +%description +e_dbus provides a convenience wrapper for EFL applications using DBus. + +%package devel +Summary: e_dbus headers, static libraries, documentation and test programs +Group: System Environment/Libraries +Requires: %{name} = %{version} + +%description devel +Headers, static libraries, test programs and documentation for e_dbus + +%prep +%setup -q + +%build +%{configure} --prefix=%{_prefix} +%{__make} %{?_smp_mflags} %{?mflags} + +%install +%{__make} %{?mflags_install} DESTDIR=$RPM_BUILD_ROOT install + +# Get rid of unneeded testing cruft. +%{__rm} -rf $RPM_BUILD_ROOT%{_datadir}/%{name} + +%clean +test "x$RPM_BUILD_ROOT" != "x/" && rm -rf $RPM_BUILD_ROOT + +%post +/sbin/ldconfig + +%postun +/sbin/ldconfig + +%files +%defattr(-, root, root) +%doc AUTHORS COPYING* README +%{_bindir}/* +%{_libdir}/*.so.* + +%files devel +%defattr(-, root, root) +%{_includedir}/*.h +%{_libdir}/*.so +%{_libdir}/*.la +%{_libdir}/*.a +%{_libdir}/pkgconfig/* + +%changelog diff --git a/ebluez.pc.in b/ebluez.pc.in new file mode 100644 index 0000000..4164376 --- /dev/null +++ b/ebluez.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: ebluez +Description: bluetooth device manager (bluez) +@pkgconfig_requires_private@: ecore edbus +Version: @VERSION@ +Libs: -L${libdir} -lebluez +Cflags: -I${includedir} diff --git a/econnman.pc.in b/econnman.pc.in new file mode 100644 index 0000000..c306ee6 --- /dev/null +++ b/econnman.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: econnman +Description: network connection manager (connman) +@pkgconfig_requires_private@: ecore edbus +Version: @VERSION@ +Libs: -L${libdir} -leconnman +Cflags: -I${includedir} diff --git a/edbus.pc.in b/edbus.pc.in new file mode 100644 index 0000000..fa7c0e3 --- /dev/null +++ b/edbus.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: edbus +Description: DBus convenience library +@pkgconfig_requires_private@: ecore dbus-1 +Version: @VERSION@ +Libs: -L${libdir} -ledbus +Cflags: -I${includedir} diff --git a/ehal.pc.in b/ehal.pc.in new file mode 100644 index 0000000..a68d112 --- /dev/null +++ b/ehal.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: ehal +Description: Hal convenience library +@pkgconfig_requires_private@: ecore edbus +Version: @VERSION@ +Libs: -L${libdir} -lehal +Cflags: -I${includedir} diff --git a/enotify.pc.in b/enotify.pc.in new file mode 100644 index 0000000..d7059da --- /dev/null +++ b/enotify.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: enotify +Description: Notification convenience library +@pkgconfig_requires_private@: ecore edbus +Version: @VERSION@ +Libs: -L${libdir} -lenotify +Cflags: -I${includedir} diff --git a/eofono.pc.in b/eofono.pc.in new file mode 100644 index 0000000..ca65fa1 --- /dev/null +++ b/eofono.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: eofono +Description: oFono D-Bus wrappers +@pkgconfig_requires_private@: ecore edbus +Version: @VERSION@ +Libs: -L${libdir} -leofono +Cflags: -I${includedir} diff --git a/eukit.pc.in b/eukit.pc.in new file mode 100644 index 0000000..02de42d --- /dev/null +++ b/eukit.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: eukit +Description: udisks/upower convenience library +@pkgconfig_requires_private@: ecore edbus +Version: @VERSION@ +Libs: -L${libdir} -leukit +Cflags: -I${includedir} @@ -0,0 +1,10 @@ +#!/bin/sh + +doxygen + +if [ ! -e doc/html/images ]; then + mkdir -p doc/html/images +fi + +cp doc/images/*.png doc/images/*.gif doc/html/images + diff --git a/m4/ac_attribute.m4 b/m4/ac_attribute.m4 new file mode 100644 index 0000000..23479a9 --- /dev/null +++ b/m4/ac_attribute.m4 @@ -0,0 +1,47 @@ +dnl Copyright (C) 2004-2008 Kim Woelders +dnl Copyright (C) 2008 Vincent Torri <vtorri at univ-evry dot fr> +dnl That code is public domain and can be freely used or copied. +dnl Originally snatched from somewhere... + +dnl Macro for checking if the compiler supports __attribute__ + +dnl Usage: AC_C___ATTRIBUTE__ +dnl call AC_DEFINE for HAVE___ATTRIBUTE__ and __UNUSED__ +dnl if the compiler supports __attribute__, HAVE___ATTRIBUTE__ is +dnl defined to 1 and __UNUSED__ is defined to __attribute__((unused)) +dnl otherwise, HAVE___ATTRIBUTE__ is not defined and __UNUSED__ is +dnl defined to nothing. + +AC_DEFUN([AC_C___ATTRIBUTE__], +[ + +AC_MSG_CHECKING([for __attribute__]) + +AC_CACHE_VAL([ac_cv___attribute__], + [AC_TRY_COMPILE( + [ +#include <stdlib.h> + +int func(int x); +int foo(int x __attribute__ ((unused))) +{ + exit(1); +} + ], + [], + [ac_cv___attribute__="yes"], + [ac_cv___attribute__="no"] + )]) + +AC_MSG_RESULT($ac_cv___attribute__) + +if test "x${ac_cv___attribute__}" = "xyes" ; then + AC_DEFINE([HAVE___ATTRIBUTE__], [1], [Define to 1 if your compiler has __attribute__]) + AC_DEFINE([__UNUSED__], [__attribute__((unused))], [Macro declaring a function argument to be unused]) + else + AC_DEFINE([__UNUSED__], [], [Macro declaring a function argument to be unused]) +fi + +]) + +dnl End of ac_attribute.m4 diff --git a/src/.cvsignore b/src/.cvsignore new file mode 100644 index 0000000..282522d --- /dev/null +++ b/src/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..97baf85 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,2 @@ +MAINTAINERCLEANFILES = Makefile.in +SUBDIRS = lib bin diff --git a/src/bin/.cvsignore b/src/bin/.cvsignore new file mode 100644 index 0000000..9ee1dc8 --- /dev/null +++ b/src/bin/.cvsignore @@ -0,0 +1,11 @@ +.deps +Makefile +Makefile.in +.libs +e_dbus_hal +e_dbus_test +e_dbus_test_client +e_dbus_nm +e_dbus_notify +e_dbus_notification_daemon +e-notify-send diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am new file mode 100644 index 0000000..208a918 --- /dev/null +++ b/src/bin/Makefile.am @@ -0,0 +1,104 @@ +MAINTAINERCLEANFILES = Makefile.in + +EDBUS_CPPFLAGS = \ +-I$(top_srcdir)/src/lib/dbus \ +-I$(top_srcdir)/src/lib/notification \ +-I$(top_srcdir)/src/lib/connman \ +-I$(top_srcdir)/src/lib/bluez \ +-I$(top_srcdir)/src/lib/ofono \ +-I$(top_srcdir)/src/lib/ukit \ +@EDBUS_CFLAGS@ \ +@EINA_CFLAGS@ + +LIBS = \ +@EDBUS_LIBS@ \ +@EINA_LIBS@ + +EDBUS_PROG = e_dbus_test e_dbus_test_client +if BUILD_ENOTIFY +ENOTIFY_PROG = e_dbus_notify e_dbus_notification_daemon e-notify-send +endif +if BUILD_ECONNMAN +ECONNMAN_PROG = e_dbus_connman_test +ECONNMAN_PROG_NOINST = e_dbus_connman_test_api +endif +if BUILD_EBLUEZ +EBLUEZ_PROG = e_dbus_bluez_test +endif +if BUILD_EOFONO +EOFONO_PROG = e_dbus_ofono_test +endif +if BUILD_EUKIT +EUKIT_PROG = e_dbus_ukit_test +endif + +bin_PROGRAMS = \ +$(EDBUS_PROG) \ +$(ENOTIFY_PROG) \ +$(ECONNMAN_PROG) \ +$(EBLUEZ_PROG) \ +$(EOFONO_PROG) \ +$(EUKIT_PROG) + +noinst_PROGRAMS = \ +$(ECONNMAN_PROG_NOINST) + +e_dbus_test_SOURCES = \ +test.c + +e_dbus_test_CPPFLAGS = $(EDBUS_CPPFLAGS) +e_dbus_test_LDADD = $(top_builddir)/src/lib/dbus/libedbus.la + +e_dbus_test_client_SOURCES = \ +test_client.c + +e_dbus_test_client_CPPFLAGS = $(EDBUS_CPPFLAGS) +e_dbus_test_client_LDADD = $(top_builddir)/src/lib/dbus/libedbus.la + +if BUILD_ENOTIFY +e_dbus_notify_SOURCES = \ + notify.c + +e_dbus_notify_CPPFLAGS = $(EDBUS_CPPFLAGS) +e_dbus_notify_LDADD = $(top_builddir)/src/lib/notification/libenotify.la + +e_dbus_notification_daemon_SOURCES = \ + notification_daemon.c + +e_dbus_notification_daemon_CPPFLAGS = $(EDBUS_CPPFLAGS) +e_dbus_notification_daemon_LDADD = $(top_builddir)/src/lib/notification/libenotify.la + +e_notify_send_SOURCES = \ + notify-send.c + +e_notify_send_CPPFLAGS = $(EDBUS_CPPFLAGS) +e_notify_send_LDADD = $(top_builddir)/src/lib/notification/libenotify.la +endif + +if BUILD_ECONNMAN +e_dbus_connman_test_SOURCES = e_dbus_connman_test.c +e_dbus_connman_test_CPPFLAGS = $(EDBUS_CPPFLAGS) +e_dbus_connman_test_LDADD = $(top_builddir)/src/lib/connman/libeconnman.la + +e_dbus_connman_test_api_SOURCES = e_dbus_connman_test_api.c +e_dbus_connman_test_api_CPPFLAGS = $(EDBUS_CPPFLAGS) +e_dbus_connman_test_api_LDADD = $(top_builddir)/src/lib/connman/libeconnman.la +endif + +if BUILD_EBLUEZ +e_dbus_bluez_test_SOURCES = e_dbus_bluez_test.c +e_dbus_bluez_test_CPPFLAGS = $(EDBUS_CPPFLAGS) +e_dbus_bluez_test_LDADD = $(top_builddir)/src/lib/bluez/libebluez.la +endif + +if BUILD_EOFONO +e_dbus_ofono_test_SOURCES = e_dbus_ofono_test.c +e_dbus_ofono_test_CPPFLAGS = $(EDBUS_CPPFLAGS) +e_dbus_ofono_test_LDADD = $(top_builddir)/src/lib/ofono/libeofono.la +endif + +if BUILD_EUKIT +e_dbus_ukit_test_SOURCES = e_dbus_ukit_test.c +e_dbus_ukit_test_CPPFLAGS = $(EDBUS_CPPFLAGS) +e_dbus_ukit_test_LDADD = $(top_builddir)/src/lib/ukit/libeukit.la +endif diff --git a/src/bin/e_dbus_bluez_test.c b/src/bin/e_dbus_bluez_test.c new file mode 100644 index 0000000..8006b8e --- /dev/null +++ b/src/bin/e_dbus_bluez_test.c @@ -0,0 +1,853 @@ +#include "E_Bluez.h" +#include <stdio.h> +#include <string.h> +#include <ctype.h> +#include <errno.h> + +typedef struct _E_Msgbus_Data E_Msgbus_Data; + +struct _E_Msgbus_Data { + E_DBus_Connection *conn; + E_DBus_Object *obj; +}; + +static E_Msgbus_Data *_msgbus_data = NULL; + +static E_DBus_Interface *iface = NULL; + +static void +_method_success_check(void *data, DBusMessage *msg, DBusError *error) +{ + const char *name = data; + + if ((!error) || (!dbus_error_is_set(error))) + { + printf("SUCCESS: method %s() finished successfully.\n", name); + return; + } + + printf("FAILURE: method %s() finished with error: %s %s\n", + name, error->name, error->message); + dbus_error_free(error); +} + +static void +_default_adapter_callback(void *data, DBusMessage *msg, DBusError *err) +{ + E_Bluez_Element *element; + const char *path; + + if (dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path, + DBUS_TYPE_INVALID) == EINA_FALSE) + printf("FAILURE: failed to get default adapter\n"); + + printf("SUCCESS: default adapter: %s\n", path); + + element = e_bluez_element_get(path); + e_bluez_element_print(stdout, element); + return; + +} + +static void +_create_paired_device_cb(void *data, DBusMessage *msg, DBusError *err) +{ + e_dbus_object_interface_detach(_msgbus_data->obj, iface); + e_dbus_object_free(_msgbus_data->obj); + e_dbus_interface_unref(iface); + _method_success_check(data, msg, err); +} + +static DBusMessage* +_request_pincode_cb(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessage *reply; + char pin[16]; + char *p = pin; + int ret; + + printf("Enter PIN Code:\n"); + ret = scanf("%15s", p); + if (ret != 1) + return NULL; + + reply = dbus_message_new_method_return(msg); + dbus_message_append_args(reply, DBUS_TYPE_STRING, &p, + DBUS_TYPE_INVALID); + + return reply; +} + +static void +_elements_print(E_Bluez_Element **elements, unsigned int count) +{ + unsigned int i; + for (i = 0; i < count; i++) + { + printf("--- element %d:\n", i); + e_bluez_element_print(stdout, elements[i]); + } + free(elements); + printf("END: all elements count = %u\n", count); +} + +static int +_on_element_add(void *data, int type, void *info) +{ + E_Bluez_Element *element = info; + printf(">>> %s\n", element->path); + return 1; +} + +static int +_on_element_del(void *data, int type, void *info) +{ + E_Bluez_Element *element = info; + printf("<<< %s\n", element->path); + return 1; +} + +static int +_on_element_updated(void *data, int type, void *info) +{ + E_Bluez_Element *element = info; + printf("!!! %s\n", element->path); + e_bluez_element_print(stderr, element); + return 1; +} + +static int +_on_device_found(void *data, int type, void *info) +{ + E_Bluez_Device_Found *device = info; + printf("!!! %s\n", device->adapter->path); + printf(":::DeviceFound %s\n", device->name); + e_bluez_element_array_print(stderr, device->array); + printf("\n"); + + e_bluez_devicefound_free(device); + return 1; +} + +static int +_on_cmd_quit(char *cmd, char *args) +{ + fputs("Bye!\n", stderr); + ecore_main_loop_quit(); + return 0; +} + +static int +_on_cmd_sync(char *cmd, char *args) +{ + e_bluez_manager_sync_elements(); + return 1; +} + +static char * +_tok(char *p) +{ + p = strchr(p, ' '); + if (!p) + return NULL; + + *p = '\0'; + p++; + while (isspace(*p)) + p++; + if (*p == '\0') + return NULL; + + return p; +} + +static int +_on_cmd_get_all(char *cmd, char *args) +{ + E_Bluez_Element **elements; + char *type; + unsigned int count; + Eina_Bool ret; + + if (!args) + type = NULL; + else + type = args; + + if (type) + ret = e_bluez_elements_get_all_type(type, &count, &elements); + else + ret = e_bluez_elements_get_all(&count, &elements); + + if (!ret) + fputs("ERROR: could not get elements\n", stderr); + else + { + printf("BEG: all elements type=%s count = %d\n", type, count); + _elements_print(elements, count); + } + + return 1; +} + +static E_Bluez_Element * +_element_from_args(char *args, char **next_args) +{ + E_Bluez_Element *element; + + if (!args) + { + fputs("ERROR: missing element path\n", stderr); + *next_args = NULL; + return NULL; + } + + *next_args = _tok(args); + element = e_bluez_element_get(args); + if (!element) + fprintf(stderr, "ERROR: no element called \"%s\".\n", args); + + return element; +} + +static int +_on_cmd_print(char *cmd, char *args) +{ + char *next_args; + E_Bluez_Element *element = _element_from_args(args, &next_args); + if (element) + e_bluez_element_print(stdout, element); + return 1; +} + +static int +_on_cmd_get_properties(char *cmd, char *args) +{ + char *next_args; + E_Bluez_Element *element = _element_from_args(args, &next_args); + if (element) + e_bluez_element_properties_sync(element); + return 1; +} + +static int +_on_cmd_property_set(char *cmd, char *args) +{ + char *next_args, *name, *p; + E_Bluez_Element *element = _element_from_args(args, &next_args); + void *value; + long vlong; + unsigned short vu16; + unsigned int vu32; + int type; + + if (!element) + return 1; + + if (!next_args) + { + fputs("ERROR: missing parameters name, type and value.\n", stderr); + return 1; + } + + name = next_args; + p = _tok(name); + if (!p) + { + fputs("ERROR: missing parameters type and value.\n", stderr); + return 1; + } + + next_args = _tok(p); + if (!next_args) + { + fputs("ERROR: missing parameter value.\n", stderr); + return 1; + } + + type = p[0]; + switch (type) + { + case DBUS_TYPE_BOOLEAN: + vlong = !!atol(next_args); + value = &vlong; + fprintf(stderr, "DBG: boolean is: %ld\n", vlong); + break; + case DBUS_TYPE_UINT16: + vu16 = strtol(next_args, &p, 0); + if (p == next_args) + { + fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args); + return 1; + } + value = &vu16; + fprintf(stderr, "DBG: u16 is: %hu\n", vu16); + break; + case DBUS_TYPE_UINT32: + vu32 = strtol(next_args, &p, 0); + if (p == next_args) + { + fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args); + return 1; + } + value = &vu32; + fprintf(stderr, "DBG: u16 is: %u\n", vu32); + break; + case DBUS_TYPE_STRING: + case DBUS_TYPE_OBJECT_PATH: + p = next_args + strlen(next_args); + if (p > next_args) + p--; + while (p > next_args && isspace(*p)) + p--; + if (p <= next_args) + { + fprintf(stderr, "ERROR: invalid string \"%s\".\n", next_args); + } + p[1] = '\0'; + value = next_args; + fprintf(stderr, "DBG: string is: \"%s\"\n", next_args); + break; + default: + fprintf(stderr, "ERROR: don't know how to parse type '%c' (%d)\n", + type, type); + return 1; + } + + fprintf(stderr, "set_property %s [%p] %s %c %p...\n", + args, element, name, type, value); + if (!e_bluez_element_property_set(element, name, type, value)) + fputs("ERROR: error setting property.\n", stderr); + + return 1; +} + +/* Manager Commands */ + +static int +_on_cmd_manager_get(char *cmd, char *args) +{ + E_Bluez_Element *element; + element = e_bluez_manager_get(); + e_bluez_element_print(stderr, element); + return 1; +} + +static int +_on_cmd_manager_default_adapter(char *cmd, char *args) +{ + return e_bluez_manager_default_adapter(_default_adapter_callback, NULL); +} + +/* Adapter Commands */ + +static int +_on_cmd_adapter_register_agent(char *cmd, char *args) +{ + char *next_args, *path, *cap; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (!next_args) { + fputs("ERROR: missing parameters name, type and value.\n", stderr); + return 1; + } + + path = next_args; + cap = _tok(path); + if (!cap) { + fputs("ERROR: missing parameters name, type and value.\n", stderr); + return 1; + } + + if (e_bluez_adapter_agent_register(element, + path, cap, _method_success_check, "adapter_register_agent")) + printf(":::Registering agent %s (%s)...\n", path, cap); + else + fprintf(stderr, "ERROR: can't register agent %s\n", path); + + return 1; +} + +static int +_on_cmd_adapter_unregister_agent(char *cmd, char *args) +{ + char *path, *next_args; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (!args) + { + fputs("ERROR: missing the object path\n", stderr); + return 1; + } + + path = next_args; + if (e_bluez_adapter_agent_unregister(element, + path, _method_success_check, "adapter_unregister_agent")) + printf(":::Unregistering agent %s...\n", path); + else + fprintf(stderr, "ERROR: can't unregister agent %s\n", path); + + return 1; +} + +static int +_on_cmd_adapter_get_address(char *cmd, char *args) +{ + const char *address; + char *next_args; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (e_bluez_adapter_address_get(element, &address)) + printf(":::Adapter address = \"%s\"\n", address); + else + fputs("ERROR: can't get adapter address\n", stderr); + return 1; +} + +static int +_on_cmd_adapter_get_name(char *cmd, char *args) +{ + const char *name; + char *next_args; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (e_bluez_adapter_name_get(element, &name)) + printf(":::Adapter name = \"%s\"\n", name); + else + fputs("ERROR: can't get adapter name\n", stderr); + return 1; +} + +_on_cmd_adapter_set_name(char *cmd, char *args) +{ + char *path, *next_args; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (!next_args) { + fprintf(stderr, "ERROR: missing name value\n"); + return 1; + } + + if (e_bluez_adapter_name_set(element, next_args, _method_success_check, + "adapter_set_name")) + printf(":::Adapter %s Name set to %s\n", element->path, next_args); + else + fputs("ERROR: can't set adapter name\n", stderr); + return 1; +} + +static int +_on_cmd_adapter_get_powered(char *cmd, char *args) +{ + char *next_args; + Eina_Bool powered; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (e_bluez_adapter_powered_get(element, &powered)) + printf(":::Adapter powered = \"%hhu\"\n", powered); + else + fputs("ERROR: can't get adapter powered\n", stderr); + return 1; +} + +static int +_on_cmd_adapter_set_powered(char *cmd, char *args) +{ + char *next_args; + Eina_Bool powered; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (!args) + { + fputs("ERROR: missing the powered value\n", stderr); + return 1; + } + + powered = !!atol(next_args); + + if (e_bluez_adapter_powered_set + (element, powered, _method_success_check, "adapter_set_powered")) + printf(":::Adapter %s Powered set to %hhu\n", element->path, powered); + else + fputs("ERROR: can't set device powered\n", stderr); + return 1; +} + +static int +_on_cmd_adapter_get_discoverable(char *cmd, char *args) +{ + char *next_args; + Eina_Bool discoverable; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (e_bluez_adapter_discoverable_get(element, &discoverable)) + printf(":::Adapter discoverable = \"%hhu\"\n", discoverable); + else + fputs("ERROR: can't get adapter discoverable\n", stderr); + return 1; +} + +static int +_on_cmd_adapter_set_discoverable(char *cmd, char *args) +{ + char *next_args; + Eina_Bool discoverable; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (!args) + { + fputs("ERROR: missing the discoverable value\n", stderr); + return 1; + } + + discoverable = !!atol(next_args); + + if (e_bluez_adapter_discoverable_set + (element, discoverable, _method_success_check, "adapter_set_discoverable")) + printf(":::Adapter %s discoverable set to %hhu\n", element->path, discoverable); + else + fputs("ERROR: can't set adapter discoverable\n", stderr); + return 1; +} + +static int +_on_cmd_adapter_get_discoverable_timeout(char *cmd, char *args) +{ + char *next_args; + unsigned int timeout; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (e_bluez_adapter_discoverable_timeout_get(element, &timeout)) + printf(":::Adapter %s DiscovableTimeout = %hu\n", element->path, timeout); + else + fputs("ERROR: can't get adapter discoverable timeout\n", stderr); + return 1; +} + +static int +_on_cmd_adapter_set_discoverable_timeout(char *cmd, char *args) +{ + char *device_path, *next_args, *p; + unsigned int timeout; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (!next_args) { + fprintf(stderr, "ERROR: missing timeout value\n"); + return 1; + } + + timeout = strtol(next_args, &p, 0); + if (p == next_args) + { + fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args); + return 1; + } + + if (e_bluez_adapter_discoverable_timeout_set(element, timeout, + _method_success_check, + "adapter_set_discoverable_timeout")) + printf(":::Adapter %s scan interval set to %hu\n", element->path, timeout); + else + fputs("ERROR: can't set adapter discoverable timeout\n", stderr); + return 1; +} + +static int +_on_cmd_adapter_get_discovering(char *cmd, char *args) +{ + char *next_args; + Eina_Bool discovering; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (e_bluez_adapter_discovering_get(element, &discovering)) + printf(":::Adapter discovering = \"%hhu\"\n", discovering); + else + fputs("ERROR: can't get adapter's Discovering\n", stderr); + return 1; +} + +static int +_on_cmd_adapter_start_discovery(char *cmd, char *args) +{ + char *next_args; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (e_bluez_adapter_start_discovery(element, + _method_success_check, "adapter_start_discovery")) + printf(":::Adapter Start Discovery for %s\n", element->path); + else + fputs("ERROR: can't start discovery on adapter \n", stderr); + return 1; +} + +static int +_on_cmd_adapter_stop_discovery(char *cmd, char *args) +{ + char *next_args; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (e_bluez_adapter_stop_discovery(element, + _method_success_check, "adapter_stop_discovery")) + printf(":::Adapter Stop Discovery for %s\n", element->path); + else + fputs("ERROR: can't stop discovery on adapter \n", stderr); + return 1; +} + +static int +_on_cmd_adapter_create_paired_device(char *cmd, char *args) +{ + char *next_args, *path, *cap, *device; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (!next_args) { + fputs("ERROR: missing parameters name, type and value.\n", stderr); + return 1; + } + + path = next_args; + cap = _tok(path); + if (!cap) { + fputs("ERROR: missing parameters name, type and value.\n", stderr); + return 1; + } + device = _tok(cap); + if (!device) { + fputs("ERROR: missing parameters name, type and value.\n", stderr); + return 1; + } + + if (e_bluez_adapter_create_paired_device(element, path, cap, device, + _create_paired_device_cb, "adapter_create_paired_device")) { + printf(":::Creating Paired Device %s (%s)...\n", path, cap); + iface = e_dbus_interface_new("org.bluez.Agent"); + if (!iface) { + fputs("WARNING: Cannot add org.bluez.Agent interface",stderr); + return 0; + } + _msgbus_data->obj = e_dbus_object_add(_msgbus_data->conn, path, NULL); + e_dbus_object_interface_attach(_msgbus_data->obj, iface); + e_dbus_interface_method_add(iface, "RequestPinCode", "o", "s", + _request_pincode_cb); + + } + else + fprintf(stderr, "ERROR: can't create paired device %s\n", path); + + return 1; +} + +/* Devices Commands */ + +static int +_on_cmd_device_get_name(char *cmd, char *args) +{ + const char *name; + char *next_args; + E_Bluez_Element *element = _element_from_args(args, &next_args); + + if (!element) + return 1; + + if (e_bluez_device_name_get(element, &name)) + printf(":::Device name = \"%s\"\n", name); + else + fputs("ERROR: can't get device name\n", stderr); + return 1; +} + +static int +_on_input(void *data, Ecore_Fd_Handler *fd_handler) +{ + char buf[256]; + char *cmd, *args; + const struct { + const char *cmd; + int (*cb)(char *cmd, char *args); + } *itr, maps[] = { + {"quit", _on_cmd_quit}, + {"sync", _on_cmd_sync}, + {"get_all", _on_cmd_get_all}, + {"print", _on_cmd_print}, + {"get_properties", _on_cmd_get_properties}, + {"set_property", _on_cmd_property_set}, + {"manager_get", _on_cmd_manager_get}, + {"manager_default_adapter", _on_cmd_manager_default_adapter}, + {"adapter_register_agent", _on_cmd_adapter_register_agent}, + {"adapter_unregister_agent", _on_cmd_adapter_unregister_agent}, + {"adapter_get_address", _on_cmd_adapter_get_address}, + {"adapter_get_name", _on_cmd_adapter_get_name}, + {"adapter_set_name", _on_cmd_adapter_set_name}, + {"adapter_get_powered", _on_cmd_adapter_get_powered}, + {"adapter_set_powered", _on_cmd_adapter_set_powered}, + {"adapter_get_discoverable", _on_cmd_adapter_get_discoverable}, + {"adapter_set_discoverable", _on_cmd_adapter_set_discoverable}, + {"adapter_get_discoverable_timeout", _on_cmd_adapter_get_discoverable_timeout}, + {"adapter_set_discoverable_timeout", _on_cmd_adapter_set_discoverable_timeout}, + {"adapter_get_discovering", _on_cmd_adapter_get_discovering}, + {"adapter_start_discovery", _on_cmd_adapter_start_discovery}, + {"adapter_stop_discovery", _on_cmd_adapter_stop_discovery}, + {"adapter_create_paired_device", _on_cmd_adapter_create_paired_device}, + {"device_get_name", _on_cmd_device_get_name}, + {NULL, NULL} + }; + + + if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) + { + fputs("ERROR: reading from stdin, exit\n", stderr); + return 0; + } + + if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) + { + fputs("ERROR: nothing to read?\n", stderr); + return 0; + } + + if (!fgets(buf, sizeof(buf), stdin)) + { + fprintf(stderr, "ERROR: could not read command: %s\n", strerror(errno)); + ecore_main_loop_quit(); + return 0; + } + + cmd = buf; + while (isspace(*cmd)) + cmd++; + + args = strchr(cmd, ' '); + if (args) + { + char *p; + + *args = '\0'; + args++; + + while (isspace(*args)) + args++; + + p = args + strlen(args) - 1; + if (*p == '\n') + *p = '\0'; + } + else + { + char *p; + + p = cmd + strlen(cmd) - 1; + if (*p == '\n') + *p = '\0'; + } + + if (strcmp(cmd, "help") == 0) + { + if (args) + { + printf("Commands with '%s' in the name:\n", args); + for (itr = maps; itr->cmd != NULL; itr++) + if (strstr(itr->cmd, args)) + printf("\t%s\n", itr->cmd); + } + else + { + fputs("Commands:\n", stdout); + for (itr = maps; itr->cmd != NULL; itr++) + printf("\t%s\n", itr->cmd); + } + fputc('\n', stdout); + return 1; + } + + for (itr = maps; itr->cmd != NULL; itr++) + if (strcmp(itr->cmd, cmd) == 0) + return itr->cb(cmd, args); + + printf("unknown command \"%s\", args=%s\n", cmd, args); + return 1; +} + +int +main(int argc, char *argv[]) +{ + ecore_init(); + e_dbus_init(); + eina_init(); + + _msgbus_data = calloc(1, sizeof(E_Msgbus_Data)); + _msgbus_data->conn = e_dbus_bus_get(DBUS_BUS_SYSTEM); + if (!_msgbus_data->conn) { + printf("ERROR: can't connect to system session\n"); + return -1; + } + + e_bluez_system_init(_msgbus_data->conn); + + ecore_event_handler_add(E_BLUEZ_EVENT_ELEMENT_ADD, _on_element_add, NULL); + ecore_event_handler_add(E_BLUEZ_EVENT_ELEMENT_DEL, _on_element_del, NULL); + ecore_event_handler_add(E_BLUEZ_EVENT_ELEMENT_UPDATED, + _on_element_updated, NULL); + ecore_event_handler_add(E_BLUEZ_EVENT_DEVICE_FOUND, + _on_device_found, NULL); + + ecore_main_fd_handler_add + (0, ECORE_FD_READ | ECORE_FD_ERROR, _on_input, NULL, NULL, NULL); + + ecore_main_loop_begin(); + + e_bluez_system_shutdown(); + + e_dbus_connection_close(_msgbus_data->conn); + eina_shutdown(); + e_dbus_shutdown(); + ecore_shutdown(); + + fputs("DBG: clean exit.\n", stderr); + + return 0; +} diff --git a/src/bin/e_dbus_connman_test.c b/src/bin/e_dbus_connman_test.c new file mode 100644 index 0000000..76b3da4 --- /dev/null +++ b/src/bin/e_dbus_connman_test.c @@ -0,0 +1,2481 @@ +#include "E_Connman.h" +#include <stdio.h> +#include <string.h> +#include <ctype.h> +#include <errno.h> + +static void +_method_success_check(void *data, DBusMessage *msg, DBusError *error) +{ + const char *name = data; + + if ((!error) || (!dbus_error_is_set(error))) + { + printf("SUCCESS: method %s() finished successfully.\n", name); + return; + } + + printf("FAILURE: method %s() finished with error: %s %s\n", + name, error->name, error->message); + dbus_error_free(error); +} + +static void +_elements_print(E_Connman_Element **elements, unsigned int count) +{ + unsigned int i; + for (i = 0; i < count; i++) + { + printf("--- element %d:\n", i); + e_connman_element_print(stdout, elements[i]); + } + free(elements); + printf("END: all elements count = %u\n", count); +} + +static void +_strings_print(const char **strings, unsigned int count) +{ + unsigned int i; + for (i = 0; i < count; i++) + printf("--- strings %d: \"%s\"\n", i, strings[i]); + free(strings); + printf("END: all strings count = %u\n", count); +} + +static int +_on_element_add(void *data, int type, void *info) +{ + E_Connman_Element *element = info; + printf(">>> %s\n", element->path); + return 1; +} + +static int +_on_element_del(void *data, int type, void *info) +{ + E_Connman_Element *element = info; + printf("<<< %s\n", element->path); + return 1; +} + +static int +_on_element_updated(void *data, int type, void *info) +{ + E_Connman_Element *element = info; + printf("!!! %s\n", element->path); + e_connman_element_print(stderr, element); + return 1; +} + +static int +_on_cmd_quit(char *cmd, char *args) +{ + fputs("Bye!\n", stderr); + ecore_main_loop_quit(); + return 0; +} + +static int +_on_cmd_sync(char *cmd, char *args) +{ + e_connman_manager_sync_elements(); + return 1; +} + +static char * +_tok(char *p) +{ + p = strchr(p, ' '); + if (!p) + return NULL; + + *p = '\0'; + p++; + while (isspace(*p)) + p++; + if (*p == '\0') + return NULL; + + return p; +} + +static int +_on_cmd_get_all(char *cmd, char *args) +{ + E_Connman_Element **elements; + char *type; + unsigned int count; + bool ret; + + if (!args) + type = NULL; + else + type = args; + + if (type) + ret = e_connman_elements_get_all_type(type, &count, &elements); + else + ret = e_connman_elements_get_all(&count, &elements); + + if (!ret) + fputs("ERROR: could not get elements\n", stderr); + else + { + printf("BEG: all elements type=%s count = %d\n", type, count); + _elements_print(elements, count); + } + + return 1; +} + +static E_Connman_Element * +_element_from_args(char *args, char **next_args) +{ + E_Connman_Element *element; + + if (!args) + { + fputs("ERROR: missing element path\n", stderr); + *next_args = NULL; + return NULL; + } + + *next_args = _tok(args); + element = e_connman_element_get(args); + if (!element) + fprintf(stderr, "ERROR: no element called \"%s\".\n", args); + + return element; +} + +static int +_on_cmd_print(char *cmd, char *args) +{ + char *next_args; + E_Connman_Element *element = _element_from_args(args, &next_args); + if (element) + e_connman_element_print(stdout, element); + return 1; +} + +static int +_on_cmd_get_properties(char *cmd, char *args) +{ + char *next_args; + E_Connman_Element *element = _element_from_args(args, &next_args); + if (element) + e_connman_element_properties_sync(element); + return 1; +} + +static int +_on_cmd_property_set(char *cmd, char *args) +{ + char *next_args, *name, *p; + E_Connman_Element *element = _element_from_args(args, &next_args); + void *value; + long vlong; + unsigned short vu16; + unsigned int vu32; + int type; + + if (!element) + return 1; + + if (!next_args) + { + fputs("ERROR: missing parameters name, type and value.\n", stderr); + return 1; + } + + name = next_args; + p = _tok(name); + if (!p) + { + fputs("ERROR: missing parameters type and value.\n", stderr); + return 1; + } + + next_args = _tok(p); + if (!next_args) + { + fputs("ERROR: missing parameter value.\n", stderr); + return 1; + } + + type = p[0]; + switch (type) + { + case DBUS_TYPE_BOOLEAN: + vlong = !!atol(next_args); + value = &vlong; + fprintf(stderr, "DBG: boolean is: %ld\n", vlong); + break; + case DBUS_TYPE_UINT16: + vu16 = strtol(next_args, &p, 0); + if (p == next_args) + { + fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args); + return 1; + } + value = &vu16; + fprintf(stderr, "DBG: u16 is: %hu\n", vu16); + break; + case DBUS_TYPE_UINT32: + vu32 = strtol(next_args, &p, 0); + if (p == next_args) + { + fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args); + return 1; + } + value = &vu32; + fprintf(stderr, "DBG: u16 is: %u\n", vu32); + break; + case DBUS_TYPE_STRING: + case DBUS_TYPE_OBJECT_PATH: + p = next_args + strlen(next_args); + if (p > next_args) + p--; + while (p > next_args && isspace(*p)) + p--; + if (p <= next_args) + { + fprintf(stderr, "ERROR: invalid string \"%s\".\n", next_args); + } + p[1] = '\0'; + value = next_args; + fprintf(stderr, "DBG: string is: \"%s\"\n", next_args); + break; + default: + fprintf(stderr, "ERROR: don't know how to parse type '%c' (%d)\n", + type, type); + return 1; + } + + fprintf(stderr, "set_property %s [%p] %s %c %p...\n", + args, element, name, type, value); + if (!e_connman_element_property_set(element, name, type, value)) + fputs("ERROR: error setting property.\n", stderr); + + return 1; +} + + +/* Manager Commands */ + +static int +_on_cmd_manager_get(char *cmd, char *args) +{ + E_Connman_Element *element; + element = e_connman_manager_get(); + e_connman_element_print(stderr, element); + return 1; +} + +static int +_on_cmd_manager_get_profiles(char *cmd, char *args) +{ + unsigned int count; + E_Connman_Element **profiles; + + if (!e_connman_manager_profiles_get(&count, &profiles)) + { + fputs("ERROR: can't get profiles\n", stderr); + return 1; + } + printf("BEG: all manager profiles elements count = %d\n", count); + _elements_print(profiles, count); + return 1; +} + +static int +_on_cmd_manager_get_services(char *cmd, char *args) +{ + unsigned int count; + E_Connman_Element **services; + + if (!e_connman_manager_services_get(&count, &services)) + { + fputs("ERROR: can't get services\n", stderr); + return 1; + } + printf("BEG: all manager services elements count = %d\n", count); + _elements_print(services, count); + return 1; +} + +static int +_on_cmd_manager_register_agent(char *cmd, char *args) +{ + char *path; + + if (!args) + { + fputs("ERROR: missing the object path\n", stderr); + return 1; + } + + path = args; + if (e_connman_manager_agent_register + (path, _method_success_check, "manager_register_agent")) + printf(":::Registering agent %s...\n", path); + else + fprintf(stderr, "ERROR: can't register agent %s\n", path); + + return 1; +} + +static int +_on_cmd_manager_unregister_agent(char *cmd, char *args) +{ + char *path; + + if (!args) + { + fputs("ERROR: missing the object path\n", stderr); + return 1; + } + + path = args; + if (e_connman_manager_agent_unregister + (path, _method_success_check, "manager_unregister_agent")) + printf(":::Unregistering agent %s...\n", path); + else + fprintf(stderr, "ERROR: can't unregister agent %s\n", path); + + return 1; +} + +static int +_on_cmd_manager_get_state(char *cmd, char *args) +{ + const char *state; + if (e_connman_manager_state_get(&state)) + printf(":::Manager state = \"%s\"\n", state); + else + fputs("ERROR: can't get manager state\n", stderr); + return 1; +} + +static int +_on_cmd_manager_get_offline_mode(char *cmd, char *args) +{ + bool offline; + if (e_connman_manager_offline_mode_get(&offline)) + printf(":::Manager Offline Mode = %hhu\n", offline); + else + fputs("ERROR: can't get manager offline mode\n", stderr); + return 1; +} + +static int +_on_cmd_manager_set_offline_mode(char *cmd, char *args) +{ + bool offline; + if (!args) + { + fputs("ERROR: missing the offline mode value\n", stderr); + return 1; + } + _tok(args); + offline = !!atol(args); + if (e_connman_manager_offline_mode_set + (offline, _method_success_check, "manager_set_offline_mode")) + + printf(":::Manager Offline Mode set to %hhu\n", offline); + else + fputs("ERROR: can't set manager offline mode\n", stderr); + return 1; +} + +static int +_on_cmd_manager_request_scan(char *cmd, char *args) +{ + if (args) + _tok(args); + + if (!args) + args = ""; + + if (e_connman_manager_request_scan + (args, _method_success_check, "manager_request_scan")) + printf(":::Manager Request Scan for %s\n", args[0] ? args : "<all>"); + else + fputs("ERROR: can't request scan on manager\n", stderr); + return 1; +} + +static int +_on_cmd_manager_technology_enable(char *cmd, char *args) +{ + if (!args) + { + fputs("ERROR: missing the technology type\n", stderr); + return 1; + } + _tok(args); + + if (e_connman_manager_technology_enable + (args, _method_success_check, "manager_technology_enable")) + printf(":::Manager Enable Technology %s\n", args); + else + fputs("ERROR: can't enable technology on manager\n", stderr); + return 1; +} + +static int +_on_cmd_manager_technology_disable(char *cmd, char *args) +{ + if (!args) + { + fputs("ERROR: missing the technology type\n", stderr); + return 1; + } + _tok(args); + + if (e_connman_manager_technology_disable + (args, _method_success_check, "manager_technology_disable")) + printf(":::Manager Disable Technology %s\n", args); + else + fputs("ERROR: can't disable technology on manager\n", stderr); + return 1; +} + +static int +_on_cmd_manager_get_technologies_available(char *cmd, char *args) +{ + const char **strings; + unsigned int count; + + if (!e_connman_manager_technologies_available_get(&count, &strings)) + fputs("ERROR: can't get available technologies\n", stderr); + else + { + printf("BEG: available technologies count = %u\n", count); + _strings_print(strings, count); + } + + return 1; +} + +static int +_on_cmd_manager_get_technologies_enabled(char *cmd, char *args) +{ + const char **strings; + unsigned int count; + + if (!e_connman_manager_technologies_enabled_get(&count, &strings)) + fputs("ERROR: can't get enabled technologies\n", stderr); + else + { + printf("BEG: enabled technologies count = %u\n", count); + _strings_print(strings, count); + } + + return 1; +} + +static int +_on_cmd_manager_get_technologies_connected(char *cmd, char *args) +{ + const char **strings; + unsigned int count; + + if (!e_connman_manager_technologies_connected_get(&count, &strings)) + fputs("ERROR: can't get connected technologies\n", stderr); + else + { + printf("BEG: connected technologies count = %u\n", count); + _strings_print(strings, count); + } + + return 1; +} + +static int +_on_cmd_manager_profile_remove(char *cmd, char *args) +{ + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the profile path\n", stderr); + return 1; + } + _tok(args); + + e = e_connman_profile_get(args); + if (e_connman_manager_profile_remove + (e, _method_success_check, "manager_profile_remove")) + printf(":::Manager Remove Profile %s\n", args); + else + fputs("ERROR: can't remove profile from manager\n", stderr); + return 1; +} + +static int +_on_cmd_manager_profile_get_active(char *cmd, char *args) +{ + E_Connman_Element *e; + + if (!e_connman_manager_profile_active_get(&e)) + fputs("ERROR: can't active_get profile from manager\n", stderr); + else + e_connman_element_print(stderr, e); + return 1; +} + +static int +_on_cmd_manager_profile_set_active(char *cmd, char *args) +{ + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the profile path\n", stderr); + return 1; + } + _tok(args); + + e = e_connman_profile_get(args); + if (e_connman_manager_profile_active_set + (e, _method_success_check, "manager_profile_set_active")) + printf(":::Manager Active Profile set to %s\n", args); + else + fputs("ERROR: can't set active profile\n", stderr); + return 1; +} + +/* Device Commands */ +static int +_on_cmd_device_propose_scan(char *cmd, char *args) +{ + char *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the device path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_device_get(path); + if (e_connman_device_propose_scan + (e, _method_success_check, "device_propose_scan")) + printf(":::Proposing scan %s...\n", path); + else + fputs("ERROR: can't propose scan\n", stderr); + return 1; +} + +static int +_on_cmd_device_get_address(char *cmd, char *args) +{ + const char *address, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the device path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_device_get(path); + if (e_connman_device_address_get(e, &address)) + printf(":::Device %s Address = \"%s\"\n", path, address); + else + fputs("ERROR: can't get device address\n", stderr); + return 1; +} + +static int +_on_cmd_device_get_name(char *cmd, char *args) +{ + const char *name, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the device path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_device_get(path); + if (e_connman_device_name_get(e, &name)) + printf(":::Device %s Name = \"%s\"\n", path, name); + else + fputs("ERROR: can't get device name\n", stderr); + return 1; +} + +static int +_on_cmd_device_get_type(char *cmd, char *args) +{ + const char *type, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the device path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_device_get(path); + if (e_connman_device_type_get(e, &type)) + printf(":::Device %s Type = \"%s\"\n", path, type); + else + fputs("ERROR: can't get device type\n", stderr); + return 1; +} + +static int +_on_cmd_device_get_interface(char *cmd, char *args) +{ + const char *interface, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the device path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_device_get(path); + if (e_connman_device_interface_get(e, &interface)) + printf(":::Device %s Interface = \"%s\"\n", path, interface); + else + fputs("ERROR: can't get device interface\n", stderr); + return 1; +} + +static int +_on_cmd_device_get_powered(char *cmd, char *args) +{ + char *path; + bool powered; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the device path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_device_get(path); + if (e_connman_device_powered_get(e, &powered)) + printf(":::Device %s Powered = %hhu\n", path, powered); + else + fputs("ERROR: can't get device powered\n", stderr); + return 1; +} + +static int +_on_cmd_device_set_powered(char *cmd, char *args) +{ + char *device_path, *next_args; + bool powered; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the device path\n", stderr); + return 1; + } + device_path = args; + next_args = _tok(args); + if (!next_args) + { + fputs("ERROR: missing the powered value\n", stderr); + return 1; + } + powered = !!atol(next_args); + + e = e_connman_device_get(device_path); + if (e_connman_device_powered_set + (e, powered, _method_success_check, "device_set_powered")) + printf(":::Device %s powered set to %hhu\n", device_path, powered); + else + fputs("ERROR: can't set device powered\n", stderr); + return 1; +} + +static int +_on_cmd_device_get_scan_interval(char *cmd, char *args) +{ + char *path; + unsigned short scan_interval; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the device path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_device_get(path); + if (e_connman_device_scan_interval_get(e, &scan_interval)) + printf(":::Device %s ScanInterval = %hu\n", path, scan_interval); + else + fputs("ERROR: can't get device scan interval\n", stderr); + return 1; +} + +static int +_on_cmd_device_set_scan_interval(char *cmd, char *args) +{ + char *device_path, *next_args, *p; + unsigned short scan_interval; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the device path\n", stderr); + return 1; + } + device_path = args; + next_args = _tok(args); + if (!next_args) + { + fputs("ERROR: missing the scan interval value\n", stderr); + return 1; + } + scan_interval = strtol(next_args, &p, 0); + if (p == next_args) + { + fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args); + return 1; + } + + e = e_connman_device_get(device_path); + if (e_connman_device_scan_interval_set + (e, scan_interval, _method_success_check, "device_set_scan_interval")) + printf(":::Device %s scan interval set to %hu\n", device_path, scan_interval); + else + fputs("ERROR: can't set device scan interval\n", stderr); + return 1; +} + +static int +_on_cmd_device_get_scanning(char *cmd, char *args) +{ + char *path; + bool scanning; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the device path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_device_get(path); + if (e_connman_device_scanning_get(e, &scanning)) + printf(":::Device %s Scanning = %hhu\n", path, scanning); + else + fputs("ERROR: can't get device scanning\n", stderr); + return 1; +} + +static int +_on_cmd_device_get_networks(char *cmd, char *args) +{ + E_Connman_Element **networks; + unsigned int count; + char *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the device path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_device_get(path); + if (!e_connman_device_networks_get(e, &count, &networks)) + { + fputs("ERROR: can't get networks\n", stderr); + return 1; + } + + printf("BEG: all device network elements count = %d\n", count); + _elements_print(networks, count); + return 1; +} + +/* Profile Commands */ + +static int +_on_cmd_profile_get_name(char *cmd, char *args) +{ + const char *name, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the profile path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_profile_get(path); + if (e_connman_profile_name_get(e, &name)) + printf(":::Profile %s Name = \"%s\"\n", path, name); + else + fputs("ERROR: can't get profile name\n", stderr); + return 1; +} + +static int +_on_cmd_profile_set_name(char *cmd, char *args) +{ + char *path, *next_args; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the profile path\n", stderr); + return 1; + } + path = args; + next_args = _tok(args); + if (!next_args) + { + fputs("ERROR: missing the offline mode value\n", stderr); + return 1; + } + _tok(next_args); + + e = e_connman_profile_get(path); + if (e_connman_profile_name_set + (e, next_args, _method_success_check, "profile_set_name")) + printf(":::Profile %s Name set to %s\n", path, next_args); + else + fputs("ERROR: can't set profile name\n", stderr); + return 1; +} + +static int +_on_cmd_profile_get_offline_mode(char *cmd, char *args) +{ + char *path; + bool offline; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the profile path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_profile_get(path); + if (e_connman_profile_offline_mode_get(e, &offline)) + printf(":::Profile %s Offline Mode = %hhu\n", path, offline); + else + fputs("ERROR: can't get profile offline mode\n", stderr); + return 1; +} + +static int +_on_cmd_profile_set_offline_mode(char *cmd, char *args) +{ + char *path, *next_args; + bool offline; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the profile path\n", stderr); + return 1; + } + path = args; + next_args = _tok(args); + if (!next_args) + { + fputs("ERROR: missing the offline mode value\n", stderr); + return 1; + } + _tok(next_args); + offline = !!atol(next_args); + + e = e_connman_profile_get(path); + if (e_connman_profile_offline_mode_set + (e, offline, _method_success_check, "profile_set_offline_mode")) + printf(":::Profile %s Offline Mode set to %hhu\n", path, offline); + else + fputs("ERROR: can't set profile offline mode\n", stderr); + return 1; +} + +static int +_on_cmd_profile_get_services(char *cmd, char *args) +{ + E_Connman_Element **services; + E_Connman_Element *e; + unsigned int count; + char *path; + + if (!args) + { + fputs("ERROR: missing the profile path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_profile_get(path); + if (!e_connman_profile_services_get(e, &count, &services)) + { + fputs("ERROR: can't get services\n", stderr); + return 1; + } + printf("BEG: all profile services count = %d\n", count); + _elements_print(services, count); + return 1; +} + + +/* Network Commands */ + +static int +_on_cmd_network_get_address(char *cmd, char *args) +{ + const char *address, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the network path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_network_get(path); + if (e_connman_network_address_get(e, &address)) + printf(":::Network %s Address = \"%s\"\n", path, address); + else + fputs("ERROR: can't get network address\n", stderr); + return 1; +} + +static int +_on_cmd_network_get_name(char *cmd, char *args) +{ + const char *name, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the network path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_network_get(path); + if (e_connman_network_name_get(e, &name)) + printf(":::Network %s Name = \"%s\"\n", path, name); + else + fputs("ERROR: can't get network name\n", stderr); + return 1; +} + +static int +_on_cmd_network_get_connected(char *cmd, char *args) +{ + char *path; + bool connected; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the network path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_network_get(path); + if (e_connman_network_connected_get(e, &connected)) + printf(":::Network %s Connected = %hhu\n", path, connected); + else + fputs("ERROR: can't get network connected\n", stderr); + return 1; +} + +static int +_on_cmd_network_get_strength(char *cmd, char *args) +{ + char *path; + unsigned char strength; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the network path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_network_get(path); + if (e_connman_network_strength_get(e, &strength)) + printf(":::Network %s Strength = %#02hhx (%d)\n", path, strength, strength); + else + fputs("ERROR: can't get network strength\n", stderr); + return 1; +} + +static int +_on_cmd_network_get_frequency(char *cmd, char *args) +{ + char *path; + unsigned short frequency; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the network path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_network_get(path); + if (e_connman_network_frequency_get(e, &frequency)) + printf(":::Network %s Frequency = %#04hx (%d)\n", path, frequency, frequency); + else + fputs("ERROR: can't get network frequency\n", stderr); + return 1; +} + +static int +_on_cmd_network_get_device(char *cmd, char *args) +{ + E_Connman_Element *e, *device; + char *path; + + if (!args) + { + fputs("ERROR: missing the network path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_network_get(path); + if (!e_connman_network_device_get(e, &device)) + fputs("ERROR: can't get network device\n", stderr); + else + e_connman_element_print(stderr, device); + return 1; +} + +static int +_on_cmd_network_get_wifi_ssid(char *cmd, char *args) +{ + unsigned char *bytes; + char *path; + unsigned int i, count; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the network path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_network_get(path); + if (e_connman_network_wifi_ssid_get(e, &count, &bytes)) + { + printf(":::Network %s Wifi SSID = ", path); + for (i = 0; i < count; i++) + printf("%#02hhx (\"%c\"), ", bytes[i], bytes[i]); + printf("\n"); + } + else + fputs("ERROR: can't get network wifi ssid\n", stderr); + return 1; +} + +static int +_on_cmd_network_get_wifi_mode(char *cmd, char *args) +{ + const char *wifi_mode, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the network path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_network_get(path); + if (e_connman_network_wifi_mode_get(e, &wifi_mode)) + printf(":::Network %s Wifi Mode = \"%s\"\n", path, wifi_mode); + else + fputs("ERROR: can't get network wifi mode\n", stderr); + return 1; +} + +static int +_on_cmd_network_get_wifi_security(char *cmd, char *args) +{ + const char *wifi_security, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the network path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_network_get(path); + if (e_connman_network_wifi_security_get(e, &wifi_security)) + printf(":::Network %s Wifi Security = \"%s\"\n", path, wifi_security); + else + fputs("ERROR: can't get network wifi security\n", stderr); + return 1; +} + +static int +_on_cmd_network_get_wifi_passphrase(char *cmd, char *args) +{ + const char *wifi_passphrase, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the network path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_network_get(path); + if (e_connman_network_wifi_passphrase_get(e, &wifi_passphrase)) + printf(":::Network %s Wifi Passphrase = \"%s\"\n", path, wifi_passphrase); + else + fputs("ERROR: can't get network wifi passphrase\n", stderr); + return 1; +} + +static int +_on_cmd_network_get_wifi_channel(char *cmd, char *args) +{ + char *path; + E_Connman_Element *e; + unsigned short wifi_channel; + + if (!args) + { + fputs("ERROR: missing the network path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_network_get(path); + if (e_connman_network_wifi_channel_get(e, &wifi_channel)) + printf(":::Network %s Wifi Channel = %#02hx (%d)\n", path, wifi_channel, wifi_channel); + else + fputs("ERROR: can't get network wifi channel\n", stderr); + return 1; +} + +static int +_on_cmd_network_get_wifi_eap(char *cmd, char *args) +{ + const char *wifi_eap, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the network path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_network_get(path); + if (e_connman_network_wifi_eap_get(e, &wifi_eap)) + printf(":::Network %s Wifi EAP = \"%s\"\n", path, wifi_eap); + else + fputs("ERROR: can't get network wifi eap\n", stderr); + return 1; +} + +/* Services Commands */ +static int +_on_cmd_service_connect(char *cmd, char *args) +{ + char *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_connect + (e, _method_success_check, "service_connect")) + printf(":::Connecting to Service %s...\n", path); + else + fputs("ERROR: can't connect to service\n", stderr); + return 1; +} + +static int +_on_cmd_service_disconnect(char *cmd, char *args) +{ + char *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_disconnect + (e, _method_success_check, "service_disconnect")) + printf(":::Disconnecting Service %s...\n", path); + else + fputs("ERROR: can't disconnect service\n", stderr); + return 1; +} + +static int +_on_cmd_service_remove(char *cmd, char *args) +{ + char *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_remove + (e, _method_success_check, "service_remove")) + printf(":::Removing Service %s...\n", path); + else + fputs("ERROR: can't remove service\n", stderr); + return 1; +} + +static int +_on_cmd_service_move_before(char *cmd, char *args) +{ + char *path, *service_path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + service_path = args; + path = _tok(args); + + if (!path) + { + fputs("ERROR: missing the object service\n", stderr); + return 1; + } + _tok(path); + + e = e_connman_service_get(service_path); + if (e_connman_service_move_before + (e, path, _method_success_check, "service_move_before")) + printf(":::Moving before %s...\n", path); + else + fputs("ERROR: can't move before\n", stderr); + return 1; +} + +static int +_on_cmd_service_move_after(char *cmd, char *args) +{ + char *path, *service_path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + service_path = args; + path = _tok(args); + + if (!path) + { + fputs("ERROR: missing the object service\n", stderr); + return 1; + } + _tok(path); + + e = e_connman_service_get(service_path); + if (e_connman_service_move_after + (e, path, _method_success_check, "service_move_after")) + printf(":::Moving after %s...\n", path); + else + fputs("ERROR: can't move after\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_state(char *cmd, char *args) +{ + const char *state, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_state_get(e, &state)) + printf(":::Service %s State = \"%s\"\n", path, state); + else + fputs("ERROR: can't get service state\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_error(char *cmd, char *args) +{ + const char *error, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_error_get(e, &error)) + printf(":::Service %s Error = \"%s\"\n", path, error); + else + fputs("ERROR: can't get service error\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_name(char *cmd, char *args) +{ + const char *name, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_name_get(e, &name)) + printf(":::Service %s Name = \"%s\"\n", path, name); + else + fputs("ERROR: can't get service name\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_type(char *cmd, char *args) +{ + const char *type, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_type_get(e, &type)) + printf(":::Service %s Type = \"%s\"\n", path, type); + else + fputs("ERROR: can't get service type\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_mode(char *cmd, char *args) +{ + const char *mode, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_mode_get(e, &mode)) + printf(":::Service %s Mode = \"%s\"\n", path, mode); + else + fputs("ERROR: can't get service mode\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_security(char *cmd, char *args) +{ + const char *security, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_security_get(e, &security)) + printf(":::Service %s Security = \"%s\"\n", path, security); + else + fputs("ERROR: can't get service security\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_passphrase(char *cmd, char *args) +{ + const char *passphrase, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_passphrase_get(e, &passphrase)) + printf(":::Service %s Passphrase = \"%s\"\n", path, passphrase); + else + fputs("ERROR: can't get service passphrase\n", stderr); + return 1; +} + +static int +_on_cmd_service_set_passphrase(char *cmd, char *args) +{ + char *passphrase, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + path = args; + passphrase = _tok(args); + + if (!passphrase) + { + fputs("ERROR: missing the passphrase value\n", stderr); + return 1; + } + _tok(passphrase); + + e = e_connman_service_get(path); + if (e_connman_service_passphrase_set + (e, passphrase, _method_success_check, "service_set_passphrase")) + printf(":::Service %s passphrase set to \"%s\"\n", path, passphrase); + else + fputs("ERROR: can't set service passphrase\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_passphrase_required(char *cmd, char *args) +{ + const char *path; + bool passphrase; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_passphrase_required_get(e, &passphrase)) + printf(":::Service %s Passphrase Required = %hhu\n", path, passphrase); + else + fputs("ERROR: can't get service passphrase required\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_strength(char *cmd, char *args) +{ + const char *path; + unsigned char strength; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_strength_get(e, &strength)) + printf(":::Service %s Strength = %#02hhx (%d)\n", path, strength, strength); + else + fputs("ERROR: can't get service strength\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_favorite(char *cmd, char *args) +{ + const char *path; + bool favorite; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_favorite_get(e, &favorite)) + printf(":::Service %s Favorite = %hhu\n", path, favorite); + else + fputs("ERROR: can't get service favorite\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_immutable(char *cmd, char *args) +{ + const char *path; + bool immutable; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_immutable_get(e, &immutable)) + printf(":::Service %s Immutable = %hhu\n", path, immutable); + else + fputs("ERROR: can't get service immutable\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_auto_connect(char *cmd, char *args) +{ + const char *path; + bool auto_connect; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_auto_connect_get(e, &auto_connect)) + printf(":::Service %s Auto Connect = %hhu\n", path, auto_connect); + else + fputs("ERROR: can't get service auto connect\n", stderr); + return 1; +} + +static int +_on_cmd_service_set_auto_connect(char *cmd, char *args) +{ + char *path, *next_args; + bool auto_connect; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + path = args; + next_args = _tok(args); + + if (!next_args) + { + fputs("ERROR: missing the auto connect value\n", stderr); + return 1; + } + _tok(next_args); + auto_connect = !!atol(next_args); + + e = e_connman_service_get(path); + if (e_connman_service_auto_connect_set + (e, auto_connect, _method_success_check, "service_set_auto_connect")) + printf(":::Service %s auto connect set to %d\n", path, auto_connect); + else + fputs("ERROR: can't set service auto connect\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_setup_required(char *cmd, char *args) +{ + const char *path; + bool setup_required; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_setup_required_get(e, &setup_required)) + printf(":::Service %s Setup Required = %hhu\n", path, setup_required); + else + fputs("ERROR: can't get service setup required\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_apn(char *cmd, char *args) +{ + const char *apn, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_apn_get(e, &apn)) + printf(":::Service %s APN = \"%s\"\n", path, apn); + else + fputs("ERROR: can't get service APN\n", stderr); + return 1; +} + +static int +_on_cmd_service_set_apn(char *cmd, char *args) +{ + char *apn, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + path = args; + apn = _tok(args); + + if (!apn) + { + fputs("ERROR: missing the apn value\n", stderr); + return 1; + } + _tok(apn); + + e = e_connman_service_get(path); + if (e_connman_service_apn_set + (e, apn, _method_success_check, "service_set_apn")) + printf(":::Service %s APN set to \"%s\"\n", path, apn); + else + fputs("ERROR: can't set service APN\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_mcc(char *cmd, char *args) +{ + const char *mcc, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_mcc_get(e, &mcc)) + printf(":::Service %s MCC = \"%s\"\n", path, mcc); + else + fputs("ERROR: can't get service MCC\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_mnc(char *cmd, char *args) +{ + const char *mnc, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_mnc_get(e, &mnc)) + printf(":::Service %s MNC = \"%s\"\n", path, mnc); + else + fputs("ERROR: can't get service MNC\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_roaming(char *cmd, char *args) +{ + const char *path; + bool roaming; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_roaming_get(e, &roaming)) + printf(":::Service %s Roaming = %hhu\n", path, roaming); + else + fputs("ERROR: can't get service roaming\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_ipv4_method(char *cmd, char *args) +{ + const char *ipv4_method, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_ipv4_method_get(e, &ipv4_method)) + printf(":::Service %s IPv4 Method = \"%s\"\n", path, ipv4_method); + else + fputs("ERROR: can't get service ipv4 method\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_ipv4_address(char *cmd, char *args) +{ + const char *ipv4_address, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_ipv4_address_get(e, &ipv4_address)) + printf(":::Service %s IPv4 Address = \"%s\"\n", path, ipv4_address); + else + fputs("ERROR: can't get service ipv4 address\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_ipv4_gateway(char *cmd, char *args) +{ + const char *ipv4_gateway, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_ipv4_gateway_get(e, &ipv4_gateway)) + printf(":::Service %s IPv4 Gateway = \"%s\"\n", path, ipv4_gateway); + else + fputs("ERROR: can't get service ipv4 gateway\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_ipv4_netmask(char *cmd, char *args) +{ + const char *ipv4_netmask, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_ipv4_netmask_get(e, &ipv4_netmask)) + printf(":::Service %s IPv4 Netmask = \"%s\"\n", path, ipv4_netmask); + else + fputs("ERROR: can't get service ipv4 netmask\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_ipv4_configuration_method(char *cmd, char *args) +{ + const char *ipv4_method, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_ipv4_configuration_method_get(e, &ipv4_method)) + printf(":::Service %s IPv4 Configuration Method = \"%s\"\n", + path, ipv4_method); + else + fputs("ERROR: can't get service ipv4_configuration method\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_ipv4_configuration_address(char *cmd, char *args) +{ + const char *ipv4_address, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_ipv4_configuration_address_get(e, &ipv4_address)) + printf(":::Service %s IPv4 Configuration Address = \"%s\"\n", + path, ipv4_address); + else + fputs("ERROR: can't get service ipv4_configuration address\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_ipv4_configuration_gateway(char *cmd, char *args) +{ + const char *ipv4_gateway, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_ipv4_configuration_gateway_get(e, &ipv4_gateway)) + printf(":::Service %s IPv4 Configuration Gateway = \"%s\"\n", + path, ipv4_gateway); + else + fputs("ERROR: can't get service ipv4_configuration gateway\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_ipv4_configuration_netmask(char *cmd, char *args) +{ + const char *ipv4_netmask, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_ipv4_configuration_netmask_get(e, &ipv4_netmask)) + printf(":::Service %s IPv4 Configuration Netmask = \"%s\"\n", + path, ipv4_netmask); + else + fputs("ERROR: can't get service ipv4 configuration netmask\n", stderr); + return 1; +} + +static int +_on_cmd_service_ipv4_configure_dhcp(char *cmd, char *args) +{ + char *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + path = args; + _tok(args); + + e = e_connman_service_get(path); + if (e_connman_service_ipv4_configure_dhcp + (e, _method_success_check, "service_ipv4_configure_dhcp")) + printf(":::Service %s IPv4 Configuration set to DHCP\n", path); + else + fputs("ERROR: can't set service ipv4_configuration dhcp\n", stderr); + return 1; +} + +static int +_on_cmd_service_ipv4_configure_manual(char *cmd, char *args) +{ + char *path, *next_args, *address, *netmask = NULL; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + path = args; + next_args = _tok(args); + if (!next_args) + { + fputs("ERROR: missing the service address\n", stderr); + return 1; + } + + address = next_args; + next_args = _tok(next_args); + if (next_args) + { + netmask = next_args; + _tok(next_args); + } + + e = e_connman_service_get(path); + if (e_connman_service_ipv4_configure_manual + (e, address, netmask, + _method_success_check, "service_ipv4_configure_manual")) + printf(":::Service %s IPv4 Configuration set to Manual (%s/%s)\n", + path, address, netmask); + else + fputs("ERROR: can't set service ipv4_configuration manual\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_ethernet_method(char *cmd, char *args) +{ + const char *ethernet_method, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_ethernet_method_get(e, ðernet_method)) + printf(":::Service %s Ethernet Method = \"%s\"\n", path, ethernet_method); + else + fputs("ERROR: can't get service ethernet method\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_ethernet_address(char *cmd, char *args) +{ + const char *ethernet_address, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_ethernet_address_get(e, ðernet_address)) + printf(":::Service %s Ethernet Address = \"%s\"\n", + path, ethernet_address); + else + fputs("ERROR: can't get service ethernet address\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_ethernet_mtu(char *cmd, char *args) +{ + const char *path; + E_Connman_Element *e; + unsigned short ethernet_mtu; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_ethernet_mtu_get(e, ðernet_mtu)) + printf(":::Service %s Ethernet MTU = %hu\n", path, ethernet_mtu); + else + fputs("ERROR: can't get service ethernet mtu\n", stderr); + return 1; +} + +static int +_on_cmd_service_get_ethernet_netmask(char *cmd, char *args) +{ + const char *ethernet_netmask, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the service path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_service_get(path); + if (e_connman_service_ethernet_netmask_get(e, ðernet_netmask)) + printf(":::Service %s Ethernet Netmask = \"%s\"\n", + path, ethernet_netmask); + else + fputs("ERROR: can't get service ethernet netmask\n", stderr); + return 1; +} + +static int +_on_cmd_technology_get_devices(char *cmd, char *args) +{ + E_Connman_Element **devices; + E_Connman_Element *e; + unsigned int count; + char *path; + + if (!args) + { + fputs("ERROR: missing the technology path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_technology_get(path); + if (!e_connman_technology_devices_get(e, &count, &devices)) + { + fputs("ERROR: can't get devices\n", stderr); + return 1; + } + printf("BEG: all technology devices count = %d\n", count); + _elements_print(devices, count); + return 1; +} + +static int +_on_cmd_technology_get_state(char *cmd, char *args) +{ + const char *state, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the technology path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_technology_get(path); + if (e_connman_technology_state_get(e, &state)) + printf(":::Technology %s State = \"%s\"\n", path, state); + else + fputs("ERROR: can't get technology state\n", stderr); + return 1; +} + +static int +_on_cmd_technology_get_type(char *cmd, char *args) +{ + const char *type, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the technology path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_technology_get(path); + if (e_connman_technology_type_get(e, &type)) + printf(":::Technology %s Type = \"%s\"\n", path, type); + else + fputs("ERROR: can't get technology type\n", stderr); + return 1; +} + +static int +_on_cmd_technology_get_name(char *cmd, char *args) +{ + const char *name, *path; + E_Connman_Element *e; + + if (!args) + { + fputs("ERROR: missing the technology path\n", stderr); + return 1; + } + _tok(args); + path = args; + + e = e_connman_technology_get(path); + if (e_connman_technology_name_get(e, &name)) + printf(":::Technology %s Name = \"%s\"\n", path, name); + else + fputs("ERROR: can't get technology name\n", stderr); + return 1; +} + +static int +_on_input(void *data, Ecore_Fd_Handler *fd_handler) +{ + char buf[256]; + char *cmd, *args; + const struct { + const char *cmd; + int (*cb)(char *cmd, char *args); + } *itr, maps[] = { + {"quit", _on_cmd_quit}, + {"sync", _on_cmd_sync}, + {"get_all", _on_cmd_get_all}, + {"print", _on_cmd_print}, + {"get_properties", _on_cmd_get_properties}, + {"set_property", _on_cmd_property_set}, + {"manager_get", _on_cmd_manager_get}, + {"manager_get_profiles", _on_cmd_manager_get_profiles}, + {"manager_get_services", _on_cmd_manager_get_services}, + {"manager_register_agent", _on_cmd_manager_register_agent}, + {"manager_unregister_agent", _on_cmd_manager_unregister_agent}, + {"manager_get_state", _on_cmd_manager_get_state}, + {"manager_get_offline_mode", _on_cmd_manager_get_offline_mode}, + {"manager_set_offline_mode", _on_cmd_manager_set_offline_mode}, + {"manager_request_scan", _on_cmd_manager_request_scan}, + {"manager_technology_enable", _on_cmd_manager_technology_enable}, + {"manager_technology_disable", _on_cmd_manager_technology_disable}, + {"manager_get_technologies_available", _on_cmd_manager_get_technologies_available}, + {"manager_get_technologies_enabled", _on_cmd_manager_get_technologies_enabled}, + {"manager_get_technologies_connected", _on_cmd_manager_get_technologies_connected}, + {"manager_profile_remove", _on_cmd_manager_profile_remove}, + {"manager_profile_get_active", _on_cmd_manager_profile_get_active}, + {"manager_profile_set_active", _on_cmd_manager_profile_set_active}, + {"device_propose_scan", _on_cmd_device_propose_scan}, + {"device_get_address", _on_cmd_device_get_address}, + {"device_get_name", _on_cmd_device_get_name}, + {"device_get_type", _on_cmd_device_get_type}, + {"device_get_interface", _on_cmd_device_get_interface}, + {"device_get_powered", _on_cmd_device_get_powered}, + {"device_set_powered", _on_cmd_device_set_powered}, + {"device_get_scan_interval", _on_cmd_device_get_scan_interval}, + {"device_set_scan_interval", _on_cmd_device_set_scan_interval}, + {"device_get_scanning", _on_cmd_device_get_scanning}, + {"device_get_networks", _on_cmd_device_get_networks}, + {"profile_get_name", _on_cmd_profile_get_name}, + {"profile_set_name", _on_cmd_profile_set_name}, + {"profile_get_offline_mode", _on_cmd_profile_get_offline_mode}, + {"profile_set_offline_mode", _on_cmd_profile_set_offline_mode}, + {"profile_get_services", _on_cmd_profile_get_services}, + {"network_get_address", _on_cmd_network_get_address}, + {"network_get_name", _on_cmd_network_get_name}, + {"network_get_connected", _on_cmd_network_get_connected}, + {"network_get_strength", _on_cmd_network_get_strength}, + {"network_get_frequency", _on_cmd_network_get_frequency}, + {"network_get_device", _on_cmd_network_get_device}, + {"network_get_wifi_ssid", _on_cmd_network_get_wifi_ssid}, + {"network_get_wifi_mode", _on_cmd_network_get_wifi_mode}, + {"network_get_wifi_security", _on_cmd_network_get_wifi_security}, + {"network_get_wifi_passphrase", _on_cmd_network_get_wifi_passphrase}, + {"network_get_wifi_channel", _on_cmd_network_get_wifi_channel}, + {"network_get_wifi_eap", _on_cmd_network_get_wifi_eap}, + {"service_connect", _on_cmd_service_connect}, + {"service_disconnect", _on_cmd_service_disconnect}, + {"service_remove", _on_cmd_service_remove}, + {"service_move_before", _on_cmd_service_move_before}, + {"service_move_after", _on_cmd_service_move_after}, + {"service_get_state", _on_cmd_service_get_state}, + {"service_get_error", _on_cmd_service_get_error}, + {"service_get_name", _on_cmd_service_get_name}, + {"service_get_type", _on_cmd_service_get_type}, + {"service_get_mode", _on_cmd_service_get_mode}, + {"service_get_security", _on_cmd_service_get_security}, + {"service_get_passphrase", _on_cmd_service_get_passphrase}, + {"service_set_passphrase", _on_cmd_service_set_passphrase}, + {"service_get_passphrase_required", _on_cmd_service_get_passphrase_required}, + {"service_get_strength", _on_cmd_service_get_strength}, + {"service_get_favorite", _on_cmd_service_get_favorite}, + {"service_get_immutable", _on_cmd_service_get_immutable}, + {"service_get_auto_connect", _on_cmd_service_get_auto_connect}, + {"service_set_auto_connect", _on_cmd_service_set_auto_connect}, + {"service_get_setup_required", _on_cmd_service_get_setup_required}, + {"service_get_apn", _on_cmd_service_get_apn}, + {"service_set_apn", _on_cmd_service_set_apn}, + {"service_get_mcc", _on_cmd_service_get_mcc}, + {"service_get_mnc", _on_cmd_service_get_mnc}, + {"service_get_roaming", _on_cmd_service_get_roaming}, + {"service_get_ipv4_method", _on_cmd_service_get_ipv4_method}, + {"service_get_ipv4_address", _on_cmd_service_get_ipv4_address}, + {"service_get_ipv4_gateway", _on_cmd_service_get_ipv4_gateway}, + {"service_get_ipv4_netmask", _on_cmd_service_get_ipv4_netmask}, + {"service_get_ipv4_configuration_method", _on_cmd_service_get_ipv4_configuration_method}, + {"service_get_ipv4_configuration_address", _on_cmd_service_get_ipv4_configuration_address}, + {"service_get_ipv4_configuration_gateway", _on_cmd_service_get_ipv4_configuration_gateway}, + {"service_get_ipv4_configuration_netmask", _on_cmd_service_get_ipv4_configuration_netmask}, + {"service_ipv4_configure_dhcp", _on_cmd_service_ipv4_configure_dhcp}, + {"service_ipv4_configure_manual", _on_cmd_service_ipv4_configure_manual}, + {"service_get_ethernet_method", _on_cmd_service_get_ethernet_method}, + {"service_get_ethernet_address", _on_cmd_service_get_ethernet_address}, + {"service_get_ethernet_mtu", _on_cmd_service_get_ethernet_mtu}, + {"service_get_ethernet_netmask", _on_cmd_service_get_ethernet_netmask}, + {"technology_get_devices", _on_cmd_technology_get_devices}, + {"technology_get_state", _on_cmd_technology_get_state}, + {"technology_get_type", _on_cmd_technology_get_type}, + {"technology_get_name", _on_cmd_technology_get_name}, + {NULL, NULL} + }; + + + if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) + { + fputs("ERROR: reading from stdin, exit\n", stderr); + return 0; + } + + if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) + { + fputs("ERROR: nothing to read?\n", stderr); + return 0; + } + + if (!fgets(buf, sizeof(buf), stdin)) + { + fprintf(stderr, "ERROR: could not read command: %s\n", strerror(errno)); + ecore_main_loop_quit(); + return 0; + } + + cmd = buf; + while (isspace(*cmd)) + cmd++; + + args = strchr(cmd, ' '); + if (args) + { + char *p; + + *args = '\0'; + args++; + + while (isspace(*args)) + args++; + + p = args + strlen(args) - 1; + if (*p == '\n') + *p = '\0'; + } + else + { + char *p; + + p = cmd + strlen(cmd) - 1; + if (*p == '\n') + *p = '\0'; + } + + if (strcmp(cmd, "help") == 0) + { + if (args) + { + printf("Commands with '%s' in the name:\n", args); + for (itr = maps; itr->cmd != NULL; itr++) + if (strstr(itr->cmd, args)) + printf("\t%s\n", itr->cmd); + } + else + { + fputs("Commands:\n", stdout); + for (itr = maps; itr->cmd != NULL; itr++) + printf("\t%s\n", itr->cmd); + } + fputc('\n', stdout); + return 1; + } + + for (itr = maps; itr->cmd != NULL; itr++) + if (strcmp(itr->cmd, cmd) == 0) + return itr->cb(cmd, args); + + printf("unknown command \"%s\", args=%s\n", cmd, args); + return 1; +} + +int +main(int argc, char *argv[]) +{ + E_DBus_Connection *c; + + ecore_init(); + e_dbus_init(); + eina_init(); + + c = e_dbus_bus_get(DBUS_BUS_SYSTEM); + if (!c) { + printf("ERROR: can't connect to system session\n"); + return -1; + } + + e_connman_system_init(c); + ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_ADD, _on_element_add, NULL); + ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_DEL, _on_element_del, NULL); + ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_UPDATED, + _on_element_updated, NULL); + + ecore_main_fd_handler_add + (0, ECORE_FD_READ | ECORE_FD_ERROR, _on_input, NULL, NULL, NULL); + + ecore_main_loop_begin(); + + e_connman_system_shutdown(); + + e_dbus_connection_close(c); + eina_shutdown(); + e_dbus_shutdown(); + ecore_shutdown(); + + fputs("DBG: clean exit.\n", stderr); + + return 0; +} diff --git a/src/bin/e_dbus_connman_test_api.c b/src/bin/e_dbus_connman_test_api.c new file mode 100644 index 0000000..86eb007 --- /dev/null +++ b/src/bin/e_dbus_connman_test_api.c @@ -0,0 +1,624 @@ +#include "E_Connman.h" +#include <stdio.h> +#include <string.h> + +#define DBG(...) EINA_LOG_DBG(__VA_ARGS__) +#define INF(...) EINA_LOG_INFO(__VA_ARGS__) +#define WRN(...) EINA_LOG_WARN(__VA_ARGS__) +#define ERR(...) EINA_LOG_ERR(__VA_ARGS__) + +static int success = 0; +static int failure = 0; +static Ecore_Timer *exiter = NULL; + +static bool +_test_string_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, const char **value)) +{ + const char *value; + bool ret; + + INF("BEGIN: testing string get %s of element %s...\n", name, element->path); + ret = func(element, &value); + if (ret) + INF("SUCCESS: testing string get %s of element %s: %s\n", + name, element->path, value); + else + WRN("FAILURE: testing string get %s of element %s\n", + name, element->path); + + return ret; +} + +static bool +_test_bool_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, bool *value)) +{ + bool value, ret; + + INF("BEGIN: testing bool get %s of element %s...\n", name, element->path); + ret = func(element, &value); + if (ret) + INF("SUCCESS: testing bool get %s of element %s: %hhu\n", + name, element->path, value); + else + WRN("FAILURE: testing bool get %s of element %s\n", + name, element->path); + + return ret; +} + +static bool +_test_uchar_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, unsigned char *value)) +{ + unsigned char value; + bool ret; + + INF("BEGIN: testing uchar get %s of element %s...\n", name, element->path); + ret = func(element, &value); + if (ret) + INF("SUCCESS: testing uchar get %s of element %s: %hhu\n", + name, element->path, value); + else + WRN("FAILURE: testing uchar get %s of element %s\n", + name, element->path); + + return ret; +} + +static bool +_test_ushort_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, unsigned short *value)) +{ + unsigned short value; + bool ret; + + INF("BEGIN: testing ushort get %s of element %s...\n", name, element->path); + ret = func(element, &value); + if (ret) + INF("SUCCESS: testing ushort get %s of element %s: %hu\n", + name, element->path, value); + else + WRN("FAILURE: testing ushort get %s of element %s\n", + name, element->path); + + return ret; +} + +static bool +_test_uchar_array_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, unsigned int *count, unsigned char **value)) +{ + unsigned char *value; + unsigned int count; + bool ret; + + INF("BEGIN: testing ushort get %s of element %s...\n", name, element->path); + ret = func(element, &count, &value); + if (ret) + { + INF("SUCCESS: testing ushort get %s of element %s: %p\n", + name, element->path, value); + free(value); + } + else + WRN("FAILURE: testing ushort get %s of element %s\n", + name, element->path); + + return ret; +} + +static bool +_test_element_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, E_Connman_Element **value)) +{ + E_Connman_Element *value; + bool ret; + + INF("BEGIN: testing element get %s of element %s...\n", name, element->path); + ret = func(element, &value); + if (ret) + INF("SUCCESS: testing element get %s of element %s: %p\n", + name, element->path, value); + else + WRN("FAILURE: testing element get %s of element %s\n", + name, element->path); + + return ret; +} + +static bool +_test_elements_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, unsigned int *count, E_Connman_Element ***elements)) +{ + E_Connman_Element **value; + unsigned int count; + bool ret; + + INF("BEGIN: testing elements get %s of element %s...\n", + name, element->path); + ret = func(element, &count, &value); + if (ret) + { + INF("SUCCESS: testing elements get %s of element %s: %p\n", + name, element->path, value); + free(value); + } + else + WRN("FAILURE: testing elements get %s of element %s\n", + name, element->path); + + return ret; +} + +static bool +_test_element_get_global(const char *name, bool (*func)(E_Connman_Element **value)) +{ + E_Connman_Element *value; + bool ret; + + INF("BEGIN: testing element get %s\n", name); + ret = func(&value); + if (ret) + INF("SUCCESS: testing element get %s: %p\n", name, value); + else + WRN("FAILURE: testing element get %s\n", name); + + return ret; +} + +static bool +_test_elements_get_global(const char *name, bool (*func)(unsigned int *count, E_Connman_Element ***elements)) +{ + E_Connman_Element **value; + unsigned int count; + bool ret; + + INF("BEGIN: testing elements get %s\n", name); + ret = func(&count, &value); + if (ret) + { + INF("SUCCESS: testing elements get %s: %p\n", name, value); + free(value); + } + else + WRN("FAILURE: testing elements get %s\n", name); + + return ret; +} + +static bool +_test_string_get_global(const char *name, bool (*func)(const char **value)) +{ + const char *value; + bool ret; + + INF("BEGIN: testing string get %s...\n", name); + ret = func(&value); + if (ret) + INF("SUCCESS: testing string get %s: %s\n", name, value); + else + WRN("FAILURE: testing string get %s\n", name); + + return ret; +} + +static bool +_test_bool_get_global(const char *name, bool (*func)(bool *value)) +{ + bool value, ret; + + INF("BEGIN: testing bool get %s...\n", name); + ret = func(&value); + if (ret) + INF("SUCCESS: testing bool get %s: %hhu\n", name, value); + else + WRN("FAILURE: testing bool get %s\n", name); + + return ret; +} + +static bool +_test_strings_get_global(const char *name, bool (*func)(unsigned int *count, const char ***elements)) +{ + const char **value; + unsigned int count; + bool ret; + + INF("BEGIN: testing strings get %s\n", name); + ret = func(&count, &value); + if (ret) + { + INF("SUCCESS: testing strings get %s: %p\n", name, value); + free(value); + } + else + WRN("FAILURE: testing strings get %s\n", name); + + return ret; +} + + +struct test_desc +{ + const char *name; + enum { + TEST_DESC_TYPE_STRING_GET, + TEST_DESC_TYPE_BOOL_GET, + TEST_DESC_TYPE_UCHAR_GET, + TEST_DESC_TYPE_USHORT_GET, + TEST_DESC_TYPE_UCHAR_ARRAY_GET, + TEST_DESC_TYPE_ELEMENT_GET, + TEST_DESC_TYPE_ELEMENTS_GET, + TEST_DESC_TYPE_ELEMENT_GET_GLOBAL, + TEST_DESC_TYPE_ELEMENTS_GET_GLOBAL, + TEST_DESC_TYPE_STRING_GET_GLOBAL, + TEST_DESC_TYPE_BOOL_GET_GLOBAL, + TEST_DESC_TYPE_STRINGS_GET_GLOBAL, + TEST_DESC_TYPE_LAST + } type; + union { + bool (*string_get)(const E_Connman_Element *element, const char **value); + bool (*bool_get)(const E_Connman_Element *element, bool *value); + bool (*uchar_get)(const E_Connman_Element *element, unsigned char *value); + bool (*ushort_get)(const E_Connman_Element *element, unsigned short*value); + bool (*uchar_array_get)(const E_Connman_Element *element, unsigned int *count, unsigned char **value); + bool (*element_get)(const E_Connman_Element *element, E_Connman_Element **value); + bool (*elements_get)(const E_Connman_Element *element, unsigned int *count, E_Connman_Element ***elements); + bool (*element_get_global)(E_Connman_Element **element); + bool (*elements_get_global)(unsigned int *count, E_Connman_Element ***elements); + bool (*string_get_global)(const char **value); + bool (*bool_get_global)(bool *value); + bool (*strings_get_global)(unsigned int *count, const char ***strings); + void *dummy; + } func; + bool may_fail; +}; + +#define TEST_DESC_STRING_GET(_func, may_fail) \ + {#_func, TEST_DESC_TYPE_STRING_GET, .func.string_get=_func, may_fail} +#define TEST_DESC_BOOL_GET(_func, may_fail) \ + {#_func, TEST_DESC_TYPE_BOOL_GET, .func.bool_get=_func, may_fail} +#define TEST_DESC_UCHAR_GET(_func, may_fail) \ + {#_func, TEST_DESC_TYPE_UCHAR_GET, .func.uchar_get=_func, may_fail} +#define TEST_DESC_USHORT_GET(_func, may_fail) \ + {#_func, TEST_DESC_TYPE_USHORT_GET, .func.ushort_get=_func, may_fail} +#define TEST_DESC_UCHAR_ARRAY_GET(_func, may_fail) \ + {#_func, TEST_DESC_TYPE_UCHAR_ARRAY_GET, .func.uchar_array_get=_func, may_fail} +#define TEST_DESC_ELEMENT_GET(_func, may_fail) \ + {#_func, TEST_DESC_TYPE_ELEMENT_GET, .func.element_get=_func, may_fail} +#define TEST_DESC_ELEMENTS_GET(_func, may_fail) \ + {#_func, TEST_DESC_TYPE_ELEMENTS_GET, .func.elements_get=_func, may_fail} +#define TEST_DESC_ELEMENT_GET_GLOBAL(_func, may_fail) \ + {#_func, TEST_DESC_TYPE_ELEMENT_GET_GLOBAL, .func.element_get_global=_func, may_fail} +#define TEST_DESC_ELEMENTS_GET_GLOBAL(_func, may_fail) \ + {#_func, TEST_DESC_TYPE_ELEMENTS_GET_GLOBAL, .func.elements_get_global=_func, may_fail} +#define TEST_DESC_STRING_GET_GLOBAL(_func, may_fail) \ + {#_func, TEST_DESC_TYPE_STRING_GET_GLOBAL, .func.string_get_global=_func, may_fail} +#define TEST_DESC_BOOL_GET_GLOBAL(_func, may_fail) \ + {#_func, TEST_DESC_TYPE_BOOL_GET_GLOBAL, .func.bool_get_global=_func, may_fail} +#define TEST_DESC_STRINGS_GET_GLOBAL(_func, may_fail) \ + {#_func, TEST_DESC_TYPE_STRINGS_GET_GLOBAL, .func.strings_get_global=_func, may_fail} +#define TEST_DESC_SENTINEL {NULL, TEST_DESC_TYPE_LAST, .func.dummy=NULL} + +static bool +_test_element(E_Connman_Element *element, const struct test_desc *test_descs) +{ + const struct test_desc *itr; + int total, ok = 0, fail = 0; + bool ret = 1; + + for (itr = test_descs; itr->type != TEST_DESC_TYPE_LAST; itr++) + { + bool r; + + switch (itr->type) + { + case TEST_DESC_TYPE_STRING_GET: + r = _test_string_get(element, itr->name, itr->func.string_get); + break; + case TEST_DESC_TYPE_BOOL_GET: + r = _test_bool_get(element, itr->name, itr->func.bool_get); + break; + case TEST_DESC_TYPE_UCHAR_GET: + r = _test_uchar_get(element, itr->name, itr->func.uchar_get); + break; + case TEST_DESC_TYPE_USHORT_GET: + r = _test_ushort_get(element, itr->name, itr->func.ushort_get); + break; + case TEST_DESC_TYPE_UCHAR_ARRAY_GET: + r = _test_uchar_array_get + (element, itr->name, itr->func.uchar_array_get); + break; + case TEST_DESC_TYPE_ELEMENT_GET: + r = _test_element_get + (element, itr->name, itr->func.element_get); + break; + case TEST_DESC_TYPE_ELEMENTS_GET: + r = _test_elements_get + (element, itr->name, itr->func.elements_get); + break; + case TEST_DESC_TYPE_ELEMENT_GET_GLOBAL: + r = _test_element_get_global + (itr->name, itr->func.element_get_global); + break; + case TEST_DESC_TYPE_ELEMENTS_GET_GLOBAL: + r = _test_elements_get_global + (itr->name, itr->func.elements_get_global); + break; + case TEST_DESC_TYPE_STRING_GET_GLOBAL: + r = _test_string_get_global + (itr->name, itr->func.string_get_global); + break; + case TEST_DESC_TYPE_BOOL_GET_GLOBAL: + r = _test_bool_get_global + (itr->name, itr->func.bool_get_global); + break; + case TEST_DESC_TYPE_STRINGS_GET_GLOBAL: + r = _test_strings_get_global + (itr->name, itr->func.strings_get_global); + break; + default: + ERR("unknown test type %d (%s)\n", itr->type, itr->name); + r = 0; + break; + } + + if (r || itr->may_fail) + ok++; + else + { + ERR("test failed %s, element %s [%s]\n", + itr->name, element->path, element->interface); + fail++; + ret = 0; + } + } + + total = ok + failure; + success += ok; + failure += fail; + if (total == 0) + { + INF("no tests for %s [%s]\n", element->path, element->interface); + return 1; + } + + INF("testing %s success: %d, failure: %d: %d%% [%s]\n", + element->path, ok, fail, (ok * 100) / total, + element->interface); + + return ret; +} + +static const struct test_desc test_desc_manager[] = { + TEST_DESC_STRING_GET_GLOBAL(e_connman_manager_state_get, 0), + TEST_DESC_BOOL_GET_GLOBAL(e_connman_manager_offline_mode_get, 0), + //TEST_DESC_STRING_SET_GLOBAL(e_connman_manager_request_scan, 0), + //TEST_DESC_BOOL_SET_GLOBAL(e_connman_manager_offline_mode_set, 0), + TEST_DESC_ELEMENTS_GET_GLOBAL(e_connman_manager_profiles_get, 0), + TEST_DESC_ELEMENTS_GET_GLOBAL(e_connman_manager_services_get, 1), + TEST_DESC_STRING_GET_GLOBAL(e_connman_manager_technology_default_get, 0), + TEST_DESC_STRINGS_GET_GLOBAL(e_connman_manager_technologies_available_get, 0), + TEST_DESC_STRINGS_GET_GLOBAL(e_connman_manager_technologies_enabled_get, 0), + TEST_DESC_STRINGS_GET_GLOBAL(e_connman_manager_technologies_connected_get, 0), + TEST_DESC_ELEMENT_GET_GLOBAL(e_connman_manager_profile_active_get, 0), + TEST_DESC_SENTINEL +}; + +static const struct test_desc test_desc_device[] = { + TEST_DESC_STRING_GET(e_connman_device_address_get, 0), + TEST_DESC_STRING_GET(e_connman_device_name_get, 0), + TEST_DESC_STRING_GET(e_connman_device_type_get, 0), + TEST_DESC_STRING_GET(e_connman_device_interface_get, 0), + TEST_DESC_BOOL_GET(e_connman_device_powered_get, 0), + //TEST_DESC_BOOL_SET(e_connman_device_powered_set, 0), + TEST_DESC_USHORT_GET(e_connman_device_scan_interval_get, 1), + //TEST_DESC_USHORT_SET(e_connman_device_scan_interval_set, 1), + TEST_DESC_BOOL_GET(e_connman_device_scanning_get, 1), + TEST_DESC_ELEMENTS_GET(e_connman_device_networks_get, 1), + TEST_DESC_SENTINEL +}; + +static const struct test_desc test_desc_profile[] = { + TEST_DESC_STRING_GET(e_connman_profile_name_get, 1), + //TEST_DESC_STRING_SET(e_connman_profile_name_set, 1), + TEST_DESC_BOOL_GET(e_connman_profile_offline_mode_get, 0), + //TEST_DESC_BOOL_SET(e_connman_profile_offline_mode_set, 0), + TEST_DESC_ELEMENTS_GET(e_connman_profile_services_get, 1), + TEST_DESC_SENTINEL +}; + +static const struct test_desc test_desc_network[] = { + TEST_DESC_STRING_GET(e_connman_network_address_get, 0), + TEST_DESC_STRING_GET(e_connman_network_name_get, 0), + TEST_DESC_BOOL_GET(e_connman_network_connected_get, 0), + TEST_DESC_UCHAR_GET(e_connman_network_strength_get, 1), + TEST_DESC_USHORT_GET(e_connman_network_frequency_get, 1), + TEST_DESC_ELEMENT_GET(e_connman_network_device_get, 0), + TEST_DESC_UCHAR_ARRAY_GET(e_connman_network_wifi_ssid_get, 1), + TEST_DESC_STRING_GET(e_connman_network_wifi_mode_get, 1), + TEST_DESC_STRING_GET(e_connman_network_wifi_security_get, 1), + TEST_DESC_STRING_GET(e_connman_network_wifi_passphrase_get, 1), + TEST_DESC_USHORT_GET(e_connman_network_wifi_channel_get, 1), + TEST_DESC_STRING_GET(e_connman_network_wifi_eap_get, 1), + TEST_DESC_SENTINEL +}; + +static const struct test_desc test_desc_service[] = { + /* TODO: need to check exactly what properties may fail */ + TEST_DESC_STRING_GET(e_connman_service_state_get, 1), + TEST_DESC_STRING_GET(e_connman_service_error_get, 1), + TEST_DESC_STRING_GET(e_connman_service_name_get, 0), + TEST_DESC_STRING_GET(e_connman_service_type_get, 0), + TEST_DESC_STRING_GET(e_connman_service_mode_get, 1), + TEST_DESC_STRING_GET(e_connman_service_security_get, 1), + TEST_DESC_STRING_GET(e_connman_service_passphrase_get, 1), + //TEST_DESC_STRING_SET(e_connman_service_passphrase_set, 1), + TEST_DESC_BOOL_GET(e_connman_service_passphrase_required_get, 1), + TEST_DESC_UCHAR_GET(e_connman_service_strength_get, 1), + TEST_DESC_BOOL_GET(e_connman_service_favorite_get, 0), + TEST_DESC_BOOL_GET(e_connman_service_immutable_get, 0), + TEST_DESC_BOOL_GET(e_connman_service_auto_connect_get, 0), + //TEST_DESC_BOOL_SET(e_connman_service_auto_connect_set, 1), + TEST_DESC_BOOL_GET(e_connman_service_setup_required_get, 1), + TEST_DESC_STRING_GET(e_connman_service_apn_get, 1), + //TEST_DESC_STRING_SET(e_connman_service_apn_set, 1), + TEST_DESC_STRING_GET(e_connman_service_mcc_get, 1), + TEST_DESC_STRING_GET(e_connman_service_mnc_get, 1), + TEST_DESC_BOOL_GET(e_connman_service_roaming_get, 1), + TEST_DESC_STRING_GET(e_connman_service_ipv4_method_get, 1), + TEST_DESC_STRING_GET(e_connman_service_ipv4_address_get, 1), + TEST_DESC_STRING_GET(e_connman_service_ipv4_gateway_get, 1), + TEST_DESC_STRING_GET(e_connman_service_ipv4_netmask_get, 1), + TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_method_get, 1), + TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_address_get, 1), + TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_gateway_get, 1), + TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_netmask_get, 1), + TEST_DESC_STRING_GET(e_connman_service_ethernet_method_get, 1), + TEST_DESC_STRING_GET(e_connman_service_ethernet_address_get, 1), + TEST_DESC_USHORT_GET(e_connman_service_ethernet_mtu_get, 1), + TEST_DESC_STRING_GET(e_connman_service_ethernet_netmask_get, 1), + TEST_DESC_SENTINEL +}; + +static int +_quit(void *data) +{ + ecore_main_loop_quit(); + return 0; +} + +static int +_on_exiter(void *data) +{ + e_connman_system_shutdown(); + ecore_idle_enterer_add(_quit, NULL); + exiter = NULL; + return 0; +} + +static void +_exiter_reschedule(void) +{ + if (exiter) + ecore_timer_del(exiter); + exiter = ecore_timer_add(10, _on_exiter, NULL); +} + +struct test_element_timer_data +{ + E_Connman_Element *element; + Ecore_Timer *timer; +}; + +static int +_test_element_timer(void *data) +{ + struct test_element_timer_data *d = data; + E_Connman_Element *element = d->element; + + if (e_connman_element_is_device(element)) + _test_element(element, test_desc_device); + else if (e_connman_element_is_profile(element)) + _test_element(element, test_desc_profile); + else if (e_connman_element_is_network(element)) + _test_element(element, test_desc_network); + else if (e_connman_element_is_manager(element)) + _test_element(element, test_desc_manager); + else if (e_connman_element_is_service(element)) + _test_element(element, test_desc_service); + else + ERR("!!! don't know how to test %s [%s]\n", + element->path, element->interface); + + _exiter_reschedule(); + + d->timer = NULL; + return 0; +} + +static void +_element_listener(void *data, const E_Connman_Element *element) +{ + struct test_element_timer_data *d = data; + if (d->timer) + ecore_timer_del(d->timer); + d->timer = ecore_timer_add(1.0, _test_element_timer, d); + _exiter_reschedule(); +} + +static void +_element_listener_free(void *data) +{ + struct test_element_timer_data *d = data; + if (d->timer) + ecore_timer_del(d->timer); + free(d); +} + +static int +_on_element_add(void *data, int type, void *info) +{ + E_Connman_Element *element = info; + struct test_element_timer_data *d; + + d = malloc(sizeof(*d)); + if (!d) + return 1; + + d->element = element; + d->timer = ecore_timer_add(1.0, _test_element_timer, d); + e_connman_element_listener_add + (element, _element_listener, d, _element_listener_free); + + return 1; +} + +static int +_on_element_del(void *data, int type, void *info) +{ + return 1; +} + +static int +_on_element_updated(void *data, int type, void *info) +{ + return 1; +} + +int +main(int argc, char *argv[]) +{ + E_DBus_Connection *c; + int total; + + ecore_init(); + e_dbus_init(); + eina_init(); + + c = e_dbus_bus_get(DBUS_BUS_SYSTEM); + if (!c) { + printf("ERROR: can't connect to system session\n"); + return -1; + } + + e_connman_system_init(c); + ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_ADD, _on_element_add, NULL); + ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_DEL, _on_element_del, NULL); + ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_UPDATED, + _on_element_updated, NULL); + + _exiter_reschedule(); + + ecore_main_loop_begin(); + + e_dbus_connection_close(c); + eina_stringshare_dump(); + eina_shutdown(); + e_dbus_shutdown(); + ecore_shutdown(); + + total = success + failure; + if (total == 0) + fputs("DBG: clean exit, no tests executed.\n", stderr); + else + fprintf(stderr, "DBG: clean exit, success: %d, failure: %d, %d%%\n", + success, failure, (success * 100) / total); + + return 0; +} diff --git a/src/bin/e_dbus_ofono_test.c b/src/bin/e_dbus_ofono_test.c new file mode 100644 index 0000000..c60438c --- /dev/null +++ b/src/bin/e_dbus_ofono_test.c @@ -0,0 +1,514 @@ +#include "E_Ofono.h" +#include <stdio.h> +#include <string.h> +#include <ctype.h> +#include <errno.h> + +static void +_method_success_check(void *data, DBusMessage *msg, DBusError *error) +{ + const char *name = data; + + if ((!error) || (!dbus_error_is_set(error))) + { + printf("SUCCESS: method %s() finished successfully.\n", name); + return; + } + + printf("FAILURE: method %s() finished with error: %s %s\n", + name, error->name, error->message); + dbus_error_free(error); +} + +static void +_elements_print(E_Ofono_Element **elements, unsigned int count) +{ + unsigned int i; + for (i = 0; i < count; i++) + { + printf("--- element %d:\n", i); + e_ofono_element_print(stdout, elements[i]); + } + free(elements); + printf("END: all elements count = %u\n", count); +} + +static int +_on_element_add(void *data, int type, void *info) +{ + E_Ofono_Element *element = info; + printf(">>> %s %s\n", element->path, element->interface); + return 1; +} + +static int +_on_element_del(void *data, int type, void *info) +{ + E_Ofono_Element *element = info; + printf("<<< %s %s\n", element->path, element->interface); + return 1; +} + +static int +_on_element_updated(void *data, int type, void *info) +{ + E_Ofono_Element *element = info; + printf("!!! %s %s\n", element->path, element->interface); + e_ofono_element_print(stderr, element); + return 1; +} +static int +_on_cmd_quit(char *cmd, char *args) +{ + fputs("Bye!\n", stderr); + ecore_main_loop_quit(); + return 0; +} + +static int +_on_cmd_sync(char *cmd, char *args) +{ + e_ofono_manager_sync_elements(); + return 1; +} + +static char * +_tok(char *p) +{ + p = strchr(p, ' '); + if (!p) + return NULL; + + *p = '\0'; + p++; + while (isspace(*p)) + p++; + if (*p == '\0') + return NULL; + + return p; +} + +static int +_on_cmd_get_all(char *cmd, char *args) +{ + E_Ofono_Element **elements; + char *type; + unsigned int count; + Eina_Bool ret; + + if (!args) + type = NULL; + else + type = args; + + if (type) + ret = e_ofono_elements_get_all_type(type, &count, &elements); + else + ret = e_ofono_elements_get_all(&count, &elements); + + if (!ret) + fputs("ERROR: could not get elements\n", stderr); + else + { + printf("BEG: all elements type=%s count = %d\n", type, count); + _elements_print(elements, count); + } + + return 1; +} + +static E_Ofono_Element * +_element_from_args(char *interface, char *args, char **next_args) +{ + E_Ofono_Element *element; + + if (!args) + { + fputs("ERROR: missing element path\n", stderr); + *next_args = NULL; + return NULL; + } + + if (!interface) + { + interface = _tok(args); + *next_args = _tok(interface); + } + else + *next_args = _tok(args); + + element = e_ofono_element_get(args, interface); + if (!element) + fprintf(stderr, "ERROR: no element called \"%s %s\".\n", args, interface); + + return element; +} + +static int +_on_cmd_print(char *cmd, char *args) +{ + char *next_args; + E_Ofono_Element *element = _element_from_args(NULL, args, &next_args); + if (element) + e_ofono_element_print(stdout, element); + return 1; +} + +static int +_on_cmd_get_properties(char *cmd, char *args) +{ + char *next_args; + E_Ofono_Element *element = _element_from_args(NULL, args, &next_args); + if (element) + e_ofono_element_properties_sync(element); + return 1; +} + +static int +_on_cmd_property_set(char *cmd, char *args) +{ + char *next_args, *name, *p; + E_Ofono_Element *element = _element_from_args(NULL, args, &next_args); + void *value; + long vlong; + unsigned short vu16; + unsigned int vu32; + int type; + + if (!element) + return 1; + + if (!next_args) + { + fputs("ERROR: missing parameters name, type and value.\n", stderr); + return 1; + } + + name = next_args; + p = _tok(name); + if (!p) + { + fputs("ERROR: missing parameters type and value.\n", stderr); + return 1; + } + + next_args = _tok(p); + if (!next_args) + { + fputs("ERROR: missing parameter value.\n", stderr); + return 1; + } + + type = p[0]; + switch (type) + { + case DBUS_TYPE_BOOLEAN: + vlong = !!atol(next_args); + value = &vlong; + fprintf(stderr, "DBG: boolean is: %ld\n", vlong); + break; + case DBUS_TYPE_UINT16: + vu16 = strtol(next_args, &p, 0); + if (p == next_args) + { + fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args); + return 1; + } + value = &vu16; + fprintf(stderr, "DBG: u16 is: %hu\n", vu16); + break; + case DBUS_TYPE_UINT32: + vu32 = strtol(next_args, &p, 0); + if (p == next_args) + { + fprintf(stderr, "ERROR: invalid number \"%s\".\n", next_args); + return 1; + } + value = &vu32; + fprintf(stderr, "DBG: u16 is: %u\n", vu32); + break; + case DBUS_TYPE_STRING: + case DBUS_TYPE_OBJECT_PATH: + p = next_args + strlen(next_args); + if (p > next_args) + p--; + while (p > next_args && isspace(*p)) + p--; + if (p <= next_args) + { + fprintf(stderr, "ERROR: invalid string \"%s\".\n", next_args); + } + p[1] = '\0'; + value = next_args; + fprintf(stderr, "DBG: string is: \"%s\"\n", next_args); + break; + default: + fprintf(stderr, "ERROR: don't know how to parse type '%c' (%d)\n", + type, type); + return 1; + } + + fprintf(stderr, "set_property %s [%p] %s %c %p...\n", + args, element, name, type, value); + if (!e_ofono_element_property_set(element, name, type, value)) + fputs("ERROR: error setting property.\n", stderr); + + return 1; +} + +/* Manager Commands */ + +static int +_on_cmd_manager_get(char *cmd, char *args) +{ + E_Ofono_Element *element; + element = e_ofono_manager_get(); + e_ofono_element_print(stderr, element); + return 1; +} + +static int +_on_cmd_manager_modems_get(char *cmd, char *args) +{ + char *path; + Eina_Array_Iterator iterator; + unsigned int i; + Eina_Array *modems = NULL; + + if(e_ofono_manager_modems_get(&modems)) + { + printf("["); + if (modems) + EINA_ARRAY_ITER_NEXT(modems, i, path, iterator) + printf(" %s", path); + printf(" ]\n"); + } + + return 1; +} + +/* Modem Commands */ + +static int +_on_cmd_modem_set_powered(char *cmd, char *args) +{ + char *next_args; + Eina_Bool powered; + E_Ofono_Element *element = _element_from_args("org.ofono.Modem", args, &next_args); + + if (!element) + return 1; + + if (!args) + { + fputs("ERROR: missing the powered value\n", stderr); + return 1; + } + + powered = !!atol(next_args); + + if (e_ofono_modem_powered_set + (element, powered, _method_success_check, "modem_set_powered")) + printf(":::Modem %s Powered set to %hhu\n", element->path, powered); + else + fputs("ERROR: can't set Modem Powered\n", stderr); + return 1; +} + +/* SMS Commands */ + +static int +_on_cmd_sms_sca_set(char *cmd, char *args) +{ + char *next_args, *sca; + E_Ofono_Element *element = _element_from_args("org.ofono.SmsManager", args, + &next_args); + + if (!element) + return 1; + + if (!args) + { + fputs("ERROR: missing service center address\n", stderr); + return 1; + } + + sca = next_args; + if (e_ofono_sms_sca_set(element, sca, _method_success_check, + "sms_sca_set")) + printf(":::Service Center Address on modem %s set to %s\n", + element->path, sca); + else + fputs("ERROR: couldn't change Service Center Address\n", stderr); + + return 1; +} + +static int +_on_cmd_sms_send_message(char *cmd, char *args) +{ + char *next_args, *number, *message; + E_Ofono_Element *element = _element_from_args("org.ofono.SmsManager", args, + &next_args); + + if (!element) + return 1; + + number = next_args; + if (!number) + { + fputs("ERROR: missing recipient number and message text.\n", stderr); + return 1; + } + + message = _tok(number); + if (!message) + { + fputs("ERROR: missing message text.\n", stderr); + return 1; + } + + if (!e_ofono_sms_send_message(element, number, message, + _method_success_check, "sms_send_message")) + fputs("ERROR: error setting property.\n", stderr); + + return 1; +} + +static int +_on_input(void *data, Ecore_Fd_Handler *fd_handler) +{ + char buf[256]; + char *cmd, *args; + const struct { + const char *cmd; + int (*cb)(char *cmd, char *args); + } *itr, maps[] = { + {"quit", _on_cmd_quit}, + {"sync", _on_cmd_sync}, + {"get_all", _on_cmd_get_all}, + {"print", _on_cmd_print}, + {"get_properties", _on_cmd_get_properties}, + {"set_property", _on_cmd_property_set}, + {"manager_get", _on_cmd_manager_get}, + {"manager_modems_get", _on_cmd_manager_modems_get}, + {"modem_set_powered", _on_cmd_modem_set_powered}, + {"sms_sca_set", _on_cmd_sms_sca_set}, + {"sms_send_message", _on_cmd_sms_send_message}, + {NULL, NULL} + }; + + + if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) + { + fputs("ERROR: reading from stdin, exit\n", stderr); + return 0; + } + + if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) + { + fputs("ERROR: nothing to read?\n", stderr); + return 0; + } + + if (!fgets(buf, sizeof(buf), stdin)) + { + fprintf(stderr, "ERROR: could not read command: %s\n", strerror(errno)); + ecore_main_loop_quit(); + return 0; + } + + cmd = buf; + while (isspace(*cmd)) + cmd++; + + args = strchr(cmd, ' '); + if (args) + { + char *p; + + *args = '\0'; + args++; + + while (isspace(*args)) + args++; + + p = args + strlen(args) - 1; + if (*p == '\n') + *p = '\0'; + } + else + { + char *p; + + p = cmd + strlen(cmd) - 1; + if (*p == '\n') + *p = '\0'; + } + + if (strcmp(cmd, "help") == 0) + { + if (args) + { + printf("Commands with '%s' in the name:\n", args); + for (itr = maps; itr->cmd != NULL; itr++) + if (strstr(itr->cmd, args)) + printf("\t%s\n", itr->cmd); + } + else + { + fputs("Commands:\n", stdout); + for (itr = maps; itr->cmd != NULL; itr++) + printf("\t%s\n", itr->cmd); + } + fputc('\n', stdout); + return 1; + } + + for (itr = maps; itr->cmd != NULL; itr++) + if (strcmp(itr->cmd, cmd) == 0) + return itr->cb(cmd, args); + + printf("unknown command \"%s\", args=%s\n", cmd, args); + return 1; +} + +int +main(int argc, char *argv[]) +{ + E_DBus_Connection *c; + + ecore_init(); + e_dbus_init(); + eina_init(); + + c = e_dbus_bus_get(DBUS_BUS_SYSTEM); + if (!c) { + printf("ERROR: can't connect to system session\n"); + return -1; + } + + e_ofono_system_init(c); + + ecore_event_handler_add(E_OFONO_EVENT_ELEMENT_ADD, _on_element_add, NULL); + ecore_event_handler_add(E_OFONO_EVENT_ELEMENT_DEL, _on_element_del, NULL); + ecore_event_handler_add(E_OFONO_EVENT_ELEMENT_UPDATED, + _on_element_updated, NULL); + + ecore_main_fd_handler_add + (0, ECORE_FD_READ | ECORE_FD_ERROR, _on_input, NULL, NULL, NULL); + + ecore_main_loop_begin(); + + e_ofono_system_shutdown(); + + e_dbus_connection_close(c); + eina_shutdown(); + e_dbus_shutdown(); + ecore_shutdown(); + + fputs("DBG: clean exit.\n", stderr); + + return 0; +} diff --git a/src/bin/e_dbus_ukit_test.c b/src/bin/e_dbus_ukit_test.c new file mode 100644 index 0000000..9cadf34 --- /dev/null +++ b/src/bin/e_dbus_ukit_test.c @@ -0,0 +1,146 @@ +#include <E_Ukit.h> +#include <E_DBus.h> +#include <Ecore.h> +#include <stdio.h> + +static E_DBus_Connection *econ = NULL; + +Eina_Bool +print_prop(const Eina_Hash *hash, const void *key, void *data, void *fdata) +{ + const Eina_List *strlist, *l; + char *y; + E_Ukit_Property *p = data; + E_Ukit_Properties props; + int err = 0; + + props.properties = (Eina_Hash*)hash; + switch (p->type) + { + case E_UKIT_PROPERTY_TYPE_STRING: + printf("\t%s = [%s]\n", (char*)key, e_ukit_property_string_get(&props, key, &err)); + break; + case E_UKIT_PROPERTY_TYPE_INT: + printf("\t%s = [%d]\n", (char*)key, e_ukit_property_int_get(&props, key, &err)); + break; + case E_UKIT_PROPERTY_TYPE_UINT32: + printf("\t%s = [%u]\n", (char*)key, (long long unsigned)e_ukit_property_uint32_get(&props, key, &err)); + break; + case E_UKIT_PROPERTY_TYPE_UINT64: + printf("\t%s = [%llu]\n", (char*)key, (long long unsigned)e_ukit_property_uint64_get(&props, key, &err)); + break; + case E_UKIT_PROPERTY_TYPE_INT64: + printf("\t%s = [%lld]\n", (char*)key, (long long int)e_ukit_property_int64_get(&props, key, &err)); + break; + case E_UKIT_PROPERTY_TYPE_BOOL: + printf("\t%s = [%d]\n", (char*)key, e_ukit_property_bool_get(&props, key, &err)); + break; + case E_UKIT_PROPERTY_TYPE_DOUBLE: + printf("\t%s = [%f]\n", (char*)key, e_ukit_property_double_get(&props, key, &err)); + break; + case E_UKIT_PROPERTY_TYPE_STRLIST: + printf("\t%s = [", (char*)key); + strlist = e_ukit_property_strlist_get(&props, key, &err); + EINA_LIST_FOREACH(strlist, l, y) + printf("%s%s", y, (l->next) ? " " : ""); + printf("]\n"); + break; + } + + return 1; +} + +static void +hash_props(void *user_data, void *reply_data, DBusError *error) +{ + printf("%s:\n", (char*)user_data); + E_Ukit_Get_All_Properties_Return *ret = reply_data; + + if (!ret || dbus_error_is_set(error)) + { + free(user_data); + dbus_error_free(error); + return; + } + + eina_hash_foreach(ret->properties, print_prop, NULL); + printf("\n"); + free(user_data); +} + +static void +test_mount(void *user_data, void *reply_data, DBusError *error) +{ + E_Ukit_Get_Property_Return *ret = reply_data; + + if (!ret || dbus_error_is_set(error)) + { + free(user_data); + dbus_error_free(error); + return; + } + + if (ret->val.b) + { + printf("[%s] is mounted!\n\tGrabbing more stats to fill your screen...\n", (char*)user_data); + e_udisks_get_all_properties(econ, user_data, hash_props, strdup(user_data)); + } + else printf("[%s] is not mounted!\n", (char*)user_data); + free(user_data); +} + +static void +print_devs(void *user_data, void *reply_data, DBusError *error) +{ + E_Ukit_Get_All_Devices_Return *ret = reply_data; + Eina_List *l; + char *udi; + + if (!ret || !ret->strings || dbus_error_is_set(error)) + { + free(user_data); + dbus_error_free(error); + return; + } + + EINA_LIST_FOREACH(ret->strings, l, udi) + { + if (!strcmp((char*)user_data, "disks")) + e_udisks_get_property(econ, udi, "DeviceIsMounted", test_mount, strdup(udi)); + else + e_upower_get_all_properties(econ, udi, hash_props, strdup(udi)); + } + free(user_data); +} +static int +my_quit(void *data) +{ + ecore_main_loop_quit(); + return 0; +} + +int main(void) +{ + ecore_init(); + eina_init(); + e_dbus_init(); + e_ukit_init(); + + econ = e_dbus_bus_get(DBUS_BUS_SYSTEM); + if (econ) + { + e_udisks_get_all_devices(econ, print_devs, strdup("disks")); + e_upower_get_all_devices(econ, print_devs, strdup("power")); + } + /*add a short timer to quit to try and ensure that all the tests run*/ + ecore_timer_add(1, my_quit, NULL); + ecore_main_loop_begin(); + + if (econ) e_dbus_connection_close(econ); + e_ukit_shutdown(); + e_dbus_shutdown(); + eina_shutdown(); + ecore_shutdown(); + + return 0; +} diff --git a/src/bin/notification_daemon.c b/src/bin/notification_daemon.c new file mode 100644 index 0000000..ffddc4a --- /dev/null +++ b/src/bin/notification_daemon.c @@ -0,0 +1,196 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> + +#include <Ecore.h> +#include <E_Notification_Daemon.h> + +typedef struct Daemon_Data Daemon_Data; +typedef struct Timer_Data Timer_Data; + +struct Timer_Data +{ + Daemon_Data *d; + E_Notification *n; +}; + +struct Daemon_Data +{ + E_Notification_Daemon *daemon; + Eina_List *open_notes; + + Eina_List *history; + int history_start; + int max_history_length; + int default_timeout; + + int next_id; +}; + +void +daemon_note_close(Daemon_Data *dd, E_Notification *n, int reason) +{ + printf("Close notification #%d\n", e_notification_id_get(n)); + + if (eina_list_data_find(dd->open_notes, n)) + { + dd->open_notes = eina_list_remove(dd->open_notes, n); + e_notification_closed_set(n, 1); + e_notification_daemon_signal_notification_closed(dd->daemon, e_notification_id_get(n), reason); + e_notification_unref(n); + } +} + +int +cb_note_close_timer(void *data) +{ + Timer_Data *td = data; + + if (!e_notification_closed_get(td->n)) + daemon_note_close(td->d, td->n, E_NOTIFICATION_CLOSED_EXPIRED); + + e_notification_unref(td->n); + free(td); + + return 0; +} + +void +daemon_note_show(Daemon_Data *d, E_Notification *n) +{ + e_notification_ref(n); + d->open_notes = eina_list_append(d->open_notes, n); + e_notification_ref(n); + d->history = eina_list_append(d->history, n); + + // adjust history + if (eina_list_count(d->history) > d->max_history_length) + { + E_Notification *old; + old = eina_list_data_get(d->history); + d->history = eina_list_remove_list(d->history, d->history); + d->history_start = e_notification_id_get(old) + 1; + e_notification_unref(old); + } + + { + int timeout; + + timeout = e_notification_timeout_get(n); + Timer_Data *td = calloc(1, sizeof(Timer_Data)); + td->d = d; + e_notification_ref(n); + td->n = n; + ecore_timer_add(timeout == -1 ? d->default_timeout : (float)timeout / 1000, cb_note_close_timer, td); + } + + printf("Received notification from %s:\n%s\n%s\n\n", + e_notification_app_name_get(n), + e_notification_summary_get(n), e_notification_body_get(n) + ); +} + +E_Notification * +daemon_note_open_find(Daemon_Data *d, int id) +{ + E_Notification *n; + Eina_List *l; + + EINA_LIST_FOREACH(d->open_notes, l, n) + if (e_notification_id_get(n) == id) return n; + + return NULL; +} + +E_Notification * +daemon_note_history_find(Daemon_Data *d, int id) +{ + if (id < d->history_start) return NULL; + + // TODO + + return NULL; +} + + + +int +cb_notify(E_Notification_Daemon *daemon, E_Notification *n) +{ + Daemon_Data *dd; + unsigned int replaces_id; + unsigned int new_id; + + dd = e_notification_daemon_data_get(daemon); + replaces_id = e_notification_replaces_id_get(n); + if (replaces_id) + { + // close old one flagged as replaced + } + + new_id = dd->next_id++; + e_notification_id_set(n, new_id); + + daemon_note_show(dd, n); + + return new_id; +} + +void +cb_close_notification(E_Notification_Daemon *daemon, unsigned int notification_id) +{ + Daemon_Data *dd; + E_Notification *n; + dd = e_notification_daemon_data_get(daemon); + n = daemon_note_open_find(dd, notification_id); + if (n) + daemon_note_close(dd, n, E_NOTIFICATION_CLOSED_REQUESTED); + // else send error? +} + + +int +main() +{ + E_Notification_Daemon *d; + E_Notification *n; + Daemon_Data *dd; + + + ecore_init(); + + dd = calloc(1, sizeof(Daemon_Data)); + dd->open_notes = NULL; + dd->history = NULL; + dd->next_id = dd->history_start = 1; + dd->max_history_length = 5; + dd->default_timeout = 5; + + /* set up the daemon */ + d = e_notification_daemon_add("e_notification_module", "Enlightenment"); + e_notification_daemon_data_set(d, dd); + dd->daemon = d; + e_notification_daemon_callback_notify_set(d, cb_notify); + e_notification_daemon_callback_close_notification_set(d, cb_close_notification); + + ecore_main_loop_begin(); + while (dd->open_notes) + { + n = eina_list_data_get(dd->open_notes); + e_notification_unref(n); + dd->open_notes = eina_list_remove_list(dd->open_notes, dd->open_notes); + } + while (dd->history) + { + n = eina_list_data_get(dd->history); + e_notification_unref(n); + dd->history = eina_list_remove_list(dd->history, dd->history); + } + free(dd); + e_notification_daemon_free(d); + ecore_shutdown(); + + return 0; +} diff --git a/src/bin/notify-send.c b/src/bin/notify-send.c new file mode 100644 index 0000000..89be670 --- /dev/null +++ b/src/bin/notify-send.c @@ -0,0 +1,175 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> +#include <string.h> +#include <limits.h> +#include <errno.h> +#include <getopt.h> + +#include <Ecore.h> +#include <E_Notify.h> + +void +version(void) +{ + printf("e-notify-send "VERSION"\n"); +} + +void +usage(void) +{ + printf("Usage:\n" + " e-notify-send [OPTION...] <SUMMARY> [BODY] - create a notification\n" + "\n" + "Help Options:\n" + " -?, --help Show help options\n" + "\n" + "Application Options:\n" + " -n, --name=NAME Specifies the application name to use (default is e-notify-send).\n" + " -u, --urgency=LEVEL Specifies the urgency level (low, normal, critical).\n" + " -t, --expire-time=TIME Specifies the timeout in milliseconds at which to expire the notification.\n" + " -r, --replace=ID Specifies the ID of notification to replace.\n" + " -p, --print-id Prints the ID of notification to STDOUT.\n" + " -i, --icon=ICON Specifies an icon filename or stock icon to display.\n" + " -c, --category=TYPE Specifies the notification category.\n" + " -v, --version Version of the package.\n" + "\n"); +} + +int +read_int_arg(long long *result, const char *name, intmax_t min, intmax_t max) +{ + char *endptr; + + errno = 0; + *result = strtoll(optarg, &endptr, 10); + if ((errno != 0 && *result == 0) || endptr == optarg) + { + fprintf(stderr, "Cannot parse integer value '%s' for %s\n", optarg, name); + return 0; + } + else if (*result > max || *result < min) + { + fprintf(stderr, "Integer value '%s' for %s out of range\n", optarg, name); + return 0; + } + + return 1; +} + +void +send_cb(void *user_data __UNUSED__, void *method_return, DBusError *error __UNUSED__) +{ + E_Notification_Return_Notify *r = method_return; + + if(!r) + return; + + printf("%u\n", r->notification_id ); + + ecore_main_loop_quit(); +} + +int +main(int argc, char **argv) +{ + int ch; + long long value; + int print_id = 0; + E_Notification *n; + + e_notification_init(); + n = e_notification_new(); + e_notification_app_name_set(n, "e-notify-send"); + e_notification_timeout_set(n, -1); + + /* options descriptor */ + static struct option longopts[] = { + { "help", no_argument, NULL, '?' }, + { "name", required_argument, NULL, 'n' }, + { "urgency", required_argument, NULL, 'u' }, + { "expire-time", required_argument, NULL, 't' }, + { "replace", required_argument, NULL, 'r' }, + { "print-id", no_argument, NULL, 'p' }, + { "icon", required_argument, NULL, 'i' }, + { "category", required_argument, NULL, 'c' }, + { "version", no_argument, NULL, 'v' }, + { NULL, 0, NULL, 0 } + }; + + while ((ch = getopt_long(argc, argv, "p?vn:u:t:r:i:c:", longopts, NULL)) != -1) + switch (ch) { + case '?': + usage(); + return EXIT_SUCCESS; + break; + case 'v': + version(); + return EXIT_SUCCESS; + break; + case 'n': + e_notification_app_name_set(n, optarg); + break; + case 'u': + if (!strcasecmp(optarg, "low")) + e_notification_hint_urgency_set(n, E_NOTIFICATION_URGENCY_LOW); + else if (!strcasecmp(optarg, "normal")) + e_notification_hint_urgency_set(n, E_NOTIFICATION_URGENCY_NORMAL); + else if (!strcasecmp(optarg, "critical")) + e_notification_hint_urgency_set(n, E_NOTIFICATION_URGENCY_CRITICAL); + else + printf("Urgency level must be: low, normal or critical\n"); + break; + case 't': + if (!read_int_arg(&value, "-t", INT_MIN, INT_MAX)) + return EXIT_FAILURE; + else + e_notification_timeout_set(n, (int)value); + break; + case 'r': + if (!read_int_arg(&value, "-r", 0, UINT_MAX)) + return EXIT_FAILURE; + else + e_notification_replaces_id_set(n, (unsigned int)value); + break; + case 'i': + e_notification_app_icon_set(n, optarg); + break; + case 'c': + e_notification_hint_category_set(n, optarg); + break; + case 'p': + print_id = 1; + break; + default: + usage(); + return EXIT_FAILURE; + } + argc -= optind; + argv += optind; + + if (argc < 1) + { + usage(); + return EXIT_FAILURE; + } + + e_notification_summary_set(n, argv[0]); + if (argc > 1) e_notification_body_set(n, argv[1]); + + + if (print_id) + { + e_notification_send(n, send_cb, NULL); + ecore_main_loop_begin(); + } + else + e_notification_send(n, NULL, NULL); + + e_notification_unref(n); + e_notification_shutdown(); + + return EXIT_SUCCESS; +} diff --git a/src/bin/notify.c b/src/bin/notify.c new file mode 100644 index 0000000..5b588ef --- /dev/null +++ b/src/bin/notify.c @@ -0,0 +1,89 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> + +#include <Ecore.h> +#include <E_DBus.h> +#include <E_Notify.h> + +void +cb_sent(void *data __UNUSED__, void *ret, DBusError *err) +{ + E_Notification_Return_Notify *notify; + notify = ret; + if (notify) + { + printf("id: %d\n", notify->notification_id); + } + else if (dbus_error_is_set(err)) + { + printf("Error: %s\n", err->message); + } + + free(notify); +} + +int +cb_timer(void *data __UNUSED__) +{ + E_Notification *n; + char buf[1024]; + static int num = 0; + static const char *icons[] = { + "xterm", + "firefox", + "gvim" + }; + + snprintf(buf, sizeof(buf), "<i>%s</i> says <b>Hello</b> #%d", icons[num%3], num / 3); + n = e_notification_full_new(icons[num%3], 0, icons[num%3], "Summary", buf, -1); + e_notification_send(n, cb_sent, NULL); + e_notification_unref(n); + num++; + + return 1; +} + +void +cb_action_invoked(void *data __UNUSED__, int type __UNUSED__, void *event) +{ + E_Notification_Event_Action_Invoked *ev; + + ev = event; + printf("Action (%d): %s\n", ev->notification_id, ev->action_id); + free(ev); +} + +void +cb_note_closed(void *data __UNUSED__, int type __UNUSED__, void *event) +{ + E_Notification_Event_Notification_Closed *ev; + static const char *reasons[] = { + "Expired", + "Dismissed", + "Requested", + "Undefined" + }; + + ev = event; + printf("Note %d closed: %s\n", ev->notification_id, reasons[ev->reason]); + free(ev); +} + +int +main() +{ + int ret = 0; + ecore_init(); + if (e_notification_init()) + { + ecore_timer_add(1, cb_timer, NULL); + ecore_main_loop_begin(); + e_notification_shutdown(); + } + + ecore_shutdown(); + return ret; +} diff --git a/src/bin/test.c b/src/bin/test.c new file mode 100644 index 0000000..249cd4a --- /dev/null +++ b/src/bin/test.c @@ -0,0 +1,112 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef _WIN32 +# define DBUS_API_SUBJECT_TO_CHANGE +#endif + +#include <stdio.h> +#include <string.h> + +#include <Ecore.h> + +#include "E_DBus.h" + +void +copy_message(DBusMessageIter *from, DBusMessageIter *to) +{ + int type; + printf(" copy message\n"); + while((type = dbus_message_iter_get_arg_type(from)) != DBUS_TYPE_INVALID) + { + printf(" copy type: %c\n", type); + if (dbus_type_is_basic(type)) + { + /* XXX is int64 big enough to hold all basic types? */ + dbus_int64_t val; + dbus_message_iter_get_basic(from, &val); + dbus_message_iter_append_basic(to, type, &val); + } + else if (dbus_type_is_container(type)) + { + int subtype; + + subtype = dbus_message_iter_get_element_type(from); + if (type == DBUS_TYPE_ARRAY && dbus_type_is_fixed(subtype)) + { + int n; + void *val; + dbus_message_iter_get_fixed_array(from, &val, &n); + dbus_message_iter_append_fixed_array(to, subtype, val, n); + } + else + { + DBusMessageIter fsub, tsub; + char *sig; + dbus_message_iter_recurse(from, &fsub); + sig = dbus_message_iter_get_signature(&fsub); + dbus_message_iter_open_container(to, type, sig, &tsub); + copy_message(&fsub, &tsub); + dbus_message_iter_close_container(to, &tsub); + } + } + dbus_message_iter_next(from); + } +} + +DBusMessage * +cb_repeat(E_DBus_Object *obj __UNUSED__, DBusMessage *msg) +{ + DBusMessage *reply; + DBusMessageIter from, to; + + printf("\n\nREPEAT\n--------\n"); + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init(msg, &from); + dbus_message_iter_init_append(reply, &to); + + copy_message(&from, &to); + return reply; +} + +void +cb_request_name(void *data __UNUSED__, DBusMessage *msg __UNUSED__, DBusError *err __UNUSED__) +{ + // XXX check that this actually succeeded and handle errors... + printf("request name\n"); +} + +int +_setup(E_DBus_Connection *conn) +{ + E_DBus_Object *repeater; + E_DBus_Interface *iface; + e_dbus_request_name(conn, "org.e.Repeater", 0, cb_request_name, NULL); + repeater = e_dbus_object_add(conn, "/org/e/Repeater", NULL); + iface = e_dbus_interface_new("org.e.Repeater"); + e_dbus_interface_method_add(iface, "Repeat", NULL, NULL, cb_repeat); + e_dbus_object_interface_attach(repeater, iface); + return 1; +} + +int +main () +{ + E_DBus_Connection *conn; + ecore_init(); + e_dbus_init(); + + conn = e_dbus_bus_get(DBUS_BUS_SESSION); + + if (conn) + { + if (_setup(conn)) ecore_main_loop_begin(); + e_dbus_connection_close(conn); + } + + e_dbus_shutdown(); + ecore_shutdown(); + + return 0; +} diff --git a/src/bin/test_client.c b/src/bin/test_client.c new file mode 100644 index 0000000..4709158 --- /dev/null +++ b/src/bin/test_client.c @@ -0,0 +1,75 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> + +#include <Ecore.h> +#include <E_DBus.h> + +#define NUM_LOOPS 10000 + +static dbus_uint32_t msg_num = 0; + +void +cb_reply(void *data __UNUSED__, DBusMessage *reply, DBusError *error) +{ + dbus_uint32_t val; + if (dbus_error_is_set(error)) + { + printf("Error: %s - %s\n", error->name, error->message); + return; + } + + dbus_message_get_args(reply, error, DBUS_TYPE_UINT32, &val, DBUS_TYPE_INVALID); + printf("Received: %d\n", val); + if (val == NUM_LOOPS - 1) ecore_main_loop_quit(); +} + +int +send_message(void *data) +{ + + DBusMessage *msg; + E_DBus_Connection *conn; + + conn = data; + + msg = dbus_message_new_method_call( + "org.e.Repeater", + "/org/e/Repeater", + "org.e.Repeater", + "Repeat" + ); + + dbus_message_append_args(msg, DBUS_TYPE_UINT32, &msg_num, DBUS_TYPE_INVALID); + msg_num++; + e_dbus_message_send(conn, msg, cb_reply, -1, NULL); + dbus_message_unref(msg); + printf("Sent: %d\n", msg_num); + return 1; +} + +int +main() +{ + E_DBus_Connection *conn; + int ret = 0; + ecore_init(); + e_dbus_init(); + + conn = e_dbus_bus_get(DBUS_BUS_SESSION); + if (conn) + ecore_timer_add(0.0, send_message, conn); + else + { + printf("Error: could not connect to session bus.\n"); + ret = 1; + } + + ecore_main_loop_begin(); + + e_dbus_shutdown(); + ecore_shutdown(); + return ret; +} diff --git a/src/lib/.cvsignore b/src/lib/.cvsignore new file mode 100644 index 0000000..e995588 --- /dev/null +++ b/src/lib/.cvsignore @@ -0,0 +1,3 @@ +.deps +Makefile +Makefile.in diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am new file mode 100644 index 0000000..f51bcb2 --- /dev/null +++ b/src/lib/Makefile.am @@ -0,0 +1,3 @@ +MAINTAINERCLEANFILES = Makefile.in + +SUBDIRS=dbus hal notification connman bluez ofono ukit diff --git a/src/lib/bluez/E_Bluez.h b/src/lib/bluez/E_Bluez.h new file mode 100644 index 0000000..87cc1a7 --- /dev/null +++ b/src/lib/bluez/E_Bluez.h @@ -0,0 +1,165 @@ +#ifndef E_BLUEZ_H +#define E_BLUEZ_H + +#include <stdint.h> +#include <stdio.h> + +#include <Eina.h> +#include <Ecore.h> +#include <E_DBus.h> + +#ifdef EAPI +#undef EAPI +#endif +#ifdef _MSC_VER +# ifdef BUILDING_DLL +# define EAPI __declspec(dllexport) +# else +# define EAPI __declspec(dllimport) +# endif +#else +# ifdef __GNUC__ +# if __GNUC__ >= 4 +# define EAPI __attribute__ ((visibility("default"))) +# else +# define EAPI +# endif +# else +# define EAPI +# endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + /* Ecore Events */ + extern int E_BLUEZ_EVENT_MANAGER_IN; + extern int E_BLUEZ_EVENT_MANAGER_OUT; + extern int E_BLUEZ_EVENT_ELEMENT_ADD; + extern int E_BLUEZ_EVENT_ELEMENT_DEL; + extern int E_BLUEZ_EVENT_ELEMENT_UPDATED; + extern int E_BLUEZ_EVENT_DEVICE_FOUND; + // TODO: extern int E_BLUEZ_EVENT_DEVICE_DISAPPEARED; + + typedef struct _E_Bluez_Element E_Bluez_Element; + typedef struct _E_Bluez_Array E_Bluez_Array; + typedef struct _E_Bluez_Device_Found E_Bluez_Device_Found; + + struct _E_Bluez_Element + { + const char *path; + const char *interface; + E_DBus_Signal_Handler *signal_handler; + E_DBus_Signal_Handler *device_found_handler; + Eina_Inlist *props; + + /* private */ + struct { + Eina_Inlist *properties_get; + Eina_Inlist *property_set; + Eina_Inlist *agent_register; + Eina_Inlist *agent_unregister; + Eina_Inlist *start_discovery; + Eina_Inlist *stop_discovery; + Eina_Inlist *create_paired_device; + } _pending; + struct { + Ecore_Idler *changed; + } _idler; + Eina_Inlist *_listeners; + int _references; + }; + + struct _E_Bluez_Array + { + int type; + Eina_Array *array; + }; + + struct _E_Bluez_Device_Found + { + E_Bluez_Element *adapter; + const char *name; + E_Bluez_Array *array; + }; + + /* General Public API */ + EAPI unsigned int e_bluez_system_init(E_DBus_Connection *edbus_conn) EINA_ARG_NONNULL(1); + EAPI unsigned int e_bluez_system_shutdown(void); + + /* Manager Methods */ + EAPI E_Bluez_Element *e_bluez_manager_get(void) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_manager_default_adapter(E_DBus_Method_Return_Cb cb, void *data) EINA_WARN_UNUSED_RESULT; + + /* Adapter Methods */ + EAPI E_Bluez_Element *e_bluez_adapter_get(const char *path) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI Eina_Bool e_bluez_adapter_agent_register(E_Bluez_Element *element, const char *object_path, const char *capability, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_agent_unregister(E_Bluez_Element *element, const char *object_path, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_address_get(const E_Bluez_Element *element, const char **address) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_name_get(const E_Bluez_Element *element, const char **name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_name_set(E_Bluez_Element *element, const char *name, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1,2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_powered_get(const E_Bluez_Element *element, Eina_Bool *powered) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_powered_set(E_Bluez_Element *profile, Eina_Bool powered, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_discoverable_get(const E_Bluez_Element *element, Eina_Bool *discoverable) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_discoverable_set(E_Bluez_Element *profile, Eina_Bool discoverable, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_discoverable_timeout_get(const E_Bluez_Element *element, unsigned int *timeout) EINA_ARG_NONNULL(1,2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_discoverable_timeout_set(E_Bluez_Element *element, unsigned int timeout, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_discovering_get(const E_Bluez_Element *element, Eina_Bool *discovering) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_start_discovery(E_Bluez_Element *element, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_stop_discovery(E_Bluez_Element *element, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_adapter_create_paired_device(E_Bluez_Element *element, const char *object_path, const char *capability, const char *device, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT; + + /* Device Found Methods */ + EAPI void e_bluez_devicefound_free(E_Bluez_Device_Found *device) EINA_ARG_NONNULL(1); + EAPI const char *e_bluez_devicefound_alias_get(const E_Bluez_Device_Found *device) EINA_ARG_NONNULL(1); + + /* Devices Methods */ + EAPI E_Bluez_Element *e_bluez_device_get(const char *path) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_device_name_get(const E_Bluez_Element *element, const char **name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_device_alias_get(const E_Bluez_Element *element, const char **alias) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_device_paired_get(const E_Bluez_Element *element, Eina_Bool *paired) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + /* Low-Level API: + * + * Should just be used to work around problems until proper solution + * is made into e_bluez. + */ + EAPI Eina_Bool e_bluez_manager_sync_elements(void); + + EAPI Eina_Bool e_bluez_elements_get_all(unsigned int *count, E_Bluez_Element ***p_elements) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_elements_get_all_type(const char *type, unsigned int *count, E_Bluez_Element ***p_elements) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + EAPI E_Bluez_Element *e_bluez_element_get(const char *path); + + EAPI void e_bluez_element_listener_add(E_Bluez_Element *element, void (*cb)(void *data, const E_Bluez_Element *element), const void *data, void (*free_data)(void *data)) EINA_ARG_NONNULL(1, 2); + EAPI void e_bluez_element_listener_del(E_Bluez_Element *element, void (*cb)(void *data, const E_Bluez_Element *element), const void *data) EINA_ARG_NONNULL(1, 2); + + EAPI int e_bluez_element_ref(E_Bluez_Element *element) EINA_ARG_NONNULL(1); + EAPI int e_bluez_element_unref(E_Bluez_Element *element) EINA_ARG_NONNULL(1); + + EAPI void e_bluez_element_print(FILE *fp, const E_Bluez_Element *element) EINA_ARG_NONNULL(1, 2); + EAPI void e_bluez_element_array_print(FILE *fp, E_Bluez_Array *array); + + EAPI Eina_Bool e_bluez_element_properties_sync(E_Bluez_Element *element) EINA_ARG_NONNULL(1); + EAPI Eina_Bool e_bluez_element_properties_sync_full(E_Bluez_Element *element, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1); + + EAPI Eina_Bool e_bluez_element_property_set(E_Bluez_Element *element, const char *prop, int type, const void *value) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_element_property_set_full(E_Bluez_Element *element, const char *prop, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_element_property_dict_set_full(E_Bluez_Element *element, const char *prop, const char *key, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + + EAPI void e_bluez_element_properties_list(const E_Bluez_Element *element, Eina_Bool (*cb)(void *data, const E_Bluez_Element *element, const char *name, int type, const void *value), const void *data) EINA_ARG_NONNULL(1, 2); + + EAPI Eina_Bool e_bluez_element_property_type_get_stringshared(const E_Bluez_Element *element, const char *name, int *type) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_element_property_type_get(const E_Bluez_Element *element, const char *name, int *type) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_element_property_dict_get_stringshared(const E_Bluez_Element *element, const char *dict_name, const char *key_name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_element_property_get_stringshared(const E_Bluez_Element *element, const char *name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_element_property_get(const E_Bluez_Element *element, const char *name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT; + + EAPI Eina_Bool e_bluez_element_is_adapter(const E_Bluez_Element *element) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_bluez_element_is_device(const E_Bluez_Element *element) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + +#ifdef __cplusplus +} +#endif +#endif /* E_BLUEZ_H */ diff --git a/src/lib/bluez/Makefile.am b/src/lib/bluez/Makefile.am new file mode 100644 index 0000000..b0e3c9c --- /dev/null +++ b/src/lib/bluez/Makefile.am @@ -0,0 +1,29 @@ +MAINTAINERCLEANFILES = Makefile.in + +AM_CPPFLAGS = \ +-I $(top_srcdir)/src/lib/dbus \ +@EDBUS_CFLAGS@ @EVAS_CFLAGS@ @EINA_CFLAGS@ + +if BUILD_EBLUEZ + +lib_LTLIBRARIES = libebluez.la +include_HEADERS = E_Bluez.h + +libebluez_la_SOURCES = \ +E_Bluez.h \ +e_bluez_private.h \ +e_bluez.c \ +e_bluez_element.c \ +e_bluez_manager.c \ +e_bluez_adapter.c \ +e_bluez_device.c \ +e_bluez_devicefound.c + +libebluez_la_LIBADD = \ +@EDBUS_LIBS@ @EVAS_LIBS@ \ +$(top_builddir)/src/lib/dbus/libedbus.la \ +@EINA_LIBS@ + +libebluez_la_LDFLAGS = -version-info @version_info@ @ebluez_release_info@ + +endif diff --git a/src/lib/bluez/e_bluez.c b/src/lib/bluez/e_bluez.c new file mode 100644 index 0000000..9014da3 --- /dev/null +++ b/src/lib/bluez/e_bluez.c @@ -0,0 +1,364 @@ +#include "e_bluez_private.h" +#include <stdlib.h> +#include <string.h> + +static E_DBus_Signal_Handler *cb_name_owner_changed = NULL; +static DBusPendingCall *pending_get_name_owner = NULL; +static unsigned int init_count = 0; +static char *unique_name = NULL; + +static const char bus_name[] = "org.bluez"; +static const char fdo_bus_name[] = "org.freedesktop.DBus"; +static const char fdo_interface[] = "org.freedesktop.DBus"; +static const char fdo_path[] = "/org/freedesktop/DBus"; + +E_DBus_Connection *e_bluez_conn = NULL; + +EAPI int E_BLUEZ_EVENT_MANAGER_IN = 0; +EAPI int E_BLUEZ_EVENT_MANAGER_OUT = 0; +EAPI int E_BLUEZ_EVENT_ELEMENT_ADD = 0; +EAPI int E_BLUEZ_EVENT_ELEMENT_DEL = 0; +EAPI int E_BLUEZ_EVENT_ELEMENT_UPDATED = 0; +EAPI int E_BLUEZ_EVENT_DEVICE_FOUND = 0; + +const char *e_bluez_iface_manager = NULL; +const char *e_bluez_iface_adapter = NULL; +const char *e_bluez_iface_device = NULL; +const char *e_bluez_prop_address = NULL; +const char *e_bluez_prop_name = NULL; +const char *e_bluez_prop_alias = NULL; +const char *e_bluez_prop_class = NULL; +const char *e_bluez_prop_icon = NULL; +const char *e_bluez_prop_paired = NULL; +const char *e_bluez_prop_trusted = NULL; +const char *e_bluez_prop_connected = NULL; +const char *e_bluez_prop_uuids = NULL; +const char *e_bluez_prop_powered = NULL; +const char *e_bluez_prop_discoverable = NULL; +const char *e_bluez_prop_pairable = NULL; +const char *e_bluez_prop_discoverabletimeout = NULL; +const char *e_bluez_prop_pairabletimeout = NULL; +const char *e_bluez_prop_discovering = NULL; +const char *e_bluez_prop_devices = NULL; + +int _e_dbus_bluez_log_dom = -1; + +const char * +e_bluez_system_bus_name_get(void) +{ + return unique_name ? unique_name : bus_name; +} + +/*********************************************************************** + * Manager + ***********************************************************************/ + +/* + * FIXME: Do we really need to call Manager.GetProperties()? + */ + +/** + * Synchronize elements with server. + * + * This will call Manager.GetProperties() on server, retrieve properties + * and some element paths and then request their properties. + * + * This call will add events E_BLUEZ_EVENT_ELEMENT_ADD and + * E_BLUEZ_EVENT_ELEMENT_UPDATED to the main loop. + * + * This will not remove stale elements. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_manager_sync_elements(void) +{ + E_Bluez_Element *manager; + + if (!unique_name) + return EINA_FALSE; + manager = e_bluez_element_register(manager_path, e_bluez_iface_manager); + if (manager) + e_bluez_element_properties_sync(manager); + else + return EINA_FALSE; + + DBG("sync_manager: %s (%s)", unique_name, bus_name); + + return EINA_TRUE; +} + +static void +_e_bluez_system_name_owner_exit(void) +{ + e_bluez_manager_clear_elements(); + ecore_event_add(E_BLUEZ_EVENT_MANAGER_OUT, NULL, NULL, NULL); + + free(unique_name); + unique_name = NULL; +} + +static void +_e_bluez_system_name_owner_enter(const char *uid) +{ + DBG("enter bluez at %s (old was %s)", uid, unique_name); + if (unique_name && strcmp(unique_name, uid) == 0) + { + DBG("same unique_name for bluez, ignore."); + return; + } + + if (unique_name) + _e_bluez_system_name_owner_exit(); + + unique_name = strdup(uid); + + ecore_event_add(E_BLUEZ_EVENT_MANAGER_IN, NULL, NULL, NULL); + e_bluez_manager_sync_elements(); +} + + +static void +_e_bluez_system_name_owner_changed(void *data __UNUSED__, DBusMessage *msg) +{ + DBusError err; + const char *name, *from, *to; + + dbus_error_init(&err); + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_STRING, &from, + DBUS_TYPE_STRING, &to, + DBUS_TYPE_INVALID)) + { + ERR("could not get NameOwnerChanged arguments: %s: %s", + err.name, err.message); + dbus_error_free(&err); + return; + } + + if (strcmp(name, bus_name) != 0) + return; + + DBG("NameOwnerChanged from=[%s] to=[%s]", from, to); + + if (from[0] == '\0' && to[0] != '\0') + _e_bluez_system_name_owner_enter(to); + else if (from[0] != '\0' && to[0] == '\0') + { + DBG("exit bluez at %s", from); + if (strcmp(unique_name, from) != 0) + DBG("%s was not the known name %s, ignored.", from, unique_name); + else + _e_bluez_system_name_owner_exit(); + } + else + DBG("unknow change from %s to %s", from, to); +} + +static void +_e_bluez_get_name_owner(void *data __UNUSED__, DBusMessage *msg, DBusError *err) +{ + DBusMessageIter itr; + int t; + const char *uid; + + pending_get_name_owner = NULL; + + if (!_dbus_callback_check_and_init(msg, &itr, err)) + return; + + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING)) + return; + + dbus_message_iter_get_basic(&itr, &uid); + if (!uid) + { + ERR("no name owner!"); + return; + } + + _e_bluez_system_name_owner_enter(uid); + return; +} + +/** + * Initialize E BlueZ (E_Bluez) system. + * + * This will connect and watch org.bluez.Manager and Element + * events and translate to Ecore main loop events, also provide a + * proxy for method invocation on server. + * + * Interesting events are: + * - E_BLUEZ_EVENT_MANAGER_IN: issued when bluez is avaiable. + * - E_BLUEZ_EVENT_MANAGER_OUT: issued when bluez connection is lost. + * - E_BLUEZ_EVENT_ELEMENT_ADD: element was added. + * - E_BLUEZ_EVENT_ELEMENT_DEL: element was deleted. + * - E_BLUEZ_EVENT_ELEMENT_UPDATED: element was updated (properties + * or state changed). + * - E_BLUEZ_EVENT_DEVICE_FOUND: a device was found, raised after calling + * Adapter.StartDiscorvery() + * + * Manager IN/OUT events do not provide any event information, just + * tells you that system is usable or not. After manager is out, all + * elements will be removed, so after this event do not use the system anymore. + * + * Element events will give you an element object. After DEL event callback + * returns, that element will not be valid anymore. + */ +unsigned int +e_bluez_system_init(E_DBus_Connection *edbus_conn) +{ + init_count++; + + if (init_count > 1) + return init_count; + + _e_dbus_bluez_log_dom = eina_log_domain_register + ("e_dbus_bluez", EINA_LOG_DEFAULT_COLOR); + + if(_e_dbus_bluez_log_dom < 0) + { + EINA_LOG_ERR + ("impossible to create a log domain for edbus_bluez module"); + return -1; + } + + if (E_BLUEZ_EVENT_MANAGER_IN == 0) + E_BLUEZ_EVENT_MANAGER_IN = ecore_event_type_new(); + if (E_BLUEZ_EVENT_MANAGER_OUT == 0) + E_BLUEZ_EVENT_MANAGER_OUT = ecore_event_type_new(); + if (E_BLUEZ_EVENT_ELEMENT_ADD == 0) + E_BLUEZ_EVENT_ELEMENT_ADD = ecore_event_type_new(); + if (E_BLUEZ_EVENT_ELEMENT_DEL == 0) + E_BLUEZ_EVENT_ELEMENT_DEL = ecore_event_type_new(); + if (E_BLUEZ_EVENT_ELEMENT_UPDATED == 0) + E_BLUEZ_EVENT_ELEMENT_UPDATED = ecore_event_type_new(); + if (E_BLUEZ_EVENT_DEVICE_FOUND == 0) + E_BLUEZ_EVENT_DEVICE_FOUND = ecore_event_type_new(); + + if (e_bluez_iface_manager == NULL) + e_bluez_iface_manager = eina_stringshare_add("org.bluez.Manager"); + if (e_bluez_iface_adapter == NULL) + e_bluez_iface_adapter = eina_stringshare_add("org.bluez.Adapter"); + if (e_bluez_iface_device == NULL) + e_bluez_iface_device = eina_stringshare_add("org.bluez.Device"); + if (e_bluez_prop_address == NULL) + e_bluez_prop_address = eina_stringshare_add("Address"); + if (e_bluez_prop_name == NULL) + e_bluez_prop_name = eina_stringshare_add("Name"); + if (e_bluez_prop_alias == NULL) + e_bluez_prop_alias = eina_stringshare_add("Alias"); + if (e_bluez_prop_class == NULL) + e_bluez_prop_class = eina_stringshare_add("Class"); + if (e_bluez_prop_icon == NULL) + e_bluez_prop_icon = eina_stringshare_add("Icon"); + if (e_bluez_prop_paired == NULL) + e_bluez_prop_paired = eina_stringshare_add("Paired"); + if (e_bluez_prop_trusted == NULL) + e_bluez_prop_trusted = eina_stringshare_add("Trusted"); + if (e_bluez_prop_connected == NULL) + e_bluez_prop_connected = eina_stringshare_add("Connected"); + if (e_bluez_prop_uuids == NULL) + e_bluez_prop_uuids = eina_stringshare_add("UUIDs"); + if (e_bluez_prop_powered == NULL) + e_bluez_prop_powered = eina_stringshare_add("Powered"); + if (e_bluez_prop_discoverable == NULL) + e_bluez_prop_discoverable = eina_stringshare_add("Discoverable"); + if (e_bluez_prop_pairable == NULL) + e_bluez_prop_pairable = eina_stringshare_add("Pairable"); + if (e_bluez_prop_discoverabletimeout == NULL) + e_bluez_prop_discoverabletimeout = eina_stringshare_add("DiscoverableTimeout"); + if (e_bluez_prop_pairabletimeout == NULL) + e_bluez_prop_pairabletimeout = eina_stringshare_add("PairableTimeout"); + if (e_bluez_prop_discovering == NULL) + e_bluez_prop_discovering = eina_stringshare_add("Discovering"); + if (e_bluez_prop_devices == NULL) + e_bluez_prop_devices = eina_stringshare_add("Devices"); + + e_bluez_conn = edbus_conn; + cb_name_owner_changed = e_dbus_signal_handler_add + (e_bluez_conn, fdo_bus_name, fdo_path, fdo_interface, "NameOwnerChanged", + _e_bluez_system_name_owner_changed, NULL); + + if (pending_get_name_owner) + dbus_pending_call_cancel(pending_get_name_owner); + + pending_get_name_owner = e_dbus_get_name_owner + (e_bluez_conn, bus_name, _e_bluez_get_name_owner, NULL); + + e_bluez_elements_init(); + + return init_count; +} + + +static inline void +_stringshare_del(const char **str) +{ + if (!*str) + return; + eina_stringshare_del(*str); + *str = NULL; +} + +/** + * Shutdown bluez system. + * + * When count drops to 0 resources will be released and no calls should be + * made anymore. + */ +unsigned int +e_bluez_system_shutdown(void) +{ + if (init_count == 0) + { + ERR("bluez system already shut down."); + return 0; + } + init_count--; + if (init_count > 0) + return init_count; + + _stringshare_del(&e_bluez_iface_manager); + _stringshare_del(&e_bluez_iface_adapter); + _stringshare_del(&e_bluez_iface_device); + _stringshare_del(&e_bluez_prop_address); + _stringshare_del(&e_bluez_prop_name); + _stringshare_del(&e_bluez_prop_alias); + _stringshare_del(&e_bluez_prop_class); + _stringshare_del(&e_bluez_prop_icon); + _stringshare_del(&e_bluez_prop_paired); + _stringshare_del(&e_bluez_prop_trusted); + _stringshare_del(&e_bluez_prop_connected); + _stringshare_del(&e_bluez_prop_uuids); + _stringshare_del(&e_bluez_prop_powered); + _stringshare_del(&e_bluez_prop_discoverable); + _stringshare_del(&e_bluez_prop_pairable); + _stringshare_del(&e_bluez_prop_discoverabletimeout); + _stringshare_del(&e_bluez_prop_pairabletimeout); + _stringshare_del(&e_bluez_prop_discovering); + _stringshare_del(&e_bluez_prop_devices); + + if (pending_get_name_owner) + { + dbus_pending_call_cancel(pending_get_name_owner); + pending_get_name_owner = NULL; + } + + if (cb_name_owner_changed) + { + e_dbus_signal_handler_del(e_bluez_conn, cb_name_owner_changed); + cb_name_owner_changed = NULL; + } + + if (unique_name) + _e_bluez_system_name_owner_exit(); + + e_bluez_elements_shutdown(); + eina_log_domain_unregister(_e_dbus_bluez_log_dom); + e_bluez_conn = NULL; + + return init_count; +} diff --git a/src/lib/bluez/e_bluez_adapter.c b/src/lib/bluez/e_bluez_adapter.c new file mode 100644 index 0000000..36bbfdb --- /dev/null +++ b/src/lib/bluez/e_bluez_adapter.c @@ -0,0 +1,440 @@ +#include "e_bluez_private.h" + +E_Bluez_Element * +e_bluez_adapter_get(const char *path) +{ + E_Bluez_Element *adapter; + + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); + + adapter = e_bluez_element_get(path); + if (!adapter) + return NULL; + + if (!e_bluez_element_is_adapter(adapter)) + { + WRN("path '%s' is not a adapter!", path); + return NULL; + } + + return adapter; +} + +static void +_device_found_callback(void *data, DBusMessage *msg) +{ + E_Bluez_Element *element = (E_Bluez_Element *)data; + E_Bluez_Device_Found *device; + DBusMessageIter itr; + int t; + char *name = NULL; + void *value = NULL; + + DBG("Device found %s", element->path); + + if (!_dbus_callback_check_and_init(msg, &itr, NULL)) + return; + + device = calloc(sizeof(E_Bluez_Device_Found), 1); + if (!device) + { + ERR("No memory to alocate E_Bluez_Device_Found"); + return; + } + + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING)) + { + ERR("missing device name in DeviceFound"); + return; + } + dbus_message_iter_get_basic(&itr, &name); + + dbus_message_iter_next(&itr); + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_ARRAY)) + { + ERR("missing array in DeviceFound"); + return; + } + + value = e_bluez_element_iter_get_array(&itr, name); + + if (!value) + return; + + device->name = eina_stringshare_add(name); + device->adapter = element; + device->array = value; + + ecore_event_add(E_BLUEZ_EVENT_DEVICE_FOUND, device, NULL, NULL); +} + +/** + * Register new agent for handling user requests. + * + * Call method RegisterAgent(object) on server in order to + * register new agent for handling user requests. + * + * @param element adapter's element + * @param object_path object to be registered. + * @param capability input/output agent capabilities + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_adapter_agent_register(E_Bluez_Element *element, const char *object_path, const char *capability, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "RegisterAgent"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(object_path, 0); + + return e_bluez_element_call_with_path_and_string + (element, name, object_path, capability, NULL, + &element->_pending.agent_register, cb, data); +} + +/** + * Unregister an existing agent. + * + * Call method UnregisterAgent(object) on server in order to + * unregister an existing agent. + * + * @param element adapter's element + * @param object_path agent to be unregistered. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_adapter_agent_unregister(E_Bluez_Element *element, const char *object_path, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "UnregisterAgent"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(object_path, 0); + + return e_bluez_element_call_with_path + (element, name, object_path, NULL, + &element->_pending.agent_unregister, cb, data); +} + +/** + * Get property "Address" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param address where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_adapter_address_get(const E_Bluez_Element *element, const char **address) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(address, 0); + + return e_bluez_element_property_get_stringshared + (element, e_bluez_prop_address, NULL, address); +} + +/** + * Get property "Name" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param name where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_adapter_name_get(const E_Bluez_Element *element, const char **name) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + + return e_bluez_element_property_get_stringshared + (element, e_bluez_prop_name, NULL, name); +} + +/** + * Call method SetProperty("Name", name) at the given element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_BLUEZ_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * @param name value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + * @see e_bluez_adapter_name_get() + */ +Eina_Bool +e_bluez_adapter_name_set(E_Bluez_Element *element, const char *name, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return e_bluez_element_property_set_full + (element, e_bluez_prop_name, DBUS_TYPE_STRING, name, cb, data); +} + +/** + * Get property "Powered" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param powered where to store the property value, must be a pointer + * to booleans (Eina_Bool *). + * + * @return 1 on success, 0 otherwise. + * @see e_bluez_adapter_powered_set() + */ +Eina_Bool +e_bluez_adapter_powered_get(const E_Bluez_Element *element, Eina_Bool *powered) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(powered, 0); + + return e_bluez_element_property_get_stringshared + (element, e_bluez_prop_powered, NULL, powered); +} + +/** + * Call method SetProperty("Powered", powered) at the given element on server. + * + * + * @param powered value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_adapter_powered_set(E_Bluez_Element *element, Eina_Bool powered, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return e_bluez_element_property_set_full + (element, e_bluez_prop_powered, DBUS_TYPE_BOOLEAN, + &powered, cb, data); +} + +/** + * Get property "Discoverable" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param discoverable where to store the property value, must be a pointer + * to booleans (Eina_Bool *). + * + * @return 1 on success, 0 otherwise. + * @see e_bluez_adapter_discoverable_set() + */ +Eina_Bool +e_bluez_adapter_discoverable_get(const E_Bluez_Element *element, Eina_Bool *discoverable) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(discoverable, 0); + + return e_bluez_element_property_get_stringshared + (element, e_bluez_prop_discoverable, NULL, discoverable); +} + +/** + * Call method SetProperty("Discoverable", discoverable) at the given + * element on server. + * + * @param discoverable value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_adapter_discoverable_set(E_Bluez_Element *element, Eina_Bool discoverable, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return e_bluez_element_property_set_full + (element, e_bluez_prop_discoverable, DBUS_TYPE_BOOLEAN, + &discoverable, cb, data); +} + +/** + * Get property "DiscoverableTimeout" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param adapter path to get property. + * @param discoverable timeout where to store the property value, must be a pointer + * to uint32 (unsigned int *). + * + * @return 1 on success, 0 otherwise. + * @see e_bluez_adapter_discoverable_timeout_set() + */ +Eina_Bool +e_bluez_adapter_discoverable_timeout_get(const E_Bluez_Element *element, unsigned int *timeout) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(timeout, 0); + return e_bluez_element_property_get_stringshared + (element, e_bluez_prop_discoverabletimeout, NULL, timeout); +} + +/** + * Call method SetProperty("DiscoverableTimeout", timeout) at the + * given element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_BLUEZ_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * @param adapter path to set property. + * @param discoverable timeout value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + * @see e_bluez_adapter_discoverable_timeout_get() + */ +Eina_Bool +e_bluez_adapter_discoverable_timeout_set(E_Bluez_Element *element, unsigned int timeout, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return e_bluez_element_property_set_full + (element, e_bluez_prop_discoverabletimeout, DBUS_TYPE_UINT32, + &timeout, cb, data); +} +/** + * Get property "Discovering" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param discovering where to store the property value, must be a pointer + * to booleans (Eina_Bool *). + * + * @return 1 on success, 0 otherwise. + * @see e_bluez_adapter_discovering_set() + */ +Eina_Bool +e_bluez_adapter_discovering_get(const E_Bluez_Element *element, Eina_Bool *discovering) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(discovering, 0); + + return e_bluez_element_property_get_stringshared + (element, e_bluez_prop_discovering, NULL, discovering); +} + +/** + * Start Discovery of Bluetooth Devices + * + * call StartDiscovery() + * + * @param element the adapter's element. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_adapter_start_discovery(E_Bluez_Element *element, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "StartDiscovery"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + + element->device_found_handler = + e_dbus_signal_handler_add + (e_bluez_conn, e_bluez_system_bus_name_get(), + element->path, element->interface, "DeviceFound", + _device_found_callback, element); + + return e_bluez_element_call_full + (element, name, NULL, &element->_pending.start_discovery, cb, data); +} + +/** + * Stop Discovery of Bluetooth Devices + * + * call StopDiscovery() + * + * @param element the adapter's element. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_adapter_stop_discovery(E_Bluez_Element *element, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "StopDiscovery"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + + return e_bluez_element_call_full + (element, name, NULL, &element->_pending.stop_discovery, cb, data); +} + +/** + * Create a new Paired Device. + * + * Call method CreatePairedDevice() + * + * @param element adapter's element + * @param object_path object to be registered. + * @param capability input/output agent capabilities + * @param device device to pair with + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_adapter_create_paired_device(E_Bluez_Element *element, const char *object_path, const char *capability, const char *device, E_DBus_Method_Return_Cb cb, const void *data) +{ + DBusMessageIter itr; + DBusMessage *msg; + + const char name[] = "CreatePairedDevice"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(object_path, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(device, 0); + + msg = dbus_message_new_method_call + (e_bluez_system_bus_name_get(), element->path, element->interface, + name); + + if (!msg) + return 0; + + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &device); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_OBJECT_PATH, &object_path); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &capability); + + return e_bluez_element_message_send + (element, name, NULL, msg, + &element->_pending.create_paired_device, cb, data); +} diff --git a/src/lib/bluez/e_bluez_device.c b/src/lib/bluez/e_bluez_device.c new file mode 100644 index 0000000..3f68c4a --- /dev/null +++ b/src/lib/bluez/e_bluez_device.c @@ -0,0 +1,91 @@ +#include "e_bluez_private.h" + +E_Bluez_Element * +e_bluez_device_get(const char *path) +{ + E_Bluez_Element *device; + + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); + + device = e_bluez_element_get(path); + if (!device) + return NULL; + + if (!e_bluez_element_is_device(device)) + { + WRN("path '%s' is not a device!", path); + return NULL; + } + + return device; +} + +/** + * Get property "Name" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param address where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_device_name_get(const E_Bluez_Element *element, const char **name) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + + return e_bluez_element_property_get_stringshared + (element, e_bluez_prop_name, NULL, name); +} + +/** + * Get property "Alias" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param address where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_device_alias_get(const E_Bluez_Element *element, const char **alias) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(alias, 0); + + return e_bluez_element_property_get_stringshared + (element, e_bluez_prop_alias, NULL, alias); +} + +/** + * Get property "Paired" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param powered where to store the property value, must be a pointer + * to boolean (Eina_Bool *). + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_device_paired_get(const E_Bluez_Element *element, Eina_Bool *paired) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(paired, 0); + + return e_bluez_element_property_get_stringshared + (element, e_bluez_prop_paired, NULL, paired); +} diff --git a/src/lib/bluez/e_bluez_devicefound.c b/src/lib/bluez/e_bluez_devicefound.c new file mode 100644 index 0000000..2390384 --- /dev/null +++ b/src/lib/bluez/e_bluez_devicefound.c @@ -0,0 +1,36 @@ +#include "e_bluez_private.h" + +/** + * Free a E_Bluez_Device_Found struct + * + * @param device the struct to be freed + */ +void +e_bluez_devicefound_free(E_Bluez_Device_Found *device) +{ + EINA_SAFETY_ON_NULL_RETURN(device); + + eina_stringshare_del(device->name); + e_bluez_element_array_free(device->array, NULL); +} + +/** + * Return the pointer to the stringshared alias for the given found device. + * + * @return stringshared pointer, or @c NULL if unknown. + */ +const char * +e_bluez_devicefound_alias_get(const E_Bluez_Device_Found *device) +{ + E_Bluez_Element_Dict_Entry *entry; + + EINA_SAFETY_ON_NULL_RETURN_VAL(device, NULL); + + entry = e_bluez_element_array_dict_find_stringshared + (device->array, e_bluez_prop_alias); + + if ((entry) && (entry->type == DBUS_TYPE_STRING)) + return entry->value.str; + + return NULL; +} diff --git a/src/lib/bluez/e_bluez_element.c b/src/lib/bluez/e_bluez_element.c new file mode 100644 index 0000000..e9a3293 --- /dev/null +++ b/src/lib/bluez/e_bluez_element.c @@ -0,0 +1,2249 @@ +#include "e_bluez_private.h" +#include <string.h> +#include <errno.h> + +static Eina_Hash *elements = NULL; + +typedef struct _E_Bluez_Element_Pending E_Bluez_Element_Pending; +typedef struct _E_Bluez_Element_Call_Data E_Bluez_Element_Call_Data; +typedef struct _E_Bluez_Element_Property E_Bluez_Element_Property; +typedef struct _E_Bluez_Element_Listener E_Bluez_Element_Listener; + +struct _E_Bluez_Element_Pending +{ + EINA_INLIST; + DBusPendingCall *pending; + void *data; + E_DBus_Method_Return_Cb user_cb; + void *user_data; +}; + +struct _E_Bluez_Element_Call_Data +{ + E_Bluez_Element *element; + E_DBus_Method_Return_Cb cb; + E_Bluez_Element_Pending *pending; + Eina_Inlist **p_list; +}; + +struct _E_Bluez_Element_Property +{ + EINA_INLIST; + const char *name; + int type; + union { + Eina_Bool boolean; + const char *str; + unsigned short u16; + unsigned int u32; + unsigned char byte; + const char *path; + void *variant; + E_Bluez_Array *array; + } value; +}; + +struct _E_Bluez_Element_Listener +{ + EINA_INLIST; + void (*cb)(void *data, const E_Bluez_Element *element); + void *data; + void (*free_data)(void *data); +}; + +static void +_e_bluez_element_event_no_free(void *data __UNUSED__, void *ev) +{ + E_Bluez_Element *element = ev; + e_bluez_element_unref(element); +} + +void +e_bluez_element_event_add(int event_type, E_Bluez_Element *element) +{ + e_bluez_element_ref(element); + ecore_event_add + (event_type, element, _e_bluez_element_event_no_free, element); +} + +static void +e_bluez_element_call_dispatch_and_free(void *d, DBusMessage *msg, DBusError *err) +{ + E_Bluez_Element_Call_Data *data = d; + E_Bluez_Element_Pending *pending; + + pending = data->pending; + pending->pending = NULL; + + if (data->cb) + data->cb(data->element, msg, err); + + if (pending->user_cb) + pending->user_cb(pending->user_data, msg, err); + + pending->data = NULL; + *data->p_list = eina_inlist_remove(*data->p_list, EINA_INLIST_GET(pending)); + free(pending); + free(data); +} + +static void +e_bluez_element_pending_cancel_and_free(Eina_Inlist **pending) +{ + while (*pending) + { + E_Bluez_Element_Pending *p = (E_Bluez_Element_Pending *)*pending; + DBusError err; + + dbus_pending_call_cancel(p->pending); + + dbus_error_init(&err); + dbus_set_error(&err, "Canceled", "Pending method call was canceled."); + e_bluez_element_call_dispatch_and_free(p->data, NULL, &err); + dbus_error_free(&err); + } +} + +void +e_bluez_element_listener_add(E_Bluez_Element *element, void (*cb)(void *data, const E_Bluez_Element *element), const void *data, void (*free_data)(void *data)) +{ + E_Bluez_Element_Listener *l; + + if (!element) + { + ERR("safety check failed: element == NULL"); + goto error; + } + if (!cb) + { + ERR("safety check failed: cb == NULL"); + goto error; + } + + l = malloc(sizeof(*l)); + if (!l) + { + ERR("could not allocate E_Bluez_Element_Listener"); + goto error; + } + + l->cb = cb; + l->data = (void *)data; + l->free_data = free_data; + + element->_listeners = eina_inlist_append + (element->_listeners, EINA_INLIST_GET(l)); + + return; + + error: + if (free_data) + free_data((void *)data); +} + +void +e_bluez_element_listener_del(E_Bluez_Element *element, void (*cb)(void *data, const E_Bluez_Element *element), const void *data) +{ + E_Bluez_Element_Listener *l; + + EINA_SAFETY_ON_NULL_RETURN(element); + EINA_SAFETY_ON_NULL_RETURN(cb); + + EINA_INLIST_FOREACH(element->_listeners, l) + if ((l->cb == cb) && (l->data == data)) + { + element->_listeners = eina_inlist_remove + (element->_listeners, EINA_INLIST_GET(l)); + if (l->free_data) l->free_data(l->data); + free(l); + return; + } +} + +static void +_e_bluez_element_listeners_call_do(E_Bluez_Element *element) +{ + E_Bluez_Element_Listener *l, **shadow; + unsigned int i, count; + + /* NB: iterate on a copy in order to allow listeners to be deleted + * from callbacks. number of listeners should be small, so the + * following should do fine. + */ + count = eina_inlist_count(element->_listeners); + if (count < 1) + goto end; + + shadow = alloca(sizeof(*shadow) * count); + if (!shadow) + goto end; + + i = 0; + EINA_INLIST_FOREACH(element->_listeners, l) + shadow[i++] = l; + + for (i = 0; i < count; i++) + shadow[i]->cb(shadow[i]->data, element); + + end: + e_bluez_element_event_add(E_BLUEZ_EVENT_ELEMENT_UPDATED, element); +} + +static int +_e_bluez_element_listeners_call_idler(void *data) +{ + E_Bluez_Element *element = data; + _e_bluez_element_listeners_call_do(element); + element->_idler.changed = NULL; + return 0; +} + +static void +_e_bluez_element_listeners_call(E_Bluez_Element *element) +{ + if (element->_idler.changed) + return; + element->_idler.changed = ecore_idler_add + (_e_bluez_element_listeners_call_idler, element); +} + +/*********************************************************************** + * Property + ***********************************************************************/ + +static void +_e_bluez_element_dict_entry_free(E_Bluez_Element_Dict_Entry *entry) +{ + switch (entry->type) + { + case DBUS_TYPE_BOOLEAN: + case DBUS_TYPE_BYTE: + case DBUS_TYPE_INT16: + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + break; + case DBUS_TYPE_OBJECT_PATH: + eina_stringshare_del(entry->value.path); + break; + case DBUS_TYPE_STRING: + eina_stringshare_del(entry->value.str); + break; + default: + ERR("don't know how to free dict entry '%s' of type %c (%d)", + entry->name, entry->type, entry->type); + } + + eina_stringshare_del(entry->name); + free(entry); +} + +static E_Bluez_Element_Dict_Entry * +_e_bluez_element_dict_entry_new(DBusMessageIter *itr) +{ + E_Bluez_Element_Dict_Entry *entry; + DBusMessageIter e_itr, v_itr; + int t; + const char *key = NULL; + void *value = NULL; + + dbus_message_iter_recurse(itr, &e_itr); + + t = dbus_message_iter_get_arg_type(&e_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING)) + { + ERR("invalid format for dict entry. first type not a string: %c (%d)", + t, t); + return NULL; + } + + dbus_message_iter_get_basic(&e_itr, &key); + if (!key || !key[0]) + { + ERR("invalid format for dict entry. no key."); + return NULL; + } + + dbus_message_iter_next(&e_itr); + t = dbus_message_iter_get_arg_type(&e_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_VARIANT)) + { + ERR("invalid format for dict entry '%s'. " + "second type not a variant: %c (%d)", + key, t, t); + return NULL; + } + + dbus_message_iter_recurse(&e_itr, &v_itr); + + t = dbus_message_iter_get_arg_type(&v_itr); + if ((t == DBUS_TYPE_INVALID) || (t == DBUS_TYPE_ARRAY)) + { + ERR("invalid type for dict value for entry '%s': %c (%d)", + key, t, t); + return NULL; + } + + entry = calloc(1, sizeof(*entry)); + if (!entry) + { + ERR("could not allocate memory for dict entry."); + return NULL; + } + + dbus_message_iter_get_basic(&v_itr, &value); + switch (t) + { + case DBUS_TYPE_BOOLEAN: + entry->value.boolean = (Eina_Bool)(long)value; + break; + case DBUS_TYPE_BYTE: + entry->value.byte = (unsigned char)(long)value; + break; + case DBUS_TYPE_INT16: + entry->value.i16 = (short)(long)value; + break; + case DBUS_TYPE_UINT16: + entry->value.u16 = (unsigned short)(long)value; + break; + case DBUS_TYPE_UINT32: + entry->value.u32 = (unsigned int)(long)value; + break; + case DBUS_TYPE_STRING: + entry->value.str = eina_stringshare_add(value); + break; + case DBUS_TYPE_OBJECT_PATH: + entry->value.path = eina_stringshare_add(value); + break; + default: + ERR("don't know how to create dict entry '%s' for of type %c (%d)", + key, t, t); + free(entry); + return NULL; + } + + entry->name = eina_stringshare_add(key); + entry->type = t; + return entry; +} + +E_Bluez_Element_Dict_Entry * +e_bluez_element_array_dict_find_stringshared(const E_Bluez_Array *array, const char *key) +{ + E_Bluez_Element_Dict_Entry *entry; + Eina_Array_Iterator iterator; + unsigned int i; + + EINA_ARRAY_ITER_NEXT(array->array, i, entry, iterator) + if (entry->name == key) + return entry; + + return NULL; +} + +void +e_bluez_element_array_free(E_Bluez_Array *array, E_Bluez_Array *new __UNUSED__) +{ + Eina_Array_Iterator iterator; + unsigned int i; + void *item; + + if (!array) + return; + + switch (array->type) + { + case DBUS_TYPE_BOOLEAN: + case DBUS_TYPE_BYTE: + case DBUS_TYPE_INT16: + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + break; + case DBUS_TYPE_OBJECT_PATH: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + eina_stringshare_del(item); + break; + case DBUS_TYPE_STRING: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + eina_stringshare_del(item); + break; + case DBUS_TYPE_DICT_ENTRY: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + _e_bluez_element_dict_entry_free(item); + break; + default: + ERR("don't know how to free array of values of type %c (%d)", + array->type, array->type); + break; + } + eina_array_free(array->array); + free(array); +} + +static void +_e_bluez_element_property_value_free(E_Bluez_Element_Property *property) +{ + switch (property->type) + { + case 0: + return; + case DBUS_TYPE_BOOLEAN: + case DBUS_TYPE_BYTE: + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + break; + case DBUS_TYPE_STRING: + eina_stringshare_del(property->value.str); + break; + case DBUS_TYPE_OBJECT_PATH: + eina_stringshare_del(property->value.path); + break; + case DBUS_TYPE_ARRAY: + e_bluez_element_array_free(property->value.array, NULL); + break; + default: + ERR("don't know how to free value of property type %c (%d)", + property->type, property->type); + } +} + +static const char * +_e_bluez_element_get_interface(const char *key) +{ + const char *interface = NULL, *tail; + char head; + + head = key[0]; + tail = key + 1; + + switch (head) + { + case 'A': + if (strcmp(tail, "dapters") == 0) + interface = e_bluez_iface_adapter; + break; + case 'D': + if (strcmp(tail, "evices") == 0) + interface = e_bluez_iface_device; + break; + default: + break; + } + + if (!interface) + ERR("failed to find interface for property \"%s\"", key); + + return interface; +} + +static void +_e_bluez_element_item_register(const char *key, const char *item) +{ + E_Bluez_Element *element; + const char *interface; + + interface = _e_bluez_element_get_interface(key); + if (!interface) + return; + element = e_bluez_element_register(item, interface); + if ((element) && (!e_bluez_element_properties_sync(element))) + WRN("could not get properties of %s", element->path); +} + +/* Match 2 arrays to find which are new and which are old elements + * For new elements, register them under prop_name property + * For old elements, unregister them, sending proper DEL event + */ +static void +_e_bluez_element_array_match(E_Bluez_Array *old, E_Bluez_Array *new, const char *prop_name) +{ + Eina_List *deleted = NULL; + Eina_Array_Iterator iter_old, iter_new; + unsigned int i_old = 0, i_new = 0; + void *item_old, *item_new; + Eina_List *l; + void *data; + + if (!old) + return; + if (old->type != DBUS_TYPE_OBJECT_PATH) + return; + + if ((!new) || (!new->array) || eina_array_count_get(new->array) == 0) + { + if ((!old) || (!old->array) || eina_array_count_get(old->array) == 0) + return; + else + { + iter_old = old->array->data; + goto out_remove_remaining; + } + } + + iter_new = new->array->data; + item_new = *iter_new; + EINA_ARRAY_ITER_NEXT(old->array, i_old, item_old, iter_old) + { + if (item_old == item_new) + { + i_new++; + if (i_new >= eina_array_count_get(new->array)) + { + i_old++; + break; + } + + iter_new++; + item_new = *iter_new; + } + else + deleted = eina_list_append(deleted, item_old); + } + + for(; i_new < eina_array_count_get(new->array); iter_new++, i_new++) + { + Eina_Bool found = 0; + item_new = *iter_new; + if (!item_new) + break; + + EINA_LIST_FOREACH(deleted, l, data) + { + if (data == item_new) + { + deleted = eina_list_remove_list(deleted, l); + found = 1; + break; + } + } + if (!found) + { + _e_bluez_element_item_register(prop_name, item_new); + DBG("Add element %s\n", (const char *) item_new); + } + } + + /* everybody after i_old on old->array + everybody from deleted list + will be removed + */ + EINA_LIST_FREE(deleted, data) + { + E_Bluez_Element *e = e_bluez_element_get(data); + if (e) + e_bluez_element_unregister(e); + DBG("Delete element %s\n", (const char *) data); + } + +out_remove_remaining: + for(; i_old < eina_array_count_get(old->array); iter_old++, i_old++) + { + E_Bluez_Element *e; + item_old = *iter_old; + if (!item_old) + break; + + e = e_bluez_element_get(item_old); + if (e) + e_bluez_element_unregister(e); + DBG("Delete element %s\n", (const char *) item_old); + } +} + +static Eina_Bool +_e_bluez_element_property_update(E_Bluez_Element_Property *property, int type, void *data) +{ + int changed = 0; + + if ((type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) && data) + data = (char *)eina_stringshare_add(data); + + if (property->type != type) + { + if (property->type) + DBG("property type changed from '%c' to '%c'", + property->type, type); + _e_bluez_element_property_value_free(property); + memset(&property->value, 0, sizeof(property->value)); + property->type = type; + changed = 1; + } + + switch (type) + { + case DBUS_TYPE_BOOLEAN: + if (changed || property->value.boolean != (Eina_Bool)(long)data) + { + property->value.boolean = (Eina_Bool)(long)data; + changed = 1; + } + break; + case DBUS_TYPE_BYTE: + if (changed || property->value.byte != (unsigned char)(long)data) + { + property->value.byte = (unsigned char)(long)data; + changed = 1; + } + break; + case DBUS_TYPE_UINT16: + if (changed || property->value.u16 != (unsigned short)(long)data) + { + property->value.u16 = (unsigned short)(long)data; + changed = 1; + } + break; + case DBUS_TYPE_UINT32: + if (changed || property->value.u32 != (unsigned int)(long)data) + { + property->value.u32 = (unsigned int)(long)data; + changed = 1; + } + break; + case DBUS_TYPE_STRING: + if (changed) + property->value.str = data; + else + { + if (property->value.str) + eina_stringshare_del(property->value.str); + if (property->value.str != data) + { + property->value.str = data; + changed = 1; + } + } + break; + case DBUS_TYPE_OBJECT_PATH: + if (changed) + property->value.path = data; + else + { + if (property->value.path) + eina_stringshare_del(property->value.path); + if (property->value.path != data) + { + property->value.path = data; + changed = 1; + } + } + break; + case DBUS_TYPE_ARRAY: + if (!changed) + if (property->value.array) + { + _e_bluez_element_array_match(property->value.array, data, property->name); + e_bluez_element_array_free(property->value.array, data); + } + property->value.array = data; + changed = 1; + break; + default: + ERR("don't know how to update property type %c (%d)", type, type); + } + + return changed; +} + +static E_Bluez_Element_Property * +_e_bluez_element_property_new(const char *name, int type, void *data) +{ + E_Bluez_Element_Property *property; + + property = calloc(1, sizeof(*property)); + if (!property) + { + eina_stringshare_del(name); + ERR("could not allocate property: %s", strerror(errno)); + return NULL; + } + + property->name = name; + _e_bluez_element_property_update(property, type, data); + return property; +} + +static void +_e_bluez_element_property_free(E_Bluez_Element_Property *property) +{ + _e_bluez_element_property_value_free(property); + eina_stringshare_del(property->name); + free(property); +} + +/*********************************************************************** + * Element + ***********************************************************************/ +unsigned char * +e_bluez_element_bytes_array_get_stringshared(const E_Bluez_Element *element, const char *property, unsigned int *count) +{ + Eina_Array_Iterator iterator; + E_Bluez_Array *array; + unsigned char *ret, *p; + unsigned int i; + void *item; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(property, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, NULL); + + *count = 0; + + if (!e_bluez_element_property_get_stringshared + (element, property, NULL, &array)) + return NULL; + + if ((!array) || (!(array->array))) + return NULL; + + *count = eina_array_count_get(array->array); + ret = malloc(*count * sizeof(unsigned char)); + if (!ret) + { + ERR("could not allocate return array of %d bytes: %s", + *count, strerror(errno)); + return NULL; + } + p = ret; + + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + { + *p = (unsigned char)(long)item; + p++; + } + return ret; +} + +Eina_Bool +e_bluez_element_objects_array_get_stringshared(const E_Bluez_Element *element, const char *property, unsigned int *count, E_Bluez_Element ***elements) +{ + E_Bluez_Element **ret, **p; + Eina_Array_Iterator iterator; + E_Bluez_Array *array; + unsigned int i; + int type; + void *item; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(property, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(elements, 0); + + *count = 0; + *elements = NULL; + + if (!e_bluez_element_property_get_stringshared + (element, property, &type, &array)) + return 0; + + if (type != DBUS_TYPE_ARRAY) + { + ERR("property %s is not an array!", property); + return 0; + } + + if ((!array) || (!array->array) || (array->type == DBUS_TYPE_INVALID)) + return 0; + + if (array->type != DBUS_TYPE_OBJECT_PATH) + { + ERR("property %s is not an array of object paths!", property); + return 0; + } + + *count = eina_array_count_get(array->array); + ret = malloc(*count * sizeof(E_Bluez_Element *)); + if (!ret) + { + ERR("could not allocate return array of %d elements: %s", + *count, strerror(errno)); + *count = 0; + return 0; + } + p = ret; + + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + { + E_Bluez_Element *e = e_bluez_element_get(item); + if (!e) + continue; + *p = e; + p++; + } + *count = p - ret; + *elements = ret; + return 1; +} + +/* strings are just pointers (references), no strdup or stringshare_add/ref */ +Eina_Bool +e_bluez_element_strings_array_get_stringshared(const E_Bluez_Element *element, const char *property, unsigned int *count, const char ***strings) +{ + const char **ret, **p; + Eina_Array_Iterator iterator; + E_Bluez_Array *array; + unsigned int i; + int type; + void *item; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(property, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(strings, 0); + + *count = 0; + *strings = NULL; + + if (!e_bluez_element_property_get_stringshared + (element, property, &type, &array)) + return 0; + + if (type != DBUS_TYPE_ARRAY) + { + ERR("property %s is not an array!", property); + return 0; + } + + if ((!array) || (!array->array) || (array->type == DBUS_TYPE_INVALID)) + return 0; + + if (array->type != DBUS_TYPE_STRING) + { + ERR("property %s is not an array of strings!", property); + return 0; + } + + *count = eina_array_count_get(array->array); + ret = malloc(*count * sizeof(char *)); + if (!ret) + { + ERR("could not allocate return array of %d strings: %s", + *count, strerror(errno)); + *count = 0; + return 0; + } + p = ret; + + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + { + if (!item) + continue; + *p = item; + p++; + } + *count = p - ret; + *strings = ret; + return 1; +} + +void +e_bluez_element_array_print(FILE *fp, E_Bluez_Array *array) +{ + Eina_Array_Iterator iterator; + unsigned int i; + void *item; + + if (!array) + return; + + switch (array->type) + { + case DBUS_TYPE_OBJECT_PATH: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "\"%s\", ", (const char *)item); + break; + case DBUS_TYPE_STRING: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "\"%s\", ", (const char *)item); + break; + case DBUS_TYPE_BYTE: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "%#02hhx (\"%c\"), ", (unsigned char)(long)item, + (unsigned char)(long)item); + break; + case DBUS_TYPE_UINT16: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "%#04hx (%hu), ", (unsigned short)(long)item, + (unsigned short)(long)item); + break; + case DBUS_TYPE_UINT32: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "%#08x (%u), ", (unsigned int)(long)item, + (unsigned int)(long)item); + break; + case DBUS_TYPE_DICT_ENTRY: + fputs("{ ", fp); + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + { + E_Bluez_Element_Dict_Entry *entry = item; + fprintf(fp, "%s: ", entry->name); + switch (entry->type) + { + case DBUS_TYPE_OBJECT_PATH: + fprintf(fp, "\"%s\", ", entry->value.path); + break; + case DBUS_TYPE_STRING: + fprintf(fp, "\"%s\", ", entry->value.str); + break; + case DBUS_TYPE_BOOLEAN: + fprintf(fp, "%hhu, ", + entry->value.boolean); + break; + case DBUS_TYPE_BYTE: + fprintf(fp, "%#02hhx (\"%c\"), ", + entry->value.byte, entry->value.byte); + break; + case DBUS_TYPE_INT16: + fprintf(fp, "%#04hx (%hi), ", + entry->value.i16, entry->value.i16); + break; + case DBUS_TYPE_UINT16: + fprintf(fp, "%#04hx (%hu), ", + entry->value.u16, entry->value.u16); + break; + case DBUS_TYPE_UINT32: + fprintf(fp, "%#08x (%u), ", + entry->value.u32, entry->value.u32); + break; + default: + fprintf(fp, "<UNKNOWN TYPE '%c'>", entry->type); + } + } + fputs("}", fp); + break; + default: + fprintf(fp, "<UNKNOWN ARRAY TYPE '%c'>", array->type); + } +} + +/** + * Print element to file descriptor. + */ +void +e_bluez_element_print(FILE *fp, const E_Bluez_Element *element) +{ + const E_Bluez_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN(fp); + if (!element) + { + fputs("Error: no element to print\n", fp); + return; + } + + fprintf(fp, + "Element %p: %s [%s]\n" + "\tProperties:\n", + element, element->path, element->interface); + + EINA_INLIST_FOREACH(element->props, p) + { + fprintf(fp, "\t\t%s (%c) = ", p->name, p->type); + + switch (p->type) + { + case DBUS_TYPE_STRING: + fprintf(fp, "\"%s\"", p->value.str); + break; + case DBUS_TYPE_OBJECT_PATH: + fprintf(fp, "\"%s\"", p->value.path); + break; + case DBUS_TYPE_BOOLEAN: + fprintf(fp, "%hhu", p->value.boolean); + break; + case DBUS_TYPE_BYTE: + fprintf(fp, "%#02hhx (%d), ", p->value.byte, p->value.byte); + break; + case DBUS_TYPE_UINT16: + fprintf(fp, "%hu", p->value.u16); + break; + case DBUS_TYPE_UINT32: + fprintf(fp, "%u", p->value.u32); + break; + case DBUS_TYPE_ARRAY: + e_bluez_element_array_print(fp, p->value.array); + break; + default: + fputs("don't know how to print type", fp); + } + + fputc('\n', fp); + } +} + +static E_Bluez_Element * +e_bluez_element_new(const char *path, const char *interface) +{ + E_Bluez_Element *element; + + element = calloc(1, sizeof(*element)); + if (!element) + { + ERR("could not allocate element: %s", strerror(errno)); + return NULL; + } + + element->path = eina_stringshare_add(path); + element->interface = eina_stringshare_ref(interface); + element->_references = 1; + + return element; +} + +static void +e_bluez_element_extra_properties_free(E_Bluez_Element *element) +{ + while (element->props) + { + E_Bluez_Element_Property *prop; + prop = (E_Bluez_Element_Property *)element->props; + element->props = element->props->next; + _e_bluez_element_property_free(prop); + } +} + +static void +e_bluez_element_free(E_Bluez_Element *element) +{ + if (element->_idler.changed) + ecore_idler_del(element->_idler.changed); + + while (element->_listeners) + { + E_Bluez_Element_Listener *l = (void *)element->_listeners; + element->_listeners = eina_inlist_remove + (element->_listeners, element->_listeners); + + if (l->free_data) l->free_data(l->data); + free(l); + } + + e_bluez_element_pending_cancel_and_free(&element->_pending.properties_get); + e_bluez_element_pending_cancel_and_free(&element->_pending.property_set); + e_bluez_element_pending_cancel_and_free(&element->_pending.agent_register); + e_bluez_element_pending_cancel_and_free(&element->_pending.agent_unregister); + + e_bluez_element_extra_properties_free(element); + eina_stringshare_del(element->interface); + eina_stringshare_del(element->path); + free(element); +} + +/** + * Add reference to element. + */ +int +e_bluez_element_ref(E_Bluez_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return ++element->_references; +} + +/** + * Remove reference from element. + * + * If reference count drops to 0 element will be freed. + */ +int +e_bluez_element_unref(E_Bluez_Element *element) +{ + int i; + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + + i = --element->_references; + if (i == 0) + e_bluez_element_free(element); + else if (i < 0) + ERR("element %p references %d < 0", element, i); + return i; +} + +/** + * Send message with callbacks set to work with bluez elements. + * + * If this call fails (returns 0), pending callbacks will not be called, + * not even with error messages. + * + * @return 1 on success, 0 on failure. + */ +Eina_Bool +e_bluez_element_message_send(E_Bluez_Element *element, const char *method_name, E_DBus_Method_Return_Cb cb, DBusMessage *msg, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + E_Bluez_Element_Call_Data *data; + E_Bluez_Element_Pending *p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(msg, 0); + + data = malloc(sizeof(*data)); + if (!data) + { + ERR("could not alloc e_bluez_element_call_data: %s", + strerror(errno)); + dbus_message_unref(msg); + return 0; + } + + p = malloc(sizeof(*p)); + if (!p) + { + ERR("could not alloc E_Bluez_Element_Pending: %s", + strerror(errno)); + free(data); + dbus_message_unref(msg); + return 0; + } + + data->element = element; + data->cb = cb; + data->pending = p; + data->p_list = pending; + p->user_cb = user_cb; + p->user_data = (void *)user_data; + p->data = data; + p->pending = e_dbus_message_send + (e_bluez_conn, msg, e_bluez_element_call_dispatch_and_free, -1, data); + dbus_message_unref(msg); + + if (p->pending) + { + *pending = eina_inlist_append(*pending, EINA_INLIST_GET(p)); + return 1; + } + + ERR("failed to call %s (obj=%s, path=%s, iface=%s)", + method_name, e_bluez_system_bus_name_get(), + element->path, element->interface); + free(data); + free(p); + return 0; +} + +Eina_Bool +e_bluez_element_call_full(E_Bluez_Element *element, const char *method_name, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + + msg = dbus_message_new_method_call + (e_bluez_system_bus_name_get(), element->path, element->interface, + method_name); + + return e_bluez_element_message_send + (element, method_name, cb, msg, pending, user_cb, user_data); +} + +static Eina_Bool +_e_bluez_element_property_value_add(E_Bluez_Element *element, const char *name, int type, void *value) +{ + E_Bluez_Element_Property *p; + + name = eina_stringshare_add(name); + EINA_INLIST_FOREACH(element->props, p) + { + if (p->name == name) + { + eina_stringshare_del(name); + return _e_bluez_element_property_update(p, type, value); + } + } + + p = _e_bluez_element_property_new(name, type, value); + if (!p) + { + ERR("could not create property %s (%c)", name, type); + return 0; + } + + element->props = eina_inlist_append(element->props, EINA_INLIST_GET(p)); + return 1; +} + +E_Bluez_Array * +e_bluez_element_iter_get_array(DBusMessageIter *itr, const char *key) +{ + E_Bluez_Array *array; + DBusMessageIter e_itr; + + array = malloc(sizeof(E_Bluez_Array)); + if (!array) + { + ERR("could not create new e_bluez array."); + return NULL; + } + array->array = eina_array_new(16); + if (!(array->array)) + { + ERR("could not create new eina array."); + free(array); + return NULL; + } + + dbus_message_iter_recurse(itr, &e_itr); + array->type = dbus_message_iter_get_arg_type(&e_itr); + if (array->type == DBUS_TYPE_INVALID) + { + DBG("array %s is of type 'invalid' (empty?)", key); + eina_array_free(array->array); + free(array); + return NULL; + } + + do + { + switch (array->type) + { + case DBUS_TYPE_OBJECT_PATH: + { + const char *path; + + dbus_message_iter_get_basic(&e_itr, &path); + path = eina_stringshare_add(path); + eina_array_push(array->array, path); + _e_bluez_element_item_register(key, path); + } + break; + case DBUS_TYPE_STRING: + { + const char *str; + + dbus_message_iter_get_basic(&e_itr, &str); + str = eina_stringshare_add(str); + eina_array_push(array->array, str); + } + break; + case DBUS_TYPE_BYTE: + { + unsigned char byte; + dbus_message_iter_get_basic(&e_itr, &byte); + eina_array_push(array->array, (void *)(long)byte); + } + break; + case DBUS_TYPE_DICT_ENTRY: + { + E_Bluez_Element_Dict_Entry *entry; + entry = _e_bluez_element_dict_entry_new(&e_itr); + if (entry) + eina_array_push(array->array, entry); + } + break; + default: + ERR("don't know how to build array '%s' of type %c (%d)", + key, array->type, array->type); + eina_array_free(array->array); + free(array); + return NULL; + } + } + while (dbus_message_iter_next(&e_itr)); + return array; +} + +static void +_e_bluez_element_get_properties_callback(void *user_data, DBusMessage *msg, DBusError *err) +{ + E_Bluez_Element *element = user_data; + DBusMessageIter itr, s_itr; + int t, changed; + + DBG("get_properties msg=%p", msg); + + if (!_dbus_callback_check_and_init(msg, &itr, err)) + return; + + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_ARRAY)) + return; + + changed = 0; + dbus_message_iter_recurse(&itr, &s_itr); + do + { + DBusMessageIter e_itr, v_itr; + const char *key; + void *value = NULL; + int r; + + t = dbus_message_iter_get_arg_type(&s_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_DICT_ENTRY)) + continue; + + dbus_message_iter_recurse(&s_itr, &e_itr); + + t = dbus_message_iter_get_arg_type(&e_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING)) + continue; + + dbus_message_iter_get_basic(&e_itr, &key); + dbus_message_iter_next(&e_itr); + t = dbus_message_iter_get_arg_type(&e_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_VARIANT)) + continue; + + dbus_message_iter_recurse(&e_itr, &v_itr); + t = dbus_message_iter_get_arg_type(&v_itr); + if (t == DBUS_TYPE_ARRAY) + value = e_bluez_element_iter_get_array(&v_itr, key); + else if (t != DBUS_TYPE_INVALID) + { + dbus_message_iter_get_basic(&v_itr, &value); + } + else + { + ERR("property has invalid type %s", key); + continue; + } + + r = _e_bluez_element_property_value_add(element, key, t, value); + if (r < 0) + ERR("failed to add property value %s (%c)", key, t); + else if (r == 1) + { + INF("property value changed %s (%c)", key, t); + changed = 1; + } + } + while (dbus_message_iter_next(&s_itr)); + + if (changed) + _e_bluez_element_listeners_call(element); +} + +/** + * Sync element properties with server. + * + * Call method GetProperties() at the given element on server in order to sync + * them. + * + * @param element to call method on server. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_element_properties_sync_full(E_Bluez_Element *element, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "GetProperties"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return e_bluez_element_call_full + (element, name, _e_bluez_element_get_properties_callback, + &element->_pending.properties_get, cb, data); +} + +/** + * Sync element properties with server, simple version. + * + * Call method GetProperties() at the given element on server in order to sync + * them. This is the simple version and there is no check of server reply + * for errors. + * + * @param element to call method on server. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_element_properties_sync(E_Bluez_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return e_bluez_element_properties_sync_full(element, NULL, NULL); +} + +/** + * Call method SetProperty(prop, {key: value}) at the given element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_BLUEZ_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * @param element to call method on server. + * @param prop property name. + * @param key dict key name. + * @param type DBus type to use for value. + * @param value pointer to value, just like regular DBus, see + * dbus_message_iter_append_basic(). + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_element_property_dict_set_full(E_Bluez_Element *element, const char *prop, const char *key, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "SetProperty"; + DBusMessage *msg; + DBusMessageIter itr, variant, dict, entry; + char typestr[32]; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(prop, 0); + + msg = dbus_message_new_method_call + (e_bluez_system_bus_name_get(), element->path, element->interface, name); + + if (!msg) + return 0; + + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &prop); + + if ((size_t)snprintf(typestr, sizeof(typestr), + (DBUS_TYPE_ARRAY_AS_STRING + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + "%c" + DBUS_DICT_ENTRY_END_CHAR_AS_STRING), + type) >= sizeof(typestr)) + { + ERR("sizeof(typestr) is too small!"); + return 0; + } + + dbus_message_iter_open_container(&itr, DBUS_TYPE_VARIANT, typestr, &variant); + + snprintf(typestr, sizeof(typestr), + (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + "%c" + DBUS_DICT_ENTRY_END_CHAR_AS_STRING), + type); + + dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY, typestr, &dict); + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry); + + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); + + if ((type == DBUS_TYPE_STRING) || (type == DBUS_TYPE_OBJECT_PATH)) + dbus_message_iter_append_basic(&entry, type, &value); + else + dbus_message_iter_append_basic(&entry, type, value); + + dbus_message_iter_close_container(&dict, &entry); + dbus_message_iter_close_container(&variant, &dict); + dbus_message_iter_close_container(&itr, &variant); + + return e_bluez_element_message_send + (element, name, NULL, msg, &element->_pending.property_set, cb, data); +} + +/** + * Call method SetProperty(prop, value) at the given element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_BLUEZ_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * @param element to call method on server. + * @param prop property name. + * @param type DBus type to use for value. + * @param value pointer to value, just like regular DBus, see + * dbus_message_iter_append_basic(). + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_element_property_set_full(E_Bluez_Element *element, const char *prop, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "SetProperty"; + char typestr[2]; + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(prop, 0); + + msg = dbus_message_new_method_call + (e_bluez_system_bus_name_get(), element->path, element->interface, name); + + if (!msg) + return 0; + + DBusMessageIter itr, v; + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &prop); + + typestr[0] = type; + typestr[1] = '\0'; + dbus_message_iter_open_container(&itr, DBUS_TYPE_VARIANT, typestr, &v); + if ((type == DBUS_TYPE_STRING) || (type == DBUS_TYPE_OBJECT_PATH)) + dbus_message_iter_append_basic(&v, type, &value); + else if (type == DBUS_TYPE_BOOLEAN) + { + unsigned int b = *(char *)value; + dbus_message_iter_append_basic(&v, type, &b); + } + else + dbus_message_iter_append_basic(&v, type, value); + dbus_message_iter_close_container(&itr, &v); + + return e_bluez_element_message_send + (element, name, NULL, msg, &element->_pending.property_set, cb, data); +} + +/** + * Call method SetProperty(prop, value) at the given element on server. + * + * This is the simple version and there is no check of server reply + * for errors. + * + * @param element to call method on server. + * @param prop property name. + * @param type DBus type to use for value. + * @param value pointer to value, just like regular DBus, see + * dbus_message_iter_append_basic(). + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_element_property_set(E_Bluez_Element *element, const char *prop, int type, const void *value) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(prop, 0); + return e_bluez_element_property_set_full + (element, prop, type, value, NULL, NULL); +} + +Eina_Bool +e_bluez_element_call_with_path(E_Bluez_Element *element, const char *method_name, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + DBusMessageIter itr; + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(string, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + + msg = dbus_message_new_method_call + (e_bluez_system_bus_name_get(), element->path, element->interface, + method_name); + + if (!msg) + return 0; + + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_OBJECT_PATH, &string); + + return e_bluez_element_message_send + (element, method_name, cb, msg, pending, user_cb, user_data); +} + +Eina_Bool +e_bluez_element_call_with_string(E_Bluez_Element *element, const char *method_name, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + DBusMessageIter itr; + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(string, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + + msg = dbus_message_new_method_call + (e_bluez_system_bus_name_get(), element->path, element->interface, + method_name); + + if (!msg) + return 0; + + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &string); + + return e_bluez_element_message_send + (element, method_name, cb, msg, pending, user_cb, user_data); +} + +Eina_Bool +e_bluez_element_call_with_path_and_string(E_Bluez_Element *element, const char *method_name, const char *path, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + DBusMessageIter itr; + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(path, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(string, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + + msg = dbus_message_new_method_call + (e_bluez_system_bus_name_get(), element->path, element->interface, + method_name); + + if (!msg) + return 0; + + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_OBJECT_PATH, &path); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &string); + + return e_bluez_element_message_send + (element, method_name, cb, msg, pending, user_cb, user_data); +} + +/** + * Get property type. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param name property name, must be previously stringshared + * @param type will contain the value type. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_element_property_type_get_stringshared(const E_Bluez_Element *element, const char *name, int *type) +{ + const E_Bluez_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(type, 0); + + EINA_INLIST_FOREACH(element->props, p) + { + if (p->name == name) + { + *type = p->type; + return 1; + } + } + + WRN("element %s (%p) has no property with name \"%s\".", + element->path, element, name); + return 0; +} + +/** + * Get property type. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param name property name + * @param type will contain the value type. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_element_property_type_get(const E_Bluez_Element *element, const char *name, int *type) +{ + Eina_Bool ret; + name = eina_stringshare_add(name); + ret = e_bluez_element_property_type_get_stringshared(element, name, type); + eina_stringshare_del(name); + return ret; +} + +void +e_bluez_element_list_properties(const E_Bluez_Element *element, Eina_Bool (*cb)(void *data, const E_Bluez_Element *element, const char *name, int type, const void *value), const void *data) +{ + const E_Bluez_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN(element); + EINA_SAFETY_ON_NULL_RETURN(cb); + + EINA_INLIST_FOREACH(element->props, p) + { + const void *value = NULL; + + switch (p->type) + { + case DBUS_TYPE_STRING: + value = &p->value.str; + break; + case DBUS_TYPE_OBJECT_PATH: + value = &p->value.path; + break; + case DBUS_TYPE_BOOLEAN: + value = (void *)(unsigned long)p->value.boolean; + break; + case DBUS_TYPE_UINT16: + value = &p->value.u16; + break; + case DBUS_TYPE_UINT32: + value = &p->value.u32; + break; + default: + ERR("unsupported type %c", p->type); + } + + if (!cb((void *)data, element, p->name, p->type, value)) + return; + } +} + +/** + * Get dict value given its key inside a dict property. + * + * This will look into properties for one of type dict that contains + * the given key, to find the property. If no property is found then + * 0 is returned. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param dict_name property name, must be previously stringshared + * @param key key inside dict, must be previously stringshared + * @param type if provided it will contain the value type. + * @param value where to store the property value, must be a pointer to the + * exact type, (Eina_Bool *) for booleans, (char **) for strings, and so on. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_element_property_dict_get_stringshared(const E_Bluez_Element *element, const char *dict_name, const char *key, int *type, void *value) +{ + const E_Bluez_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(dict_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(key, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(value, 0); + + EINA_INLIST_FOREACH(element->props, p) + { + E_Bluez_Element_Dict_Entry *entry; + E_Bluez_Array *array; + + if (p->name != dict_name) + continue; + if (p->type != DBUS_TYPE_ARRAY) + { + WRN("element %s (%p) has property \"%s\" is not an array: %c (%d)", + element->path, element, dict_name, p->type, p->type); + return 0; + } + array = p->value.array; + if ((!array) || (array->type != DBUS_TYPE_DICT_ENTRY)) + { + int t = array ? array->type : DBUS_TYPE_INVALID; + WRN("element %s (%p) has property \"%s\" is not a dict: %c (%d)", + element->path, element, dict_name, t, t); + return 0; + } + entry = e_bluez_element_array_dict_find_stringshared(array, key); + if (!entry) + { + WRN("element %s (%p) has no dict property with name \"%s\" with " + "key \"%s\".", + element->path, element, dict_name, key); + return 0; + } + + if (type) *type = entry->type; + + switch (entry->type) + { + case DBUS_TYPE_BOOLEAN: + *(Eina_Bool *)value = entry->value.boolean; + return 1; + case DBUS_TYPE_BYTE: + *(unsigned char *)value = entry->value.byte; + return 1; + case DBUS_TYPE_INT16: + *(short *)value = entry->value.i16; + return 1; + case DBUS_TYPE_UINT16: + *(unsigned short *)value = entry->value.u16; + return 1; + case DBUS_TYPE_UINT32: + *(unsigned int *)value = entry->value.u32; + return 1; + case DBUS_TYPE_STRING: + *(const char **)value = entry->value.str; + return 1; + case DBUS_TYPE_OBJECT_PATH: + *(const char **)value = entry->value.path; + return 1; + default: + ERR("don't know how to get property %s, key %s type %c (%d)", + dict_name, key, entry->type, entry->type); + return 0; + } + } + + WRN("element %s (%p) has no property with name \"%s\".", + element->path, element, dict_name); + return 0; +} + +/** + * Get property value given its name. + * + * This will look into properties, to find the property. + * If no property is found then 0 is returned. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param name property name, must be previously stringshared + * @param type if provided it will contain the value type. + * @param value where to store the property value, must be a pointer to the + * exact type, (Eina_Bool *) for booleans, (char **) for strings, and so on. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_element_property_get_stringshared(const E_Bluez_Element *element, const char *name, int *type, void *value) +{ + const E_Bluez_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(value, 0); + + EINA_INLIST_FOREACH(element->props, p) + { + if (p->name != name) + continue; + + if (type) *type = p->type; + + switch (p->type) + { + case DBUS_TYPE_BOOLEAN: + *(Eina_Bool *)value = p->value.boolean; + return 1; + case DBUS_TYPE_BYTE: + *(unsigned char *)value = p->value.byte; + return 1; + case DBUS_TYPE_UINT16: + *(unsigned short *)value = p->value.u16; + return 1; + case DBUS_TYPE_UINT32: + *(unsigned int *)value = p->value.u32; + return 1; + case DBUS_TYPE_STRING: + *(const char **)value = p->value.str; + return 1; + case DBUS_TYPE_OBJECT_PATH: + *(const char **)value = p->value.path; + return 1; + case DBUS_TYPE_ARRAY: + *(E_Bluez_Array **)value = p->value.array; + return 1; + default: + ERR("don't know how to get property type %c (%d)", + p->type, p->type); + return 0; + } + } + + WRN("element %s (%p) has no property with name \"%s\".", + element->path, element, name); + return 0; +} + +/** + * Get property value given its name. + * + * This will look into properties, to find the property. + * If no property is found then 0 is returned. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param name property name + * @param type if provided it will contain the value type. + * @param value where to store the property value, must be a pointer to the + * exact type, (Eina_Bool *) for booleans, (char **) for strings, and so on. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_element_property_get(const E_Bluez_Element *element, const char *name, int *type, void *value) +{ + Eina_Bool ret; + name = eina_stringshare_add(name); + ret = e_bluez_element_property_get_stringshared + (element, name, type, value); + eina_stringshare_del(name); + return ret; +} + + +struct e_bluez_elements_for_each_data +{ + Eina_Hash_Foreach cb; + void *data; +}; + +Eina_Bool +_e_bluez_elements_for_each(Eina_Hash *hash __UNUSED__, const char *key, void *data, void *fdata) +{ + struct e_bluez_elements_for_each_data *each_data = fdata; + + each_data->cb(elements, key, data, each_data->data); + return 1; +} + +/** + * Call the given function for each existing element. + * + * @param cb function to call for each element. It will get as parameters, + * in order: the element pointer and the given @a user_data. + * @param user_data data to give to @a cb for each element. + */ +void +e_bluez_elements_for_each(Eina_Hash_Foreach cb, const void *user_data) +{ + struct e_bluez_elements_for_each_data data = {cb, (void *)user_data}; + + EINA_SAFETY_ON_NULL_RETURN(cb); + + eina_hash_foreach(elements, (Eina_Hash_Foreach) _e_bluez_elements_for_each, + &data); +} + +static Eina_Bool +_e_bluez_elements_get_allocate(unsigned int *count, E_Bluez_Element ***p_elements) +{ + *count = eina_hash_population(elements); + if (*count == 0) + { + *p_elements = NULL; + return 1; + } + + *p_elements = malloc(*count * sizeof(E_Bluez_Element *)); + if (!*p_elements) + { + ERR("could not allocate return array of %d elements: %s", + *count, strerror(errno)); + *count = 0; + return 0; + } + return 1; +} + +Eina_Bool +_e_bluez_elements_get_all(Eina_Hash *hash __UNUSED__, const char *key __UNUSED__, void *data, void *fdata) +{ + E_Bluez_Element *element = data; + E_Bluez_Element ***p_ret = fdata; + + **p_ret = element; + (*p_ret)++; + return 1; +} + +/** + * Get all known elements. + * + * No reference is added to these elements, since there are no threads + * in the system, you are free to add references yourself right after + * the return of this call without race condition, elements by the + * system (ie: elementRemoved signal)could only be touched on the next + * main loop iteration. + * + * @param count return the number of elements in array. + * @param p_elements array with all elements, these are not referenced + * and in no particular order, just set if return is 1. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_elements_get_all(unsigned int *count, E_Bluez_Element ***p_elements) +{ + E_Bluez_Element **p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(p_elements, 0); + + if (!_e_bluez_elements_get_allocate(count, p_elements)) + return 0; + p = *p_elements; + eina_hash_foreach(elements, (Eina_Hash_Foreach) _e_bluez_elements_get_all, + &p); + return 1; +} + +struct e_bluez_elements_get_all_str_data +{ + E_Bluez_Element **elements; + int count; + const char *str; +}; + +Eina_Bool +_e_bluez_elements_get_all_type(Eina_Hash *hash __UNUSED__, const char *key __UNUSED__, void *e, void *user_data) +{ + struct e_bluez_elements_get_all_str_data *data = user_data; + E_Bluez_Element *element = e; + + if ((data->str) && (element->interface != data->str)) + return 1; + + data->elements[data->count] = element; + data->count++; + return 1; +} + +/** + * Get all known elements of type. + * + * No reference is added to these elements, since there are no threads + * in the system, you are free to add references yourself right after + * the return of this call without race condition, elements by the + * system (ie: ElementRemoved signal) could only be touched on the next + * main loop iteration. + * + * @param type type to filter, or NULL to get all. + * @param count return the number of elements in array. + * @param p_elements array with all elements, these are not referenced + * and in no particular order, just set if return is 1. + * + * @return 1 on success, 0 otherwise. + * + * @see e_bluez_elements_get_all() + */ +Eina_Bool +e_bluez_elements_get_all_type(const char *type, unsigned int *count, E_Bluez_Element ***p_elements) +{ + struct e_bluez_elements_get_all_str_data data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(p_elements, 0); + + if (!_e_bluez_elements_get_allocate(count, p_elements)) + return 0; + + data.elements = *p_elements; + data.count = 0; + data.str = eina_stringshare_add(type); + eina_hash_foreach(elements, + (Eina_Hash_Foreach) _e_bluez_elements_get_all_type, + &data); + + eina_stringshare_del(data.str); + *count = data.count; + return 1; +} + +/** + * Get the element registered at given path. + * + * @param path the path to query for registered object. + * + * @return element pointer if found, NULL otherwise. No references are added. + */ +E_Bluez_Element * +e_bluez_element_get(const char *path) +{ + E_Bluez_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); + element = eina_hash_find(elements, path); + + return element; +} + +static void +_e_bluez_element_property_changed_callback(void *data, DBusMessage *msg) +{ + E_Bluez_Element *element = (E_Bluez_Element *)data; + DBusMessageIter itr, v_itr; + int t, r, changed = 0; + const char *name = NULL; + void *value = NULL; + + DBG("Property changed in element %s", element->path); + + if (!_dbus_callback_check_and_init(msg, &itr, NULL)) + return; + + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING)) + { + ERR("missing name in property changed signal"); + return; + } + dbus_message_iter_get_basic(&itr, &name); + + dbus_message_iter_next(&itr); + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_VARIANT)) + { + ERR("missing value in property changed signal"); + return; + } + dbus_message_iter_recurse(&itr, &v_itr); + t = dbus_message_iter_get_arg_type(&v_itr); + + if (t == DBUS_TYPE_ARRAY) + value = e_bluez_element_iter_get_array(&v_itr, name); + else if (t != DBUS_TYPE_INVALID) + dbus_message_iter_get_basic(&v_itr, &value); + else + { + ERR("property has invalid type %s", name); + return; + } + + r = _e_bluez_element_property_value_add(element, name, t, value); + if (r < 0) + ERR("failed to add property value %s (%c)", name, t); + else if (r == 1) + { + INF("property value changed %s (%c)", name, t); + changed = 1; + } + if (changed) + _e_bluez_element_listeners_call(element); +} + +/** + * Register the given path, possible creating and element and return it. + * + * This will check if path is already registered, in that case the + * exiting element is returned. If it was not registered yet, a new + * element is created, registered and returned. + * + * This call will not add extra references to the object. + * + * @param path the path to register the element + * + * @return the registered object, no references are added. + */ +E_Bluez_Element * +e_bluez_element_register(const char *path, const char *interface) +{ + E_Bluez_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(interface, NULL); + + element = eina_hash_find(elements, path); + if (element) + return element; + + element = e_bluez_element_new(path, interface); + if (!element) + return NULL; + + if (!eina_hash_add(elements, element->path, element)) + { + ERR("could not add element %s to hash, delete it.", path); + e_bluez_element_free(element); + return NULL; + } + + element->signal_handler = + e_dbus_signal_handler_add + (e_bluez_conn, e_bluez_system_bus_name_get(), + element->path, element->interface, "PropertyChanged", + _e_bluez_element_property_changed_callback, element); + + e_bluez_element_event_add(E_BLUEZ_EVENT_ELEMENT_ADD, element); + + return element; +} + +static void +_e_bluez_element_event_unregister_and_free(void *data __UNUSED__, void *ev) +{ + E_Bluez_Element *element = ev; + e_bluez_element_unref(element); +} + +static void +_e_bluez_element_unregister_internal(E_Bluez_Element *element) +{ + if (element->signal_handler) + { + e_dbus_signal_handler_del(e_bluez_conn, element->signal_handler); + element->signal_handler = NULL; + } + + ecore_event_add(E_BLUEZ_EVENT_ELEMENT_DEL, element, + _e_bluez_element_event_unregister_and_free, NULL); +} + +/** + * Forget about the given element. + * + * This will remove the element from the pool of known objects, then + * add an E_BLUEZ_EVENT_ELEMENT_DEL and after that will unreference it, + * possible freeing it. + * + * @param element element to forget about. Its reference will be removed. + */ +void +e_bluez_element_unregister(E_Bluez_Element *element) +{ + if (!element) + return; + + if (elements) + eina_hash_del_by_key(elements, element->path); +} + +/** + * Remove all known elements. + * + * This will remove all known elements but will NOT add any + * E_BLUEZ_EVENT_ELEMENT_DEL to main loop. + * + * This is just useful to make sure next e_bluez_manager_sync_elements() + * will not leave any stale elements. This is unlikely to happen, as + * E_Bluez is supposed to catch all required events to avoid stale elements. + */ +void +e_bluez_manager_clear_elements(void) +{ + e_bluez_elements_shutdown(); + e_bluez_elements_init(); +} + +/** + * Creates elements hash. + * + * This has no init counter since its already guarded by other code. + * @internal + */ +void +e_bluez_elements_init(void) +{ + EINA_SAFETY_ON_FALSE_RETURN(elements == NULL); + elements = + eina_hash_string_superfast_new(EINA_FREE_CB + (_e_bluez_element_unregister_internal)); +} + +void +e_bluez_elements_shutdown(void) +{ + EINA_SAFETY_ON_FALSE_RETURN(elements != NULL); + eina_hash_free(elements); + elements = NULL; +} + +static inline Eina_Bool +_e_bluez_element_is(const E_Bluez_Element *element, const char *interface) +{ + return element->interface == interface; +} + +Eina_Bool +e_bluez_element_is_adapter(const E_Bluez_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, EINA_FALSE); + return _e_bluez_element_is(element, e_bluez_iface_adapter); +} + +Eina_Bool +e_bluez_element_is_device(const E_Bluez_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, EINA_FALSE); + return _e_bluez_element_is(element, e_bluez_iface_device); +} diff --git a/src/lib/bluez/e_bluez_manager.c b/src/lib/bluez/e_bluez_manager.c new file mode 100644 index 0000000..47434c7 --- /dev/null +++ b/src/lib/bluez/e_bluez_manager.c @@ -0,0 +1,33 @@ +#include "e_bluez_private.h" + +/** + * Get the element manager. + * + * @return element pointer if found, NULL otherwise. + */ +E_Bluez_Element * +e_bluez_manager_get(void) +{ + return e_bluez_element_get(manager_path); +} + +/** + * + * Call method DefaultAdapter() on Manager. + * TODO: Soon this method will be replaced by ANY adapter inside BlueZ, so we + * won't need t to call it anymore. + * + * @param cb function to call when server replies or some error happens. + * + * @return 1 on success, 0 otherwise. + */ +Eina_Bool +e_bluez_manager_default_adapter(E_DBus_Method_Return_Cb cb, void *data) +{ + E_Bluez_Element *element = e_bluez_element_get(manager_path); + const char name[] = "DefaultAdapter"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return e_bluez_element_call_full + (element, name, NULL, &element->_pending.properties_get, cb, data); +} diff --git a/src/lib/bluez/e_bluez_private.h b/src/lib/bluez/e_bluez_private.h new file mode 100644 index 0000000..4eb0e4f --- /dev/null +++ b/src/lib/bluez/e_bluez_private.h @@ -0,0 +1,153 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_ALLOCA_H +# include <alloca.h> +#elif defined __GNUC__ +# define alloca __builtin_alloca +#elif defined _AIX +# define alloca __alloca +#elif defined _MSC_VER +# include <malloc.h> +# define alloca _alloca +#else +# include <stddef.h> +# ifdef __cplusplus +extern "C" +# endif +void *alloca (size_t); +#endif + +#include <stdio.h> + +#include <Eina.h> +#include <eina_safety_checks.h> + +#include "E_Bluez.h" + +static const char manager_path[] = "/"; + +extern const char *e_bluez_iface_manager; +extern const char *e_bluez_iface_adapter; +extern const char *e_bluez_iface_device; +extern const char *e_bluez_prop_address; +extern const char *e_bluez_prop_name; +extern const char *e_bluez_prop_alias; +extern const char *e_bluez_prop_class; +extern const char *e_bluez_prop_icon; +extern const char *e_bluez_prop_paired; +extern const char *e_bluez_prop_trusted; +extern const char *e_bluez_prop_connected; +extern const char *e_bluez_prop_uuids; +extern const char *e_bluez_prop_powered; +extern const char *e_bluez_prop_discoverable; +extern const char *e_bluez_prop_pairable; +extern const char *e_bluez_prop_discoverabletimeout; +extern const char *e_bluez_prop_pairabletimeout; +extern const char *e_bluez_prop_discovering; +extern const char *e_bluez_prop_devices; + +extern int _e_dbus_bluez_log_dom; + +typedef struct _E_Bluez_Element_Dict_Entry E_Bluez_Element_Dict_Entry; + +struct _E_Bluez_Element_Dict_Entry +{ + const char *name; + int type; + union { + Eina_Bool boolean; + const char *str; + short i16; + unsigned short u16; + unsigned int u32; + unsigned char byte; + const char *path; + } value; +}; + +#ifndef EINA_LOG_DEFAULT_COLOR +#define EINA_LOG_DEFAULT_COLOR EINA_COLOR_CYAN +#endif + +#undef DBG +#undef INF +#undef WRN +#undef ERR + +#define DBG(...) EINA_LOG_DOM_DBG(_e_dbus_bluez_log_dom , __VA_ARGS__) +#define INF(...) EINA_LOG_DOM_INFO(_e_dbus_bluez_log_dom , __VA_ARGS__) +#define WRN(...) EINA_LOG_DOM_WARN(_e_dbus_bluez_log_dom , __VA_ARGS__) +#define ERR(...) EINA_LOG_DOM_ERR(_e_dbus_bluez_log_dom , __VA_ARGS__) + +static inline Eina_Bool +__dbus_callback_check_and_init(const char *file, int line, const char *function, DBusMessage *msg, DBusMessageIter *itr, DBusError *err) +{ + if (!msg) + { + if (err) + eina_log_print(_e_dbus_bluez_log_dom, EINA_LOG_LEVEL_ERR, + file, function, line, + "an error was reported by server: " + "name=\"%s\", message=\"%s\"", + err->name, err->message); + else + eina_log_print(_e_dbus_bluez_log_dom, EINA_LOG_LEVEL_ERR, + file, function, line, + "callback without message arguments!"); + + return 0; + } + + if (!dbus_message_iter_init(msg, itr)) + { + eina_log_print(_e_dbus_bluez_log_dom, EINA_LOG_LEVEL_ERR, + file, function, line, + "could not init iterator."); + return 0; + } + + return 1; +} + +#define _dbus_callback_check_and_init(msg, itr, err) \ + __dbus_callback_check_and_init(__FILE__, __LINE__, __FUNCTION__, \ + msg, itr, err) + +static inline Eina_Bool +__dbus_iter_type_check(const char *file, int line, const char *function, int type, int expected, const char *expected_name) +{ + if (type == expected) + return 1; + + ERR(file, function, line, + "expected type %s (%c) but got %c instead!", + expected_name, expected, type); + + return 0; +} +#define _dbus_iter_type_check(t, e) __dbus_iter_type_check(__FILE__, __LINE__, __FUNCTION__, t, e, #e) + +extern E_DBus_Connection *e_bluez_conn; + +const char *e_bluez_system_bus_name_get(void); + +void e_bluez_manager_clear_elements(void); + +void e_bluez_elements_init(void); +void e_bluez_elements_shutdown(void); + +E_Bluez_Element *e_bluez_element_register(const char *path, const char *interface); +void e_bluez_element_unregister(E_Bluez_Element *element); + +Eina_Bool e_bluez_element_message_send(E_Bluez_Element *element, const char *method_name, E_DBus_Method_Return_Cb cb, DBusMessage *msg, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); +E_Bluez_Array *e_bluez_element_iter_get_array(DBusMessageIter *itr, const char *key); +void e_bluez_element_event_add(int event_type, E_Bluez_Element *element); +E_Bluez_Element_Dict_Entry * e_bluez_element_array_dict_find_stringshared(const E_Bluez_Array *array, const char *key); +void e_bluez_element_array_free(E_Bluez_Array *array, E_Bluez_Array *new __UNUSED__); + +Eina_Bool e_bluez_element_call_full(E_Bluez_Element *element, const char *method_name, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); +Eina_Bool e_bluez_element_call_with_path(E_Bluez_Element *element, const char *method_name, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); +Eina_Bool e_bluez_element_call_with_string(E_Bluez_Element *element, const char *method_name, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); +Eina_Bool e_bluez_element_call_with_path_and_string(E_Bluez_Element *element, const char *method_name, const char *path, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); diff --git a/src/lib/connman/E_Connman.h b/src/lib/connman/E_Connman.h new file mode 100644 index 0000000..b0ec4b3 --- /dev/null +++ b/src/lib/connman/E_Connman.h @@ -0,0 +1,325 @@ +#ifndef E_CONNMAN_H +#define E_CONNMAN_H + +#include <stdint.h> +#include <stdbool.h> +#include <stdio.h> + +#include <Eina.h> +#include <Ecore.h> +#include <E_DBus.h> + +#ifdef EAPI +#undef EAPI +#endif +#ifdef _MSC_VER +# ifdef BUILDING_DLL +# define EAPI __declspec(dllexport) +# else +# define EAPI __declspec(dllimport) +# endif +#else +# ifdef __GNUC__ +# if __GNUC__ >= 4 +# define EAPI __attribute__ ((visibility("default"))) +# else +# define EAPI +# endif +# else +# define EAPI +# endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + /* Ecore Events */ + extern int E_CONNMAN_EVENT_MANAGER_IN; + extern int E_CONNMAN_EVENT_MANAGER_OUT; + extern int E_CONNMAN_EVENT_ELEMENT_ADD; + extern int E_CONNMAN_EVENT_ELEMENT_DEL; + extern int E_CONNMAN_EVENT_ELEMENT_UPDATED; + + typedef struct _E_Connman_Element E_Connman_Element; + + struct _E_Connman_Element + { + const char *path; + const char *interface; + E_DBus_Signal_Handler *signal_handler; + Eina_Inlist *props; + + /* private */ + struct { + Eina_Inlist *properties_get; + Eina_Inlist *property_set; + Eina_Inlist *agent_register; + Eina_Inlist *agent_unregister; + Eina_Inlist *request_scan; + Eina_Inlist *technology_enable; + Eina_Inlist *technology_disable; + Eina_Inlist *profile_remove; + Eina_Inlist *device_propose_scan; + Eina_Inlist *service_connect; + Eina_Inlist *service_disconnect; + Eina_Inlist *service_remove; + Eina_Inlist *service_move_before; + Eina_Inlist *service_move_after; + Eina_Inlist *service_clear_property; + } _pending; + struct { + Ecore_Idler *changed; + } _idler; + Eina_Inlist *_listeners; + int _references; + }; + + /* General Public API */ + EAPI unsigned int e_connman_system_init(E_DBus_Connection *edbus_conn) EINA_ARG_NONNULL(1); + EAPI unsigned int e_connman_system_shutdown(void); + + /* Manager Methods */ + EAPI E_Connman_Element *e_connman_manager_get(void) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_manager_agent_register(const char *object_path, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_manager_agent_unregister(const char *object_path, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_manager_state_get(const char **state) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_manager_offline_mode_get(bool *offline) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_manager_offline_mode_set(bool offline, E_DBus_Method_Return_Cb cb, const void *data) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_manager_profiles_get(unsigned int *count, E_Connman_Element ***p_elements) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_manager_services_get(unsigned int *count, E_Connman_Element ***p_elements) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_manager_technologies_get(unsigned int *count, E_Connman_Element ***p_elements) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_manager_request_scan(const char *type, E_DBus_Method_Return_Cb cb, const void *data) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_manager_technology_default_get(const char **type) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_manager_technology_enable(const char *type, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_manager_technology_disable(const char *type, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_manager_technologies_available_get(unsigned int *count, const char ***strings) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_manager_technologies_enabled_get(unsigned int *count, const char ***strings) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_manager_technologies_connected_get(unsigned int *count, const char ***strings) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_manager_profile_remove(const E_Connman_Element *profile, E_DBus_Method_Return_Cb cb, const void *data) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_manager_profile_active_get(E_Connman_Element **profile) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_manager_profile_active_set(const E_Connman_Element *profile, E_DBus_Method_Return_Cb cb, const void *data) EINA_WARN_UNUSED_RESULT; + + + // TODO: profile_create() + // TODO: service_connect() (actually creates and connect) + // TODO: signal E_CONNMAN_EVENT_MANAGER_STATE_CHANGED + + + /* Profile Methods */ + EAPI E_Connman_Element *e_connman_profile_get(const char *path) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_profile_name_get(const E_Connman_Element *profile, const char **name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_profile_name_set(E_Connman_Element *profile, const char *name, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_profile_offline_mode_get(const E_Connman_Element *profile, bool *offline) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_profile_offline_mode_set(E_Connman_Element *profile, bool offline, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_profile_services_get(const E_Connman_Element *profile, unsigned int *count, E_Connman_Element ***p_elements) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + + + /* Services Methods */ + EAPI E_Connman_Element *e_connman_service_get(const char *path) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_connect(E_Connman_Element *service, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_service_disconnect(E_Connman_Element *service, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_remove(E_Connman_Element *service, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_clear_property(E_Connman_Element *service, const char *property, E_DBus_Method_Return_Cb cb, const void *data); + + EAPI bool e_connman_service_move_before(E_Connman_Element *service, const char *object_path, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_service_move_after(E_Connman_Element *service, const char *object_path, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_state_get(const E_Connman_Element *service, const char **state) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_error_get(const E_Connman_Element *service, const char **error) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_name_get(const E_Connman_Element *service, const char **name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_type_get(const E_Connman_Element *service, const char **type) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_mode_get(const E_Connman_Element *service, const char **mode) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_security_get(const E_Connman_Element *service, const char **security) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_passphrase_get(const E_Connman_Element *service, const char **passphrase) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_service_passphrase_set(E_Connman_Element *service, const char *passphrase, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_passphrase_required_get(const E_Connman_Element *service, bool *passphrase_required) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_strength_get(const E_Connman_Element *service, unsigned char *strength) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_favorite_get(const E_Connman_Element *service, bool *favorite) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_immutable_get(const E_Connman_Element *service, bool *immutable) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_auto_connect_get(const E_Connman_Element *service, bool *auto_connect) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_service_auto_connect_set(E_Connman_Element *service, bool auto_connect, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_setup_required_get(const E_Connman_Element *service, bool *setup_required) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_apn_get(const E_Connman_Element *service, const char **apn) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_service_apn_set(E_Connman_Element *service, const char *apn, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_mcc_get(const E_Connman_Element *service, const char **mcc) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_mnc_get(const E_Connman_Element *service, const char **mnc) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_roaming_get(const E_Connman_Element *service, bool *roaming) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_ipv4_method_get(const E_Connman_Element *service, const char **method) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_ipv4_address_get(const E_Connman_Element *service, const char **address) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_ipv4_gateway_get(const E_Connman_Element *service, const char **gateway) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_ipv4_netmask_get(const E_Connman_Element *service, const char **netmask) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_ipv4_configuration_method_get(const E_Connman_Element *service, const char **method) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_ipv4_configuration_address_get(const E_Connman_Element *service, const char **address) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_ipv4_configuration_gateway_get(const E_Connman_Element *service, const char **gateway) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_ipv4_configuration_netmask_get(const E_Connman_Element *service, const char **netmask) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_ethernet_method_get(const E_Connman_Element *service, const char **method) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_ethernet_address_get(const E_Connman_Element *service, const char **address) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_ethernet_mtu_get(const E_Connman_Element *service, unsigned short *mtu) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_service_ethernet_netmask_get(const E_Connman_Element *service, const char **netmask) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + /* Methods to configure IPv4 service */ + EAPI bool e_connman_service_ipv4_configure_dhcp(E_Connman_Element *service, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_service_ipv4_configure_manual(E_Connman_Element *service, const char *address, const char *netmask, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + /* Technologies methods */ + EAPI E_Connman_Element *e_connman_technology_get(const char *path) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_technology_state_get(const E_Connman_Element *technology, const char **state) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_technology_name_get(const E_Connman_Element *technology, const char **state) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_technology_type_get(const E_Connman_Element *technology, const char **state) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_technology_devices_get(const E_Connman_Element *technology, unsigned int *count, E_Connman_Element ***t_elements) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + + // TODO: ethernet_speed_get (not in connman yet) + // TODO: ethernet_duplex_get (not in connman yet) + + /* Low-Level API: + * + * Should just be used to work around problems until proper solution + * is made into e_connman. + */ + EAPI bool e_connman_manager_sync_elements(void); + + EAPI bool e_connman_elements_get_all(unsigned int *count, E_Connman_Element ***p_elements) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_elements_get_all_type(const char *type, unsigned int *count, E_Connman_Element ***p_elements) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + EAPI E_Connman_Element *e_connman_element_get(const char *path); + + EAPI void e_connman_element_listener_add(E_Connman_Element *element, void (*cb)(void *data, const E_Connman_Element *element), const void *data, void (*free_data)(void *data)) EINA_ARG_NONNULL(1, 2); + EAPI void e_connman_element_listener_del(E_Connman_Element *element, void (*cb)(void *data, const E_Connman_Element *element), const void *data) EINA_ARG_NONNULL(1, 2); + + EAPI int e_connman_element_ref(E_Connman_Element *element) EINA_ARG_NONNULL(1); + EAPI int e_connman_element_unref(E_Connman_Element *element) EINA_ARG_NONNULL(1); + + EAPI void e_connman_element_print(FILE *fp, const E_Connman_Element *element) EINA_ARG_NONNULL(1, 2); + + + EAPI bool e_connman_element_properties_sync(E_Connman_Element *element) EINA_ARG_NONNULL(1); + EAPI bool e_connman_element_properties_sync_full(E_Connman_Element *element, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1); + + EAPI bool e_connman_element_property_set(E_Connman_Element *element, const char *prop, int type, const void *value) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_element_property_set_full(E_Connman_Element *element, const char *prop, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_element_property_dict_set_full(E_Connman_Element *element, const char *prop, const char *key, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + + EAPI void e_connman_element_properties_list(const E_Connman_Element *element, bool (*cb)(void *data, const E_Connman_Element *element, const char *name, int type, const void *value), const void *data) EINA_ARG_NONNULL(1, 2); + + EAPI bool e_connman_element_property_type_get_stringshared(const E_Connman_Element *element, const char *name, int *type) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_element_property_type_get(const E_Connman_Element *element, const char *name, int *type) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_element_property_dict_get_stringshared(const E_Connman_Element *element, const char *dict_name, const char *key_name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_element_property_get_stringshared(const E_Connman_Element *element, const char *name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_element_property_get(const E_Connman_Element *element, const char *name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_element_is_manager(const E_Connman_Element *element) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_element_is_device(const E_Connman_Element *element) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_element_is_profile(const E_Connman_Element *element) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_element_is_network(const E_Connman_Element *element) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_element_is_service(const E_Connman_Element *element) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_element_is_technology(const E_Connman_Element *element) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + + /* Device Methods: Low-Level API + * + * Fine tune device, such as turn off and change scan interval. + */ + EAPI E_Connman_Element *e_connman_device_get(const char *path) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_device_propose_scan(E_Connman_Element *device, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_device_address_get(const E_Connman_Element *device, const char **address); + + EAPI bool e_connman_device_name_get(const E_Connman_Element *device, const char **name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_device_type_get(const E_Connman_Element *device, const char **type) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_device_interface_get(const E_Connman_Element *device, const char **interface) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_device_powered_get(const E_Connman_Element *device, bool *powered) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_device_powered_set(E_Connman_Element *device, bool powered, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_device_scan_interval_get(const E_Connman_Element *device, unsigned short *scan_interval) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI bool e_connman_device_scan_interval_set(E_Connman_Element *device, unsigned short scan_interval, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_device_scanning_get(const E_Connman_Element *device, bool *scanning) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_device_networks_get(const E_Connman_Element *device, unsigned int *count, E_Connman_Element ***p_elements) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + + + /* Network Methods: Low-Level API + * + * The network API is informational only, to set these parameters, + * use the services API instead. + */ + EAPI E_Connman_Element *e_connman_network_get(const char *path) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_network_address_get(const E_Connman_Element *network, const char **address) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_network_name_get(const E_Connman_Element *network, const char **name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_network_connected_get(const E_Connman_Element *network, bool *connected) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_network_strength_get(const E_Connman_Element *network, unsigned char *strength) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_network_frequency_get(const E_Connman_Element *network, unsigned short *frequency) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_network_device_get(const E_Connman_Element *network, E_Connman_Element **element) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_network_wifi_ssid_get(const E_Connman_Element *network, unsigned int *count, unsigned char **wifi_ssid) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_network_wifi_mode_get(const E_Connman_Element *network, const char **wifi_mode) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_network_wifi_security_get(const E_Connman_Element *network, const char **wifi_security) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_network_wifi_passphrase_get(const E_Connman_Element *network, const char **wifi_passphrase) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_network_wifi_channel_get(const E_Connman_Element *network, unsigned short *wifi_channel) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI bool e_connman_network_wifi_eap_get(const E_Connman_Element *network, const char **wifi_eap) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + +#ifdef __cplusplus +} +#endif +#endif /* E_CONNMAN_H */ diff --git a/src/lib/connman/Makefile.am b/src/lib/connman/Makefile.am new file mode 100644 index 0000000..b972e30 --- /dev/null +++ b/src/lib/connman/Makefile.am @@ -0,0 +1,31 @@ +MAINTAINERCLEANFILES = Makefile.in + +AM_CPPFLAGS = \ +-I $(top_srcdir)/src/lib/dbus \ +@EDBUS_CFLAGS@ @EVAS_CFLAGS@ @EINA_CFLAGS@ + +if BUILD_ECONNMAN + +lib_LTLIBRARIES = libeconnman.la +include_HEADERS = E_Connman.h + +libeconnman_la_SOURCES = \ +E_Connman.h \ +e_connman_private.h \ +e_connman.c \ +e_connman_device.c \ +e_connman_element.c \ +e_connman_manager.c \ +e_connman_network.c \ +e_connman_profile.c \ +e_connman_service.c \ +e_connman_technology.c + +libeconnman_la_LIBADD = \ +@EDBUS_LIBS@ @EVAS_LIBS@ \ +$(top_builddir)/src/lib/dbus/libedbus.la \ +@EINA_LIBS@ + +libeconnman_la_LDFLAGS = -version-info @version_info@ @econnman_release_info@ + +endif diff --git a/src/lib/connman/e_connman.c b/src/lib/connman/e_connman.c new file mode 100644 index 0000000..d4fc128 --- /dev/null +++ b/src/lib/connman/e_connman.c @@ -0,0 +1,534 @@ +#include "e_connman_private.h" +#include <stdlib.h> +#include <string.h> + +static E_DBus_Signal_Handler *cb_name_owner_changed = NULL; +static DBusPendingCall *pending_get_name_owner = NULL; +static unsigned int init_count = 0; +static char *unique_name = NULL; + +static const char bus_name[] = "org.moblin.connman"; +static const char fdo_bus_name[] = "org.freedesktop.DBus"; +static const char fdo_interface[] = "org.freedesktop.DBus"; +static const char fdo_path[] = "/org/freedesktop/DBus"; + +E_DBus_Connection *e_connman_conn = NULL; + +EAPI int E_CONNMAN_EVENT_MANAGER_IN = 0; +EAPI int E_CONNMAN_EVENT_MANAGER_OUT = 0; +EAPI int E_CONNMAN_EVENT_ELEMENT_ADD = 0; +EAPI int E_CONNMAN_EVENT_ELEMENT_DEL = 0; +EAPI int E_CONNMAN_EVENT_ELEMENT_UPDATED = 0; + +const char *e_connman_iface_manager = NULL; +const char *e_connman_iface_network = NULL; +const char *e_connman_iface_profile = NULL; +const char *e_connman_iface_service = NULL; +const char *e_connman_iface_device = NULL; +const char *e_connman_iface_connection = NULL; +const char *e_connman_iface_technology = NULL; + +const char *e_connman_prop_available = NULL; +const char *e_connman_prop_connected = NULL; +const char *e_connman_prop_connections = NULL; +const char *e_connman_prop_default = NULL; +const char *e_connman_prop_device = NULL; +const char *e_connman_prop_devices = NULL; +const char *e_connman_prop_interface = NULL; +const char *e_connman_prop_ipv4 = NULL; +const char *e_connman_prop_ipv4_configuration = NULL; +const char *e_connman_prop_ethernet = NULL; +const char *e_connman_prop_method = NULL; +const char *e_connman_prop_address = NULL; +const char *e_connman_prop_gateway = NULL; +const char *e_connman_prop_netmask = NULL; +const char *e_connman_prop_mtu = NULL; +const char *e_connman_prop_name = NULL; +const char *e_connman_prop_network = NULL; +const char *e_connman_prop_networks = NULL; +const char *e_connman_prop_offline_mode = NULL; +const char *e_connman_prop_policy = NULL; +const char *e_connman_prop_powered = NULL; +const char *e_connman_prop_priority = NULL; +const char *e_connman_prop_profiles = NULL; +const char *e_connman_prop_profile_active = NULL; +const char *e_connman_prop_services = NULL; +const char *e_connman_prop_technologies = NULL; +const char *e_connman_prop_remember = NULL; +const char *e_connman_prop_scan_interval = NULL; +const char *e_connman_prop_scanning = NULL; +const char *e_connman_prop_state = NULL; +const char *e_connman_prop_strength = NULL; +const char *e_connman_prop_frequency = NULL; +const char *e_connman_prop_type = NULL; +const char *e_connman_prop_wifi_mode = NULL; +const char *e_connman_prop_wifi_passphrase = NULL; +const char *e_connman_prop_wifi_security = NULL; +const char *e_connman_prop_wifi_ssid = NULL; +const char *e_connman_prop_wifi_channel = NULL; +const char *e_connman_prop_wifi_eap = NULL; +const char *e_connman_prop_error = NULL; +const char *e_connman_prop_mode = NULL; +const char *e_connman_prop_security = NULL; +const char *e_connman_prop_passphrase = NULL; +const char *e_connman_prop_passphrase_required = NULL; +const char *e_connman_prop_favorite = NULL; +const char *e_connman_prop_immutable = NULL; +const char *e_connman_prop_auto_connect = NULL; +const char *e_connman_prop_setup_required = NULL; +const char *e_connman_prop_apn = NULL; +const char *e_connman_prop_mcc = NULL; +const char *e_connman_prop_mnc = NULL; +const char *e_connman_prop_roaming = NULL; +const char *e_connman_prop_technology_default = NULL; +const char *e_connman_prop_technologies_available = NULL; +const char *e_connman_prop_technologies_enabled= NULL; +const char *e_connman_prop_technologies_connected = NULL; + + +int _e_dbus_connman_log_dom = -1; + +const char * +e_connman_system_bus_name_get(void) +{ + return unique_name ? unique_name : bus_name; +} + + +/*********************************************************************** + * Manager + ***********************************************************************/ + +/** + * Synchronize elements with server. + * + * This will call Manager.GetProperties() on server, retrieve properties + * and some element paths and then request their properties. + * + * This call will add events E_CONNMAN_EVENT_ELEMENT_ADD and + * E_CONNMAN_EVENT_ELEMENT_UPDATED to the main loop. + * + * This will not remove stale elements. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_sync_elements(void) +{ + E_Connman_Element *manager; + + if (!unique_name) + return EINA_FALSE; + manager = e_connman_element_register(manager_path, e_connman_iface_manager); + if (manager) + e_connman_element_properties_sync(manager); + else + return EINA_FALSE; + + DBG("sync_manager: %s (%s)", unique_name, bus_name); + + return EINA_TRUE; +} + +static void +_e_connman_system_name_owner_exit(void) +{ + e_connman_manager_clear_elements(); + ecore_event_add(E_CONNMAN_EVENT_MANAGER_OUT, NULL, NULL, NULL); + + free(unique_name); + unique_name = NULL; +} + +static void +_e_connman_system_name_owner_enter(const char *uid) +{ + DBG("enter connman at %s (old was %s)", uid, unique_name); + if (unique_name && strcmp(unique_name, uid) == 0) + { + DBG("same unique_name for connman, ignore."); + return; + } + + if (unique_name) + _e_connman_system_name_owner_exit(); + + unique_name = strdup(uid); + + ecore_event_add(E_CONNMAN_EVENT_MANAGER_IN, NULL, NULL, NULL); + e_connman_manager_sync_elements(); +} + +static void +_e_connman_system_name_owner_changed(void *data __UNUSED__, DBusMessage *msg) +{ + DBusError err; + const char *name, *from, *to; + + dbus_error_init(&err); + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_STRING, &from, + DBUS_TYPE_STRING, &to, + DBUS_TYPE_INVALID)) + { + ERR("could not get NameOwnerChanged arguments: %s: %s", + err.name, err.message); + dbus_error_free(&err); + return; + } + + if (strcmp(name, bus_name) != 0) + return; + + DBG("NameOwnerChanged from=[%s] to=[%s]", from, to); + + if (from[0] == '\0' && to[0] != '\0') + _e_connman_system_name_owner_enter(to); + else if (from[0] != '\0' && to[0] == '\0') + { + DBG("exit connman at %s", from); + if (strcmp(unique_name, from) != 0) + DBG("%s was not the known name %s, ignored.", from, unique_name); + else + _e_connman_system_name_owner_exit(); + } + else + DBG("unknow change from %s to %s", from, to); +} + +static void +_e_connman_get_name_owner(void *data __UNUSED__, DBusMessage *msg, DBusError *err) +{ + DBusMessageIter itr; + int t; + const char *uid; + + pending_get_name_owner = NULL; + + if (!_dbus_callback_check_and_init(msg, &itr, err)) + return; + + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING)) + return; + + dbus_message_iter_get_basic(&itr, &uid); + if (!uid) + { + ERR("no name owner!"); + return; + } + + _e_connman_system_name_owner_enter(uid); + return; +} + +/** + * Initialize E Connection Manager (E_Connman) system. + * + * This will connect and watch org.moblin.connman.Manager and Element + * events and translate to Ecore main loop events, also provide a + * proxy for method invocation on server. + * + * Interesting events are: + * - E_CONNMAN_EVENT_MANAGER_IN: issued when connman is avaiable. + * - E_CONNMAN_EVENT_MANAGER_OUT: issued when connman connection is lost. + * - E_CONNMAN_EVENT_ELEMENT_ADD: element was added. + * - E_CONNMAN_EVENT_ELEMENT_DEL: element was deleted. + * - E_CONNMAN_EVENT_ELEMENT_UPDATED: element was updated (properties + * or state changed). + * + * Manager IN/OUT events do not provide any event information, just + * tells you that system is usable or not. After manager is out, all + * elements will be removed, so after this event do not use the system anymore. + * + * Element events will give you an element object. After DEL event callback + * returns, that element will not be valid anymore. + */ +unsigned int +e_connman_system_init(E_DBus_Connection *edbus_conn) +{ + init_count++; + + if (init_count > 1) + return init_count; + + _e_dbus_connman_log_dom = eina_log_domain_register + ("e_dbus_connman", EINA_LOG_DEFAULT_COLOR); + + if(_e_dbus_connman_log_dom < 0) + { + EINA_LOG_ERR + ("impossible to create a log domain for edbus_connman module"); + return -1; + } + + if (E_CONNMAN_EVENT_MANAGER_IN == 0) + E_CONNMAN_EVENT_MANAGER_IN = ecore_event_type_new(); + if (E_CONNMAN_EVENT_MANAGER_OUT == 0) + E_CONNMAN_EVENT_MANAGER_OUT = ecore_event_type_new(); + if (E_CONNMAN_EVENT_ELEMENT_ADD == 0) + E_CONNMAN_EVENT_ELEMENT_ADD = ecore_event_type_new(); + if (E_CONNMAN_EVENT_ELEMENT_DEL == 0) + E_CONNMAN_EVENT_ELEMENT_DEL = ecore_event_type_new(); + if (E_CONNMAN_EVENT_ELEMENT_UPDATED == 0) + E_CONNMAN_EVENT_ELEMENT_UPDATED = ecore_event_type_new(); + + if (e_connman_iface_manager == NULL) + e_connman_iface_manager = eina_stringshare_add("org.moblin.connman.Manager"); + if (e_connman_iface_network == NULL) + e_connman_iface_network = eina_stringshare_add("org.moblin.connman.Network"); + if (e_connman_iface_profile == NULL) + e_connman_iface_profile = eina_stringshare_add("org.moblin.connman.Profile"); + if (e_connman_iface_service == NULL) + e_connman_iface_service = eina_stringshare_add("org.moblin.connman.Service"); + if (e_connman_iface_device == NULL) + e_connman_iface_device = eina_stringshare_add("org.moblin.connman.Device"); + if (e_connman_iface_connection == NULL) + e_connman_iface_connection = eina_stringshare_add("org.moblin.connman.Connection"); + if (e_connman_iface_technology == NULL) + e_connman_iface_technology = eina_stringshare_add("org.moblin.connman.Technology"); + + if (e_connman_prop_available == NULL) + e_connman_prop_available = eina_stringshare_add("Available"); + if (e_connman_prop_connected == NULL) + e_connman_prop_connected = eina_stringshare_add("Connected"); + if (e_connman_prop_connections == NULL) + e_connman_prop_connections = eina_stringshare_add("Connections"); + if (e_connman_prop_default == NULL) + e_connman_prop_default = eina_stringshare_add("Default"); + if (e_connman_prop_device == NULL) + e_connman_prop_device = eina_stringshare_add("Device"); + if (e_connman_prop_devices == NULL) + e_connman_prop_devices = eina_stringshare_add("Devices"); + if (e_connman_prop_interface == NULL) + e_connman_prop_interface = eina_stringshare_add("Interface"); + if (e_connman_prop_ipv4 == NULL) + e_connman_prop_ipv4 = eina_stringshare_add("IPv4"); + if (e_connman_prop_ipv4_configuration == NULL) + e_connman_prop_ipv4_configuration = eina_stringshare_add("IPv4.Configuration"); + if (e_connman_prop_ethernet == NULL) + e_connman_prop_ethernet = eina_stringshare_add("Ethernet"); + if (e_connman_prop_method == NULL) + e_connman_prop_method = eina_stringshare_add("Method"); + if (e_connman_prop_address == NULL) + e_connman_prop_address = eina_stringshare_add("Address"); + if (e_connman_prop_gateway == NULL) + e_connman_prop_gateway = eina_stringshare_add("Gateway"); + if (e_connman_prop_netmask == NULL) + e_connman_prop_netmask = eina_stringshare_add("Netmask"); + if (e_connman_prop_mtu == NULL) + e_connman_prop_mtu = eina_stringshare_add("MTU"); + if (e_connman_prop_name == NULL) + e_connman_prop_name = eina_stringshare_add("Name"); + if (e_connman_prop_network == NULL) + e_connman_prop_network = eina_stringshare_add("Network"); + if (e_connman_prop_networks == NULL) + e_connman_prop_networks = eina_stringshare_add("Networks"); + if (e_connman_prop_offline_mode == NULL) + e_connman_prop_offline_mode = eina_stringshare_add("OfflineMode"); + if (e_connman_prop_policy == NULL) + e_connman_prop_policy = eina_stringshare_add("Policy"); + if (e_connman_prop_powered == NULL) + e_connman_prop_powered = eina_stringshare_add("Powered"); + if (e_connman_prop_priority == NULL) + e_connman_prop_priority = eina_stringshare_add("Priority"); + if (e_connman_prop_profiles == NULL) + e_connman_prop_profiles = eina_stringshare_add("Profiles"); + if (e_connman_prop_profile_active == NULL) + e_connman_prop_profile_active = eina_stringshare_add("ActiveProfile"); + if (e_connman_prop_services == NULL) + e_connman_prop_services = eina_stringshare_add("Services"); + if (e_connman_prop_technologies == NULL) + e_connman_prop_technologies = eina_stringshare_add("Technologies"); + if (e_connman_prop_remember == NULL) + e_connman_prop_remember = eina_stringshare_add("Remember"); + if (e_connman_prop_scan_interval == NULL) + e_connman_prop_scan_interval = eina_stringshare_add("ScanInterval"); + if (e_connman_prop_scanning == NULL) + e_connman_prop_scanning = eina_stringshare_add("Scanning"); + if (e_connman_prop_state == NULL) + e_connman_prop_state = eina_stringshare_add("State"); + if (e_connman_prop_strength == NULL) + e_connman_prop_strength = eina_stringshare_add("Strength"); + if (e_connman_prop_frequency == NULL) + e_connman_prop_frequency = eina_stringshare_add("Frequency"); + if (e_connman_prop_type == NULL) + e_connman_prop_type = eina_stringshare_add("Type"); + if (e_connman_prop_wifi_mode == NULL) + e_connman_prop_wifi_mode = eina_stringshare_add("WiFi.Mode"); + if (e_connman_prop_wifi_passphrase == NULL) + e_connman_prop_wifi_passphrase = eina_stringshare_add("WiFi.Passphrase"); + if (e_connman_prop_wifi_security == NULL) + e_connman_prop_wifi_security = eina_stringshare_add("WiFi.Security"); + if (e_connman_prop_wifi_ssid == NULL) + e_connman_prop_wifi_ssid = eina_stringshare_add("WiFi.SSID"); + if (e_connman_prop_wifi_channel == NULL) + e_connman_prop_wifi_channel = eina_stringshare_add("WiFi.Channel"); + if (e_connman_prop_wifi_eap == NULL) + e_connman_prop_wifi_eap = eina_stringshare_add("WiFi.EAP"); + if (e_connman_prop_error == NULL) + e_connman_prop_error = eina_stringshare_add("Error"); + if (e_connman_prop_mode == NULL) + e_connman_prop_mode = eina_stringshare_add("Mode"); + if (e_connman_prop_security == NULL) + e_connman_prop_security = eina_stringshare_add("Security"); + if (e_connman_prop_passphrase == NULL) + e_connman_prop_passphrase = eina_stringshare_add("Passphrase"); + if (e_connman_prop_passphrase_required == NULL) + e_connman_prop_passphrase_required = eina_stringshare_add("PassphraseRequired"); + if (e_connman_prop_favorite == NULL) + e_connman_prop_favorite = eina_stringshare_add("Favorite"); + if (e_connman_prop_immutable == NULL) + e_connman_prop_immutable = eina_stringshare_add("Immutable"); + if (e_connman_prop_auto_connect == NULL) + e_connman_prop_auto_connect = eina_stringshare_add("AutoConnect"); + if (e_connman_prop_setup_required == NULL) + e_connman_prop_setup_required = eina_stringshare_add("SetupRequired"); + if (e_connman_prop_apn == NULL) + e_connman_prop_apn = eina_stringshare_add("APN"); + if (e_connman_prop_mcc == NULL) + e_connman_prop_mcc = eina_stringshare_add("MCC"); + if (e_connman_prop_mnc == NULL) + e_connman_prop_mnc = eina_stringshare_add("MCN"); + if (e_connman_prop_roaming == NULL) + e_connman_prop_roaming = eina_stringshare_add("Roaming"); + if (e_connman_prop_technology_default == NULL) + e_connman_prop_technology_default = eina_stringshare_add("DefaultTechnology"); + if (e_connman_prop_technologies_available == NULL) + e_connman_prop_technologies_available = eina_stringshare_add("AvailableTechnologies"); + if (e_connman_prop_technologies_enabled == NULL) + e_connman_prop_technologies_enabled = eina_stringshare_add("EnabledTechnologies"); + if (e_connman_prop_technologies_connected == NULL) + e_connman_prop_technologies_connected = eina_stringshare_add("ConnectedTechnologies"); + + e_connman_conn = edbus_conn; + cb_name_owner_changed = e_dbus_signal_handler_add + (e_connman_conn, fdo_bus_name, fdo_path, fdo_interface, "NameOwnerChanged", + _e_connman_system_name_owner_changed, NULL); + + if (pending_get_name_owner) + dbus_pending_call_cancel(pending_get_name_owner); + + pending_get_name_owner = e_dbus_get_name_owner + (e_connman_conn, bus_name, _e_connman_get_name_owner, NULL); + + e_connman_elements_init(); + + return init_count; +} + +static inline void +_stringshare_del(const char **str) +{ + if (!*str) + return; + eina_stringshare_del(*str); + *str = NULL; +} + +/** + * Shutdown connman system. + * + * When count drops to 0 resources will be released and no calls should be + * made anymore. + */ +unsigned int +e_connman_system_shutdown(void) +{ + if (init_count == 0) + { + ERR("connman system already shut down."); + return 0; + } + init_count--; + if (init_count > 0) + return init_count; + + _stringshare_del(&e_connman_iface_manager); + _stringshare_del(&e_connman_iface_network); + _stringshare_del(&e_connman_iface_profile); + _stringshare_del(&e_connman_iface_service); + _stringshare_del(&e_connman_iface_device); + _stringshare_del(&e_connman_iface_connection); + _stringshare_del(&e_connman_iface_technology); + + _stringshare_del(&e_connman_prop_available); + _stringshare_del(&e_connman_prop_connected); + _stringshare_del(&e_connman_prop_connections); + _stringshare_del(&e_connman_prop_default); + _stringshare_del(&e_connman_prop_device); + _stringshare_del(&e_connman_prop_devices); + _stringshare_del(&e_connman_prop_interface); + _stringshare_del(&e_connman_prop_ipv4); + _stringshare_del(&e_connman_prop_ipv4_configuration); + _stringshare_del(&e_connman_prop_ethernet); + _stringshare_del(&e_connman_prop_method); + _stringshare_del(&e_connman_prop_address); + _stringshare_del(&e_connman_prop_gateway); + _stringshare_del(&e_connman_prop_netmask); + _stringshare_del(&e_connman_prop_mtu); + _stringshare_del(&e_connman_prop_name); + _stringshare_del(&e_connman_prop_network); + _stringshare_del(&e_connman_prop_networks); + _stringshare_del(&e_connman_prop_offline_mode); + _stringshare_del(&e_connman_prop_policy); + _stringshare_del(&e_connman_prop_powered); + _stringshare_del(&e_connman_prop_priority); + _stringshare_del(&e_connman_prop_profiles); + _stringshare_del(&e_connman_prop_profile_active); + _stringshare_del(&e_connman_prop_services); + _stringshare_del(&e_connman_prop_technologies); + _stringshare_del(&e_connman_prop_remember); + _stringshare_del(&e_connman_prop_scan_interval); + _stringshare_del(&e_connman_prop_scanning); + _stringshare_del(&e_connman_prop_state); + _stringshare_del(&e_connman_prop_strength); + _stringshare_del(&e_connman_prop_frequency); + _stringshare_del(&e_connman_prop_type); + _stringshare_del(&e_connman_prop_wifi_mode); + _stringshare_del(&e_connman_prop_wifi_passphrase); + _stringshare_del(&e_connman_prop_wifi_security); + _stringshare_del(&e_connman_prop_wifi_ssid); + _stringshare_del(&e_connman_prop_wifi_channel); + _stringshare_del(&e_connman_prop_wifi_eap); + _stringshare_del(&e_connman_prop_error); + _stringshare_del(&e_connman_prop_mode); + _stringshare_del(&e_connman_prop_security); + _stringshare_del(&e_connman_prop_passphrase); + _stringshare_del(&e_connman_prop_passphrase_required); + _stringshare_del(&e_connman_prop_favorite); + _stringshare_del(&e_connman_prop_immutable); + _stringshare_del(&e_connman_prop_auto_connect); + _stringshare_del(&e_connman_prop_setup_required); + _stringshare_del(&e_connman_prop_apn); + _stringshare_del(&e_connman_prop_mcc); + _stringshare_del(&e_connman_prop_mnc); + _stringshare_del(&e_connman_prop_roaming); + _stringshare_del(&e_connman_prop_technology_default); + _stringshare_del(&e_connman_prop_technologies_available); + _stringshare_del(&e_connman_prop_technologies_enabled); + _stringshare_del(&e_connman_prop_technologies_connected); + + if (pending_get_name_owner) + { + dbus_pending_call_cancel(pending_get_name_owner); + pending_get_name_owner = NULL; + } + + if (cb_name_owner_changed) + { + e_dbus_signal_handler_del(e_connman_conn, cb_name_owner_changed); + cb_name_owner_changed = NULL; + } + + if (unique_name) + _e_connman_system_name_owner_exit(); + + e_connman_elements_shutdown(); + eina_log_domain_unregister(_e_dbus_connman_log_dom); + e_connman_conn = NULL; + + return init_count; +} diff --git a/src/lib/connman/e_connman_device.c b/src/lib/connman/e_connman_device.c new file mode 100644 index 0000000..1907747 --- /dev/null +++ b/src/lib/connman/e_connman_device.c @@ -0,0 +1,343 @@ +#include "e_connman_private.h" + +E_Connman_Element * +e_connman_device_get(const char *path) +{ + E_Connman_Element *device; + + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); + + device = e_connman_element_get(path); + if (!device) + return NULL; + + if (!e_connman_element_is_device(device)) + { + WRN("path '%s' is not a device!", path); + return NULL; + } + + return device; +} + +/** + * Propose device to scan. + * + * Call method ProposeScan() at the given device on server in order to propose it + * to scan. + * + * @param device path to call method on server. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_device_propose_scan(E_Connman_Element *device, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "ProposeScan"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(device, 0); + return e_connman_element_call_full + (device, name, NULL, &device->_pending.device_propose_scan, cb, data); +} + +/** + * Get property "Address" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The device address (mac-address for ethernet, wifi...). + * + * This address can be used for directly displaying it in + * the application. It has pure informational purpose. + * + * @param device path to get property. + * @param address where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_device_address_get(const E_Connman_Element *device, const char **address) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(device, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(address, 0); + return e_connman_element_property_get_stringshared + (device, e_connman_prop_address, NULL, address); +} + +/** + * Get property "Name" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The device name (for example "Wireless" etc.) + * + * This name can be used for directly displaying it in + * the application. It has pure informational purpose. + * + * @param device path to get property. + * @param name where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_device_name_get(const E_Connman_Element *device, const char **name) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(device, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + return e_connman_element_property_get_stringshared + (device, e_connman_prop_name, NULL, name); +} + +/** + * Get property "Type" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The device type (for example "ethernet", "wifi" etc.) + * + * @param device path to get property. + * @param type where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_device_type_get(const E_Connman_Element *device, const char **type) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(device, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(type, 0); + return e_connman_element_property_get_stringshared + (device, e_connman_prop_type, NULL, type); +} + +/** + * Get property "Interface" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The device interface (for example "eth0" etc.) + * + * This value is for pure informational purposes. It + * is not guaranteed that it is always present. + * + * @param device path to get property. + * @param interface where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_device_interface_get(const E_Connman_Element *device, const char **interface) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(device, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(interface, 0); + return e_connman_element_property_get_stringshared + (device, e_connman_prop_interface, NULL, interface); +} + +/** + * Get property "Powered" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * Switch a device on or off. This will also modify + * the list of networks in range. All known networks + * will be still available via the Networks property. + * + * Changing this value doesn't change the value of the + * Policy property. + * + * The value of this property can be changed by other + * parts of the system (including the kernel). An + * example would be modifications via the "ifconfig" + * command line utility. + * + * @param device path to get property. + * @param powered where to store the property value, must be a pointer + * to boolean (bool *). + * + * @return 1 on success, 0 otherwise. + * @see e_connman_device_powered_set() + */ +bool +e_connman_device_powered_get(const E_Connman_Element *device, bool *powered) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(device, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(powered, 0); + return e_connman_element_property_get_stringshared + (device, e_connman_prop_powered, NULL, powered); +} + +/** + * Call method SetProperty("Powered", powered) at the given element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_CONNMAN_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * Switch a device on or off. This will also modify + * the list of networks in range. All known networks + * will be still available via the Networks property. + * + * Changing this value doesn't change the value of the + * Policy property. + * + * The value of this property can be changed by other + * parts of the system (including the kernel). An + * example would be modifications via the "ifconfig" + * command line utility. + * + * @param device path to set property. + * @param powered value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + * @see e_connman_device_powered_get() + */ +bool +e_connman_device_powered_set(E_Connman_Element *device, bool powered, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(device, 0); + return e_connman_element_property_set_full + (device, e_connman_prop_powered, DBUS_TYPE_BOOLEAN, &powered, cb, data); +} + +/** + * Get property "ScanInterval" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The scan interval describes the time in seconds + * between automated scan attempts. Setting this + * value to 0 will disable the background scanning. + * + * The default value is 300 and so every 5 minutes + * a scan procedure will be triggered. + * + * This property is not available with all types + * of devices. Some might not support background + * scanning at all. + * + * @param device path to get property. + * @param scan_interval where to store the property value, must be a pointer + * to uint16 (unsigned short *). + * + * @return 1 on success, 0 otherwise. + * @see e_connman_device_scan_interval_set() + */ +bool +e_connman_device_scan_interval_get(const E_Connman_Element *device, unsigned short *scan_interval) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(device, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(scan_interval, 0); + return e_connman_element_property_get_stringshared + (device, e_connman_prop_scan_interval, NULL, scan_interval); +} + +/** + * Call method SetProperty("ScanInterval", scan_interval) at the given element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_CONNMAN_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * The scan interval describes the time in seconds + * between automated scan attempts. Setting this + * value to 0 will disable the background scanning. + * + * The default value is 300 and so every 5 minutes + * a scan procedure will be triggered. + * + * This property is not available with all types + * of devices. Some might not support background + * scanning at all. + * + * @param device path to set property. + * @param scan_interval value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + * @see e_connman_device_scan_interval_get() + */ +bool +e_connman_device_scan_interval_set(E_Connman_Element *device, unsigned short scan_interval, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(device, 0); + return e_connman_element_property_set_full + (device, e_connman_prop_scan_interval, DBUS_TYPE_UINT16, + &scan_interval, cb, data); +} + +/** + * Get property "Scanning" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * Indicates if a device is scanning. Not all device + * types might support this. Also some hardware might + * execute background scanning without notifying the + * driver about it. Use this property only for visual + * indication. + * + * @param device path to get property. + * @param scanning where to store the property value, must be a pointer + * to boolean (bool *). + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_device_scanning_get(const E_Connman_Element *device, bool *scanning) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(device, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(scanning, 0); + return e_connman_element_property_get_stringshared + (device, e_connman_prop_scanning, NULL, scanning); +} + +/** + * Get array of network elements. + * + * @param device path to get property. + * @param count return the number of elements in array. + * @param elements where to store elements array, just changed if return is 1. + * Elements are not referenced and in no particular order. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_device_networks_get(const E_Connman_Element *device, unsigned int *count, E_Connman_Element ***elements) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(device, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(elements, 0); + return e_connman_element_objects_array_get_stringshared + (device, e_connman_prop_networks, count, elements); +} diff --git a/src/lib/connman/e_connman_element.c b/src/lib/connman/e_connman_element.c new file mode 100644 index 0000000..940ea20 --- /dev/null +++ b/src/lib/connman/e_connman_element.c @@ -0,0 +1,2270 @@ +#include "e_connman_private.h" +#include <string.h> +#include <errno.h> + +static Eina_Hash *elements = NULL; + +typedef struct _E_Connman_Array E_Connman_Array; +typedef struct _E_Connman_Element_Pending E_Connman_Element_Pending; +typedef struct _E_Connman_Element_Call_Data E_Connman_Element_Call_Data; +typedef struct _E_Connman_Element_Property E_Connman_Element_Property; +typedef struct _E_Connman_Element_Listener E_Connman_Element_Listener; +typedef struct _E_Connman_Element_Dict_Entry E_Connman_Element_Dict_Entry; + +struct _E_Connman_Array +{ + int type; + Eina_Array *array; +}; + +struct _E_Connman_Element_Pending +{ + EINA_INLIST; + DBusPendingCall *pending; + void *data; + E_DBus_Method_Return_Cb user_cb; + void *user_data; +}; + +struct _E_Connman_Element_Call_Data +{ + E_Connman_Element *element; + E_DBus_Method_Return_Cb cb; + E_Connman_Element_Pending *pending; + Eina_Inlist **p_list; +}; + +struct _E_Connman_Element_Property +{ + EINA_INLIST; + const char *name; + int type; + union { + bool boolean; + const char *str; + unsigned short u16; + unsigned int u32; + unsigned char byte; + const char *path; + void *variant; + E_Connman_Array *array; + } value; +}; + +struct _E_Connman_Element_Dict_Entry +{ + const char *name; + int type; + union { + bool boolean; + const char *str; + unsigned short u16; + unsigned int u32; + unsigned char byte; + const char *path; + } value; +}; + +struct _E_Connman_Element_Listener +{ + EINA_INLIST; + void (*cb)(void *data, const E_Connman_Element *element); + void *data; + void (*free_data)(void *data); +}; + + +static void +_e_connman_element_event_no_free(void *data __UNUSED__, void *ev) +{ + E_Connman_Element *element = ev; + e_connman_element_unref(element); +} + +static void +e_connman_element_event_add(int event_type, E_Connman_Element *element) +{ + e_connman_element_ref(element); + ecore_event_add + (event_type, element, _e_connman_element_event_no_free, element); +} + +static void +e_connman_element_call_dispatch_and_free(void *d, DBusMessage *msg, DBusError *err) +{ + E_Connman_Element_Call_Data *data = d; + E_Connman_Element_Pending *pending; + + pending = data->pending; + pending->pending = NULL; + + if (data->cb) + data->cb(data->element, msg, err); + + if (pending->user_cb) + pending->user_cb(pending->user_data, msg, err); + + pending->data = NULL; + *data->p_list = eina_inlist_remove(*data->p_list, EINA_INLIST_GET(pending)); + free(pending); + free(data); +} + +static void +e_connman_element_pending_cancel_and_free(Eina_Inlist **pending) +{ + while (*pending) + { + E_Connman_Element_Pending *p = (E_Connman_Element_Pending *)*pending; + DBusError err; + + dbus_pending_call_cancel(p->pending); + + dbus_error_init(&err); + dbus_set_error(&err, "Canceled", "Pending method call was canceled."); + e_connman_element_call_dispatch_and_free(p->data, NULL, &err); + dbus_error_free(&err); + } +} + +void +e_connman_element_listener_add(E_Connman_Element *element, void (*cb)(void *data, const E_Connman_Element *element), const void *data, void (*free_data)(void *data)) +{ + E_Connman_Element_Listener *l; + EINA_SAFETY_ON_FALSE_GOTO(element, error); + EINA_SAFETY_ON_FALSE_GOTO(cb, error); + + l = malloc(sizeof(*l)); + if (!l) + { + ERR("could not allocate E_Connman_Element_Listener"); + goto error; + } + + l->cb = cb; + l->data = (void *)data; + l->free_data = free_data; + + element->_listeners = eina_inlist_append + (element->_listeners, EINA_INLIST_GET(l)); + + return; + + error: + if (free_data) + free_data((void *)data); +} + +void +e_connman_element_listener_del(E_Connman_Element *element, void (*cb)(void *data, const E_Connman_Element *element), const void *data) +{ + E_Connman_Element_Listener *l; + + EINA_SAFETY_ON_NULL_RETURN(element); + EINA_SAFETY_ON_NULL_RETURN(cb); + + EINA_INLIST_FOREACH(element->_listeners, l) + if ((l->cb == cb) && (l->data == data)) + { + element->_listeners = eina_inlist_remove + (element->_listeners, EINA_INLIST_GET(l)); + if (l->free_data) l->free_data(l->data); + free(l); + return; + } +} + +static void +_e_connman_element_listeners_call_do(E_Connman_Element *element) +{ + E_Connman_Element_Listener *l, **shadow; + unsigned int i, count; + + /* NB: iterate on a copy in order to allow listeners to be deleted + * from callbacks. number of listeners should be small, so the + * following should do fine. + */ + count = eina_inlist_count(element->_listeners); + if (count < 1) + goto end; + + shadow = alloca(sizeof(*shadow) * count); + if (!shadow) + goto end; + + i = 0; + EINA_INLIST_FOREACH(element->_listeners, l) + shadow[i++] = l; + + for (i = 0; i < count; i++) + shadow[i]->cb(shadow[i]->data, element); + + end: + e_connman_element_event_add(E_CONNMAN_EVENT_ELEMENT_UPDATED, element); +} + +static int +_e_connman_element_listeners_call_idler(void *data) +{ + E_Connman_Element *element = data; + _e_connman_element_listeners_call_do(element); + element->_idler.changed = NULL; + return 0; +} + +static void +_e_connman_element_listeners_call(E_Connman_Element *element) +{ + if (element->_idler.changed) + return; + element->_idler.changed = ecore_idler_add + (_e_connman_element_listeners_call_idler, element); +} + +/*********************************************************************** + * Property + ***********************************************************************/ + +static void +_e_connman_element_dict_entry_free(E_Connman_Element_Dict_Entry *entry) +{ + switch (entry->type) + { + case DBUS_TYPE_BOOLEAN: + case DBUS_TYPE_BYTE: + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + break; + case DBUS_TYPE_OBJECT_PATH: + eina_stringshare_del(entry->value.path); + break; + case DBUS_TYPE_STRING: + eina_stringshare_del(entry->value.str); + break; + default: + ERR("don't know how to free dict entry '%s' of type %c (%d)", + entry->name, entry->type, entry->type); + } + + eina_stringshare_del(entry->name); + free(entry); +} + +static E_Connman_Element_Dict_Entry * +_e_connman_element_dict_entry_new(DBusMessageIter *itr) +{ + E_Connman_Element_Dict_Entry *entry; + DBusMessageIter e_itr, v_itr; + int t; + const char *key = NULL; + void *value = NULL; + + dbus_message_iter_recurse(itr, &e_itr); + + t = dbus_message_iter_get_arg_type(&e_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING)) + { + ERR("invalid format for dict entry. first type not a string: %c (%d)", + t, t); + return NULL; + } + + dbus_message_iter_get_basic(&e_itr, &key); + if (!key || !key[0]) + { + ERR("invalid format for dict entry. no key."); + return NULL; + } + + dbus_message_iter_next(&e_itr); + t = dbus_message_iter_get_arg_type(&e_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_VARIANT)) + { + ERR("invalid format for dict entry '%s'. " + "second type not a variant: %c (%d)", + key, t, t); + return NULL; + } + + dbus_message_iter_recurse(&e_itr, &v_itr); + + t = dbus_message_iter_get_arg_type(&v_itr); + if ((t == DBUS_TYPE_INVALID) || (t == DBUS_TYPE_ARRAY)) + { + ERR("invalid type for dict value for entry '%s': %c (%d)", + key, t, t); + return NULL; + } + + entry = calloc(1, sizeof(*entry)); + if (!entry) + { + ERR("could not allocate memory for dict entry."); + return NULL; + } + + dbus_message_iter_get_basic(&v_itr, &value); + switch (t) + { + case DBUS_TYPE_BOOLEAN: + entry->value.boolean = (bool)(long)value; + break; + case DBUS_TYPE_BYTE: + entry->value.byte = (unsigned char)(long)value; + break; + case DBUS_TYPE_UINT16: + entry->value.u16 = (unsigned short)(long)value; + break; + case DBUS_TYPE_UINT32: + entry->value.u32 = (unsigned int)(long)value; + break; + case DBUS_TYPE_STRING: + entry->value.str = eina_stringshare_add(value); + break; + case DBUS_TYPE_OBJECT_PATH: + entry->value.path = eina_stringshare_add(value); + break; + default: + ERR("don't know how to create dict entry '%s' for of type %c (%d)", + key, t, t); + free(entry); + return NULL; + } + + entry->name = eina_stringshare_add(key); + entry->type = t; + return entry; +} + +static E_Connman_Element_Dict_Entry * +_e_connman_element_array_dict_find_stringshared(const E_Connman_Array *array, const char *key) +{ + E_Connman_Element_Dict_Entry *entry; + Eina_Array_Iterator iterator; + unsigned int i; + + EINA_ARRAY_ITER_NEXT(array->array, i, entry, iterator) + if (entry->name == key) + return entry; + + return NULL; +} + +static void +_e_connman_element_array_free(E_Connman_Array *array, E_Connman_Array *new __UNUSED__) +{ + Eina_Array_Iterator iterator; + unsigned int i; + void *item; + + if (!array) + return; + + switch (array->type) + { + case DBUS_TYPE_BOOLEAN: + case DBUS_TYPE_BYTE: + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + break; + case DBUS_TYPE_OBJECT_PATH: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + eina_stringshare_del(item); + break; + case DBUS_TYPE_STRING: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + eina_stringshare_del(item); + break; + case DBUS_TYPE_DICT_ENTRY: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + _e_connman_element_dict_entry_free(item); + break; + default: + ERR("don't know how to free array of values of type %c (%d)", + array->type, array->type); + break; + } + eina_array_free(array->array); + free(array); +} + +static void +_e_connman_element_property_value_free(E_Connman_Element_Property *property) +{ + switch (property->type) + { + case 0: + return; + case DBUS_TYPE_BOOLEAN: + case DBUS_TYPE_BYTE: + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + break; + case DBUS_TYPE_STRING: + eina_stringshare_del(property->value.str); + break; + case DBUS_TYPE_OBJECT_PATH: + eina_stringshare_del(property->value.path); + break; + case DBUS_TYPE_ARRAY: + _e_connman_element_array_free(property->value.array, NULL); + break; + default: + ERR("don't know how to free value of property type %c (%d)", + property->type, property->type); + } +} + +static const char * +_e_connman_element_get_interface(const char *key) +{ + const char *interface = NULL, *tail; + char head; + + head = key[0]; + tail = key + 1; + + switch (head) + { + case 'P': + if (strcmp(tail, "rofiles") == 0) + interface = e_connman_iface_profile; + break; + case 'D': + if (strcmp(tail, "evices") == 0) + interface = e_connman_iface_device; + break; + case 'N': + if (strcmp(tail, "etworks") == 0) + interface = e_connman_iface_network; + break; + case 'S': + if (strcmp(tail, "ervices") == 0) + interface = e_connman_iface_service; + break; + case 'T': + if (strcmp(tail, "echnologies") == 0) + interface = e_connman_iface_technology; + break; + default: + break; + } + + if (!interface) + ERR("failed to find interface for property \"%s\"", key); + + return interface; +} + +static void +_e_connman_element_item_register(const char *key, const char *item) +{ + E_Connman_Element *element; + const char *interface; + + interface = _e_connman_element_get_interface(key); + if (!interface) + return; + element = e_connman_element_register(item, interface); + if ((element) && (!e_connman_element_properties_sync(element))) + WRN("could not get properties of %s", element->path); +} + +/* Match 2 arrays to find which are new and which are old elements + * For new elements, register them under prop_name property + * For old elements, unregister them, sending proper DEL event + */ +static void +_e_connman_element_array_match(E_Connman_Array *old, E_Connman_Array *new, const char *prop_name) +{ + Eina_List *deleted = NULL; + Eina_Array_Iterator iter_old, iter_new; + unsigned int i_old = 0, i_new = 0; + void *item_old, *item_new; + Eina_List *l; + void *data; + + if (!old) + return; + if (old->type != DBUS_TYPE_OBJECT_PATH) + return; + + if ((!new) || (!new->array) || eina_array_count_get(new->array) == 0) + { + if ((!old) || (!old->array) || eina_array_count_get(old->array) == 0) + return; + else + { + iter_old = old->array->data; + goto out_remove_remaining; + } + } + + iter_new = new->array->data; + item_new = *iter_new; + EINA_ARRAY_ITER_NEXT(old->array, i_old, item_old, iter_old) + { + if (item_old == item_new) + { + i_new++; + if (i_new >= eina_array_count_get(new->array)) + { + i_old++; + break; + } + + iter_new++; + item_new = *iter_new; + } + else + deleted = eina_list_append(deleted, item_old); + } + + for(; i_new < eina_array_count_get(new->array); iter_new++, i_new++) + { + bool found = 0; + item_new = *iter_new; + if (!item_new) + break; + + EINA_LIST_FOREACH(deleted, l, data) + { + if (data == item_new) + { + deleted = eina_list_remove_list(deleted, l); + found = 1; + break; + } + } + if (!found) + { + _e_connman_element_item_register(prop_name, item_new); + DBG("Add element %s\n", (const char *) item_new); + } + } + + /* everybody after i_old on old->array + everybody from deleted list + will be removed + */ + EINA_LIST_FREE(deleted, data) + { + E_Connman_Element *e = e_connman_element_get(data); + if (e) + e_connman_element_unregister(e); + DBG("Delete element %s\n", (const char *) data); + } + +out_remove_remaining: + for(; i_old < eina_array_count_get(old->array); iter_old++, i_old++) + { + E_Connman_Element *e; + item_old = *iter_old; + if (!item_old) + break; + + e = e_connman_element_get(item_old); + if (e) + e_connman_element_unregister(e); + DBG("Delete element %s\n", (const char *) item_old); + } +} + +static bool +_e_connman_element_property_update(E_Connman_Element_Property *property, int type, void *data) +{ + int changed = 0; + + if ((type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) && data) + data = (char *)eina_stringshare_add(data); + + if (property->type != type) + { + if (property->type) + DBG("property type changed from '%c' to '%c'", + property->type, type); + _e_connman_element_property_value_free(property); + memset(&property->value, 0, sizeof(property->value)); + property->type = type; + changed = 1; + } + + switch (type) + { + case DBUS_TYPE_BOOLEAN: + if (changed || property->value.boolean != (bool)(long)data) + { + property->value.boolean = (bool)(long)data; + changed = 1; + } + break; + case DBUS_TYPE_BYTE: + if (changed || property->value.byte != (unsigned char)(long)data) + { + property->value.byte = (unsigned char)(long)data; + changed = 1; + } + break; + case DBUS_TYPE_UINT16: + if (changed || property->value.u16 != (unsigned short)(long)data) + { + property->value.u16 = (unsigned short)(long)data; + changed = 1; + } + break; + case DBUS_TYPE_UINT32: + if (changed || property->value.u32 != (unsigned int)(long)data) + { + property->value.u32 = (unsigned int)(long)data; + changed = 1; + } + break; + case DBUS_TYPE_STRING: + if (changed) + property->value.str = data; + else + { + if (property->value.str) + eina_stringshare_del(property->value.str); + if (property->value.str != data) + { + property->value.str = data; + changed = 1; + } + } + break; + case DBUS_TYPE_OBJECT_PATH: + if (changed) + property->value.path = data; + else + { + if (property->value.path) + eina_stringshare_del(property->value.path); + if (property->value.path != data) + { + property->value.path = data; + changed = 1; + } + } + break; + case DBUS_TYPE_ARRAY: + if (!changed) + if (property->value.array) + { + _e_connman_element_array_match(property->value.array, data, property->name); + _e_connman_element_array_free(property->value.array, data); + } + property->value.array = data; + changed = 1; + break; + default: + ERR("don't know how to update property type %c (%d)", type, type); + } + + return changed; +} + +static E_Connman_Element_Property * +_e_connman_element_property_new(const char *name, int type, void *data) +{ + E_Connman_Element_Property *property; + + property = calloc(1, sizeof(*property)); + if (!property) + { + eina_stringshare_del(name); + ERR("could not allocate property: %s", strerror(errno)); + return NULL; + } + + property->name = name; + _e_connman_element_property_update(property, type, data); + return property; +} + +static void +_e_connman_element_property_free(E_Connman_Element_Property *property) +{ + _e_connman_element_property_value_free(property); + eina_stringshare_del(property->name); + free(property); +} + +/*********************************************************************** + * Element + ***********************************************************************/ +unsigned char * +e_connman_element_bytes_array_get_stringshared(const E_Connman_Element *element, const char *property, unsigned int *count) +{ + Eina_Array_Iterator iterator; + E_Connman_Array *array; + unsigned char *ret, *p; + unsigned int i; + void *item; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(property, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, NULL); + + *count = 0; + + if (!e_connman_element_property_get_stringshared + (element, property, NULL, &array)) + return NULL; + + if ((!array) || (!(array->array))) + return NULL; + + *count = eina_array_count_get(array->array); + ret = malloc(*count * sizeof(unsigned char)); + if (!ret) + { + ERR("could not allocate return array of %d bytes: %s", + *count, strerror(errno)); + return NULL; + } + p = ret; + + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + { + *p = (unsigned char)(long)item; + p++; + } + return ret; +} + +bool +e_connman_element_objects_array_get_stringshared(const E_Connman_Element *element, const char *property, unsigned int *count, E_Connman_Element ***elements) +{ + E_Connman_Element **ret, **p; + Eina_Array_Iterator iterator; + E_Connman_Array *array; + unsigned int i; + int type; + void *item; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(property, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(elements, 0); + + *count = 0; + *elements = NULL; + + if (!e_connman_element_property_get_stringshared + (element, property, &type, &array)) + return 0; + + if (type != DBUS_TYPE_ARRAY) + { + ERR("property %s is not an array!", property); + return 0; + } + + if ((!array) || (!array->array) || (array->type == DBUS_TYPE_INVALID)) + return 0; + + if (array->type != DBUS_TYPE_OBJECT_PATH) + { + ERR("property %s is not an array of object paths!", property); + return 0; + } + + *count = eina_array_count_get(array->array); + ret = malloc(*count * sizeof(E_Connman_Element *)); + if (!ret) + { + ERR("could not allocate return array of %d elements: %s", + *count, strerror(errno)); + *count = 0; + return 0; + } + p = ret; + + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + { + E_Connman_Element *e = e_connman_element_get(item); + if (!e) + continue; + *p = e; + p++; + } + *count = p - ret; + *elements = ret; + return 1; +} + +/* strings are just pointers (references), no strdup or stringshare_add/ref */ +bool +e_connman_element_strings_array_get_stringshared(const E_Connman_Element *element, const char *property, unsigned int *count, const char ***strings) +{ + const char **ret, **p; + Eina_Array_Iterator iterator; + E_Connman_Array *array; + unsigned int i; + int type; + void *item; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(property, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(strings, 0); + + *count = 0; + *strings = NULL; + + if (!e_connman_element_property_get_stringshared + (element, property, &type, &array)) + return 0; + + if (type != DBUS_TYPE_ARRAY) + { + ERR("property %s is not an array!", property); + return 0; + } + + if ((!array) || (!array->array) || (array->type == DBUS_TYPE_INVALID)) + return 0; + + if (array->type != DBUS_TYPE_STRING) + { + ERR("property %s is not an array of strings!", property); + return 0; + } + + *count = eina_array_count_get(array->array); + ret = malloc(*count * sizeof(char *)); + if (!ret) + { + ERR("could not allocate return array of %d strings: %s", + *count, strerror(errno)); + *count = 0; + return 0; + } + p = ret; + + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + { + if (!item) + continue; + *p = item; + p++; + } + *count = p - ret; + *strings = ret; + return 1; +} + +static void +_e_connman_element_array_print(FILE *fp, E_Connman_Array *array) +{ + Eina_Array_Iterator iterator; + unsigned int i; + void *item; + + if (!array) + return; + + switch (array->type) + { + case DBUS_TYPE_OBJECT_PATH: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "\"%s\", ", (const char *)item); + break; + case DBUS_TYPE_STRING: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "\"%s\", ", (const char *)item); + break; + case DBUS_TYPE_BYTE: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "%#02hhx (\"%c\"), ", (unsigned char)(long)item, + (unsigned char)(long)item); + break; + case DBUS_TYPE_UINT16: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "%#04hx (%hu), ", (unsigned short)(long)item, + (unsigned short)(long)item); + break; + case DBUS_TYPE_UINT32: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "%#08x (%u), ", (unsigned int)(long)item, + (unsigned int)(long)item); + break; + case DBUS_TYPE_DICT_ENTRY: + fputs("{ ", fp); + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + { + E_Connman_Element_Dict_Entry *entry = item; + fprintf(fp, "%s: ", entry->name); + switch (entry->type) + { + case DBUS_TYPE_OBJECT_PATH: + fprintf(fp, "\"%s\", ", entry->value.path); + break; + case DBUS_TYPE_STRING: + fprintf(fp, "\"%s\", ", entry->value.str); + break; + case DBUS_TYPE_BYTE: + fprintf(fp, "%#02hhx (\"%c\"), ", + entry->value.byte, entry->value.byte); + break; + case DBUS_TYPE_UINT16: + fprintf(fp, "%#04hx (%hu), ", + entry->value.u16, entry->value.u16); + break; + case DBUS_TYPE_UINT32: + fprintf(fp, "%#08x (%u), ", + entry->value.u32, entry->value.u32); + break; + default: + fprintf(fp, "<UNKNOWN TYPE '%c'>", entry->type); + } + } + fputs("}", fp); + break; + default: + fprintf(fp, "<UNKNOWN ARRAY TYPE '%c'>", array->type); + } +} + +/** + * Print element to file descriptor. + */ +void +e_connman_element_print(FILE *fp, const E_Connman_Element *element) +{ + const E_Connman_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN(fp); + if (!element) + { + fputs("Error: no element to print\n", fp); + return; + } + + fprintf(fp, + "Element %p: %s [%s]\n" + "\tProperties:\n", + element, element->path, element->interface); + + EINA_INLIST_FOREACH(element->props, p) + { + fprintf(fp, "\t\t%s (%c) = ", p->name, p->type); + + switch (p->type) + { + case DBUS_TYPE_STRING: + fprintf(fp, "\"%s\"", p->value.str); + break; + case DBUS_TYPE_OBJECT_PATH: + fprintf(fp, "\"%s\"", p->value.path); + break; + case DBUS_TYPE_BOOLEAN: + fprintf(fp, "%hhu", p->value.boolean); + break; + case DBUS_TYPE_BYTE: + fprintf(fp, "%#02hhx (%d), ", p->value.byte, p->value.byte); + break; + case DBUS_TYPE_UINT16: + fprintf(fp, "%hu", p->value.u16); + break; + case DBUS_TYPE_UINT32: + fprintf(fp, "%u", p->value.u32); + break; + case DBUS_TYPE_ARRAY: + _e_connman_element_array_print(fp, p->value.array); + break; + default: + fputs("don't know how to print type", fp); + } + + fputc('\n', fp); + } +} + +static E_Connman_Element * +e_connman_element_new(const char *path, const char *interface) +{ + E_Connman_Element *element; + + element = calloc(1, sizeof(*element)); + if (!element) + { + ERR("could not allocate element: %s", strerror(errno)); + return NULL; + } + + element->path = eina_stringshare_add(path); + element->interface = eina_stringshare_ref(interface); + element->_references = 1; + + return element; +} + +static void +e_connman_element_extra_properties_free(E_Connman_Element *element) +{ + while (element->props) + { + E_Connman_Element_Property *prop; + prop = (E_Connman_Element_Property *)element->props; + element->props = element->props->next; + _e_connman_element_property_free(prop); + } +} + +static void +e_connman_element_free(E_Connman_Element *element) +{ + if (element->_idler.changed) + ecore_idler_del(element->_idler.changed); + + while (element->_listeners) + { + E_Connman_Element_Listener *l = (void *)element->_listeners; + element->_listeners = eina_inlist_remove + (element->_listeners, element->_listeners); + + if (l->free_data) l->free_data(l->data); + free(l); + } + + e_connman_element_pending_cancel_and_free(&element->_pending.properties_get); + e_connman_element_pending_cancel_and_free(&element->_pending.property_set); + e_connman_element_pending_cancel_and_free(&element->_pending.agent_register); + e_connman_element_pending_cancel_and_free(&element->_pending.agent_unregister); + e_connman_element_pending_cancel_and_free(&element->_pending.request_scan); + e_connman_element_pending_cancel_and_free(&element->_pending.technology_enable); + e_connman_element_pending_cancel_and_free(&element->_pending.technology_disable); + e_connman_element_pending_cancel_and_free(&element->_pending.profile_remove); + e_connman_element_pending_cancel_and_free(&element->_pending.device_propose_scan); + e_connman_element_pending_cancel_and_free(&element->_pending.service_connect); + e_connman_element_pending_cancel_and_free(&element->_pending.service_disconnect); + e_connman_element_pending_cancel_and_free(&element->_pending.service_remove); + e_connman_element_pending_cancel_and_free(&element->_pending.service_move_before); + e_connman_element_pending_cancel_and_free(&element->_pending.service_move_after); + e_connman_element_pending_cancel_and_free(&element->_pending.service_clear_property); + + e_connman_element_extra_properties_free(element); + eina_stringshare_del(element->interface); + eina_stringshare_del(element->path); + free(element); +} + +/** + * Add reference to element. + */ +int +e_connman_element_ref(E_Connman_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return ++element->_references; +} + +/** + * Remove reference from element. + * + * If reference count drops to 0 element will be freed. + */ +int +e_connman_element_unref(E_Connman_Element *element) +{ + int i; + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + + i = --element->_references; + if (i == 0) + e_connman_element_free(element); + else if (i < 0) + ERR("element %p references %d < 0", element, i); + return i; +} + +/** + * Send message with callbacks set to work with connman elements. + * + * If this call fails (returns 0), pending callbacks will not be called, + * not even with error messages. + * + * @return 1 on success, 0 on failure. + */ +bool +e_connman_element_message_send(E_Connman_Element *element, const char *method_name, E_DBus_Method_Return_Cb cb, DBusMessage *msg, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + E_Connman_Element_Call_Data *data; + E_Connman_Element_Pending *p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(msg, 0); + + data = malloc(sizeof(*data)); + if (!data) + { + ERR("could not alloc e_connman_element_call_data: %s", + strerror(errno)); + dbus_message_unref(msg); + return 0; + } + + p = malloc(sizeof(*p)); + if (!p) + { + ERR("could not alloc E_Connman_Element_Pending: %s", + strerror(errno)); + free(data); + dbus_message_unref(msg); + return 0; + } + + data->element = element; + data->cb = cb; + data->pending = p; + data->p_list = pending; + p->user_cb = user_cb; + p->user_data = (void *)user_data; + p->data = data; + p->pending = e_dbus_message_send + (e_connman_conn, msg, e_connman_element_call_dispatch_and_free, -1, data); + dbus_message_unref(msg); + + if (p->pending) + { + *pending = eina_inlist_append(*pending, EINA_INLIST_GET(p)); + return 1; + } + else + { + ERR("failed to call %s (obj=%s, path=%s, iface=%s)", + method_name, e_connman_system_bus_name_get(), + element->path, element->interface); + free(data); + free(p); + return 0; + } +} + +bool +e_connman_element_call_full(E_Connman_Element *element, const char *method_name, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + + msg = dbus_message_new_method_call + (e_connman_system_bus_name_get(), element->path, element->interface, + method_name); + + return e_connman_element_message_send + (element, method_name, cb, msg, pending, user_cb, user_data); +} + +static bool +_e_connman_element_property_value_add(E_Connman_Element *element, const char *name, int type, void *value) +{ + E_Connman_Element_Property *p; + + name = eina_stringshare_add(name); + EINA_INLIST_FOREACH(element->props, p) + { + if (p->name == name) + { + eina_stringshare_del(name); + return _e_connman_element_property_update(p, type, value); + } + } + + p = _e_connman_element_property_new(name, type, value); + if (!p) + { + ERR("could not create property %s (%c)", name, type); + return 0; + } + + element->props = eina_inlist_append(element->props, EINA_INLIST_GET(p)); + return 1; +} + +static E_Connman_Array * +_e_connman_element_iter_get_array(DBusMessageIter *itr, const char *key) +{ + E_Connman_Array *array; + DBusMessageIter e_itr; + + array = malloc(sizeof(E_Connman_Array)); + if (!array) + { + ERR("could not create new e_connman array."); + return NULL; + } + array->array = eina_array_new(16); + if (!(array->array)) + { + ERR("could not create new eina array."); + free(array); + return NULL; + } + + dbus_message_iter_recurse(itr, &e_itr); + array->type = dbus_message_iter_get_arg_type(&e_itr); + if (array->type == DBUS_TYPE_INVALID) + { + DBG("array %s is of type 'invalid' (empty?)", key); + eina_array_free(array->array); + free(array); + return NULL; + } + + do + { + switch (array->type) + { + case DBUS_TYPE_OBJECT_PATH: + { + const char *path; + + dbus_message_iter_get_basic(&e_itr, &path); + path = eina_stringshare_add(path); + eina_array_push(array->array, path); + _e_connman_element_item_register(key, path); + } + break; + case DBUS_TYPE_STRING: + { + const char *str; + + dbus_message_iter_get_basic(&e_itr, &str); + str = eina_stringshare_add(str); + eina_array_push(array->array, str); + } + break; + case DBUS_TYPE_BYTE: + { + unsigned char byte; + dbus_message_iter_get_basic(&e_itr, &byte); + eina_array_push(array->array, (void *)(long)byte); + } + break; + case DBUS_TYPE_DICT_ENTRY: + { + E_Connman_Element_Dict_Entry *entry; + entry = _e_connman_element_dict_entry_new(&e_itr); + if (entry) + eina_array_push(array->array, entry); + } + break; + default: + ERR("don't know how to build array '%s' of type %c (%d)", + key, array->type, array->type); + eina_array_free(array->array); + free(array); + return NULL; + } + } + while (dbus_message_iter_next(&e_itr)); + return array; +} + +static void +_e_connman_element_get_properties_callback(void *user_data, DBusMessage *msg, DBusError *err) +{ + E_Connman_Element *element = user_data; + DBusMessageIter itr, s_itr; + int t, changed; + + DBG("get_properties msg=%p", msg); + + if (!_dbus_callback_check_and_init(msg, &itr, err)) + return; + + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_ARRAY)) + return; + + changed = 0; + dbus_message_iter_recurse(&itr, &s_itr); + do + { + DBusMessageIter e_itr, v_itr; + const char *key; + void *value = NULL; + int r; + + t = dbus_message_iter_get_arg_type(&s_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_DICT_ENTRY)) + continue; + + dbus_message_iter_recurse(&s_itr, &e_itr); + + t = dbus_message_iter_get_arg_type(&e_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING)) + continue; + + dbus_message_iter_get_basic(&e_itr, &key); + dbus_message_iter_next(&e_itr); + t = dbus_message_iter_get_arg_type(&e_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_VARIANT)) + continue; + + dbus_message_iter_recurse(&e_itr, &v_itr); + t = dbus_message_iter_get_arg_type(&v_itr); + if (t == DBUS_TYPE_ARRAY) + value = _e_connman_element_iter_get_array(&v_itr, key); + else if (t != DBUS_TYPE_INVALID) { + dbus_message_iter_get_basic(&v_itr, &value); + } else { + ERR("property has invalid type %s", key); + continue; + } + + r = _e_connman_element_property_value_add(element, key, t, value); + if (r < 0) + ERR("failed to add property value %s (%c)", key, t); + else if (r == 1) + { + INF("property value changed %s (%c)", key, t); + changed = 1; + } + } + while (dbus_message_iter_next(&s_itr)); + + if (changed) + _e_connman_element_listeners_call(element); +} + +/** + * Sync element properties with server. + * + * Call method GetProperties() at the given element on server in order to sync + * them. + * + * @param element to call method on server. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_element_sync_properties_full(E_Connman_Element *element, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "GetProperties"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return e_connman_element_call_full + (element, name, _e_connman_element_get_properties_callback, + &element->_pending.properties_get, cb, data); +} + +/** + * Sync element properties with server, simple version. + * + * Call method GetProperties() at the given element on server in order to sync + * them. This is the simple version and there is no check of server reply + * for errors. + * + * @param element to call method on server. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_element_properties_sync(E_Connman_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return e_connman_element_sync_properties_full(element, NULL, NULL); +} + +/** + * Call method SetProperty(prop, {key: value}) at the given element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_CONNMAN_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * @param element to call method on server. + * @param prop property name. + * @param key dict key name. + * @param type DBus type to use for value. + * @param value pointer to value, just like regular DBus, see + * dbus_message_iter_append_basic(). + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_element_property_dict_set_full(E_Connman_Element *element, const char *prop, const char *key, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "SetProperty"; + DBusMessage *msg; + DBusMessageIter itr, variant, dict, entry; + char typestr[32]; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(prop, 0); + + msg = dbus_message_new_method_call + (e_connman_system_bus_name_get(), element->path, element->interface, name); + + if (!msg) + return 0; + + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &prop); + + if ((size_t)snprintf(typestr, sizeof(typestr), + (DBUS_TYPE_ARRAY_AS_STRING + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + "%c" + DBUS_DICT_ENTRY_END_CHAR_AS_STRING), + type) >= sizeof(typestr)) + { + ERR("sizeof(typestr) is too small!"); + return 0; + } + + dbus_message_iter_open_container(&itr, DBUS_TYPE_VARIANT, typestr, &variant); + + snprintf(typestr, sizeof(typestr), + (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + "%c" + DBUS_DICT_ENTRY_END_CHAR_AS_STRING), + type); + + dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY, typestr, &dict); + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry); + + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); + + if ((type == DBUS_TYPE_STRING) || (type == DBUS_TYPE_OBJECT_PATH)) + dbus_message_iter_append_basic(&entry, type, &value); + else + dbus_message_iter_append_basic(&entry, type, value); + + dbus_message_iter_close_container(&dict, &entry); + dbus_message_iter_close_container(&variant, &dict); + dbus_message_iter_close_container(&itr, &variant); + + return e_connman_element_message_send + (element, name, NULL, msg, &element->_pending.property_set, cb, data); +} + +/** + * Call method SetProperty(prop, value) at the given element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_CONNMAN_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * @param element to call method on server. + * @param prop property name. + * @param type DBus type to use for value. + * @param value pointer to value, just like regular DBus, see + * dbus_message_iter_append_basic(). + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_element_property_set_full(E_Connman_Element *element, const char *prop, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "SetProperty"; + char typestr[2]; + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(prop, 0); + + msg = dbus_message_new_method_call + (e_connman_system_bus_name_get(), element->path, element->interface, name); + + if (!msg) + return 0; + + DBusMessageIter itr, v; + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &prop); + + typestr[0] = type; + typestr[1] = '\0'; + dbus_message_iter_open_container(&itr, DBUS_TYPE_VARIANT, typestr, &v); + if ((type == DBUS_TYPE_STRING) || (type == DBUS_TYPE_OBJECT_PATH)) + dbus_message_iter_append_basic(&v, type, &value); + else if (type == DBUS_TYPE_BOOLEAN) + { + unsigned int b = *(char *)value; + dbus_message_iter_append_basic(&v, type, &b); + } + else + dbus_message_iter_append_basic(&v, type, value); + dbus_message_iter_close_container(&itr, &v); + + return e_connman_element_message_send + (element, name, NULL, msg, &element->_pending.property_set, cb, data); +} + +/** + * Call method SetProperty(prop, value) at the given element on server. + * + * This is the simple version and there is no check of server reply + * for errors. + * + * @param element to call method on server. + * @param prop property name. + * @param type DBus type to use for value. + * @param value pointer to value, just like regular DBus, see + * dbus_message_iter_append_basic(). + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_element_property_set(E_Connman_Element *element, const char *prop, int type, const void *value) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(prop, 0); + return e_connman_element_property_set_full + (element, prop, type, value, NULL, NULL); +} + +bool +e_connman_element_call_with_path(E_Connman_Element *element, const char *method_name, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + DBusMessageIter itr; + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(string, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + + msg = dbus_message_new_method_call + (e_connman_system_bus_name_get(), element->path, element->interface, + method_name); + + if (!msg) + return 0; + + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_OBJECT_PATH, &string); + + return e_connman_element_message_send + (element, method_name, cb, msg, pending, user_cb, user_data); +} + +bool +e_connman_element_call_with_string(E_Connman_Element *element, const char *method_name, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + DBusMessageIter itr; + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(string, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + + msg = dbus_message_new_method_call + (e_connman_system_bus_name_get(), element->path, element->interface, + method_name); + + if (!msg) + return 0; + + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &string); + + return e_connman_element_message_send + (element, method_name, cb, msg, pending, user_cb, user_data); +} + +/** + * Get property type. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param name property name, must be previously stringshared + * @param type will contain the value type. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_element_property_type_get_stringshared(const E_Connman_Element *element, const char *name, int *type) +{ + const E_Connman_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(type, 0); + + EINA_INLIST_FOREACH(element->props, p) + { + if (p->name == name) + { + *type = p->type; + return 1; + } + } + + WRN("element %s (%p) has no property with name \"%s\".", + element->path, element, name); + return 0; +} + +/** + * Get property type. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param name property name + * @param type will contain the value type. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_element_property_type_get(const E_Connman_Element *element, const char *name, int *type) +{ + bool ret; + name = eina_stringshare_add(name); + ret = e_connman_element_property_type_get_stringshared(element, name, type); + eina_stringshare_del(name); + return ret; +} + +void +e_connman_element_list_properties(const E_Connman_Element *element, bool (*cb)(void *data, const E_Connman_Element *element, const char *name, int type, const void *value), const void *data) +{ + const E_Connman_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN(element); + EINA_SAFETY_ON_NULL_RETURN(cb); + + EINA_INLIST_FOREACH(element->props, p) + { + const void *value = NULL; + + switch (p->type) + { + case DBUS_TYPE_STRING: + value = &p->value.str; + break; + case DBUS_TYPE_OBJECT_PATH: + value = &p->value.path; + break; + case DBUS_TYPE_BOOLEAN: + value = (void *)p->value.boolean; + break; + case DBUS_TYPE_UINT16: + value = &p->value.u16; + break; + case DBUS_TYPE_UINT32: + value = &p->value.u32; + break; + default: + ERR("unsupported type %c", p->type); + } + + if (!cb((void *)data, element, p->name, p->type, value)) + return; + } +} + +/** + * Get dict value given its key inside a dict property. + * + * This will look into properties for one of type dict that contains + * the given key, to find the property. If no property is found then + * 0 is returned. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param dict_name property name, must be previously stringshared + * @param key key inside dict, must be previously stringshared + * @param type if provided it will contain the value type. + * @param value where to store the property value, must be a pointer to the + * exact type, (bool *) for booleans, (char **) for strings, and so on. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_element_property_dict_get_stringshared(const E_Connman_Element *element, const char *dict_name, const char *key, int *type, void *value) +{ + const E_Connman_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(dict_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(key, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(value, 0); + + EINA_INLIST_FOREACH(element->props, p) + { + E_Connman_Element_Dict_Entry *entry; + E_Connman_Array *array; + + if (p->name != dict_name) + continue; + if (p->type != DBUS_TYPE_ARRAY) + { + WRN("element %s (%p) has property \"%s\" is not an array: %c (%d)", + element->path, element, dict_name, p->type, p->type); + return 0; + } + array = p->value.array; + if ((!array) || (array->type != DBUS_TYPE_DICT_ENTRY)) + { + int t = array ? array->type : DBUS_TYPE_INVALID; + WRN("element %s (%p) has property \"%s\" is not a dict: %c (%d)", + element->path, element, dict_name, t, t); + return 0; + } + entry = _e_connman_element_array_dict_find_stringshared(array, key); + if (!entry) + { + WRN("element %s (%p) has no dict property with name \"%s\" with " + "key \"%s\".", + element->path, element, dict_name, key); + return 0; + } + + if (type) *type = entry->type; + + switch (entry->type) + { + case DBUS_TYPE_BOOLEAN: + *(bool *)value = entry->value.boolean; + return 1; + case DBUS_TYPE_BYTE: + *(unsigned char *)value = entry->value.byte; + return 1; + case DBUS_TYPE_UINT16: + *(unsigned short *)value = entry->value.u16; + return 1; + case DBUS_TYPE_UINT32: + *(unsigned int *)value = entry->value.u32; + return 1; + case DBUS_TYPE_STRING: + *(const char **)value = entry->value.str; + return 1; + case DBUS_TYPE_OBJECT_PATH: + *(const char **)value = entry->value.path; + return 1; + default: + ERR("don't know how to get property %s, key %s type %c (%d)", + dict_name, key, entry->type, entry->type); + return 0; + } + } + + WRN("element %s (%p) has no property with name \"%s\".", + element->path, element, dict_name); + return 0; +} + +/** + * Get property value given its name. + * + * This will look into properties, to find the property. + * If no property is found then 0 is returned. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param name property name, must be previously stringshared + * @param type if provided it will contain the value type. + * @param value where to store the property value, must be a pointer to the + * exact type, (bool *) for booleans, (char **) for strings, and so on. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_element_property_get_stringshared(const E_Connman_Element *element, const char *name, int *type, void *value) +{ + const E_Connman_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(value, 0); + + EINA_INLIST_FOREACH(element->props, p) + { + if (p->name != name) + continue; + + if (type) *type = p->type; + + switch (p->type) + { + case DBUS_TYPE_BOOLEAN: + *(bool *)value = p->value.boolean; + return 1; + case DBUS_TYPE_BYTE: + *(unsigned char *)value = p->value.byte; + return 1; + case DBUS_TYPE_UINT16: + *(unsigned short *)value = p->value.u16; + return 1; + case DBUS_TYPE_UINT32: + *(unsigned int *)value = p->value.u32; + return 1; + case DBUS_TYPE_STRING: + *(const char **)value = p->value.str; + return 1; + case DBUS_TYPE_OBJECT_PATH: + *(const char **)value = p->value.path; + return 1; + case DBUS_TYPE_ARRAY: + *(E_Connman_Array **)value = p->value.array; + return 1; + default: + ERR("don't know how to get property type %c (%d)", + p->type, p->type); + return 0; + } + } + + WRN("element %s (%p) has no property with name \"%s\".", + element->path, element, name); + return 0; +} + +/** + * Get property value given its name. + * + * This will look into properties, to find the property. + * If no property is found then 0 is returned. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param name property name + * @param type if provided it will contain the value type. + * @param value where to store the property value, must be a pointer to the + * exact type, (bool *) for booleans, (char **) for strings, and so on. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_element_property_get(const E_Connman_Element *element, const char *name, int *type, void *value) +{ + bool ret; + name = eina_stringshare_add(name); + ret = e_connman_element_property_get_stringshared + (element, name, type, value); + eina_stringshare_del(name); + return ret; +} + + +struct e_connman_elements_for_each_data +{ + Eina_Hash_Foreach cb; + void *data; +}; + +Eina_Bool +_e_connman_elements_for_each(Eina_Hash *hash __UNUSED__, const char *key, void *data, void *fdata) +{ + struct e_connman_elements_for_each_data *each_data = fdata; + + each_data->cb(elements, key, data, each_data->data); + return 1; +} + +/** + * Call the given function for each existing element. + * + * @param cb function to call for each element. It will get as parameters, + * in order: the element pointer and the given @a user_data. + * @param user_data data to give to @a cb for each element. + */ +void +e_connman_elements_for_each(Eina_Hash_Foreach cb, const void *user_data) +{ + struct e_connman_elements_for_each_data data = {cb, (void *)user_data}; + + EINA_SAFETY_ON_NULL_RETURN(cb); + + eina_hash_foreach(elements, (Eina_Hash_Foreach) _e_connman_elements_for_each, + &data); +} + +static bool +_e_connman_elements_get_allocate(unsigned int *count, E_Connman_Element ***p_elements) +{ + *count = eina_hash_population(elements); + if (*count == 0) + { + *p_elements = NULL; + return 1; + } + + *p_elements = malloc(*count * sizeof(E_Connman_Element *)); + if (!*p_elements) + { + ERR("could not allocate return array of %d elements: %s", + *count, strerror(errno)); + *count = 0; + return 0; + } + return 1; +} + +Eina_Bool +_e_connman_elements_get_all(Eina_Hash *hash __UNUSED__, const char *key __UNUSED__, void *data, void *fdata) +{ + E_Connman_Element *element = data; + E_Connman_Element ***p_ret = fdata; + + **p_ret = element; + (*p_ret)++; + return 1; +} + +/** + * Get all known elements. + * + * No reference is added to these elements, since there are no threads + * in the system, you are free to add references yourself right after + * the return of this call without race condition, elements by the + * system (ie: elementRemoved signal)could only be touched on the next + * main loop iteration. + * + * @param count return the number of elements in array. + * @param p_elements array with all elements, these are not referenced + * and in no particular order, just set if return is 1. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_elements_get_all(unsigned int *count, E_Connman_Element ***p_elements) +{ + E_Connman_Element **p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(p_elements, 0); + + if (!_e_connman_elements_get_allocate(count, p_elements)) + return 0; + p = *p_elements; + eina_hash_foreach(elements, (Eina_Hash_Foreach) _e_connman_elements_get_all, + &p); + return 1; +} + +struct e_connman_elements_get_all_str_data +{ + E_Connman_Element **elements; + int count; + const char *str; +}; + +Eina_Bool +_e_connman_elements_get_all_type(Eina_Hash *hash __UNUSED__, const char *key __UNUSED__, void *e, void *user_data) +{ + struct e_connman_elements_get_all_str_data *data = user_data; + E_Connman_Element *element = e; + + if ((data->str) && (element->interface != data->str)) + return 1; + + data->elements[data->count] = element; + data->count++; + return 1; +} + +/** + * Get all known elements of type. + * + * No reference is added to these elements, since there are no threads + * in the system, you are free to add references yourself right after + * the return of this call without race condition, elements by the + * system (ie: ElementRemoved signal) could only be touched on the next + * main loop iteration. + * + * @param type type to filter, or NULL to get all. + * @param count return the number of elements in array. + * @param p_elements array with all elements, these are not referenced + * and in no particular order, just set if return is 1. + * + * @return 1 on success, 0 otherwise. + * + * @see e_connman_elements_get_all() + */ +bool +e_connman_elements_get_all_type(const char *type, unsigned int *count, E_Connman_Element ***p_elements) +{ + struct e_connman_elements_get_all_str_data data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(p_elements, 0); + + if (!_e_connman_elements_get_allocate(count, p_elements)) + return 0; + + data.elements = *p_elements; + data.count = 0; + data.str = eina_stringshare_add(type); + eina_hash_foreach(elements, + (Eina_Hash_Foreach) _e_connman_elements_get_all_type, + &data); + + eina_stringshare_del(data.str); + *count = data.count; + return 1; +} + +/** + * Get the element registered at given path. + * + * @param path the path to query for registered object. + * + * @return element pointer if found, NULL otherwise. No references are added. + */ +E_Connman_Element * +e_connman_element_get(const char *path) +{ + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); + element = eina_hash_find(elements, path); + + return element; +} + +static void +_e_connman_element_property_changed_callback(void *data, DBusMessage *msg) +{ + E_Connman_Element *element = (E_Connman_Element *)data; + DBusMessageIter itr, v_itr; + int t, r, changed = 0; + const char *name = NULL; + void *value = NULL; + + DBG("Property changed in element %s", element->path); + + if (!_dbus_callback_check_and_init(msg, &itr, NULL)) + return; + + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING)) + { + ERR("missing name in property changed signal"); + return; + } + dbus_message_iter_get_basic(&itr, &name); + + dbus_message_iter_next(&itr); + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_VARIANT)) + { + ERR("missing value in property changed signal"); + return; + } + dbus_message_iter_recurse(&itr, &v_itr); + t = dbus_message_iter_get_arg_type(&v_itr); + + if (t == DBUS_TYPE_ARRAY) + value = _e_connman_element_iter_get_array(&v_itr, name); + else if (t != DBUS_TYPE_INVALID) + dbus_message_iter_get_basic(&v_itr, &value); + else + { + ERR("property has invalid type %s", name); + return; + } + + r = _e_connman_element_property_value_add(element, name, t, value); + if (r < 0) + ERR("failed to add property value %s (%c)", name, t); + else if (r == 1) + { + INF("property value changed %s (%c)", name, t); + changed = 1; + } + if (changed) + _e_connman_element_listeners_call(element); +} + +/** + * Register the given path, possible creating and element and return it. + * + * This will check if path is already registered, in that case the + * exiting element is returned. If it was not registered yet, a new + * element is created, registered and returned. + * + * This call will not add extra references to the object. + * + * @param path the path to register the element + * + * @return the registered object, no references are added. + */ +E_Connman_Element * +e_connman_element_register(const char *path, const char *interface) +{ + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(interface, NULL); + + element = eina_hash_find(elements, path); + if (element) + return element; + + element = e_connman_element_new(path, interface); + if (!element) + return NULL; + + if (!eina_hash_add(elements, element->path, element)) + { + ERR("could not add element %s to hash, delete it.", path); + e_connman_element_free(element); + return NULL; + } + + element->signal_handler = + e_dbus_signal_handler_add + (e_connman_conn, e_connman_system_bus_name_get(), + element->path, element->interface, "PropertyChanged", + _e_connman_element_property_changed_callback, element); + + e_connman_element_event_add(E_CONNMAN_EVENT_ELEMENT_ADD, element); + + return element; +} + +static void +_e_connman_element_event_unregister_and_free(void *data __UNUSED__, void *ev) +{ + E_Connman_Element *element = ev; + e_connman_element_unref(element); +} + +static void +_e_connman_element_unregister_internal(E_Connman_Element *element) +{ + if (element->signal_handler) + { + e_dbus_signal_handler_del(e_connman_conn, element->signal_handler); + element->signal_handler = NULL; + } + + ecore_event_add(E_CONNMAN_EVENT_ELEMENT_DEL, element, + _e_connman_element_event_unregister_and_free, NULL); +} + +/** + * Forget about the given element. + * + * This will remove the element from the pool of known objects, then + * add an E_CONNMAN_EVENT_ELEMENT_DEL and after that will unreference it, + * possible freeing it. + * + * @param element element to forget about. Its reference will be removed. + */ +void +e_connman_element_unregister(E_Connman_Element *element) +{ + if (!element) + return; + + if (elements) + eina_hash_del_by_key(elements, element->path); +} + +/** + * Remove all known elements. + * + * This will remove all known elements but will NOT add any + * E_CONNMAN_EVENT_ELEMENT_DEL to main loop. + * + * This is just useful to make sure next e_connman_manager_sync_elements() + * will not leave any stale elements. This is unlikely to happen, as + * E_Connman is supposed to catch all required events to avoid stale elements. + */ +void +e_connman_manager_clear_elements(void) +{ + e_connman_elements_shutdown(); + e_connman_elements_init(); +} + +/** + * Creates elements hash. + * + * This has no init counter since its already guarded by other code. + * @internal + */ +void +e_connman_elements_init(void) +{ + EINA_SAFETY_ON_FALSE_RETURN(elements == NULL); + elements = + eina_hash_string_superfast_new(EINA_FREE_CB + (_e_connman_element_unregister_internal)); +} + +void +e_connman_elements_shutdown(void) +{ + EINA_SAFETY_ON_FALSE_RETURN(elements != NULL); + eina_hash_free(elements); + elements = NULL; +} + +static inline bool +_e_connman_element_is(const E_Connman_Element *element, const char *interface) +{ + return element->interface == interface; +} + +bool +e_connman_element_is_manager(const E_Connman_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return _e_connman_element_is(element, e_connman_iface_manager); +} + +bool +e_connman_element_is_device(const E_Connman_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return _e_connman_element_is(element, e_connman_iface_device); +} + +bool +e_connman_element_is_profile(const E_Connman_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return _e_connman_element_is(element, e_connman_iface_profile); +} + +bool +e_connman_element_is_network(const E_Connman_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return _e_connman_element_is(element, e_connman_iface_network); +} + +bool +e_connman_element_is_service(const E_Connman_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return _e_connman_element_is(element, e_connman_iface_service); +} + +bool +e_connman_element_is_technology(const E_Connman_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return _e_connman_element_is(element, e_connman_iface_technology); +} diff --git a/src/lib/connman/e_connman_manager.c b/src/lib/connman/e_connman_manager.c new file mode 100644 index 0000000..679d8eb --- /dev/null +++ b/src/lib/connman/e_connman_manager.c @@ -0,0 +1,581 @@ +#include "e_connman_private.h" + +/** + * Get the element manager. + * + * @return element pointer if found, NULL otherwise. + */ +E_Connman_Element * +e_connman_manager_get(void) +{ + return e_connman_element_get(manager_path); +} + +/** + * Register new agent for handling user requests. + * + * Call method RegisterAgent(object) on server in order to + * register new agent for handling user requests. + * + * @param object_path object to be registered. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_agent_register(const char *object_path, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "RegisterAgent"; + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(object_path, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + + return e_connman_element_call_with_path + (element, name, object_path, NULL, + &element->_pending.agent_register, cb, data); +} + +/** + * Unregister an existing agent. + * + * Call method UnregisterAgent(object) on server in order to + * unregister an existing agent. + * + * @param object_path agent to be unregistered. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_agent_unregister(const char *object_path, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "UnregisterAgent"; + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(object_path, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + + return e_connman_element_call_with_path + (element, name, object_path, NULL, + &element->_pending.agent_unregister, cb, data); +} + +/** + * Get property "State" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The global connection state of a system. Possible + * values are "online" if at least one connection exists + * and "offline" if no device is connected. + * + * In certain situations the state might change to + * the value "connected". This can only be seen if + * previously no connection was present. + * + * @param state where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_state_get(const char **state) +{ + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(state, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + return e_connman_element_property_get_stringshared + (element, e_connman_prop_state, NULL, state); +} + +/** + * Get property "OfflineMode" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The offline mode indicates the global setting for + * switching all radios on or off. Changing offline mode + * to true results in powering down all devices. When + * leaving offline mode the individual policy of each + * device decides to switch the radio back on or not. + * + * During offline mode, it is still possible to switch + * certain technologies manually back on. For example + * the limited usage of WiFi or Bluetooth devices might + * be allowed in some situations. + * + * @param offline where to store the property value, must be a pointer + * to booleans (bool *). + * + * @return 1 on success, 0 otherwise. + * @see e_connman_manager_offline_mode_set() + */ +bool +e_connman_manager_offline_mode_get(bool *offline) +{ + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(offline, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + return e_connman_element_property_get_stringshared + (element, e_connman_prop_offline_mode, NULL, offline); +} + +/** + * Call method SetProperty("OfflineMode", offline) at the given element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_CONNMAN_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * The offline mode indicates the global setting for + * switching all radios on or off. Changing offline mode + * to true results in powering down all devices. When + * leaving offline mode the individual policy of each + * device decides to switch the radio back on or not. + * + * During offline mode, it is still possible to switch + * certain technologies manually back on. For example + * the limited usage of WiFi or Bluetooth devices might + * be allowed in some situations. + * + * @param offline value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + * @see e_connman_manager_offline_mode_get() + */ +bool +e_connman_manager_offline_mode_set(bool offline, E_DBus_Method_Return_Cb cb, const void *data) +{ + E_Connman_Element *element = e_connman_manager_get(); + if (!element) + return 0; + return e_connman_element_property_set_full + (element, e_connman_prop_offline_mode, DBUS_TYPE_BOOLEAN, + &offline, cb, data); +} + +/** + * Get array of profile elements. + * + * @param count return the number of elements in array. + * @param p_elements array with all elements, these are not referenced + * and in no particular order, just set if return is 1. The + * array itself is allocated using malloc() and should be freed + * after usage is done. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_profiles_get(unsigned int *count, E_Connman_Element ***p_elements) +{ + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(p_elements, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + return e_connman_element_objects_array_get_stringshared + (element, e_connman_prop_profiles, count, p_elements); +} + +/** + * Get array of services elements. + * + * List of service object paths. The list is sorted + * internally to have the service with the default + * route always first and then the favorite services + * followed by scan results. + * + * This list represents the available services for the + * current selected profile. If the profile gets changed + * then this list will be updated. + * + * The same list is available via the profile object + * itself. It is just provided here for convenience of + * applications only dealing with the current active + * profile. + * + * @param count return the number of elements in array. + * @param p_elements array with all elements, these are not referenced + * and in no particular order, just set if return is 1. The + * array itself is allocated using malloc() and should be freed + * after usage is done. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_services_get(unsigned int *count, E_Connman_Element ***p_elements) +{ + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(p_elements, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + return e_connman_element_objects_array_get_stringshared + (element, e_connman_prop_services, count, p_elements); +} + +/** + * Get array of technology elements. + * + * @param count return the number of elements in array. + * @param p_elements array with all elements, these are not referenced + * and in no particular order, just set if return is 1. The + * array itself is allocated using malloc() and should be freed + * after usage is done. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_technologies_get(unsigned int *count, E_Connman_Element ***p_elements) +{ + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(p_elements, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + return e_connman_element_objects_array_get_stringshared + (element, e_connman_prop_technologies, count, p_elements); +} + +/** + * Request to trigger a scan for given technology. + * + * Call method RequestScan(type) on server in order to + * find new services and networks for such technology type. + * + * The empty string for type means all technolgies. + * + * @param type technology type to scan. Empty or NULL for all technologies. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_request_scan(const char *type, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "RequestScan"; + E_Connman_Element *element; + + if (!type) + type = ""; + + element = e_connman_manager_get(); + if (!element) + return 0; + + return e_connman_element_call_with_string + (element, name, type, NULL, + &element->_pending.request_scan, cb, data); +} + +/** + * Enable specified type of technology. + * + * Call method EnableTechnology(type) on server. + * + * @param type technology type to enable. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_technology_enable(const char *type, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "EnableTechnology"; + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(type, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + + return e_connman_element_call_with_string + (element, name, type, NULL, + &element->_pending.technology_enable, cb, data); +} + +/** + * Disable specified type of technology. + * + * Call method DisableTechnology(type) on server. + * + * @param type technology type to disable. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_technology_disable(const char *type, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "DisableTechnology"; + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(type, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + + return e_connman_element_call_with_string + (element, name, type, NULL, + &element->_pending.technology_disable, cb, data); +} + +/** + * Get property "DefaultTechnology" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The current connected technology which holds the default route. + * + * @param type where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_technology_default_get(const char **type) +{ + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(type, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + return e_connman_element_property_get_stringshared + (element, e_connman_prop_technology_default, NULL, type); +} + +/** + * Remove specified profile. + * + * Call method RemoveProfile(profile) on server. + * + * It is not possible to remove the current active profile. To remove + * the active profile a different one must be selected via + * ActiveProfile property first. + * + * At minimum one profile must be available all the time. + * + * @param profile element to remove, must be of type profile. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_profile_remove(const E_Connman_Element *profile, E_DBus_Method_Return_Cb cb, const void *data) +{ + E_Connman_Element *element; + const char name[] = "RemoveProfile"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(profile, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(profile->path, 0); + + if (!e_connman_element_is_profile(profile)) + return 0; + + element = e_connman_manager_get(); + if (!element) + return 0; + + return e_connman_element_call_with_path + (element, name, profile->path, NULL, + &element->_pending.profile_remove, cb, data); +} + +/** + * Get property "ActiveProfile" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element where to store the element, just changed if return is 1 + * + * @return 1 on success, 0 otherwise. + * + * @see e_connman_manager_profile_active_set() + */ +bool +e_connman_manager_profile_active_get(E_Connman_Element **profile) +{ + E_Connman_Element *element; + char *profile_path; + + EINA_SAFETY_ON_NULL_RETURN_VAL(profile, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + if (!e_connman_element_property_get_stringshared + (element, e_connman_prop_profile_active, NULL, &profile_path)) + return 0; + *profile = e_connman_element_get(profile_path); + return 1; +} + +/** + * Call method SetProperty("ActiveProfile", profile) at the given + * element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_CONNMAN_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * @param profile object to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + * @see e_connman_manager_profile_active_get() + */ +bool +e_connman_manager_profile_active_set(const E_Connman_Element *profile, E_DBus_Method_Return_Cb cb, const void *data) +{ + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(profile, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(profile->path, 0); + + if (!e_connman_element_is_profile(profile)) + return 0; + + element = e_connman_manager_get(); + if (!element) + return 0; + return e_connman_element_property_set_full + (element, e_connman_prop_profile_active, DBUS_TYPE_OBJECT_PATH, + profile->path, cb, data); +} + + +/** + * Get array of strings representing the available technologies. + * + * @param count return the number of elements in array. + * @param p_strings array with pointers to internal strings. These + * strings are not copied in any way, and they are granted to + * be eina_stringshare instances, so one can use + * eina_stringshare_ref() if he wants to save memory and cpu to + * get an extra reference. The array itself is allocated using + * malloc() and should be freed after usage is done. This + * pointer is just set if return is 1. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_technologies_available_get(unsigned int *count, const char ***p_strings) +{ + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(p_strings, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + return e_connman_element_strings_array_get_stringshared + (element, e_connman_prop_technologies_available, count, p_strings); +} + +/** + * Get array of strings representing the enabled technologies. + * + * @param count return the number of elements in array. + * @param p_strings array with pointers to internal strings. These + * strings are not copied in any way, and they are granted to + * be eina_stringshare instances, so one can use + * eina_stringshare_ref() if he wants to save memory and cpu to + * get an extra reference. The array itself is allocated using + * malloc() and should be freed after usage is done. This + * pointer is just set if return is 1. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_technologies_enabled_get(unsigned int *count, const char ***p_strings) +{ + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(p_strings, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + return e_connman_element_strings_array_get_stringshared + (element, e_connman_prop_technologies_enabled, count, p_strings); +} + +/** + * Get array of strings representing the connected technologies. + * + * @param count return the number of elements in array. + * @param p_strings array with pointers to internal strings. These + * strings are not copied in any way, and they are granted to + * be eina_stringshare instances, so one can use + * eina_stringshare_ref() if he wants to save memory and cpu to + * get an extra reference. The array itself is allocated using + * malloc() and should be freed after usage is done. This + * pointer is just set if return is 1. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_manager_technologies_connected_get(unsigned int *count, const char ***p_strings) +{ + E_Connman_Element *element; + + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(p_strings, 0); + + element = e_connman_manager_get(); + if (!element) + return 0; + return e_connman_element_strings_array_get_stringshared + (element, e_connman_prop_technologies_connected, count, p_strings); +} diff --git a/src/lib/connman/e_connman_network.c b/src/lib/connman/e_connman_network.c new file mode 100644 index 0000000..6e8c87d --- /dev/null +++ b/src/lib/connman/e_connman_network.c @@ -0,0 +1,355 @@ +#include "e_connman_private.h" + +E_Connman_Element * +e_connman_network_get(const char *path) +{ + E_Connman_Element *network; + + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); + + network = e_connman_element_get(path); + if (!network) + return NULL; + + if (!e_connman_element_is_network(network)) + { + WRN("path '%s' is not a network!", path); + return NULL; + } + + return network; +} + +/** + * Get property "Address" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The network hardware address (mac-address for ethernet, wifi...). + * + * This address can be used for directly displaying it in + * the application. It has pure informational purpose. + * + * @param network path to get property. + * @param address where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_network_address_get(const E_Connman_Element *network, const char **address) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(network, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(address, 0); + return e_connman_element_property_get_stringshared + (network, e_connman_prop_address, NULL, address); +} + +/** + * Get property "Name" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The pretty/long version of the network name. For + * example in case of WiFi this should be the UTF-8 + * valid version of the SSID. + * + * @param network path to get property. + * @param name where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_network_name_get(const E_Connman_Element *network, const char **name) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(network, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + return e_connman_element_property_get_stringshared + (network, e_connman_prop_name, NULL, name); +} + +/** + * Get property "Connected" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * Indicates that this network is currently connected. + * + * @param network path to get property. + * @param connected where to store the property value, must be a pointer + * to boolean (bool **). + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_network_connected_get(const E_Connman_Element *network, bool *connected) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(network, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(connected, 0); + return e_connman_element_property_get_stringshared + (network, e_connman_prop_connected, NULL, connected); +} + +/** + * Get property "Strength" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * Indicates the signal strength of the network. This + * is a normalized value between 0 and 100. + * + * @param network path to get property. + * @param strength where to store the property value, must be a pointer + * to byte (unsigned char*). + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_network_strength_get(const E_Connman_Element *network, unsigned char *strength) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(network, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(strength, 0); + return e_connman_element_property_get_stringshared + (network, e_connman_prop_strength, NULL, strength); +} + +/** + * Get property "Frequency" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * Indicates the frequency of the network. + * + * @param network path to get property. + * @param frequency where to store the property value, must be a pointer + * to uint16 (unsigned short*). + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_network_frequency_get(const E_Connman_Element *network, unsigned short *frequency) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(network, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(frequency, 0); + return e_connman_element_property_get_stringshared + (network, e_connman_prop_frequency, NULL, frequency); +} + +/** + * Get the device element this network + * belongs to. + * + * @param network path to get property. + * @param element where to store element, just changed if return is 1 + * + * @return 1 on success, 0 otherwise + */ +bool +e_connman_network_device_get(const E_Connman_Element *network, E_Connman_Element **element) +{ + char *device_path; + + EINA_SAFETY_ON_NULL_RETURN_VAL(network, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + + if (!e_connman_element_property_get_stringshared + (network, e_connman_prop_device, NULL, &device_path)) + return 0; + *element = e_connman_element_get(device_path); + return 1; +} + +/** + * Get property "WiFi.SSID" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the network type is WiFi, then this property is + * present and contains the binary SSID value. + * + * @param network path to get property. + * @param count return the number of elements in array. + * @param wifi_ssid where to store the property value, must be a pointer + * to array of bytes (unsigned char **). + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_network_wifi_ssid_get(const E_Connman_Element *network, unsigned int *count, unsigned char **wifi_ssid) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(network, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(wifi_ssid, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + *wifi_ssid = e_connman_element_bytes_array_get_stringshared + (network, e_connman_prop_wifi_ssid, count); + if (!*wifi_ssid) + return 0; + return 1; +} + +/** + * Get property "WiFi.Mode" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the network type is WiFi, then this property is + * present and contains the mode of the network. The + * possible values are "managed" or "adhoc". + * + * For scanned networks this value is read only, but in + * case the network was manually created it is also + * changeable. + * + * @param network path to get property. + * @param wifi_mode where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_network_wifi_mode_get(const E_Connman_Element *network, const char **wifi_mode) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(network, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(wifi_mode, 0); + return e_connman_element_property_get_stringshared + (network, e_connman_prop_wifi_mode, NULL, wifi_mode); +} + +/** + * Get property "WiFi.Security" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the network type is WiFi, then this property is + * present and contains the security method or key + * management setting. + * + * For scanned networks this value is read only, but in + * case the network was manually created it is also + * changeable. + * + * Possible values are "none", "wep", "wpa" and "wpa2". + * + * @param network path to get property. + * @param wifi_security where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_network_wifi_security_get(const E_Connman_Element *network, const char **wifi_security) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(network, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(wifi_security, 0); + return e_connman_element_property_get_stringshared + (network, e_connman_prop_wifi_security, NULL, wifi_security); +} + +/** + * Get property "WiFi.Passphrase" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the network type is WiFi and a passhrase is + * requires, then this property is present and contains + * the passphrase in clear text. + * + * For systems using PolicyKit, the access to this value + * will be protected by the security policy. + * + * @param network path to get property. + * @param wifi_passphrase where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_network_wifi_passphrase_get(const E_Connman_Element *network, const char **wifi_passphrase) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(network, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(wifi_passphrase, 0); + return e_connman_element_property_get_stringshared + (network, e_connman_prop_wifi_passphrase, NULL, wifi_passphrase); +} + +/** + * Get property "WiFi.Channel" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * Indicates the channel this network is. + * + * @param network path to get property. + * @param channel where to store the property value, must be a pointer + * to uint16 (unsigned short*). + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_network_wifi_channel_get(const E_Connman_Element *network, unsigned short *wifi_channel) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(network, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(wifi_channel, 0); + return e_connman_element_property_get_stringshared + (network, e_connman_prop_wifi_channel, NULL, wifi_channel); +} + +/** + * Get property "WiFi.EAP" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * This property is only available if WiFi.Security is "ieee8021x". + * + * For systems using PolicyKit, the access to this value + * will be protected by the security policy. + * + * @param network path to get property. + * @param wifi_eap where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_network_wifi_eap_get(const E_Connman_Element *network, const char **wifi_eap) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(network, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(wifi_eap, 0); + return e_connman_element_property_get_stringshared + (network, e_connman_prop_wifi_eap, NULL, wifi_eap); +} diff --git a/src/lib/connman/e_connman_private.h b/src/lib/connman/e_connman_private.h new file mode 100644 index 0000000..e313439 --- /dev/null +++ b/src/lib/connman/e_connman_private.h @@ -0,0 +1,180 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_ALLOCA_H +# include <alloca.h> +#elif defined __GNUC__ +# define alloca __builtin_alloca +#elif defined _AIX +# define alloca __alloca +#elif defined _MSC_VER +# include <malloc.h> +# define alloca _alloca +#else +# include <stddef.h> +# ifdef __cplusplus +extern "C" +# endif +void *alloca (size_t); +#endif + +#include <stdio.h> + +#include <Eina.h> +#include <eina_safety_checks.h> + +#include "E_Connman.h" + +static const char manager_path[] = "/"; + +extern const char *e_connman_iface_manager; +extern const char *e_connman_iface_network; +extern const char *e_connman_iface_profile; +extern const char *e_connman_iface_service; +extern const char *e_connman_iface_device; +extern const char *e_connman_iface_connection; +extern const char *e_connman_iface_technology; + +extern const char *e_connman_prop_available; +extern const char *e_connman_prop_connected; +extern const char *e_connman_prop_connections; +extern const char *e_connman_prop_default; +extern const char *e_connman_prop_device; +extern const char *e_connman_prop_devices; +extern const char *e_connman_prop_interface; +extern const char *e_connman_prop_ipv4; +extern const char *e_connman_prop_ipv4_configuration; +extern const char *e_connman_prop_ethernet; +extern const char *e_connman_prop_method; +extern const char *e_connman_prop_address; +extern const char *e_connman_prop_gateway; +extern const char *e_connman_prop_netmask; +extern const char *e_connman_prop_mtu; +extern const char *e_connman_prop_name; +extern const char *e_connman_prop_network; +extern const char *e_connman_prop_networks; +extern const char *e_connman_prop_offline_mode; +extern const char *e_connman_prop_policy; +extern const char *e_connman_prop_powered; +extern const char *e_connman_prop_priority; +extern const char *e_connman_prop_profiles; +extern const char *e_connman_prop_profile_active; +extern const char *e_connman_prop_services; +extern const char *e_connman_prop_technologies; +extern const char *e_connman_prop_remember; +extern const char *e_connman_prop_scan_interval; +extern const char *e_connman_prop_scanning; +extern const char *e_connman_prop_state; +extern const char *e_connman_prop_strength; +extern const char *e_connman_prop_frequency; +extern const char *e_connman_prop_type; +extern const char *e_connman_prop_wifi_mode; +extern const char *e_connman_prop_wifi_passphrase; +extern const char *e_connman_prop_wifi_security; +extern const char *e_connman_prop_wifi_ssid; +extern const char *e_connman_prop_wifi_channel; +extern const char *e_connman_prop_wifi_eap; +extern const char *e_connman_prop_error; +extern const char *e_connman_prop_mode; +extern const char *e_connman_prop_security; +extern const char *e_connman_prop_passphrase; +extern const char *e_connman_prop_passphrase_required; +extern const char *e_connman_prop_favorite; +extern const char *e_connman_prop_immutable; +extern const char *e_connman_prop_auto_connect; +extern const char *e_connman_prop_setup_required; +extern const char *e_connman_prop_apn; +extern const char *e_connman_prop_mcc; +extern const char *e_connman_prop_mnc; +extern const char *e_connman_prop_roaming; +extern const char *e_connman_prop_technology_default; +extern const char *e_connman_prop_technologies_available; +extern const char *e_connman_prop_technologies_enabled; +extern const char *e_connman_prop_technologies_connected; + +extern int _e_dbus_connman_log_dom; + +#ifndef EINA_LOG_DEFAULT_COLOR +#define EINA_LOG_DEFAULT_COLOR EINA_COLOR_CYAN +#endif + +#undef DBG +#undef INF +#undef WRN +#undef ERR + +#define DBG(...) EINA_LOG_DOM_DBG(_e_dbus_connman_log_dom , __VA_ARGS__) +#define INF(...) EINA_LOG_DOM_INFO(_e_dbus_connman_log_dom , __VA_ARGS__) +#define WRN(...) EINA_LOG_DOM_WARN(_e_dbus_connman_log_dom , __VA_ARGS__) +#define ERR(...) EINA_LOG_DOM_ERR(_e_dbus_connman_log_dom , __VA_ARGS__) + +static inline bool +__dbus_callback_check_and_init(const char *file, int line, const char *function, DBusMessage *msg, DBusMessageIter *itr, DBusError *err) +{ + if (!msg) + { + if (err) + eina_log_print(_e_dbus_connman_log_dom, EINA_LOG_LEVEL_ERR, + file, function, line, + "an error was reported by server: " + "name=\"%s\", message=\"%s\"", + err->name, err->message); + else + eina_log_print(_e_dbus_connman_log_dom, EINA_LOG_LEVEL_ERR, + file, function, line, + "callback without message arguments!"); + + return 0; + } + + if (!dbus_message_iter_init(msg, itr)) + { + eina_log_print(_e_dbus_connman_log_dom, EINA_LOG_LEVEL_ERR, + file, function, line, + "could not init iterator."); + return 0; + } + + return 1; +} + +#define _dbus_callback_check_and_init(msg, itr, err) \ + __dbus_callback_check_and_init(__FILE__, __LINE__, __FUNCTION__, \ + msg, itr, err) + +static inline bool +__dbus_iter_type_check(const char *file, int line, const char *function, int type, int expected, const char *expected_name) +{ + if (type == expected) + return 1; + + ERR(file, function, line, + "expected type %s (%c) but got %c instead!", + expected_name, expected, type); + + return 0; +} +#define _dbus_iter_type_check(t, e) __dbus_iter_type_check(__FILE__, __LINE__, __FUNCTION__, t, e, #e) + +extern E_DBus_Connection *e_connman_conn; + +const char *e_connman_system_bus_name_get(void); + +void e_connman_manager_clear_elements(void); + +void e_connman_elements_init(void); +void e_connman_elements_shutdown(void); + +E_Connman_Element *e_connman_element_register(const char *path, const char *interface); +void e_connman_element_unregister(E_Connman_Element *element); + +bool e_connman_element_objects_array_get_stringshared(const E_Connman_Element *element, const char *property, unsigned int *count, E_Connman_Element ***elements); +bool e_connman_element_strings_array_get_stringshared(const E_Connman_Element *element, const char *property, unsigned int *count, const char ***strings); +unsigned char *e_connman_element_bytes_array_get_stringshared(const E_Connman_Element *element, const char *property, unsigned int *count); + +bool e_connman_element_message_send(E_Connman_Element *element, const char *method_name, E_DBus_Method_Return_Cb cb, DBusMessage *msg, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); + +bool e_connman_element_call_full(E_Connman_Element *element, const char *method_name, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); +bool e_connman_element_call_with_path(E_Connman_Element *element, const char *method_name, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); +bool e_connman_element_call_with_string(E_Connman_Element *element, const char *method_name, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); diff --git a/src/lib/connman/e_connman_profile.c b/src/lib/connman/e_connman_profile.c new file mode 100644 index 0000000..4da1914 --- /dev/null +++ b/src/lib/connman/e_connman_profile.c @@ -0,0 +1,142 @@ +#include "e_connman_private.h" + +E_Connman_Element * +e_connman_profile_get(const char *path) +{ + E_Connman_Element *profile; + + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); + + profile = e_connman_element_get(path); + if (!profile) + return NULL; + + if (!e_connman_element_is_profile(profile)) + { + WRN("path '%s' is not a profile!", path); + return NULL; + } + + return profile; +} + +/** + * Get property "Name" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The profile name, if set with e_connman_profile_name_set() + * + * @param profile path to get property. + * @param name where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + * @see e_connman_profile_name_set() + */ +bool +e_connman_profile_name_get(const E_Connman_Element *profile, const char **name) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(profile, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + return e_connman_element_property_get_stringshared + (profile, e_connman_prop_name, NULL, name); +} + +/** + * Call method SetProperty("Name", name) at the given element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_CONNMAN_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * @param name value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + * @see e_connman_profile_name_get() + */ +bool +e_connman_profile_name_set(E_Connman_Element *profile, const char *name, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(profile, 0); + return e_connman_element_property_set_full + (profile, e_connman_prop_name, DBUS_TYPE_STRING, name, cb, data); +} + +/** + * Get property "OfflineMode" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The offline mode indicates the global setting for + * switching all radios on or off. Changing offline mode + * to true results in powering down all devices. + * + * @param offline where to store the property value, must be a pointer + * to booleans (bool *). + * + * @return 1 on success, 0 otherwise. + * @see e_connman_profile_offline_mode_set() + */ +bool +e_connman_profile_offline_mode_get(const E_Connman_Element *profile, bool *offline) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(profile, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(offline, 0); + return e_connman_element_property_get_stringshared + (profile, e_connman_prop_offline_mode, NULL, offline); +} + +/** + * Call method SetProperty("OfflineMode", offline) at the given element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_CONNMAN_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * The offline mode indicates the global setting for + * switching all radios on or off. Changing offline mode + * to true results in powering down all devices. + * + * @param offline value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + * @see e_connman_profile_offline_mode_get() + */ +bool +e_connman_profile_offline_mode_set(E_Connman_Element *profile, bool offline, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(profile, 0); + return e_connman_element_property_set_full + (profile, e_connman_prop_offline_mode, DBUS_TYPE_BOOLEAN, + &offline, cb, data); +} + +/** + * Get array of service elements. + * + * @param count return the number of elements in array. + * @param p_elements array with all elements, these are not referenced + * and in no particular order, just set if return is 1. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_profile_services_get(const E_Connman_Element *profile, unsigned int *count, E_Connman_Element ***p_elements) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(profile, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(p_elements, 0); + return e_connman_element_objects_array_get_stringshared + (profile, e_connman_prop_services, count, p_elements); +} diff --git a/src/lib/connman/e_connman_service.c b/src/lib/connman/e_connman_service.c new file mode 100644 index 0000000..02a08ad --- /dev/null +++ b/src/lib/connman/e_connman_service.c @@ -0,0 +1,1239 @@ +#include "e_connman_private.h" + +E_Connman_Element * +e_connman_service_get(const char *path) +{ + E_Connman_Element *service; + + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); + + service = e_connman_element_get(path); + if (!service) + return NULL; + + if (!e_connman_element_is_service(service)) + { + WRN("path '%s' is not a service!", path); + return NULL; + } + + return service; +} + +/** + * Connect this service. + * + * Connect this service. It will attempt to connect + * WiFi, WiMAX or Bluetooth services. + * + * For Ethernet devices this method can only be used + * if it has previously been disconnected. Otherwise + * the plugging of a cable will trigger connecting + * automatically. If no cable is plugged in this method + * will fail. + * + * @param service path to call method on server. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_connect(E_Connman_Element *service, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "Connect"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + return e_connman_element_call_full + (service, name, NULL, &service->_pending.service_connect, cb, data); +} + +/** + * Disconnect this service. + * + * Disconnect this service. If the service is not + * connected an error message will be generated. + * + * On Ethernet devices this will disconnect the IP + * details from the service. It will not magically + * unplug the cable. When no cable is plugged in this + * method will fail. + * + * This method can also be used to abort a previous + * connectiong attempt via the Connect method. + * + * @param service path to call method on server. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_disconnect(E_Connman_Element *service, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "Disconnect"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + return e_connman_element_call_full + (service, name, NULL, &service->_pending.service_disconnect, cb, data); +} + +/** + * Remove this service. + * + * A successfully connected service with Favorite=true + * can be removed this way. If it is connected, it will + * be automatically disconnected first. + * + * If the service requires a passphrase it will be + * cleared and forgotten when removing. + * + * This is similar to setting the Favorite property + * to false, but that is currently not supported. + * + * In the case a connection attempt failed and the + * service is in the State=failure, this method can + * also be used to reset the service. + * + * Calling this method on Ethernet devices will cause + * an error message. It is not possible to remove these + * kind of devices. + * + * @param service path to call method on server. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_remove(E_Connman_Element *service, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "Remove"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + return e_connman_element_call_full + (service, name, NULL, &service->_pending.service_remove, cb, data); +} + +/** + * Clears the value of the specified property. + * + * + * @param service path to call method on server. + * @param property to be cleared. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_clear_property(E_Connman_Element *service, const char *property, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "ClearProperty"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(property, 0); + return e_connman_element_call_with_string + (service, name, property, NULL, &service->_pending.service_clear_property, + cb, data); +} + +/** + * Move service before in favorites list. + * + * Call method MoveBefore(object service) at the given service on server. + * + * If a service has been used before, this allows a + * reorder of the favorite services. + * + * The target service object must be part of this + * profile. Moving between profiles is not supported. + * + * @param service path to call method on server. + * @param object_path object service. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_move_before(E_Connman_Element *service, const char *object_path, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "MoveBefore"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(object_path, 0); + return e_connman_element_call_with_path + (service, name, object_path, NULL, + &service->_pending.service_move_before, cb, data); +} + +/** + * Move service after in favorites list. + * + * Call method MoveAfter(object service) at the given service on server. + * + * If a service has been used before, this allows a + * reorder of the favorite services. + * + * The target service object must be part of this + * profile. Moving between profiles is not supported. + * + * @param service path to call method on server. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_move_after(E_Connman_Element *service, const char *object_path, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "MoveAfter"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(object_path, 0); + return e_connman_element_call_with_path + (service, name, object_path, NULL, + &service->_pending.service_move_after, cb, data); +} + +/** + * Get property "State" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The service state information. + * + * Valid states are "idle", "failure", "association", + * "configuration", "ready", "login" and "online". + * + * @param service path to get property. + * @param state where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_state_get(const E_Connman_Element *service, const char **state) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(state, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_state, NULL, state); +} + +/** + * Get property "Error" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The service error status details. + * + * When error occur during connection or disconnection + * the detailed information are represented in this + * property to help the user interface to present the + * user with alternate options. + * + * This property is only valid when the service is in + * the "failure" state. Otherwise it might be empty or + * not present at all. + * + * Current defined error code is "dhcp-failed". + * + * @param service path to get property. + * @param error where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_error_get(const E_Connman_Element *service, const char **error) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(error, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_error, NULL, error); +} + +/** + * Get property "Name" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The service name (for example "Wireless" etc.) + * + * This name can be used for directly displaying it in + * the application. It has pure informational purpose. + * + * For Ethernet devices and hidden WiFi networks it is + * not guaranteed that this property is present. + * + * @param service path to get property. + * @param name where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_name_get(const E_Connman_Element *service, const char **name) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_name, NULL, name); +} + +/** + * Get property "Type" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The service type (for example "ethernet", "wifi" etc.) + * + * This information should only be used to determine + * advanced properties or showing the correct icon + * to the user. + * + * @param service path to get property. + * @param type where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_type_get(const E_Connman_Element *service, const char **type) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(type, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_type, NULL, type); +} + +/** + * Get property "Mode" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the service type is WiFi or Cellular, then this + * property is present and contains the mode of the + * network. + * + * For WiFi services the possible values are "managed" + * and "adhoc". For Cellular services it describes the + * network technology. Possible values are "gprs", "edge" + * and "umts". + * + * This property might be only present for WiFi and + * Cellular services. + * + * @param service path to get property. + * @param mode where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_mode_get(const E_Connman_Element *service, const char **mode) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(mode, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_mode, NULL, mode); +} + +/** + * Get property "Security" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the service type is WiFi, then this property is + * present and contains the security method or key + * management setting. + * + * Possible values are "none", "wep", "wpa" and "rsn". + * + * This property might be only present for WiFi + * services. + * + * @param service path to get property. + * @param security where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_security_get(const E_Connman_Element *service, const char **security) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(security, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_security, NULL, security); +} + +/** + * Get property "Passphrase" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the service type is WiFi, then this property + * can be used to store a passphrase. + * + * No PropertyChanged signals will be send for this + * property. The PassphraseRequired property should + * be monitored instead. + * + * This property might also not always be included + * since it is protected by a different security policy. + * + * @param service path to get property. + * @param passphrase where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + * @see e_connman_service_passphrase_set() + */ +bool +e_connman_service_passphrase_get(const E_Connman_Element *service, const char **passphrase) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(passphrase, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_passphrase, NULL, passphrase); +} + +/** + * Set property "Passphrase" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the service type is WiFi, then this property + * can be used to store a passphrase. + * + * No PropertyChanged signals will be send for this + * property. The PassphraseRequired property should + * be monitored instead. + * + * This property might also not always be included + * since it is protected by a different security policy. + * + * @param service path to get property. + * @param passphrase value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + * @see e_connman_service_passphrase_get() + */ +bool +e_connman_service_passphrase_set(E_Connman_Element *service, const char *passphrase, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + return e_connman_element_property_set_full + (service, e_connman_prop_passphrase, DBUS_TYPE_STRING, + passphrase, cb, data); +} + +/** + * Get property "PassphraseRequired" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the service type is WiFi, then this property + * indicates if a passphrase is required. + * + * If a passphrase has been set already or if no + * passphrase is needed, then this property will + * be set to false. + * + * @param service path to get property. + * @param passphrase_required where to store the property value, must be a + * pointer to boolean (bool *). + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_passphrase_required_get(const E_Connman_Element *service, bool *passphrase_required) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(passphrase_required, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_passphrase_required, NULL, passphrase_required); +} + +/** + * Get property "Strength" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * Indicates the signal strength of the service. This + * is a normalized value between 0 and 100. + * + * This property will not be present for Ethernet + * devices. + * + * @param service path to get property. + * @param strength where to store the property value, must be a pointer + * to byte (unsigned char*). + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_strength_get(const E_Connman_Element *service, unsigned char *strength) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(strength, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_strength, NULL, strength); +} + +/** + * Get property "Favorite" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * Will be true if a cable is plugged in or the user + * selected and successfully connected to this service. + * + * This value is automatically changed and to revert + * it back to false the Remove() method needs to be + * used. + * + * @param service path to get property. + * @param favorite where to store the property value, must be a + * pointer to boolean (bool *). + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_favorite_get(const E_Connman_Element *service, bool *favorite) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(favorite, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_favorite, NULL, favorite); +} + +/** + * Get property "Immutable" value. + * + * This value will be set to true if the service is configured + * externally via a configuration file. + * + * The only valid operation are e_connman_service_connect() and + * e_connman_service_disconnect(). The e_connman_service_remove() + * method will result in an error. + + * @param service path to get property. + * @param immutable where to store the property value, must be a + * pointer to bollean (bool *). + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_immutable_get(const E_Connman_Element *service, bool *immutable) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(immutable, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_immutable, NULL, immutable); +} + +/** + * Get property "AutoConnect" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If set to true, this service will auto-connect + * when not other connection is available. + * + * For favorite services it is possible to change + * this value to prevent or permit automatic + * connection attempts. + * + * @param service path to get property. + * @param auto_connect where to store the property value, must be a + * pointer to boolean (bool *). + * + * @return 1 on success, 0 otherwise. + * @see e_connman_service_auto_connect_set() + */ +bool +e_connman_service_auto_connect_get(const E_Connman_Element *service, bool *auto_connect) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(auto_connect, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_auto_connect, NULL, auto_connect); +} + +/** + * Set property "AutoConnect" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If set to true, this service will auto-connect + * when not other connection is available. + * + * For favorite services it is possible to change + * this value to prevent or permit automatic + * connection attempts. + * + * @param service path to get property. + * @param service_favorite where to store the property value, must be a + * pointer to boolean (bool *). + * + * @return 1 on success, 0 otherwise. + * @see e_connman_service_auto_connect_get() + */ +bool +e_connman_service_auto_connect_set(E_Connman_Element *service, bool auto_connect, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + return e_connman_element_property_set_full + (service, e_connman_prop_auto_connect, DBUS_TYPE_BOOLEAN, &auto_connect, cb, data); +} + +/** + * Get property "SetupRequired" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the service is Cellular, then this property + * indicates that some extra setup steps are required. + * + * In most cases it is required to fill in the APN + * details. + * + * @param service path to get property. + * @param setup_required where to store the property value, must be a + * pointer to boolean (bool *). + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_setup_required_get(const E_Connman_Element *service, bool *setup_required) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(setup_required, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_setup_required, NULL, setup_required); +} + +/** + * Get property "APN" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the service is Cellular, then this property + * contains the APN details. + * + * The APN is network provider specific and even + * sometimes data plan specific. Possible examples + * are "isp.cingular" or "internet.t-mobile". + * + * This property might also not always be included + * since it is protected by a different security policy. + * + * @param service path to get property. + * @param apn where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + * @see e_connman_service_apn_set() + */ +bool +e_connman_service_apn_get(const E_Connman_Element *service, const char **apn) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(apn, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_apn, NULL, apn); +} + +/** + * Set property "APN" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the service is Cellular, then this property + * contains the APN details. + * + * The APN is network provider specific and even + * sometimes data plan specific. Possible examples + * are "isp.cingular" or "internet.t-mobile". + * + * This property might also not always be included + * since it is protected by a different security policy. + * + * @param service path to get property. + * @param passphrase value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + * @see e_connman_service_apn_get() + */ +bool +e_connman_service_apn_set(E_Connman_Element *service, const char *apn, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + return e_connman_element_property_set_full + (service, e_connman_prop_apn, DBUS_TYPE_STRING, + apn, cb, data); +} + +/** + * Get property "MCC" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the service is Cellular, then this property + * contains the Mobile Country Code. + * + * @param service path to get property. + * @param mcc where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_mcc_get(const E_Connman_Element *service, const char **mcc) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(mcc, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_mcc, NULL, mcc); +} + +/** + * Get property "MNC" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * If the service is Cellular, then this property + * contains the Mobile Network Code. + * + * @param service path to get property. + * @param mnc where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_mnc_get(const E_Connman_Element *service, const char **mnc) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(mnc, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_mnc, NULL, mnc); +} + +/** + * Get property "Roaming" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * This property indicates if this service is roaming. + * + * In the case of Cellular services this normally + * indicates connections to a foreign provider when + * traveling abroad. + * + * @param service path to get property. + * @param roaming where to store the property value, must be a + * pointer to boolean (bool *). + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_roaming_get(const E_Connman_Element *service, bool *roaming) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(roaming, 0); + return e_connman_element_property_get_stringshared + (service, e_connman_prop_roaming, NULL, roaming); +} + +/** + * Get property "IPv4.Method" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The IPv4 method in use. Possible values here are "dhcp" and + * "static". + * + * @param service path to get property. + * @param method where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ipv4_method_get(const E_Connman_Element *service, const char **method) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method, 0); + return e_connman_element_property_dict_get_stringshared + (service, e_connman_prop_ipv4, e_connman_prop_method, NULL, method); +} + +/** + * Get property "IPv4.Address" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The current IPv4 address. + * + * @param service path to get property. + * @param address where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ipv4_address_get(const E_Connman_Element *service, const char **address) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(address, 0); + return e_connman_element_property_dict_get_stringshared + (service, e_connman_prop_ipv4, e_connman_prop_address, NULL, address); +} + +/** + * Get property "IPv4.Gateway" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The current IPv4 gateway. + * + * @param service path to get property. + * @param gateway where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ipv4_gateway_get(const E_Connman_Element *service, const char **gateway) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(gateway, 0); + return e_connman_element_property_dict_get_stringshared + (service, e_connman_prop_ipv4, e_connman_prop_gateway, NULL, gateway); +} + +/** + * Get property "IPv4.Netmask" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The current IPv4 netmask. + * + * @param service path to get property. + * @param netmask where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ipv4_netmask_get(const E_Connman_Element *service, const char **netmask) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(netmask, 0); + return e_connman_element_property_dict_get_stringshared + (service, e_connman_prop_ipv4, e_connman_prop_netmask, NULL, netmask); +} + +/** + * Get property "IPv4.Configuration.Method" value. + * + * Unlike IPv4.Method, this is the user-set value, rather than the + * actual value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The IPv4 configured method. Possible values here are "dhcp" and + * "static". + * + * @param service path to get property. + * @param method where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ipv4_configuration_method_get(const E_Connman_Element *service, const char **method) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method, 0); + return e_connman_element_property_dict_get_stringshared + (service, e_connman_prop_ipv4_configuration, e_connman_prop_method, + NULL, method); +} + +/** + * Get property "IPv4.Configuration.Address" value. + * + * Unlike IPv4.Address, this is the user-set value, rather than the + * actual value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The current configured IPv4 address. + * + * @param service path to get property. + * @param address where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ipv4_configuration_address_get(const E_Connman_Element *service, const char **address) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(address, 0); + return e_connman_element_property_dict_get_stringshared + (service, e_connman_prop_ipv4_configuration, e_connman_prop_address, + NULL, address); +} + +/** + * Get property "IPv4.Configuration.Gateway" value. + * + * Unlike IPv4.Gateway, this is the user-set value, rather than the + * actual value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The current configured IPv4 gateway. + * + * @param service path to get property. + * @param gateway where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ipv4_configuration_gateway_get(const E_Connman_Element *service, const char **gateway) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(gateway, 0); + return e_connman_element_property_dict_get_stringshared + (service, e_connman_prop_ipv4_configuration, e_connman_prop_gateway, + NULL, gateway); +} + +/** + * Get property "IPv4.Configuration.Netmask" value. + * + * Unlike IPv4.Netmask, this is the user-set value, rather than the + * actual value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The current configured IPv4 netmask. + * + * @param service path to get property. + * @param netmask where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ipv4_configuration_netmask_get(const E_Connman_Element *service, const char **netmask) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(netmask, 0); + return e_connman_element_property_dict_get_stringshared + (service, e_connman_prop_ipv4_configuration, e_connman_prop_netmask, + NULL, netmask); +} + +/** + * Set IPv4 to connect automatically using DHCP. + * + * @param service path to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ipv4_configure_dhcp(E_Connman_Element *service, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char method[] = "dhcp"; + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + return e_connman_element_property_dict_set_full + (service, e_connman_prop_ipv4_configuration, e_connman_prop_method, + DBUS_TYPE_STRING, method, cb, data); +} + +/** + * Set IPv4 to connect using manually set parameters. + * + * @param service path to set. + * @param address IPv4 address. + * @param netmask IPv4 netmask, or @c NULL for "/32" + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ipv4_configure_manual(E_Connman_Element *service, const char *address, const char *netmask, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "SetProperty"; + const char *method = "manual"; /* not method[] as gcc screws it with dbus */ + DBusMessage *msg; + DBusMessageIter itr, variant, dict, entry; + + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(address, 0); + + msg = dbus_message_new_method_call + (e_connman_system_bus_name_get(), service->path, service->interface, name); + + if (!msg) + return 0; + + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic + (&itr, DBUS_TYPE_STRING, &e_connman_prop_ipv4_configuration); + + dbus_message_iter_open_container + (&itr, DBUS_TYPE_VARIANT, + (DBUS_TYPE_ARRAY_AS_STRING + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + DBUS_TYPE_STRING_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING), + &variant); + dbus_message_iter_open_container + (&variant, DBUS_TYPE_ARRAY, + (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + DBUS_TYPE_STRING_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING), + &dict); + + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry); + dbus_message_iter_append_basic + (&entry, DBUS_TYPE_STRING, &e_connman_prop_method); + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &method); + dbus_message_iter_close_container(&dict, &entry); + + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry); + dbus_message_iter_append_basic + (&entry, DBUS_TYPE_STRING, &e_connman_prop_address); + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &address); + dbus_message_iter_close_container(&dict, &entry); + + if (netmask) + { + dbus_message_iter_open_container + (&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry); + dbus_message_iter_append_basic + (&entry, DBUS_TYPE_STRING, &e_connman_prop_netmask); + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &netmask); + dbus_message_iter_close_container(&dict, &entry); + } + + dbus_message_iter_close_container(&variant, &dict); + dbus_message_iter_close_container(&itr, &variant); + + return e_connman_element_message_send + (service, name, NULL, msg, &service->_pending.property_set, cb, data); +} + +/** + * Get property "Ethernet.Method" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The Ethernet configuration method. Possible values here "auto". + * + * @param service path to get property. + * @param method where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ethernet_method_get(const E_Connman_Element *service, const char **method) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method, 0); + return e_connman_element_property_dict_get_stringshared + (service, e_connman_prop_ethernet, e_connman_prop_method, NULL, method); +} + +/** + * Get property "Ethernet.Address" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The current configured Ethernet address (mac-address). + * + * @param service path to get property. + * @param address where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ethernet_address_get(const E_Connman_Element *service, const char **address) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(address, 0); + return e_connman_element_property_dict_get_stringshared + (service, e_connman_prop_ethernet, e_connman_prop_address, NULL, address); +} + +/** + * Get property "Ethernet.Gateway" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The current configured Ethernet MTU. + * + * @param service path to get property. + * @param gateway where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ethernet_mtu_get(const E_Connman_Element *service, unsigned short *mtu) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(mtu, 0); + return e_connman_element_property_dict_get_stringshared + (service, e_connman_prop_ethernet, e_connman_prop_mtu, NULL, mtu); +} + +/** + * Get property "Ethernet.Netmask" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The current configured Ethernet netmask. + * + * @param service path to get property. + * @param netmask where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_service_ethernet_netmask_get(const E_Connman_Element *service, const char **netmask) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(netmask, 0); + return e_connman_element_property_dict_get_stringshared + (service, e_connman_prop_ethernet, e_connman_prop_netmask, NULL, netmask); +} diff --git a/src/lib/connman/e_connman_technology.c b/src/lib/connman/e_connman_technology.c new file mode 100644 index 0000000..198b847 --- /dev/null +++ b/src/lib/connman/e_connman_technology.c @@ -0,0 +1,132 @@ +#include "e_connman_private.h" + +E_Connman_Element * +e_connman_technology_get(const char *path) +{ + E_Connman_Element *technology; + + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); + + technology = e_connman_element_get(path); + if (!technology) + return NULL; + + if (!e_connman_element_is_technology(technology)) + { + WRN("path '%s' is not a technology!", path); + return NULL; + } + + return technology; +} + +/** + * Get property "Name" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * Name of this technology. + * + * @param technology path to get property + * @param name where to store the property value, must be a pointer + * to string (const char *), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on sucess, 0 otherwise + */ +bool +e_connman_technology_name_get(const E_Connman_Element *technology, const char **name) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(technology, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + return e_connman_element_property_get_stringshared + (technology, e_connman_prop_name, NULL, name); +} + +/** + * Get property "Type" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The technology type (for example "ethernet" etc.) + * + * This information should only be used to determine + * advanced properties or showing the correct icon + * to the user. + * + * @param technology path to get property. + * @param type where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_technology_type_get(const E_Connman_Element *technology, const char **type) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(technology, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(type, 0); + return e_connman_element_property_get_stringshared + (technology, e_connman_prop_type, NULL, type); +} + +/** + * Get property "State" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * The technology state information. + * + * Valid states are "offline", "available", "enabled", + * and "connected". + * + * @param technology path to get property. + * @param state where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_technology_state_get(const E_Connman_Element *technology, const char **state) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(technology, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(state, 0); + return e_connman_element_property_get_stringshared + (technology, e_connman_prop_state, NULL, state); +} + +/** + * Get array of device elements. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param technology path to get property. + * @param count return the number of elements in array. + * @param t_elements array with all elements, these are not referenced + * and in no particular order, just set if return is 1. The + * array itself is allocated using malloc() and should be freed + * after usage is done. + * + * @return 1 on success, 0 otherwise. + */ +bool +e_connman_technology_devices_get(const E_Connman_Element *technology, unsigned int *count, E_Connman_Element ***t_elements) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(technology, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(t_elements, 0); + return e_connman_element_objects_array_get_stringshared + (technology, e_connman_prop_devices, count, t_elements); +} diff --git a/src/lib/dbus/.cvsignore b/src/lib/dbus/.cvsignore new file mode 100644 index 0000000..e49f9e1 --- /dev/null +++ b/src/lib/dbus/.cvsignore @@ -0,0 +1,12 @@ +.deps +Makefile +Makefile.in +.libs +e_dbus.lo +e_dbus_interfaces.lo +e_dbus_message.lo +e_dbus_methods.lo +e_dbus_object.lo +e_dbus_signal.lo +e_dbus_util.lo +libedbus.la diff --git a/src/lib/dbus/E_DBus.h b/src/lib/dbus/E_DBus.h new file mode 100644 index 0000000..73621a0 --- /dev/null +++ b/src/lib/dbus/E_DBus.h @@ -0,0 +1,185 @@ +#ifndef E_DBUS_H +#define E_DBUS_H + +#define DBUS_API_SUBJECT_TO_CHANGE + +#ifdef _WIN32 +# ifdef interface +# undef interface +# endif +#endif + +#ifdef _WIN32 +# ifdef interface +# undef interface +# endif +# define DBUS_API_SUBJECT_TO_CHANGE +#endif + +#include <dbus/dbus.h> +#include <Eina.h> + +#ifdef EAPI +# undef EAPI +#endif + +#ifdef _WIN32 +# ifdef EFL_EDBUS_BUILD +# ifdef DLL_EXPORT +# define EAPI __declspec(dllexport) +# else +# define EAPI +# endif /* ! DLL_EXPORT */ +# else +# define EAPI __declspec(dllimport) +# endif /* ! EFL_EDBUS_BUILD */ +#else +# ifdef __GNUC__ +# if __GNUC__ >= 4 +# define EAPI __attribute__ ((visibility("default"))) +# else +# define EAPI +# endif +# else +# define EAPI +# endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + EAPI extern int E_DBUS_DOMAIN_GLOBAL; + EAPI extern int E_DBUS_EVENT_SIGNAL; + + typedef struct E_DBus_Connection E_DBus_Connection; + typedef struct E_DBus_Object E_DBus_Object; + typedef struct E_DBus_Interface E_DBus_Interface; + typedef struct E_DBus_Signal_Handler E_DBus_Signal_Handler; + + typedef DBusMessage *(* E_DBus_Method_Cb)(E_DBus_Object *obj, DBusMessage *message); + typedef void (*E_DBus_Method_Return_Cb) (void *data, DBusMessage *msg, DBusError *error); + typedef void (*E_DBus_Signal_Cb) (void *data, DBusMessage *msg); + + typedef void (*E_DBus_Object_Property_Get_Cb) (E_DBus_Object *obj, const char *property, int *type, void **value); + typedef int (*E_DBus_Object_Property_Set_Cb) (E_DBus_Object *obj, const char *property, int type, void *value); + +/** + * A callback function for a DBus call + * @param user_data the data passed in to the method call + * @param event_data a struct containing the return data. + */ + typedef void (*E_DBus_Callback_Func) (void *user_data, void *method_return, DBusError *error); + typedef void *(*E_DBus_Unmarshal_Func) (DBusMessage *msg, DBusError *err); + typedef void (*E_DBus_Free_Func) (void *data); + + typedef struct E_DBus_Callback E_DBus_Callback; + + + EAPI int e_dbus_init(void); + EAPI int e_dbus_shutdown(void); + +/* setting up the connection */ + + EAPI E_DBus_Connection *e_dbus_bus_get(DBusBusType type); + + EAPI void e_dbus_connection_ref(E_DBus_Connection *conn); + + EAPI E_DBus_Connection *e_dbus_connection_setup(DBusConnection *conn); + EAPI void e_dbus_connection_close(E_DBus_Connection *conn); + +/* receiving method calls */ + EAPI E_DBus_Interface *e_dbus_interface_new(const char *interface); + EAPI void e_dbus_interface_ref(E_DBus_Interface *iface); + EAPI void e_dbus_interface_unref(E_DBus_Interface *iface); + EAPI void e_dbus_object_interface_attach(E_DBus_Object *obj, E_DBus_Interface *iface); + EAPI void e_dbus_object_interface_detach(E_DBus_Object *obj, E_DBus_Interface *iface); + EAPI int e_dbus_interface_method_add(E_DBus_Interface *iface, const char *member, const char *signature, const char *reply_signature, E_DBus_Method_Cb func); + + EAPI int e_dbus_interface_signal_add(E_DBus_Interface *iface, const char *name, const char *signature); + + EAPI E_DBus_Object *e_dbus_object_add(E_DBus_Connection *conn, const char *object_path, void *data); + EAPI void e_dbus_object_free(E_DBus_Object *obj); + EAPI void *e_dbus_object_data_get(E_DBus_Object *obj); + EAPI E_DBus_Connection *e_dbus_object_conn_get(E_DBus_Object *obj); + EAPI const char *e_dbus_object_path_get(E_DBus_Object *obj); + EAPI const Eina_List *e_dbus_object_interfaces_get(E_DBus_Object *obj); + + EAPI void e_dbus_object_property_get_cb_set(E_DBus_Object *obj, E_DBus_Object_Property_Get_Cb func); + EAPI void e_dbus_object_property_set_cb_set(E_DBus_Object *obj, E_DBus_Object_Property_Set_Cb func); + + +/* sending method calls */ + + + EAPI DBusPendingCall *e_dbus_message_send(E_DBus_Connection *conn, DBusMessage *msg, E_DBus_Method_Return_Cb cb_return, int timeout, void *data); + + EAPI DBusPendingCall *e_dbus_method_call_send(E_DBus_Connection *conn, DBusMessage *msg, E_DBus_Unmarshal_Func unmarshal_func, E_DBus_Callback_Func cb_func, E_DBus_Free_Func free_func, int timeout, void *data); + + +/* signal receiving */ + + EAPI E_DBus_Signal_Handler *e_dbus_signal_handler_add(E_DBus_Connection *conn, const char *sender, const char *path, const char *interface, const char *member, E_DBus_Signal_Cb cb_signal, void *data); + EAPI void e_dbus_signal_handler_del(E_DBus_Connection *conn, E_DBus_Signal_Handler *sh); + +/* standard dbus method calls */ + + EAPI DBusPendingCall *e_dbus_request_name(E_DBus_Connection *conn, const char *name, + unsigned int flags, + E_DBus_Method_Return_Cb cb_return, + const void *data); + EAPI DBusPendingCall *e_dbus_release_name(E_DBus_Connection *conn, const char *name, + E_DBus_Method_Return_Cb cb_return, + const void *data); + + EAPI DBusPendingCall *e_dbus_get_name_owner(E_DBus_Connection *conn, const char *name, + E_DBus_Method_Return_Cb cb_return, + const void *data); + EAPI DBusPendingCall *e_dbus_list_names(E_DBus_Connection *conn, + E_DBus_Method_Return_Cb cb_return, + const void *data); + EAPI DBusPendingCall *e_dbus_list_activatable_names(E_DBus_Connection *conn, + E_DBus_Method_Return_Cb cb_return, + const void *data); + EAPI DBusPendingCall *e_dbus_name_has_owner(E_DBus_Connection *conn, const char *name, + E_DBus_Method_Return_Cb cb_return, + const void *data); + EAPI DBusPendingCall *e_dbus_start_service_by_name(E_DBus_Connection *conn, const char *name, unsigned int flags, + E_DBus_Method_Return_Cb cb_return, + const void *data); + +/* standard methods calls on objects */ + EAPI DBusPendingCall *e_dbus_peer_ping(E_DBus_Connection *conn, const char *destination, + const char *path, E_DBus_Method_Return_Cb cb_return, + const void *data); + EAPI DBusPendingCall *e_dbus_peer_get_machine_id(E_DBus_Connection *conn, + const char *destination, const char *path, + E_DBus_Method_Return_Cb cb_return, + const void *data); + EAPI DBusPendingCall *e_dbus_properties_get_all(E_DBus_Connection *conn, const char *destination, + const char *path, const char *interface, + E_DBus_Method_Return_Cb cb_return, + const void *data); + EAPI DBusPendingCall *e_dbus_properties_get(E_DBus_Connection *conn, const char *destination, + const char *path, const char *interface, + const char *property, + E_DBus_Method_Return_Cb cb_return, + const void *data); + EAPI DBusPendingCall *e_dbus_properties_set(E_DBus_Connection *conn, const char *destination, + const char *path, const char *interface, + const char *property, int value_type, + const void *value, E_DBus_Method_Return_Cb cb_return, + const void *data); + + + EAPI E_DBus_Callback *e_dbus_callback_new(E_DBus_Callback_Func cb_func, E_DBus_Unmarshal_Func unmarshal_func, E_DBus_Free_Func free_func, void *user_data); + + EAPI void e_dbus_callback_free(E_DBus_Callback *callback); + EAPI void e_dbus_callback_call(E_DBus_Callback *cb, void *data, DBusError *error); + EAPI void *e_dbus_callback_unmarshal(E_DBus_Callback *cb, DBusMessage *msg, DBusError *err); + EAPI void e_dbus_callback_return_free(E_DBus_Callback *callback, void *data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lib/dbus/Makefile.am b/src/lib/dbus/Makefile.am new file mode 100644 index 0000000..b56865b --- /dev/null +++ b/src/lib/dbus/Makefile.am @@ -0,0 +1,26 @@ +MAINTAINERCLEANFILES = Makefile.in + +AM_CPPFLAGS = \ +@EFL_EDBUS_BUILD@ \ +@EDBUS_CFLAGS@ \ +@EINA_CFLAGS@ \ +@DBUS_VERSION_CFLAGS@ + + +lib_LTLIBRARIES = libedbus.la +include_HEADERS = E_DBus.h + +libedbus_la_SOURCES = \ +e_dbus.c \ +e_dbus_message.c \ +e_dbus_methods.c \ +e_dbus_interfaces.c \ +e_dbus_object.c \ +e_dbus_util.c \ +e_dbus_signal.c + + +libedbus_la_LIBADD = @EDBUS_LIBS@ @EINA_LIBS@ +libedbus_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @edbus_release_info@ + +EXTRA_DIST = e_dbus_private.h diff --git a/src/lib/dbus/e_dbus.c b/src/lib/dbus/e_dbus.c new file mode 100644 index 0000000..89d4e81 --- /dev/null +++ b/src/lib/dbus/e_dbus.c @@ -0,0 +1,638 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> +#include <string.h> +#include <stdbool.h> + +#include "e_dbus_private.h" + +#define NUM_BUS_TYPES 3 + +/* + * TODO: + * listen for disconnected signal and clean up? + * listen for NameOwnerChanged signals for names we have SignalHandler's for + * remap SH to listen for signals from new owner + */ +int _e_dbus_log_dom = -1; +static int connection_slot = -1; + +static int _edbus_init_count = 0; +static int close_connection = 0; +EAPI int E_DBUS_EVENT_SIGNAL = 0; + +static E_DBus_Connection *shared_connections[2] = {NULL, NULL}; + +typedef struct E_DBus_Handler_Data E_DBus_Handler_Data; +typedef struct E_DBus_Timeout_Data E_DBus_Timeout_Data; + + +struct E_DBus_Handler_Data +{ + int fd; + Ecore_Fd_Handler *fd_handler; + E_DBus_Connection *cd; + DBusWatch *watch; + int enabled; +}; + +struct E_DBus_Timeout_Data +{ + Ecore_Timer *handler; + DBusTimeout *timeout; + E_DBus_Connection *cd; + int interval; +}; + +static int e_dbus_idler(void *data); + +static int +e_dbus_fd_handler(void *data, Ecore_Fd_Handler *fd_handler) +{ + E_DBus_Handler_Data *hd; + unsigned int condition = 0; + + DBG("fd handler (%ld)!", (long int)fd_handler); + + hd = data; + + if (!hd->enabled) { + DBG("handler disabled"); + if (hd->fd_handler) ecore_main_fd_handler_del(hd->fd_handler); + hd->fd_handler = NULL; + return 0; + } + if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) condition |= DBUS_WATCH_READABLE; + if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE)) condition |= DBUS_WATCH_WRITABLE; + if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) condition |= DBUS_WATCH_ERROR; + + if (condition & DBUS_WATCH_ERROR) DBG("DBUS watch error"); + dbus_watch_handle(hd->watch, condition); + hd = NULL; + + return 1; +} + + +static void +e_dbus_fd_handler_add(E_DBus_Handler_Data *hd) +{ + unsigned int dflags; + Ecore_Fd_Handler_Flags eflags; + + if (hd->fd_handler) return; + DBG("fd handler add (%d)", hd->fd); + + dflags = dbus_watch_get_flags(hd->watch); + eflags = ECORE_FD_ERROR; + if (dflags & DBUS_WATCH_READABLE) eflags |= ECORE_FD_READ; + if (dflags & DBUS_WATCH_WRITABLE) eflags |= ECORE_FD_WRITE; + + + hd->fd_handler = ecore_main_fd_handler_add(hd->fd, + eflags, + e_dbus_fd_handler, + hd, + NULL, + NULL); + + hd->cd->fd_handlers = eina_list_append(hd->cd->fd_handlers, hd->fd_handler); +} + + +static void +e_dbus_handler_data_free(void *data) +{ + E_DBus_Handler_Data *hd = data; + + DBG("e_dbus_handler_data_free"); + if (hd->fd_handler) + { + hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->cd->fd_handlers); + ecore_main_fd_handler_del(hd->fd_handler); + } + free(hd); +} + +static void +e_dbus_connection_data_watch_add(E_DBus_Connection *cd, DBusWatch *watch) +{ + E_DBus_Handler_Data *hd; + + hd = calloc(1, sizeof(E_DBus_Handler_Data)); + dbus_watch_set_data(watch, hd, e_dbus_handler_data_free); + hd->cd = cd; + hd->watch = watch; + + hd->enabled = dbus_watch_get_enabled(watch); +#if (DBUS_VERSION_MAJOR == 1 && DBUS_VERSION_MINOR == 1 && DBUS_VERSION_MICRO>= 1) || (DBUS_VERSION_MAJOR == 1 && DBUS_VERSION_MINOR > 1) || (DBUS_VERSION_MAJOR > 1) + hd->fd = dbus_watch_get_unix_fd(hd->watch); +#else + hd->fd = dbus_watch_get_fd(hd->watch); +#endif + DBG("watch add (enabled: %d)", hd->enabled); + if (hd->enabled) e_dbus_fd_handler_add(hd); +} + +static E_DBus_Connection * +e_dbus_connection_new(DBusConnection *conn) +{ + E_DBus_Connection *cd; + const char *conn_name; + + cd = calloc(1, sizeof(E_DBus_Connection)); + if (!cd) return NULL; + + cd->conn = conn; + conn_name = dbus_bus_get_unique_name(conn); + if (conn_name) + { + DBG("Connected! Name: %s", conn_name); + cd->conn_name = strdup(conn_name); + } + else + DBG("Not connected"); + + cd->shared_type = (unsigned int)-1; + cd->fd_handlers = NULL; + cd->timeouts = NULL; + + return cd; +} + +static void +e_dbus_connection_free(void *data) +{ + E_DBus_Connection *cd = data; + Ecore_Fd_Handler *fd_handler; + Ecore_Timer *timer; + DBG("e_dbus_connection free!"); + + EINA_LIST_FREE(cd->fd_handlers, fd_handler) + ecore_main_fd_handler_del(fd_handler); + + EINA_LIST_FREE(cd->timeouts, timer) + ecore_timer_del(timer); + + if (cd->shared_type != (unsigned int)-1) + shared_connections[cd->shared_type] = NULL; + + e_dbus_signal_handlers_free_all(cd); + + if (cd->conn_name) free(cd->conn_name); + + if (cd->idler) ecore_idler_del(cd->idler); + + free(cd); +} + + +static void +cb_main_wakeup(void *data) +{ + E_DBus_Connection *cd; + DBG("wakeup main!"); + + cd = data; + + if (!cd->idler) cd->idler = ecore_idler_add(e_dbus_idler, cd); + else DBG("already idling"); +} + +static void +cb_dispatch_status(DBusConnection *conn __UNUSED__, DBusDispatchStatus new_status, void *data) +{ + E_DBus_Connection *cd; + + DBG("dispatch status: %d!", new_status); + cd = data; + + if (new_status == DBUS_DISPATCH_DATA_REMAINS && !cd->idler) cd->idler = ecore_idler_add(e_dbus_idler, cd); + + else if (new_status != DBUS_DISPATCH_DATA_REMAINS && cd->idler) + { + static int dummy_event = 0; + + ecore_idler_del(cd->idler); + cd->idler = NULL; + /* post a dummy event to get the mainloop back to normal - this is + * needed because idlers are very special things that won't re-evaluate + * timers and other stuff while idelrs run - idle_exiters and enterers + * can do this safely, but not idlers. idelrs were meant to be used + * very sparingly for very special cases */ + if (dummy_event == 0) dummy_event = ecore_event_type_new(); + ecore_event_add(dummy_event, NULL, NULL, NULL); + } +} + +static int +e_dbus_timeout_handler(void *data) +{ + E_DBus_Timeout_Data *td; + + td = data; + + if (dbus_timeout_get_enabled(td->timeout)) + { + DBG("timeout_handler (not enabled, ending)"); + td->handler = NULL; + return 0; + } + + DBG("timeout handler!"); + dbus_timeout_handle(td->timeout); + return 1; +} + +static void +e_dbus_timeout_data_free(void *timeout_data) +{ + E_DBus_Timeout_Data *td = timeout_data; + DBG("e_dbus_timeout_data_free"); + if (td->handler) ecore_timer_del(td->handler); + free(td); +} + +static dbus_bool_t +cb_timeout_add(DBusTimeout *timeout, void *data) +{ + E_DBus_Connection *cd; + E_DBus_Timeout_Data *td; + + cd = data; + DBG("timeout add!"); + td = calloc(1, sizeof(E_DBus_Timeout_Data)); + td->cd = cd; + dbus_timeout_set_data(timeout, (void *)td, e_dbus_timeout_data_free); + + td->interval = dbus_timeout_get_interval(timeout); + td->timeout = timeout; + + if (dbus_timeout_get_enabled(timeout)) td->handler = ecore_timer_add(td->interval, e_dbus_timeout_handler, td); + td->cd->timeouts = eina_list_append(td->cd->timeouts, td->handler); + + return true; +} + +static void +cb_timeout_del(DBusTimeout *timeout, void *data __UNUSED__) +{ + E_DBus_Timeout_Data *td; + DBG("timeout del!"); + + td = (E_DBus_Timeout_Data *)dbus_timeout_get_data(timeout); + + if (td->handler) + { + td->cd->timeouts = eina_list_remove(td->cd->timeouts, td->handler); + ecore_timer_del(td->handler); + td->handler = NULL; + } + + /* Note: timeout data gets freed when the timeout itself is freed by dbus */ +} + +static void +cb_timeout_toggle(DBusTimeout *timeout, void *data __UNUSED__) +{ + E_DBus_Timeout_Data *td; + DBG("timeout toggle!"); + + td = (E_DBus_Timeout_Data *)dbus_timeout_get_data(timeout); + + if (dbus_timeout_get_enabled(td->timeout)) + { + td->interval = dbus_timeout_get_interval(timeout); + td->handler = ecore_timer_add(td->interval, e_dbus_timeout_handler, td); + } + else + { + ecore_timer_del(td->handler); + td->handler = NULL; + } + + +} + +static dbus_bool_t +cb_watch_add(DBusWatch *watch, void *data) +{ + E_DBus_Connection *cd; + cd = data; + + DBG("cb_watch_add"); + e_dbus_connection_data_watch_add(cd, watch); + + return true; +} + +static void +cb_watch_del(DBusWatch *watch, void *data __UNUSED__) +{ + E_DBus_Handler_Data *hd; + + DBG("cb_watch_del"); + hd = (E_DBus_Handler_Data *)dbus_watch_get_data(watch); + + if (hd->fd_handler) + { + hd->cd->fd_handlers = eina_list_remove(hd->cd->fd_handlers, hd->cd->fd_handlers); + ecore_main_fd_handler_del(hd->fd_handler); + hd->fd_handler = NULL; + } +} + +static void +cb_watch_toggle(DBusWatch *watch, void *data __UNUSED__) +{ + E_DBus_Handler_Data *hd; + + DBG("cb_watch_toggle"); + hd = dbus_watch_get_data(watch); + + if (!hd) return; + + hd->enabled = dbus_watch_get_enabled(watch); + + if (hd->enabled) e_dbus_fd_handler_add(hd); +} + +static void +e_dbus_message_free(void *data __UNUSED__, void *message) +{ + dbus_message_unref(message); +} + +static DBusHandlerResult +e_dbus_filter(DBusConnection *conn __UNUSED__, DBusMessage *message, void *user_data) +{ + E_DBus_Connection *cd = user_data; + DBG("-----------------"); + DBG("Message!"); + + DBG("type: %s", dbus_message_type_to_string(dbus_message_get_type(message))); + DBG("path: %s", dbus_message_get_path(message)); + DBG("interface: %s", dbus_message_get_interface(message)); + DBG("member: %s", dbus_message_get_member(message)); + DBG("sender: %s", dbus_message_get_sender(message)); + + switch (dbus_message_get_type(message)) + { + case DBUS_MESSAGE_TYPE_METHOD_CALL: + DBG("signature: %s", dbus_message_get_signature(message)); + break; + case DBUS_MESSAGE_TYPE_METHOD_RETURN: + DBG("reply serial %d", dbus_message_get_reply_serial(message)); + break; + case DBUS_MESSAGE_TYPE_ERROR: + DBG("error: %s", dbus_message_get_error_name(message)); + break; + case DBUS_MESSAGE_TYPE_SIGNAL: + dbus_message_ref(message); + + if (cd->signal_dispatcher) + cd->signal_dispatcher(cd, message); + + ecore_event_add(E_DBUS_EVENT_SIGNAL, message, e_dbus_message_free, NULL); + /* don't need to handle signals, they're for everyone who wants them */ + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + break; + default: + break; + } + DBG("-----------------"); + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +int e_dbus_idler_active = 0; + +static int +e_dbus_idler(void *data) +{ + E_DBus_Connection *cd; + cd = data; + + if (DBUS_DISPATCH_COMPLETE == dbus_connection_get_dispatch_status(cd->conn)) + { + DBG("done dispatching!"); + cd->idler = NULL; + return 0; + } + e_dbus_idler_active++; + dbus_connection_ref(cd->conn); + DBG("dispatch!"); + dbus_connection_dispatch(cd->conn); + dbus_connection_unref(cd->conn); + e_dbus_idler_active--; + e_dbus_signal_handlers_clean(cd); + if (!e_dbus_idler_active && close_connection) + { + do + { + e_dbus_connection_close(cd); + } while (--close_connection); + } + return 1; +} + +/** + * Retrieve a connection to the bus and integrate it with the ecore main loop. + * @param type the type of bus to connect to, e.g. DBUS_BUS_SYSTEM or DBUS_BUS_SESSION + */ +EAPI E_DBus_Connection * +e_dbus_bus_get(DBusBusType type) +{ + DBusError err; + E_DBus_Connection *econn; + DBusConnection *conn; + + /* each app only needs a single connection to either bus */ + if (type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION) + { + if (shared_connections[type]) + { + e_dbus_connection_ref(shared_connections[type]); + return shared_connections[type]; + } + } + + dbus_error_init(&err); + + conn = dbus_bus_get_private(type, &err); + if (dbus_error_is_set(&err)) + { + ERR("Error connecting to bus: %s", err.message); + dbus_error_free(&err); + return NULL; + } + + econn = e_dbus_connection_setup(conn); + if (!econn) + { + ERR("Error setting up dbus connection."); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return NULL; + } + + if (type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION) + { + econn->shared_type = type; + shared_connections[type] = econn; + } + dbus_error_free(&err); + e_dbus_connection_ref(econn); + return econn; +} + +/** + * Integrate a DBus connection with the ecore main loop + * + * @param conn - a dbus connection + */ +EAPI E_DBus_Connection * +e_dbus_connection_setup(DBusConnection *conn) +{ + E_DBus_Connection *cd; + + cd = e_dbus_connection_new(conn); + if (!cd) return NULL; + + /* connection_setup */ + dbus_connection_set_exit_on_disconnect(cd->conn, EINA_FALSE); + dbus_connection_allocate_data_slot(&connection_slot); + + dbus_connection_set_data(cd->conn, connection_slot, (void *)cd, e_dbus_connection_free); + dbus_connection_set_watch_functions(cd->conn, + cb_watch_add, + cb_watch_del, + cb_watch_toggle, + cd, + NULL); + + dbus_connection_set_timeout_functions(cd->conn, + cb_timeout_add, + cb_timeout_del, + cb_timeout_toggle, + cd, + NULL); + + dbus_connection_set_wakeup_main_function(cd->conn, cb_main_wakeup, cd, NULL); + dbus_connection_set_dispatch_status_function(cd->conn, cb_dispatch_status, cd, NULL); + dbus_connection_add_filter(cd->conn, e_dbus_filter, cd, NULL); + + cb_dispatch_status(cd->conn, dbus_connection_get_dispatch_status(cd->conn), cd); + + return cd; +} + + +/** + * Close out a connection retrieved with e_dbus_bus_get() + * @param conn the connection to close + */ +EAPI void +e_dbus_connection_close(E_DBus_Connection *conn) +{ + DBG("e_dbus_connection_close"); + + if (e_dbus_idler_active) + { + close_connection++; + return; + } + if (--(conn->refcount) != 0) return; + + dbus_connection_free_data_slot(&connection_slot); + dbus_connection_remove_filter(conn->conn, e_dbus_filter, conn); + dbus_connection_set_watch_functions (conn->conn, + NULL, + NULL, + NULL, + NULL, NULL); + + dbus_connection_set_timeout_functions (conn->conn, + NULL, + NULL, + NULL, + NULL, NULL); + + dbus_connection_set_dispatch_status_function (conn->conn, NULL, NULL, NULL); + + /* Idler functin must be cancelled when dbus connection is unreferenced */ + if (conn->idler) + { + ecore_idler_del(conn->idler); + conn->idler = NULL; + } + + dbus_connection_close(conn->conn); + dbus_connection_unref(conn->conn); + + // Note: the E_DBus_Connection gets freed when the dbus_connection is cleaned up by the previous unref +} + +EAPI void +e_dbus_connection_ref(E_DBus_Connection *conn) +{ + conn->refcount++; +} + +DBusConnection * +e_dbus_connection_dbus_connection_get(E_DBus_Connection *conn) +{ + return conn->conn; +} + +/** + * @brief Initialize e_dbus + */ +EAPI int +e_dbus_init(void) +{ + if (++_edbus_init_count != 1) + return _edbus_init_count; + + /** + * eina initialization + */ + + if (!eina_init()) + { + fprintf(stderr,"E-dbus: Enable to initialize the eina module"); + return --_edbus_init_count; + } + + _e_dbus_log_dom = eina_log_domain_register("e_dbus", E_DBUS_COLOR_DEFAULT); + if (_e_dbus_log_dom < 0) + { + EINA_LOG_ERR("Enable to create a 'e_dbus' log domain"); + eina_shutdown(); + return --_edbus_init_count; + } + + E_DBUS_EVENT_SIGNAL = ecore_event_type_new(); + e_dbus_object_init(); + + return _edbus_init_count; +} + +/** + * Shutdown e_dbus. + */ +EAPI int +e_dbus_shutdown(void) +{ + if (--_edbus_init_count) + return _edbus_init_count; + + e_dbus_object_shutdown(); + eina_log_domain_unregister(_e_dbus_log_dom); + _e_dbus_log_dom = -1; + eina_shutdown(); + + return _edbus_init_count; +} diff --git a/src/lib/dbus/e_dbus_interfaces.c b/src/lib/dbus/e_dbus_interfaces.c new file mode 100644 index 0000000..5cdb749 --- /dev/null +++ b/src/lib/dbus/e_dbus_interfaces.c @@ -0,0 +1,207 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "e_dbus_private.h" + +/** + * This file contains wrappers around the standard interfaces that + * objects on the bus should implement. + */ + +static inline DBusPendingCall * +_dbus_peer_call(E_DBus_Connection *conn, const char *method_name, const char *destination, const char *path, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = dbus_message_new_method_call + (destination, path, "org.freedesktop.DBus.Peer", method_name); + if (!msg) + { + ERR("E-dbus Error: failed to create message for method call: %s() at " + "\"%s\" at \"%s\"", + method_name, destination, path); + return NULL; + } + + ret = e_dbus_message_send(conn, msg, cb_return, -1, (void *)data); + dbus_message_unref(msg); + + if (!ret) + ERR("E-dbus Error: could not %s() \"%s\" at \"%s\".", + method_name, destination, path); + + return ret; +} + +/** + * Ping the dbus peer + * + * @param conn the dbus connection + * @param destination the bus name that the object is on + * @param path the object path + * @param cb_return a callback for a successful return + * @param data data to pass to the callbacks + */ +EAPI DBusPendingCall * +e_dbus_peer_ping(E_DBus_Connection *conn, const char *destination, const char *path, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + return _dbus_peer_call(conn, "Ping", destination, path, cb_return, data); +} + +/** + * Get the UUID of the peer + * + * @param conn the dbus connection + * @param destination the bus name that the object is on + * @param path the object path + * @param cb_return a callback for a successful return + * @param data data to pass to the callbacks + */ +EAPI DBusPendingCall * +e_dbus_peer_get_machine_id(E_DBus_Connection *conn, const char *destination, const char *path, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + return _dbus_peer_call(conn, "GetMachineId", destination, path, cb_return, data); +} + +static inline DBusMessage * +_dbus_message_property_method_call(E_DBus_Connection *conn, const char *method_name, const char *destination, const char *path, const char *interface, const char *property) +{ + DBusMessage *msg; + + if (!conn) + { + ERR("E-dbus Error: no connection for call of %s", method_name); + return NULL; + } + + msg = dbus_message_new_method_call + (destination, path, "org.freedesktop.DBus.Properties", method_name); + if (!msg) + { + ERR("E-dbus Error: failed to create message for method call: %s() at " + "\"%s\" at \"%s\"", + method_name, destination, path); + return NULL; + } + + if (property) + { + dbus_message_append_args(msg, DBUS_TYPE_STRING, &interface, + DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID); + } + else + { + dbus_message_append_args(msg, DBUS_TYPE_STRING, &interface, DBUS_TYPE_INVALID); + } + + return msg; +} + +EAPI DBusPendingCall * +e_dbus_properties_get_all(E_DBus_Connection *conn, const char *destination, const char *path, const char *interface, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = _dbus_message_property_method_call + (conn, "GetAll", destination, path, interface, NULL); + if (!msg) + return NULL; + ret = e_dbus_message_send(conn, msg, cb_return, -1, (void *)data); + dbus_message_unref(msg); + + if (!ret) + ERR("ERROR: failed to call GetAll() at \"%s\" at \"%s\"", + destination, path); + + return ret; +} + +/** + * Get the value of a property on an object + * + * @param conn the dbus connection + * @param destination the bus name that the object is on + * @param path the object path + * @param interface the interface name of the property + * @param property the name of the property + * @param cb_return a callback for a successful return + * @param data data to pass to the callbacks + */ +EAPI DBusPendingCall * +e_dbus_properties_get(E_DBus_Connection *conn, const char *destination, const char *path, const char *interface, const char *property, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = _dbus_message_property_method_call + (conn, "Get", destination, path, interface, property); + if (!msg) + return NULL; + ret = e_dbus_message_send(conn, msg, cb_return, -1, (void *)data); + dbus_message_unref(msg); + + if (!ret) + ERR("E-dbus Error: failed to call Get() at \"%s\" at \"%s\"", + destination, path); + + return ret; +} + +/** + * Set the value of a property on an object + * + * @param conn the dbus connection + * @param destination the bus name that the object is on + * @param path the object path + * @param interface the interface name of the property + * @param property the name of the property + * @param value_type the type of the property's value + * @param value a pointer to the value + * @param cb_return a callback for a successful return + * @param data data to pass to the callbacks + */ +EAPI DBusPendingCall * +e_dbus_properties_set(E_DBus_Connection *conn, const char *destination, const char *path, const char *interface, const char *property, int value_type, const void *value, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + DBusMessage *msg; + DBusMessageIter iter, sub; + DBusError err; + DBusPendingCall *ret; + char sig[2]; + + if (!dbus_type_is_basic(value_type)) + { + if (cb_return) + { + dbus_error_init(&err); + dbus_set_error(&err, "org.enlightenment.DBus.InvalidType", "Only basic types may be set using e_dbus_properties_set()"); + cb_return((void *)data, NULL, &err); + + } + return NULL; + } + + msg = _dbus_message_property_method_call + (conn, "Set", destination, path, interface, property); + if (!msg) + return NULL; + + dbus_message_iter_init_append(msg, &iter); + sig[0] = value_type; + sig[1] = 0; + dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, sig, &sub); + dbus_message_iter_append_basic(&sub, value_type, value); + dbus_message_iter_close_container(&iter, &sub); + + ret = e_dbus_message_send(conn, msg, cb_return, -1, (void *)data); + dbus_message_unref(msg); + + if (!ret) + ERR("E-dbus Error: failed to call Set() at \"%s\" at \"%s\"", + destination, path); + + return ret; +} diff --git a/src/lib/dbus/e_dbus_message.c b/src/lib/dbus/e_dbus_message.c new file mode 100644 index 0000000..9331996 --- /dev/null +++ b/src/lib/dbus/e_dbus_message.c @@ -0,0 +1,124 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "e_dbus_private.h" + +typedef struct E_DBus_Pending_Call_Data E_DBus_Pending_Call_Data; +struct E_DBus_Pending_Call_Data +{ + E_DBus_Method_Return_Cb cb_return; + void *data; +}; + +static void +cb_pending(DBusPendingCall *pending, void *user_data) +{ + DBusMessage *msg; + DBusError err; + E_DBus_Pending_Call_Data *data = user_data; + + if (!dbus_pending_call_get_completed(pending)) + { + INFO("E-dbus: NOT COMPLETED"); + free(data); + dbus_pending_call_unref(pending); + return; + } + + dbus_error_init(&err); + msg = dbus_pending_call_steal_reply(pending); + if (!msg) + { + if (data->cb_return) + { + dbus_set_error(&err, "org.enlightenment.DBus.NoReply", "There was no reply to this method call."); + data->cb_return(data->data, NULL, &err); + dbus_error_free(&err); + } + return; + } + + if (dbus_set_error_from_message(&err, msg)) + { + if (data->cb_return) + data->cb_return(data->data, NULL, &err); + dbus_error_free(&err); + } + else + { + if (data->cb_return) + data->cb_return(data->data, msg, &err); + } + + dbus_message_unref(msg); + dbus_pending_call_unref(pending); +} + + +/** + * @brief Send a DBus message with callbacks + * @param conn The DBus connection + * @param msg The message to send + * @param cb_return A callback function for returns (only used if @a msg is a method-call) + * @param timeout A timeout in milliseconds, after which a synthetic error will be generated + * @return a DBusPendingCall that can be used to cancel the current call + */ +EAPI DBusPendingCall * +e_dbus_message_send(E_DBus_Connection *conn, DBusMessage *msg, E_DBus_Method_Return_Cb cb_return, int timeout, void *data) +{ + DBusPendingCall *pending; + + if (!dbus_connection_send_with_reply(conn->conn, msg, &pending, timeout)) + return NULL; + + if (cb_return && pending) + { + E_DBus_Pending_Call_Data *pdata; + + pdata = malloc(sizeof(E_DBus_Pending_Call_Data)); + pdata->cb_return = cb_return; + pdata->data = data; + + if (!dbus_pending_call_set_notify(pending, cb_pending, pdata, free)) + { + free(pdata); + dbus_message_unref(msg); + dbus_pending_call_cancel(pending); + return NULL; + } + } + + return pending; +} + +static void +cb_method_call(void *data, DBusMessage *msg, DBusError *err) +{ + E_DBus_Callback *cb = data; + void *method_return = NULL; + DBusError new_err; + if (!cb) return; + + dbus_error_init(&new_err); + if (!dbus_error_is_set(err)) + method_return = e_dbus_callback_unmarshal(cb, msg, &new_err); + else + dbus_move_error(err, &new_err); + + e_dbus_callback_call(cb, method_return, &new_err); + e_dbus_callback_return_free(cb, method_return); + + if (dbus_error_is_set(&new_err)) + dbus_error_free(&new_err); + + e_dbus_callback_free(cb); +} + +EAPI DBusPendingCall * +e_dbus_method_call_send(E_DBus_Connection *conn, DBusMessage *msg, E_DBus_Unmarshal_Func unmarshal_func, E_DBus_Callback_Func cb_func, E_DBus_Free_Func free_func, int timeout, void *data) +{ + E_DBus_Callback *cb; + cb = e_dbus_callback_new(cb_func, unmarshal_func, free_func, data); + return e_dbus_message_send(conn, msg, cb_method_call, timeout, cb); +} diff --git a/src/lib/dbus/e_dbus_methods.c b/src/lib/dbus/e_dbus_methods.c new file mode 100644 index 0000000..636555e --- /dev/null +++ b/src/lib/dbus/e_dbus_methods.c @@ -0,0 +1,154 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "e_dbus_private.h" + +static inline DBusMessage * +_dbus_message_method_call(const char *method_name) +{ + DBusMessage *msg; + + msg = dbus_message_new_method_call + ("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", + method_name); + if (!msg) + ERR("E-dbus Error: failed to create message for method call: %s", + method_name); + return msg; +} + +static inline DBusPendingCall * +_dbus_call__void(E_DBus_Connection *conn, const const char *method_name, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + if (!conn) + { + ERR("E.dbus Error: no connection for call of %s", method_name); + return NULL; + } + + msg = _dbus_message_method_call(method_name); + if (!msg) + return NULL; + ret = e_dbus_message_send(conn, msg, cb_return, -1, (void *)data); + dbus_message_unref(msg); + + if (!ret) + ERR("E-dbus Error: failed to call %s()", method_name); + + return ret; +} + +static inline DBusPendingCall * +_dbus_call__str(E_DBus_Connection *conn, const const char *method_name, const char *str, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + if (!conn) + { + ERR("E-dbus Error: no connection for call of %s", method_name); + return NULL; + } + + msg = _dbus_message_method_call(method_name); + if (!msg) + return NULL; + dbus_message_append_args(msg, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); + ret = e_dbus_message_send(conn, msg, cb_return, -1, (void *)data); + dbus_message_unref(msg); + + if (!ret) + ERR("E-dbus Error: failed to call %s(\"%s\")", method_name, str); + + return ret; +} + +EAPI DBusPendingCall * +e_dbus_request_name(E_DBus_Connection *conn, const char *name, unsigned int flags, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + DBusPendingCall *ret; + DBusMessage *msg; + dbus_uint32_t u_flags; + + if (!conn) + { + ERR("E-dbus Error: no connection for call of RequestName"); + return NULL; + } + + u_flags = flags; + + msg = _dbus_message_method_call("RequestName"); + if (!msg) + return NULL; + dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); + ret = e_dbus_message_send(conn, msg, cb_return, -1, (void *)data); + dbus_message_unref(msg); + return ret; +} + +EAPI DBusPendingCall * +e_dbus_release_name(E_DBus_Connection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + return _dbus_call__str(conn, "ReleaseName", name, cb_return, data); +} + + +EAPI DBusPendingCall * +e_dbus_get_name_owner(E_DBus_Connection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + return _dbus_call__str(conn, "GetNameOwner", name, cb_return, data); +} + +EAPI DBusPendingCall * +e_dbus_list_names(E_DBus_Connection *conn, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + return _dbus_call__void(conn, "ListNames", cb_return, data); +} + + +EAPI DBusPendingCall * +e_dbus_list_activatable_names(E_DBus_Connection *conn, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + return _dbus_call__void(conn, "ListActivatableNames", cb_return, data); +} + +EAPI DBusPendingCall * +e_dbus_name_has_owner(E_DBus_Connection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + return _dbus_call__str(conn, "NameHasOwner", name, cb_return, data); +} + + +EAPI DBusPendingCall * +e_dbus_start_service_by_name(E_DBus_Connection *conn, const char *name, unsigned int flags, E_DBus_Method_Return_Cb cb_return, const void *data) +{ + const char method_name[] = "StartServiceByName"; + DBusMessage *msg; + DBusPendingCall *ret; + + if (!conn) + { + ERR("ERROR: no connection for call of %s", method_name); + return NULL; + } + + msg = _dbus_message_method_call(method_name); + if (!msg) + return NULL; + dbus_message_append_args(msg, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID); + ret = e_dbus_message_send(conn, msg, cb_return, -1, (void *)data); + dbus_message_unref(msg); + + if (!ret) + ERR("E-dbus Error: failed to call %s(\"%s\")", method_name, name); + + return ret; +} diff --git a/src/lib/dbus/e_dbus_object.c b/src/lib/dbus/e_dbus_object.c new file mode 100644 index 0000000..a2dc920 --- /dev/null +++ b/src/lib/dbus/e_dbus_object.c @@ -0,0 +1,717 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <string.h> + +#include "e_dbus_private.h" + +static E_DBus_Interface *introspectable_interface = NULL; +static E_DBus_Interface *properties_interface = NULL; + +typedef struct E_DBus_Method E_DBus_Method; +typedef struct E_DBus_Signal E_DBus_Signal; + +Eina_Strbuf * e_dbus_object_introspect(E_DBus_Object *obj); + +static void e_dbus_object_unregister(DBusConnection *conn, void *user_data); +static DBusHandlerResult e_dbus_object_handler(DBusConnection *conn, DBusMessage *message, void *user_data); + +static void e_dbus_interface_free(E_DBus_Interface *iface); + +static E_DBus_Method *e_dbus_method_new(const char *member, const char *signature, const char *reply_signature, E_DBus_Method_Cb func); +static void e_dbus_object_method_free(E_DBus_Method *m); + +static E_DBus_Signal *e_dbus_signal_new(const char *name, const char *signature); +static void e_dbus_object_signal_free(E_DBus_Signal *s); + +static void _introspect_indent_append(Eina_Strbuf *buf, int level); +static void _introspect_interface_append(Eina_Strbuf *buf, E_DBus_Interface *iface, int level); +static void _introspect_method_append(Eina_Strbuf *buf, E_DBus_Method *method, int level); +static void _introspect_signal_append(Eina_Strbuf *buf, E_DBus_Signal *signal, int level); +static void _introspect_arg_append(Eina_Strbuf *buf, const char *type, const char *direction, int level); + + +//static Eina_List *standard_methods = NULL; + + +static DBusObjectPathVTable vtable = { + e_dbus_object_unregister, + e_dbus_object_handler, + NULL, + NULL, + NULL, + NULL +}; + +struct E_DBus_Object +{ + E_DBus_Connection *conn; + char *path; + Eina_List *interfaces; + char *introspection_data; + int introspection_dirty; + + E_DBus_Object_Property_Get_Cb cb_property_get; + E_DBus_Object_Property_Set_Cb cb_property_set; + + void *data; +}; + +struct E_DBus_Interface +{ + char *name; + Eina_List *methods; + Eina_List *signals; + int refcount; +}; + +struct E_DBus_Method +{ + char *member; + char *signature; + char *reply_signature; + E_DBus_Method_Cb func; +}; + +struct E_DBus_Signal +{ + char *name; + char *signature; +}; + +static DBusMessage * +cb_introspect(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessage *ret; + Eina_Strbuf *buf; + + if (obj->introspection_dirty || !obj->introspection_data) + { + buf = e_dbus_object_introspect(obj); + if (!buf) + { + ret = dbus_message_new_error(msg, "org.enlightenment.NotIntrospectable", "This object does not provide introspection data"); + return ret; + } + + if (obj->introspection_data) free(obj->introspection_data); + obj->introspection_data = strdup(eina_strbuf_string_get(buf)); + eina_strbuf_free(buf); + } + //printf("XML: \n\n%s\n\n", obj->introspection_data); + ret = dbus_message_new_method_return(msg); + dbus_message_append_args(ret, DBUS_TYPE_STRING, &(obj->introspection_data), DBUS_TYPE_INVALID); + + return ret; +} + +static DBusMessage * +cb_properties_get(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessage *reply; + DBusMessageIter iter, sub; + DBusError err; + int type; + void *value; + char *property; + + dbus_error_init(&err); + dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) + { + return dbus_message_new_error(msg, err.name, err.message); + } + + obj->cb_property_get(obj, property, &type, &value); + if (type == DBUS_TYPE_INVALID) + { + return dbus_message_new_error_printf(msg, "org.enlightenment.DBus.InvalidProperty", "The property '%s' does not exist on this object.", property); + } + + if (dbus_type_is_basic(type)) + { + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(msg, &iter); + dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, e_dbus_basic_type_as_string(type), &sub); + dbus_message_iter_append_basic(&sub, type, &value); + dbus_message_iter_close_container(&iter, &sub); + return reply; + } + else + { + return dbus_message_new_error(msg, "org.enlightenment.DBus.UnsupportedType", "E_DBus currently only supports properties of a basic type."); + } +} + +static DBusMessage * +cb_properties_set(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter, sub; + int type; + void *value; + char *property; + + dbus_message_iter_init(msg, &iter); + dbus_message_iter_get_basic(&iter, &property); + dbus_message_iter_recurse(&iter, &sub); + type = dbus_message_iter_get_arg_type(&sub); + if (dbus_type_is_basic(type)) + { + dbus_message_iter_get_basic(&sub, &value); + if (obj->cb_property_set(obj, property, type, value)) + { + return dbus_message_new_method_return(msg); + } + else + { + return dbus_message_new_error_printf(msg, "org.enlightenment.DBus.InvalidProperty", "The property '%s' does not exist on this object.", property); + } + } + else + { + return dbus_message_new_error(msg, "org.enlightenment.DBus.UnsupportedType", "E_DBus currently only supports properties of a basic type."); + } + +} + +int +e_dbus_object_init(void) +{ + introspectable_interface = e_dbus_interface_new("org.freedesktop.DBus.Introspectable"); + properties_interface = e_dbus_interface_new("org.freedesktop.DBus.Properties"); + if (!introspectable_interface || !properties_interface) + { + if (introspectable_interface) e_dbus_interface_unref(introspectable_interface); + introspectable_interface = NULL; + if (properties_interface) e_dbus_interface_unref(properties_interface); + properties_interface = NULL; + return 0; + } + + e_dbus_interface_method_add(introspectable_interface, "Introspect", "", "s", cb_introspect); + e_dbus_interface_method_add(properties_interface, "Get", "s", "v", cb_properties_get); + e_dbus_interface_method_add(properties_interface, "Set", "sv", "", cb_properties_set); + return 1; +} + +void +e_dbus_object_shutdown(void) +{ + e_dbus_interface_unref(introspectable_interface); + introspectable_interface = NULL; + + e_dbus_interface_unref(properties_interface); + properties_interface = NULL; +} + +/** + * Add a dbus object. + * + * @param conn the connection on with the object should listen + * @param object_path a unique string identifying an object (e.g. org/enlightenment/WindowManager + * @param data custom data to set on the object (retrievable via + * e_dbus_object_data_get()) + */ +EAPI E_DBus_Object * +e_dbus_object_add(E_DBus_Connection *conn, const char *object_path, void *data) +{ + E_DBus_Object *obj; + + obj = calloc(1, sizeof(E_DBus_Object)); + if (!obj) return NULL; + + if (!dbus_connection_register_object_path(conn->conn, object_path, &vtable, obj)) + { + free(obj); + return NULL; + } + + obj->conn = conn; + e_dbus_connection_ref(conn); + obj->path = strdup(object_path); + obj->data = data; + obj->interfaces = NULL; + + e_dbus_object_interface_attach(obj, introspectable_interface); + + return obj; +} + +/** + * Free a dbus object + * + * @param obj the object to free + */ +EAPI void +e_dbus_object_free(E_DBus_Object *obj) +{ + E_DBus_Interface *iface; + + if (!obj) return; + + DBG("e_dbus_object_free (%s)", obj->path); + dbus_connection_unregister_object_path(obj->conn->conn, obj->path); + e_dbus_connection_close(obj->conn); + + if (obj->path) free(obj->path); + EINA_LIST_FREE(obj->interfaces, iface) + e_dbus_interface_unref(iface); + + if (obj->introspection_data) free(obj->introspection_data); + + free(obj); +} + +/** + * @brief Fetch the data pointer for a dbus object + * @param obj the dbus object + */ +EAPI void * +e_dbus_object_data_get(E_DBus_Object *obj) +{ + return obj->data; +} + +/** + * @brief Get the dbus connection of a dbus object + * @param obj the dbus object + */ +EAPI E_DBus_Connection * +e_dbus_object_conn_get(E_DBus_Object *obj) +{ + return obj->conn; +} + +/** + * @brief Get the path of a dbus object + * @param obj the dbus object + */ +EAPI const char * +e_dbus_object_path_get(E_DBus_Object *obj) +{ + return obj->path; +} + +/** + * @brief Get the interfaces of a dbus object + * @param obj the dbus object + */ +EAPI const Eina_List * +e_dbus_object_interfaces_get(E_DBus_Object *obj) +{ + return obj->interfaces; +} + +/** + * @brief Sets the callback to fetch properties from an object + * @param obj the object + * @param func the callback + */ +EAPI void +e_dbus_object_property_get_cb_set(E_DBus_Object *obj, E_DBus_Object_Property_Get_Cb func) +{ + obj->cb_property_get = func; +} + +/** + * @brief Sets the callback to set properties on an object + * @param obj the object + * @param func the callback + */ +EAPI void +e_dbus_object_property_set_cb_set(E_DBus_Object *obj, E_DBus_Object_Property_Set_Cb func) +{ + obj->cb_property_set = func; +} + +EAPI void +e_dbus_object_interface_attach(E_DBus_Object *obj, E_DBus_Interface *iface) +{ + e_dbus_interface_ref(iface); + obj->interfaces = eina_list_append(obj->interfaces, iface); + obj->introspection_dirty = 1; + DBG("e_dbus_object_interface_attach (%s, %s) ", obj->path, iface->name); +} + +EAPI void +e_dbus_object_interface_detach(E_DBus_Object *obj, E_DBus_Interface *iface) +{ + E_DBus_Interface *found; + + DBG("e_dbus_object_interface_detach (%s, %s) ", obj->path, iface->name); + found = eina_list_data_find(obj->interfaces, iface); + if (found == NULL) return; + + obj->interfaces = eina_list_remove(obj->interfaces, iface); + obj->introspection_dirty = 1; + e_dbus_interface_unref(iface); +} + +EAPI void +e_dbus_interface_ref(E_DBus_Interface *iface) +{ + iface->refcount++; + DBG("e_dbus_interface_ref (%s) = %d", iface->name, iface->refcount); +} + +EAPI void +e_dbus_interface_unref(E_DBus_Interface *iface) +{ + DBG("e_dbus_interface_unref (%s) = %d", iface->name, iface->refcount - 1); + if (--(iface->refcount) == 0) + e_dbus_interface_free(iface); +} + +static void +e_dbus_interface_free(E_DBus_Interface *iface) +{ + E_DBus_Method *m; + E_DBus_Signal *s; + + if (iface->name) free(iface->name); + EINA_LIST_FREE(iface->methods, m) + e_dbus_object_method_free(m); + EINA_LIST_FREE(iface->signals, s) + e_dbus_object_signal_free(s); + free(iface); +} + + +/** + * Add a method to an object + * + * @param iface the E_DBus_Interface to which this method belongs + * @param member the name of the method + * @param signature an optional message signature. if provided, then messages + * with invalid signatures will be automatically rejected + * (an Error response will be sent) and introspection data + * will be available. + * + * @return 1 if successful, 0 if failed (e.g. no memory) + */ +EAPI int +e_dbus_interface_method_add(E_DBus_Interface *iface, const char *member, const char *signature, const char *reply_signature, E_DBus_Method_Cb func) +{ + E_DBus_Method *m; + + m = e_dbus_method_new(member, signature, reply_signature, func); + DBG("E-dbus: Add method %s: %p", member, m); + if (!m) return 0; + + iface->methods = eina_list_append(iface->methods, m); + return 1; +} + +/** + * Add a signal to an object + * + * @param iface the E_DBus_Interface to which this signal belongs + * @param name the name of the signal + * @param signature an optional message signature. + * + * @return 1 if successful, 0 if failed (e.g. no memory) + */ +EAPI int +e_dbus_interface_signal_add(E_DBus_Interface *iface, const char *name, const char *signature) +{ + E_DBus_Signal *s; + + s = e_dbus_signal_new(name, signature); + DBG("E-dbus: Add signal %s: %p", name, s); + if (!s) return 0; + + iface->signals = eina_list_append(iface->signals, s); + return 1; +} + +EAPI E_DBus_Interface * +e_dbus_interface_new(const char *interface) +{ + E_DBus_Interface *iface; + + if (!interface) return NULL; + + iface = calloc(1, sizeof(E_DBus_Interface)); + if (!iface) return NULL; + + iface->refcount = 1; + iface->name = strdup(interface); + iface->methods = NULL; + iface->signals = NULL; + + return iface; +} + +static E_DBus_Method * +e_dbus_method_new(const char *member, const char *signature, const char *reply_signature, E_DBus_Method_Cb func) +{ + E_DBus_Method *m; + + if (!member || !func) return NULL; + + if (signature && !dbus_signature_validate(signature, NULL)) return NULL; + if (reply_signature && !dbus_signature_validate(reply_signature, NULL)) return NULL; + m = calloc(1, sizeof(E_DBus_Method)); + if (!m) return NULL; + + m->member = strdup(member); + if (signature) + m->signature = strdup(signature); + if (reply_signature) + m->reply_signature = strdup(reply_signature); + m->func = func; + + return m; +} + +static void +e_dbus_object_method_free(E_DBus_Method *m) +{ + if (!m) return; + if (m->member) free(m->member); + if (m->signature) free(m->signature); + if (m->reply_signature) free(m->reply_signature); + + free(m); +} + +static E_DBus_Signal * +e_dbus_signal_new(const char *name, const char *signature) +{ + E_DBus_Signal *s; + + if (!name) return NULL; + + if (signature && !dbus_signature_validate(signature, NULL)) return NULL; + s = calloc(1, sizeof(E_DBus_Signal)); + if (!s) return NULL; + + s->name = strdup(name); + if (signature) + s->signature = strdup(signature); + + return s; +} + +static void +e_dbus_object_signal_free(E_DBus_Signal *s) +{ + if (!s) return; + if (s->name) free(s->name); + if (s->signature) free(s->signature); + free(s); +} + +static E_DBus_Method * +e_dbus_object_method_find(E_DBus_Object *obj, const char *interface, const char *member) +{ + E_DBus_Method *m; + E_DBus_Interface *iface; + Eina_List *l, *ll; + + if (!obj || !member) return NULL; + + EINA_LIST_FOREACH(obj->interfaces, l, iface) + { + if (strcmp(interface, iface->name)) continue; + EINA_LIST_FOREACH(iface->methods, ll, m) + { + if (!strcmp(member, m->member)) + return m; + } + } + return NULL; +} + +static DBusHandlerResult +e_dbus_object_handler(DBusConnection *conn, DBusMessage *message, void *user_data) +{ + E_DBus_Object *obj; + E_DBus_Method *m; + DBusMessage *reply; + dbus_uint32_t serial; + + obj = user_data; + if (!obj) + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + m = e_dbus_object_method_find(obj, dbus_message_get_interface(message), dbus_message_get_member(message)); + + /* XXX should this send an 'invalid method' error instead? */ + if (!m) + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + if (m->signature && !dbus_message_has_signature(message, m->signature)) + reply = dbus_message_new_error_printf(message, "org.enlightenment.InvalidSignature", "Expected signature: %s", m->signature); + else + reply = m->func(obj, message); + + /* user can choose reply later */ + if (!reply) + return DBUS_HANDLER_RESULT_HANDLED; + + dbus_connection_send(conn, reply, &serial); + dbus_message_unref(reply); + + return DBUS_HANDLER_RESULT_HANDLED; +} + +static void +e_dbus_object_unregister(DBusConnection *conn __UNUSED__, void *user_data __UNUSED__) +{ + /* free up the object struct? */ +} + +Eina_Strbuf * +e_dbus_object_introspect(E_DBus_Object *obj) +{ + Eina_Strbuf *buf; + int level = 0; + E_DBus_Interface *iface; + Eina_List *l; + + buf = eina_strbuf_new(); + + /* Doctype */ + eina_strbuf_append(buf, "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n \"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"); + + eina_strbuf_append(buf, "<node name=\""); + eina_strbuf_append(buf, obj->path); + eina_strbuf_append(buf, "\">\n"); + level++; + + EINA_LIST_FOREACH(obj->interfaces, l, iface) + _introspect_interface_append(buf, iface, level); + + eina_strbuf_append(buf, "</node>\n"); + return buf; +} + +static void +_introspect_indent_append(Eina_Strbuf *buf, int level) +{ + /* XXX optimize this? */ + int i = level * 2; + while (i-- > 0) + eina_strbuf_append_char(buf, ' '); +} +static void +_introspect_interface_append(Eina_Strbuf *buf, E_DBus_Interface *iface, int level) +{ + E_DBus_Method *method; + E_DBus_Signal *signal; + Eina_List *l; + + _introspect_indent_append(buf, level); + eina_strbuf_append(buf, "<interface name=\""); + eina_strbuf_append(buf, iface->name); + eina_strbuf_append(buf, "\">\n"); + level++; + + DBG("introspect iface: %s", iface->name); + EINA_LIST_FOREACH(iface->methods, l, method) + _introspect_method_append(buf, method, level); + EINA_LIST_FOREACH(iface->signals, l, signal) + _introspect_signal_append(buf, signal, level); + + level--; + _introspect_indent_append(buf, level); + eina_strbuf_append(buf, "</interface>\n"); +} +static void +_introspect_method_append(Eina_Strbuf *buf, E_DBus_Method *method, int level) +{ + DBusSignatureIter iter; + char *type; + + _introspect_indent_append(buf, level); + DBG("introspect method: %s\n", method->member); + eina_strbuf_append(buf, "<method name=\""); + eina_strbuf_append(buf, method->member); + eina_strbuf_append(buf, "\">\n"); + level++; + + /* append args */ + if (method->signature && + method->signature[0] && + dbus_signature_validate(method->signature, NULL)) + { + dbus_signature_iter_init(&iter, method->signature); + while ((type = dbus_signature_iter_get_signature(&iter))) + { + _introspect_arg_append(buf, type, "in", level); + + dbus_free(type); + if (!dbus_signature_iter_next(&iter)) break; + } + } + + /* append reply args */ + if (method->reply_signature && + method->reply_signature[0] && + dbus_signature_validate(method->reply_signature, NULL)) + { + dbus_signature_iter_init(&iter, method->reply_signature); + while ((type = dbus_signature_iter_get_signature(&iter))) + { + _introspect_arg_append(buf, type, "out", level); + + dbus_free(type); + if (!dbus_signature_iter_next(&iter)) break; + } + } + + level--; + _introspect_indent_append(buf, level); + eina_strbuf_append(buf, "</method>\n"); +} + +static void +_introspect_signal_append(Eina_Strbuf *buf, E_DBus_Signal *signal, int level) +{ + DBusSignatureIter iter; + char *type; + + _introspect_indent_append(buf, level); + DBG("introspect signal: %s", signal->name); + eina_strbuf_append(buf, "<signal name=\""); + eina_strbuf_append(buf, signal->name); + eina_strbuf_append(buf, "\">\n"); + level++; + + /* append args */ + if (signal->signature && + signal->signature[0] && + dbus_signature_validate(signal->signature, NULL)) + { + dbus_signature_iter_init(&iter, signal->signature); + while ((type = dbus_signature_iter_get_signature(&iter))) + { + _introspect_arg_append(buf, type, NULL, level); + + dbus_free(type); + if (!dbus_signature_iter_next(&iter)) break; + } + } + + level--; + _introspect_indent_append(buf, level); + eina_strbuf_append(buf, "</signal>\n"); +} + +static void +_introspect_arg_append(Eina_Strbuf *buf, const char *type, const char *direction, int level) +{ + _introspect_indent_append(buf, level); + eina_strbuf_append(buf, "<arg type=\""); + eina_strbuf_append(buf, type); + if (direction) + { + eina_strbuf_append(buf, "\" direction=\""); + eina_strbuf_append(buf, direction); + } + eina_strbuf_append(buf, "\"/>\n"); +} + diff --git a/src/lib/dbus/e_dbus_private.h b/src/lib/dbus/e_dbus_private.h new file mode 100644 index 0000000..93fce49 --- /dev/null +++ b/src/lib/dbus/e_dbus_private.h @@ -0,0 +1,53 @@ +#ifndef E_DBUS_PRIVATE_H +#define E_DBUS_PRIVATE_H + +#include <Ecore.h> + +#include "E_DBus.h" + +#ifndef E_DBUS_COLOR_DEFAULT +#define E_DBUS_COLOR_DEFAULT EINA_COLOR_CYAN +#endif +EAPI extern int _e_dbus_log_dom; +#define DBG(...) EINA_LOG_DOM_DBG(_e_dbus_log_dom, __VA_ARGS__) +#define INFO(...) EINA_LOG_DOM_INFO(_e_dbus_log_dom, __VA_ARGS__) +#define WARN(...) EINA_LOG_DOM_WARN(_e_dbus_log_dom, __VA_ARGS__) +#define ERR(...) EINA_LOG_DOM_ERR(_e_dbus_log_dom, __VA_ARGS__) + + +struct E_DBus_Connection +{ + DBusBusType shared_type; + DBusConnection *conn; + char *conn_name; + + Eina_List *fd_handlers; + Eina_List *timeouts; + Eina_List *signal_handlers; + void (*signal_dispatcher)(E_DBus_Connection *conn, DBusMessage *msg); + + Ecore_Idler *idler; + + int refcount; +}; + +struct E_DBus_Callback +{ + E_DBus_Callback_Func cb_func; + E_DBus_Unmarshal_Func unmarshal_func; + E_DBus_Free_Func free_func; + void *user_data; +}; + +int e_dbus_object_init(void); +void e_dbus_object_shutdown(void); + +extern int e_dbus_idler_active; +void e_dbus_signal_handlers_clean(E_DBus_Connection *conn); +void e_dbus_signal_handlers_free_all(E_DBus_Connection *conn); + + +const char *e_dbus_basic_type_as_string(int type); + + +#endif diff --git a/src/lib/dbus/e_dbus_signal.c b/src/lib/dbus/e_dbus_signal.c new file mode 100644 index 0000000..37d2f9b --- /dev/null +++ b/src/lib/dbus/e_dbus_signal.c @@ -0,0 +1,308 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <string.h> + +#include "e_dbus_private.h" + +struct E_DBus_Signal_Handler +{ + char *sender; + char *path; + char *interface; + char *member; + + E_DBus_Signal_Cb cb_signal; + DBusPendingCall *get_name_owner_pending; + void *data; + unsigned char delete_me : 1; +}; + +static void cb_signal_dispatcher(E_DBus_Connection *conn, DBusMessage *msg); + +/** + * Free a signal handler + * @param sh the signal handler to free + */ +static void +e_dbus_signal_handler_free(E_DBus_Signal_Handler *sh) +{ + if (sh->sender) free(sh->sender); + free(sh); +} + +struct cb_name_owner_data +{ + E_DBus_Connection *conn; + E_DBus_Signal_Handler *sh; +}; + +static void +cb_name_owner(void *data, DBusMessage *msg, DBusError *err) +{ + const char *unique_name = NULL; + struct cb_name_owner_data *d = data; + E_DBus_Signal_Handler *sh; + + sh = d->sh; + sh->get_name_owner_pending = NULL; + free(d); + + if (dbus_error_is_set(err)) + goto error; + + dbus_message_get_args(msg, err, DBUS_TYPE_STRING, &unique_name, DBUS_TYPE_INVALID); + + if (dbus_error_is_set(err)) + goto error; + +// if (!unique_name) +// goto error; + + if (sh->sender) free(sh->sender); + sh->sender = NULL; + if (unique_name) sh->sender = strdup(unique_name); + + return; + + error: + if (err) + ERR("Error: %s %s", err->name, err->message); +/* FIXME: this is bad. the handler gets silently freed and the caller has no + * idea that it was freed - or if, or when. + conn->signal_handlers = eina_list_remove(conn->signal_handlers, sh); + e_dbus_signal_handler_free(sh); + */ + dbus_error_free(err); +} + +static int +_match_append(char *buf, int size, int *used, const char *keyword, int keyword_size, const char *value, int value_size) +{ + if(value == NULL) + return 1; + + if (*used + keyword_size + value_size + sizeof(",=''") >= size) + { + ERR("cannot add match %s='%s': too long!", keyword, value); + return 0; + } + + buf += *used; + + *buf = ','; + buf++; + + memcpy(buf, keyword, keyword_size); + buf += keyword_size; + + *buf = '='; + buf++; + + *buf = '\''; + buf++; + + memcpy(buf, value, value_size); + buf += value_size; + + *buf = '\''; + buf++; + + *buf = '\0'; + + *used += keyword_size + value_size + sizeof(",=''") - 1; + + return 1; +} + +/** + * Add a signal handler + * + * @param conn the dbus connection + * @param bus name of the signal's sender + * @param path the object path of the signal's sender + * @param interface the signal's interface + * @param memeber the signal's name + * @param cb_signal a callback to call when the signal is received + * @param data custom data to pass in to the callback + */ +EAPI E_DBus_Signal_Handler * +e_dbus_signal_handler_add(E_DBus_Connection *conn, const char *sender, const char *path, const char *interface, const char *member, E_DBus_Signal_Cb cb_signal, void *data) +{ + E_DBus_Signal_Handler *sh; + char match[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; + int len, sender_len, path_len, interface_len, member_len; + DBusError err; + + strcpy(match, "type='signal'"); + len = sizeof("type='signal'") - 1; + +#define ADD_MATCH_PIECE(PIECE) \ + do { \ + PIECE ## _len = PIECE ? strlen(PIECE) : 0; \ + if (!_match_append(match, sizeof(match), &len, #PIECE, sizeof(#PIECE) - 1, PIECE, PIECE ## _len)) \ + return NULL; \ + } while (0) + + ADD_MATCH_PIECE(sender); + ADD_MATCH_PIECE(path); + ADD_MATCH_PIECE(interface); + ADD_MATCH_PIECE(member); +#undef ADD_MATCH_PIECE + + len = path_len + interface_len + member_len + 4; + sh = malloc(sizeof(*sh) + len); + if (!sh) + { + ERR("could not allocate signal handler."); + return NULL; + } + + len = sizeof(*sh); + +#define SET_STRING(PIECE) \ + do { \ + sh->PIECE = ((char *)sh) + len; \ + if (PIECE) \ + memcpy(sh->PIECE, PIECE, PIECE ## _len + 1); \ + else \ + sh->PIECE = NULL; \ + len += PIECE ## _len + 1; \ + } while (0) + + SET_STRING(path); + SET_STRING(interface); + SET_STRING(member); +#undef SET_STRING + + if (sender) + sh->sender = strdup(sender); + else + sh->sender = NULL; + + sh->cb_signal = cb_signal; + sh->get_name_owner_pending = NULL; + sh->data = data; + sh->delete_me = 0; + + dbus_error_init(&err); + dbus_bus_add_match(conn->conn, match, NULL); + + if (!conn->signal_handlers) + { + conn->signal_handlers = NULL; + conn->signal_dispatcher = cb_signal_dispatcher; + } + + /* if we have a sender, and it is not a unique name, we need to know the unique name to match since signals will have the name owner as ther sender. */ + if (sender && sender[0] != ':') + { + struct cb_name_owner_data *data; + data = malloc(sizeof(*data)); + if (!data) + { + e_dbus_signal_handler_free(sh); + return NULL; + } + data->conn = conn; + data->sh = sh; + sh->get_name_owner_pending = + e_dbus_get_name_owner(conn, sender, cb_name_owner, data); + } + + conn->signal_handlers = eina_list_append(conn->signal_handlers, sh); + return sh; +} + +static int e_dbus_handler_deletions = 0; + +/** + * Delete a signal handler + * + * @param conn the dbus connection + * @param sh the handler to delete + */ +EAPI void +e_dbus_signal_handler_del(E_DBus_Connection *conn, E_DBus_Signal_Handler *sh) +{ + char match[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; + int len, sender_len, path_len, interface_len, member_len; + + if (sh->get_name_owner_pending) + { + dbus_pending_call_cancel(sh->get_name_owner_pending); + sh->get_name_owner_pending = NULL; + } + sh->delete_me = 1; + if (e_dbus_idler_active) + { + e_dbus_handler_deletions = 1; + return; + } + + strcpy(match, "type='signal'"); + len = sizeof("type='signal'") - 1; + +#define ADD_MATCH_PIECE(PIECE) \ + do { \ + PIECE ## _len = sh->PIECE ? strlen(sh->PIECE) : 0; \ + if (!_match_append(match, sizeof(match), &len, #PIECE, sizeof(#PIECE) - 1, sh->PIECE, PIECE ## _len)) \ + return; \ + } while (0) + + ADD_MATCH_PIECE(sender); + ADD_MATCH_PIECE(path); + ADD_MATCH_PIECE(interface); + ADD_MATCH_PIECE(member); +#undef ADD_MATCH_PIECE + + dbus_bus_remove_match(conn->conn, match, NULL); + + if (!conn->signal_handlers) return; + conn->signal_handlers = eina_list_remove(conn->signal_handlers, sh); + e_dbus_signal_handler_free(sh); +} + +static void +cb_signal_dispatcher(E_DBus_Connection *conn, DBusMessage *msg) +{ + E_DBus_Signal_Handler *sh; + Eina_List *l; + + EINA_LIST_FOREACH(conn->signal_handlers, l, sh) + { + if ((!sh->cb_signal) || (sh->delete_me)) continue; + + if (sh->sender && !dbus_message_has_sender(msg, sh->sender)) continue; + if (sh->path && !dbus_message_has_path(msg, sh->path)) continue; + if (sh->interface && !dbus_message_has_interface(msg, sh->interface)) continue; + if (sh->member && !dbus_message_has_member(msg, sh->member)) continue; + + sh->cb_signal(sh->data, msg); + } +} + +void +e_dbus_signal_handlers_clean(E_DBus_Connection *conn) +{ + E_DBus_Signal_Handler *sh; + Eina_List *l, *l_next; + + if (!e_dbus_handler_deletions) return; + e_dbus_handler_deletions = 0; + if (!conn->signal_handlers) return; + EINA_LIST_FOREACH_SAFE(conn->signal_handlers, l, l_next, sh) + { + if (sh->delete_me) + e_dbus_signal_handler_del(conn, sh); + } +} + +void +e_dbus_signal_handlers_free_all(E_DBus_Connection *conn) +{ + E_DBus_Signal_Handler *sh; + EINA_LIST_FREE(conn->signal_handlers, sh) + e_dbus_signal_handler_free(sh); +} diff --git a/src/lib/dbus/e_dbus_util.c b/src/lib/dbus/e_dbus_util.c new file mode 100644 index 0000000..e03c02e --- /dev/null +++ b/src/lib/dbus/e_dbus_util.c @@ -0,0 +1,95 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "e_dbus_private.h" + +/** + * @internal + * @brief Create a callback structure + * @param cb_func the callback function + * @param user_data data to pass to the callback + */ +EAPI E_DBus_Callback * +e_dbus_callback_new(E_DBus_Callback_Func cb_func, E_DBus_Unmarshal_Func unmarshal_func, E_DBus_Free_Func free_func, void *user_data) +{ + E_DBus_Callback *cb; + + if (!cb_func) return NULL; + + cb = calloc(1, sizeof(E_DBus_Callback)); + if (!cb) return NULL; + cb->cb_func = cb_func; + cb->unmarshal_func = unmarshal_func; + cb->free_func = free_func; + cb->user_data = user_data; + return cb; +} + +/** + * @internal + * @brief Free a callback structure + * @param callback the callback to free + */ +EAPI void +e_dbus_callback_free(E_DBus_Callback *callback) +{ + free(callback); +} + +EAPI void +e_dbus_callback_call(E_DBus_Callback *cb, void *data, DBusError *error) +{ + if (cb && cb->cb_func) + cb->cb_func(cb->user_data, data, error); +} + +EAPI void * +e_dbus_callback_unmarshal(E_DBus_Callback *cb, DBusMessage *msg, DBusError *err) +{ + if (cb && cb->unmarshal_func) + return cb->unmarshal_func(msg, err); + else + return NULL; +} + +EAPI void +e_dbus_callback_return_free(E_DBus_Callback *cb, void *data) +{ + if (cb && cb->free_func) + cb->free_func(data); +} + +const char * +e_dbus_basic_type_as_string(int type) +{ + switch (type) + { + case DBUS_TYPE_BYTE: + return DBUS_TYPE_BYTE_AS_STRING; + case DBUS_TYPE_BOOLEAN: + return DBUS_TYPE_BOOLEAN_AS_STRING; + case DBUS_TYPE_INT16: + return DBUS_TYPE_INT16_AS_STRING; + case DBUS_TYPE_UINT16: + return DBUS_TYPE_UINT16_AS_STRING; + case DBUS_TYPE_INT32: + return DBUS_TYPE_INT32_AS_STRING; + case DBUS_TYPE_UINT32: + return DBUS_TYPE_UINT32_AS_STRING; + case DBUS_TYPE_INT64: + return DBUS_TYPE_INT64_AS_STRING; + case DBUS_TYPE_UINT64: + return DBUS_TYPE_UINT64_AS_STRING; + case DBUS_TYPE_DOUBLE: + return DBUS_TYPE_DOUBLE_AS_STRING; + case DBUS_TYPE_STRING: + return DBUS_TYPE_STRING_AS_STRING; + case DBUS_TYPE_OBJECT_PATH: + return DBUS_TYPE_OBJECT_PATH_AS_STRING; + case DBUS_TYPE_SIGNATURE: + return DBUS_TYPE_SIGNATURE_AS_STRING; + default: + return NULL; + } +} diff --git a/src/lib/hal/.cvsignore b/src/lib/hal/.cvsignore new file mode 100644 index 0000000..07d6b3d --- /dev/null +++ b/src/lib/hal/.cvsignore @@ -0,0 +1,8 @@ +.deps +Makefile +Makefile.in +.libs +e_hal_device.lo +e_hal_manager.lo +e_hal_util.lo +libehal.la diff --git a/src/lib/hal/E_Hal.h b/src/lib/hal/E_Hal.h new file mode 100644 index 0000000..39a77a4 --- /dev/null +++ b/src/lib/hal/E_Hal.h @@ -0,0 +1,137 @@ +#ifndef E_HAL_H +#define E_HAL_H +#include <E_DBus.h> + +#ifdef EAPI +#undef EAPI +#endif +#ifdef _MSC_VER +# ifdef BUILDING_DLL +# define EAPI __declspec(dllexport) +# else +# define EAPI __declspec(dllimport) +# endif +#else +# ifdef __GNUC__ +# if __GNUC__ >= 4 +# define EAPI __attribute__ ((visibility("default"))) +# else +# define EAPI +# endif +# else +# define EAPI +# endif +#endif + +#define E_HAL_SENDER "org.freedesktop.Hal" +#define E_HAL_MANAGER_PATH "/org/freedesktop/Hal/Manager" +#define E_HAL_MANAGER_INTERFACE "org.freedesktop.Hal.Manager" +#define E_HAL_DEVICE_INTERFACE "org.freedesktop.Hal.Device" +#define E_HAL_DEVICE_VOLUME_INTERFACE "org.freedesktop.Hal.Device.Volume" + +/* message return types */ + +typedef struct E_Hal_Property E_Hal_Property; +typedef struct E_Hal_Properties E_Hal_Properties; + +struct E_Hal_String_List_Return +{ + Eina_List *strings; /* list of const char * */ +}; + +struct E_Hal_Bool_Return +{ + Eina_Bool boolean; +}; + +struct E_Hal_UDI_Return +{ + const char *udi; +}; + +struct E_Hal_Capability +{ + const char *udi; + const char *capability; +}; + +typedef enum +{ + E_HAL_PROPERTY_TYPE_STRING, + E_HAL_PROPERTY_TYPE_INT, + E_HAL_PROPERTY_TYPE_UINT64, + E_HAL_PROPERTY_TYPE_BOOL, + E_HAL_PROPERTY_TYPE_DOUBLE, + E_HAL_PROPERTY_TYPE_STRLIST +} E_Hal_Property_Type; + +struct E_Hal_Property +{ + E_Hal_Property_Type type; + union + { + const char *s; + int i; + dbus_bool_t b; + double d; + dbus_uint64_t u64; + Eina_List *strlist; + } val; +}; + +struct E_Hal_Properties +{ + Eina_Hash *properties; +}; + +typedef struct E_Hal_Properties E_Hal_Device_Get_All_Properties_Return; +typedef struct E_Hal_Property E_Hal_Device_Get_Property_Return; +typedef struct E_Hal_Bool_Return E_Hal_Device_Query_Capability_Return; +typedef struct E_Hal_String_List_Return E_Hal_String_List_Return; +typedef struct E_Hal_String_List_Return E_Hal_Manager_Get_All_Devices_Return; +typedef struct E_Hal_Bool_Return E_Hal_Manager_Device_Exists_Return; +typedef struct E_Hal_String_List_Return E_Hal_Manager_Find_Device_String_Match_Return; +typedef struct E_Hal_String_List_Return E_Hal_Manager_Find_Device_By_Capability_Return; + + +typedef struct E_Hal_UDI_Return E_Hal_Manager_Device_Added; +typedef struct E_Hal_UDI_Return E_Hal_Manager_Device_Removed; +typedef struct E_Hal_Capability E_Hal_Manager_New_Capability; + +#ifdef __cplusplus +extern "C" { +#endif + + EAPI int e_hal_init(void); + EAPI int e_hal_shutdown(void); + +/* org.freedesktop.Hal.Device */ + EAPI DBusPendingCall *e_hal_device_get_property(E_DBus_Connection *conn, const char *udi, const char *property, E_DBus_Callback_Func cb_func, void *data); + EAPI DBusPendingCall *e_hal_device_get_all_properties(E_DBus_Connection *conn, const char *udi, E_DBus_Callback_Func cb_func, void *data); + EAPI DBusPendingCall *e_hal_device_query_capability(E_DBus_Connection *conn, const char *udi, const char *capability, E_DBus_Callback_Func cb_func, void *data); + +/* org.freedesktop.Hal.Manager */ + EAPI DBusPendingCall *e_hal_manager_get_all_devices(E_DBus_Connection *conn, E_DBus_Callback_Func cb_func, void *data); + EAPI DBusPendingCall *e_hal_manager_device_exists(E_DBus_Connection *conn, const char *udi, E_DBus_Callback_Func cb_func, void *data); + EAPI DBusPendingCall *e_hal_manager_find_device_string_match(E_DBus_Connection *conn, const char *key, const char *value, E_DBus_Callback_Func cb_func, void *data); + EAPI DBusPendingCall *e_hal_manager_find_device_by_capability(E_DBus_Connection *conn, const char *capability, E_DBus_Callback_Func cb_func, void *data); + +/* utility functions */ + EAPI void e_hal_property_free(E_Hal_Property *prop); + EAPI const char *e_hal_property_string_get(E_Hal_Properties *properties, const char *key, int *err); + EAPI Eina_Bool e_hal_property_bool_get(E_Hal_Properties *properties, const char *key, int *err); + EAPI int e_hal_property_int_get(E_Hal_Properties *properties, const char *key, int *err); + EAPI uint64_t e_hal_property_uint64_get(E_Hal_Properties *properties, const char *key, int *err); + EAPI double e_hal_property_double_get(E_Hal_Properties *properties, const char *key, int *err); + EAPI const Eina_List *e_hal_property_strlist_get(E_Hal_Properties *properties, const char *key, int *err); + +/* (un)mount */ + EAPI DBusPendingCall *e_hal_device_volume_mount(E_DBus_Connection *conn, const char *udi, const char *mount_point, const char *fstype, Eina_List *options, E_DBus_Callback_Func cb_func, void *data); + EAPI DBusPendingCall *e_hal_device_volume_unmount(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data); + EAPI DBusPendingCall *e_hal_device_volume_eject(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lib/hal/Makefile.am b/src/lib/hal/Makefile.am new file mode 100644 index 0000000..44729ab --- /dev/null +++ b/src/lib/hal/Makefile.am @@ -0,0 +1,27 @@ +MAINTAINERCLEANFILES = Makefile.in + +AM_CPPFLAGS = \ +-I $(top_srcdir)/src/lib/dbus \ +@EDBUS_CFLAGS@ @EINA_CFLAGS@ + +if BUILD_EHAL + +lib_LTLIBRARIES = libehal.la +include_HEADERS = E_Hal.h + +noinst_HEADERS = e_hal_private.h + +libehal_la_SOURCES = \ +E_Hal.h \ +e_hal_device.c \ +e_hal_manager.c \ +e_hal_util.c \ +e_hal_main.c + +libehal_la_LIBADD = \ +@EDBUS_LIBS@ \ +$(top_builddir)/src/lib/dbus/libedbus.la \ +@EINA_LIBS@ +libehal_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @ehal_release_info@ + +endif diff --git a/src/lib/hal/e_hal_device.c b/src/lib/hal/e_hal_device.c new file mode 100644 index 0000000..bf4f191 --- /dev/null +++ b/src/lib/hal/e_hal_device.c @@ -0,0 +1,364 @@ +#include <E_Hal.h> +#include "e_hal_private.h" + +#define e_hal_device_call_new(udi, member) dbus_message_new_method_call(E_HAL_SENDER, udi, E_HAL_DEVICE_INTERFACE, member) +#define e_hal_device_volume_call_new(udi, member) dbus_message_new_method_call(E_HAL_SENDER, udi, E_HAL_DEVICE_VOLUME_INTERFACE, member) + +#if 0 +static void cb_device_get_property(void *data, DBusMessage *msg, DBusError *err); +static void cb_device_get_all_properties(void *data, DBusMessage *msg, DBusError *err); +static void cb_device_query_capability(void *data, DBusMessage *msg, DBusError *err); +#endif + +/* Device.GetProperty */ +static void * +unmarshal_device_get_property(DBusMessage *msg, DBusError *err) +{ + E_Hal_Device_Get_Property_Return *ret = NULL; + DBusMessageIter iter; + int type; + const char *str; + + ret = calloc(1, sizeof(E_Hal_Device_Get_Property_Return)); + if (!ret) + { + dbus_set_error(err, DBUS_ERROR_NO_MEMORY, ""); + return NULL; + } + + dbus_message_iter_init(msg, &iter); + type = dbus_message_iter_get_arg_type(&iter); + switch(type) + { + case DBUS_TYPE_STRING: + ret->type = E_HAL_PROPERTY_TYPE_STRING; + dbus_message_iter_get_basic(&iter, &str); + ret->val.s = eina_stringshare_add(str); + break; + case DBUS_TYPE_INT32: + ret->type = E_HAL_PROPERTY_TYPE_INT; + dbus_message_iter_get_basic(&iter, &(ret->val.i)); + break; + case DBUS_TYPE_BOOLEAN: + ret->type = E_HAL_PROPERTY_TYPE_BOOL; + dbus_message_iter_get_basic(&iter, &(ret->val.b)); + break; + case DBUS_TYPE_DOUBLE: + ret->type = E_HAL_PROPERTY_TYPE_DOUBLE; + dbus_message_iter_get_basic(&iter, &(ret->val.d)); + break; + } + + return ret; +} + +static void +free_device_get_property(void *data) +{ + E_Hal_Device_Get_Property_Return *ret = data; + + if (!ret) return; + if (ret->type == E_HAL_PROPERTY_TYPE_STRLIST) + { + const char *str; + EINA_LIST_FREE(ret->val.strlist, str) + eina_stringshare_del(str); + } + else if (ret->type == E_HAL_PROPERTY_TYPE_STRING) + eina_stringshare_del(ret->val.s); + free(ret); +} + +EAPI DBusPendingCall * +e_hal_device_get_property(E_DBus_Connection *conn, const char *udi, const char *property, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_hal_device_call_new(udi, "GetProperty"); + dbus_message_append_args(msg, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID); + ret = e_dbus_method_call_send(conn, msg, unmarshal_device_get_property, cb_func, free_device_get_property, -1, data); + dbus_message_unref(msg); + return ret; +} + +/* Device.GetAllProperties */ + +static void * +unmarshal_device_get_all_properties(DBusMessage *msg, DBusError *err) +{ + E_Hal_Device_Get_All_Properties_Return *ret = NULL; + DBusMessageIter iter, a_iter, s_iter, v_iter; + + /* a{sv} = array of string+variant */ + if (!dbus_message_has_signature(msg, "a{sv}")) + { + dbus_set_error(err, DBUS_ERROR_INVALID_SIGNATURE, ""); + return NULL; + } + + ret = calloc(1, sizeof(E_Hal_Device_Get_All_Properties_Return)); + if (!ret) + { + dbus_set_error(err, DBUS_ERROR_NO_MEMORY, ""); + return NULL; + } + + ret->properties = eina_hash_string_small_new(EINA_FREE_CB(e_hal_property_free)); + + dbus_message_iter_init(msg, &iter); + dbus_message_iter_recurse(&iter, &a_iter); + while (dbus_message_iter_get_arg_type(&a_iter) != DBUS_TYPE_INVALID) + { + const char *name; + const char *str; + E_Hal_Property *prop = calloc(1, sizeof(E_Hal_Property)); + dbus_message_iter_recurse(&a_iter, &s_iter); + dbus_message_iter_get_basic(&s_iter, &name); + dbus_message_iter_next(&s_iter); + dbus_message_iter_recurse(&s_iter, &v_iter); + + switch(dbus_message_iter_get_arg_type(&v_iter)) + { + case DBUS_TYPE_STRING: + prop->type = E_HAL_PROPERTY_TYPE_STRING; + dbus_message_iter_get_basic(&v_iter, &str); + prop->val.s = eina_stringshare_add(str); + break; + case DBUS_TYPE_INT32: + prop->type = E_HAL_PROPERTY_TYPE_INT; + dbus_message_iter_get_basic(&v_iter, &(prop->val.i)); + break; + case DBUS_TYPE_UINT64: + prop->type = E_HAL_PROPERTY_TYPE_UINT64; + dbus_message_iter_get_basic(&v_iter, &(prop->val.u64)); + break; + case DBUS_TYPE_BOOLEAN: + prop->type = E_HAL_PROPERTY_TYPE_BOOL; + dbus_message_iter_get_basic(&v_iter, &(prop->val.b)); + break; + case DBUS_TYPE_DOUBLE: + prop->type = E_HAL_PROPERTY_TYPE_DOUBLE; + dbus_message_iter_get_basic(&v_iter, &(prop->val.d)); + break; + case DBUS_TYPE_ARRAY: + prop->type = E_HAL_PROPERTY_TYPE_STRLIST; + { + DBusMessageIter list_iter; + prop->val.strlist = NULL; + dbus_message_iter_recurse(&v_iter, &list_iter); + while (dbus_message_iter_get_arg_type(&list_iter) != DBUS_TYPE_INVALID) + { + dbus_message_iter_get_basic(&list_iter, &str); + prop->val.strlist = eina_list_append(prop->val.strlist, eina_stringshare_add(str)); + dbus_message_iter_next(&list_iter); + } + } + break; + default: + WARN("Ehal Error: unexpected property type (%s): %c", name, dbus_message_iter_get_arg_type(&v_iter)); + break; + } + eina_hash_add(ret->properties, name, prop); + + dbus_message_iter_next(&a_iter); + } + + return ret; +} + +static void +free_device_get_all_properties(void *data) +{ + E_Hal_Device_Get_All_Properties_Return *ret = data; + + if (!ret) return; + eina_hash_free(ret->properties); + free(ret); +} + +EAPI DBusPendingCall * +e_hal_device_get_all_properties(E_DBus_Connection *conn, const char *udi, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_hal_device_call_new(udi, "GetAllProperties"); + ret = e_dbus_method_call_send(conn, msg, unmarshal_device_get_all_properties, cb_func, free_device_get_all_properties, -1, data); + dbus_message_unref(msg); + return ret; +} + + + +/* bool Device.QueryCapability(string udi) */ + +// XXX this is same as Device_Exists in manager. +static void * +unmarshal_device_query_capability(DBusMessage *msg, DBusError *err) +{ + E_Hal_Device_Query_Capability_Return *ret = NULL; + dbus_bool_t val; + + ret = calloc(1, sizeof(E_Hal_Manager_Device_Exists_Return)); + if (!ret) + { + dbus_set_error(err, DBUS_ERROR_NO_MEMORY, ""); + return NULL; + } + + dbus_message_get_args(msg, err, DBUS_TYPE_BOOLEAN, &val, DBUS_TYPE_INVALID); + + if (dbus_error_is_set(err)) + { + free(ret); + return NULL; + } + + ret->boolean = val; + return ret; +} + +static void +free_device_query_capability(void *data) +{ + E_Hal_Device_Query_Capability_Return *ret = data; + + if (!ret) return; + free(ret); +} + +EAPI DBusPendingCall * +e_hal_device_query_capability(E_DBus_Connection *conn, const char *udi, const char *capability, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_hal_device_call_new(udi, "QueryCapability"); + dbus_message_append_args(msg, DBUS_TYPE_STRING, &capability, DBUS_TYPE_INVALID); + ret = e_dbus_method_call_send(conn, msg, unmarshal_device_query_capability, cb_func, free_device_query_capability, -1, data); + dbus_message_unref(msg); + return ret; +} + + + +/* void Device.Mount(string mount_point, string fstype, array{string}options) */ + +/** + * @brief Mount a Volume + * + * @param conn the E_DBus_Connection + * @param udi the udi of the device object + * @param mount_point the path to mount to, or null for default + * @param fstype the fstype of the device (e.g. volume.fstype property) + * @param options a list of additional options (not sure... fstype dependant?) + * @param cb_func an optional callback to call when the mount is done + * @param data custom data pointer for the callback function + */ +EAPI DBusPendingCall * +e_hal_device_volume_mount(E_DBus_Connection *conn, const char *udi, const char *mount_point, const char *fstype, Eina_List *options, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusMessageIter iter, subiter; + Eina_List *l; + DBusPendingCall *ret; + + msg = e_hal_device_volume_call_new(udi, "Mount"); + + dbus_message_iter_init_append(msg, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &mount_point); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &fstype); + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); + + if (options) + { + const char *opt; + + EINA_LIST_FOREACH(options, l, opt) + { + dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt); + } + } + dbus_message_iter_close_container(&iter, &subiter) ; + + ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data); + dbus_message_unref(msg); + return ret; +} + +/* void Unmount(array{string} options) */ + +/** + * @brief Unmount a Volume + * + * @param conn the E_DBus_Connection + * @param udi the udi of the device object + * @param options a list of additional options (not sure... fstype dependant?) + * @param cb_func an optional callback to call when the unmount is done + * @param data cuatom data pointer for the callback function + */ +EAPI DBusPendingCall * +e_hal_device_volume_unmount(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusMessageIter iter, subiter; + Eina_List *l; + DBusPendingCall *ret; + + msg = e_hal_device_volume_call_new(udi, "Unmount"); + + dbus_message_iter_init_append(msg, &iter); + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); + if (options) + { + const char *opt; + + EINA_LIST_FOREACH(options, l, opt) + { + dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt); + } + } + dbus_message_iter_close_container(&iter, &subiter) ; + + ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data); + dbus_message_unref(msg); + return ret; +} + +/** + * @brief Eject a Volume + * + * @param conn the E_DBus_Connection + * @param udi the udi of the device object + * @param options a list of additional options (not sure... fstype dependant?) + * @param cb_func an optional callback to call when the eject is done + * @param data cuatom data pointer for the callback function + */ +EAPI DBusPendingCall * +e_hal_device_volume_eject(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusMessageIter iter, subiter; + Eina_List *l; + DBusPendingCall *ret; + + msg = e_hal_device_volume_call_new(udi, "Eject"); + + dbus_message_iter_init_append(msg, &iter); + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); + if (options) + { + const char *opt; + + EINA_LIST_FOREACH(options, l, opt) + { + dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt); + } + } + dbus_message_iter_close_container(&iter, &subiter) ; + + ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data); + dbus_message_unref(msg); + return ret; +} diff --git a/src/lib/hal/e_hal_device.h b/src/lib/hal/e_hal_device.h new file mode 100644 index 0000000..3fc478a --- /dev/null +++ b/src/lib/hal/e_hal_device.h @@ -0,0 +1,14 @@ +#ifndef E_HAL_DEVICE_H +#define E_HAL_DEVICE_H + +#include "E_Hal.h" + +typedef struct E_Hal_Properties E_Hal_Device_Get_All_Properties_Return; +typedef struct E_Hal_Property E_Hal_Device_Get_Property_Return; +typedef struct E_Hal_Bool_Return E_Hal_Device_Query_Capability_Return; + +int e_hal_device_get_property(E_DBus_Connection *conn, const char *udi, const char *property, E_Hal_Callback_Func cb_func, void *data); +int e_hal_device_get_all_properties(E_DBus_Connection *conn, const char *udi, E_Hal_Callback_Func cb_func, void *data); +int e_hal_device_query_capability(E_DBus_Connection *conn, const char *udi, const char *capability, E_Hal_Callback_Func cb_func, void *data); + +#endif diff --git a/src/lib/hal/e_hal_main.c b/src/lib/hal/e_hal_main.c new file mode 100644 index 0000000..c9d217b --- /dev/null +++ b/src/lib/hal/e_hal_main.c @@ -0,0 +1,53 @@ +#include <E_Hal.h> +#include "e_hal_private.h" + +int _e_dbus_hal_log_dom = -1; +int _e_dbus_hal_init_count = 0; + +EAPI int +e_hal_init(void) +{ + if (++_e_dbus_hal_init_count != 1) + return _e_dbus_hal_init_count; + + if (!eina_init()) + return --_e_dbus_hal_init_count; + + _e_dbus_hal_log_dom = eina_log_domain_register + ("e_hal", E_DBUS_COLOR_DEFAULT); + if (_e_dbus_hal_log_dom < 0) + { + EINA_LOG_ERR("Could not register 'e_hal' log domain."); + goto shutdown_eina; + } + + if (!e_dbus_init()) { + ERR("Could not initialize E_DBus."); + goto unregister_log_domain; + } + + return _e_dbus_hal_init_count; + + unregister_log_domain: + eina_log_domain_unregister(_e_dbus_hal_log_dom); + _e_dbus_hal_log_dom = -1; + shutdown_eina: + eina_shutdown(); + + return _e_dbus_hal_init_count; +} + +EAPI int +e_hal_shutdown(void) +{ + if (--_e_dbus_hal_init_count != 0) + return _e_dbus_hal_init_count; + + e_dbus_shutdown(); + + eina_log_domain_unregister(_e_dbus_hal_log_dom); + _e_dbus_hal_log_dom = -1; + eina_shutdown(); + + return _e_dbus_hal_init_count; +} diff --git a/src/lib/hal/e_hal_manager.c b/src/lib/hal/e_hal_manager.c new file mode 100644 index 0000000..e640be0 --- /dev/null +++ b/src/lib/hal/e_hal_manager.c @@ -0,0 +1,144 @@ +#include "E_Hal.h" +#include "e_hal_private.h" + +#define e_hal_manager_call_new(member) dbus_message_new_method_call(E_HAL_SENDER, E_HAL_MANAGER_PATH, E_HAL_MANAGER_INTERFACE, member) + +/* GetAllDevices */ + +static void * +unmarshal_string_list(DBusMessage *msg, DBusError *err) +{ + E_Hal_String_List_Return *ret = NULL; + DBusMessageIter iter, sub; + + if (!dbus_message_has_signature(msg, "as")) + { + dbus_set_error(err, DBUS_ERROR_INVALID_SIGNATURE, ""); + return NULL; + } + + ret = calloc(1, sizeof(E_Hal_String_List_Return)); + if (!ret) + { + dbus_set_error(err, DBUS_ERROR_NO_MEMORY, ""); + return NULL; + } + + ret->strings = NULL; + + dbus_message_iter_init(msg, &iter); + dbus_message_iter_recurse(&iter, &sub); + while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) + { + char *dev = NULL; + + dbus_message_iter_get_basic(&sub, &dev); + if (dev) + ret->strings = eina_list_append(ret->strings, eina_stringshare_add(dev)); + dbus_message_iter_next(&sub); + } + + return ret; +} + +static void +free_string_list(void *data) +{ + E_Hal_String_List_Return *ret = data; + const char *str; + + if (!ret) return; + EINA_LIST_FREE(ret->strings, str) + eina_stringshare_del(str); + free(ret); +} + +EAPI DBusPendingCall * +e_hal_manager_get_all_devices(E_DBus_Connection *conn, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_hal_manager_call_new("GetAllDevices"); + ret = e_dbus_method_call_send(conn, msg, unmarshal_string_list, cb_func, free_string_list, -1, data); + dbus_message_unref(msg); + return ret; +} + +/* Manager.DeviceExists(string udi) */ + +static void * +unmarshal_manager_device_exists(DBusMessage *msg, DBusError *err) +{ + E_Hal_Manager_Device_Exists_Return *ret = NULL; + dbus_bool_t val; + + ret = calloc(1, sizeof(E_Hal_Manager_Device_Exists_Return)); + if (!ret) + { + dbus_set_error(err, DBUS_ERROR_NO_MEMORY, ""); + return NULL; + } + + dbus_message_get_args(msg, err, DBUS_TYPE_BOOLEAN, &val, DBUS_TYPE_INVALID); + + if (dbus_error_is_set(err)) + { + free(ret); + return NULL; + } + + ret->boolean = val; + return ret; +} + +static void +free_manager_device_exists(void *data) +{ + E_Hal_Manager_Device_Exists_Return *ret = data; + + if (!ret) return; + free(ret); +} + +EAPI DBusPendingCall * +e_hal_manager_device_exists(E_DBus_Connection *conn, const char *udi, E_DBus_Callback_Func cb_func, void *data) +{ + DBusPendingCall *ret; + DBusMessage *msg; + + msg = e_hal_manager_call_new("DeviceExists"); + dbus_message_append_args(msg, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID); + ret = e_dbus_method_call_send(conn, msg, unmarshal_manager_device_exists, cb_func, free_manager_device_exists, -1, data); + dbus_message_unref(msg); + return ret; +} + +/* Manager.FindDeviceStringMatch */ +EAPI DBusPendingCall * +e_hal_manager_find_device_string_match(E_DBus_Connection *conn, const char *key, const char *value, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_hal_manager_call_new("FindDeviceStringMatch"); + dbus_message_append_args(msg, DBUS_TYPE_STRING, &key, DBUS_TYPE_STRING, &value, DBUS_TYPE_INVALID); + ret = e_dbus_method_call_send(conn, msg, unmarshal_string_list, cb_func, free_string_list, -1, data); + dbus_message_unref(msg); + return ret; +} + +/* Manager.FindDeviceByCapability */ + +EAPI DBusPendingCall * +e_hal_manager_find_device_by_capability(E_DBus_Connection *conn, const char *capability, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_hal_manager_call_new("FindDeviceByCapability"); + dbus_message_append_args(msg, DBUS_TYPE_STRING, &capability, DBUS_TYPE_INVALID); + ret = e_dbus_method_call_send(conn, msg, unmarshal_string_list, cb_func, free_string_list, -1, data); + dbus_message_unref(msg); + return ret; +} diff --git a/src/lib/hal/e_hal_manager.h b/src/lib/hal/e_hal_manager.h new file mode 100644 index 0000000..3714dde --- /dev/null +++ b/src/lib/hal/e_hal_manager.h @@ -0,0 +1,21 @@ +#ifndef E_HAL_MANAGER_H +#define E_HAL_MANAGER_H + +#include "E_Hal.h" + +typedef struct E_Hal_String_List_Return E_Hal_Manager_Get_All_Devices_Return; +typedef struct E_Hal_Bool_Return E_Hal_Manager_Device_Exists_Return; +typedef struct E_Hal_String_List_Return E_Hal_Manager_Find_Device_String_Match_Return; +typedef struct E_Hal_String_List_Return E_Hal_Manager_Find_Device_By_Capability_Return; + +typedef struct E_Hal_UDI_Return E_Hal_Manager_Device_Added; +typedef struct E_Hal_UDI_Return E_Hal_Manager_Device_Removed; +typedef struct E_Hal_Capability E_Hal_Manager_New_Capability; + + +int e_hal_manager_get_all_devices(E_DBus_Connection *conn, E_Hal_Callback_Func cb_func, void *data); +int e_hal_manager_device_exists(E_DBus_Connection *conn, const char *udi, E_Hal_Callback_Func cb_func, void *data); +int e_hal_manager_find_device_string_match(E_DBus_Connection *conn, const char *key, const char *value, E_Hal_Callback_Func cb_func, void *data); +int e_hal_manager_find_device_by_capability(E_DBus_Connection *conn, const char *capability, E_Hal_Callback_Func cb_func, void *data); + +#endif diff --git a/src/lib/hal/e_hal_private.h b/src/lib/hal/e_hal_private.h new file mode 100644 index 0000000..1190714 --- /dev/null +++ b/src/lib/hal/e_hal_private.h @@ -0,0 +1,26 @@ +#ifndef E_HAL_PRIVATE_H +#define E_HAL_PRIVATE_H + +#ifndef E_DBUS_COLOR_DEFAULT +#define E_DBUS_COLOR_DEFAULT EINA_COLOR_CYAN +#endif +extern int _e_dbus_hal_log_dom; +#ifdef ERR +#undef ERR +#endif +#ifdef INF +#undef INF +#endif +#ifdef WARN +#undef WARN +#endif +#ifdef DBG +#undef DBG +#endif + +#define DBG(...) EINA_LOG_DOM_DBG(_e_dbus_hal_log_dom, __VA_ARGS__) +#define INFO(...) EINA_LOG_DOM_INFO(_e_dbus_hal_log_dom, __VA_ARGS__) +#define WARN(...) EINA_LOG_DOM_WARN(_e_dbus_hal_log_dom, __VA_ARGS__) +#define ERR(...) EINA_LOG_DOM_ERR(_e_dbus_hal_log_dom, __VA_ARGS__) + +#endif diff --git a/src/lib/hal/e_hal_util.c b/src/lib/hal/e_hal_util.c new file mode 100644 index 0000000..065558a --- /dev/null +++ b/src/lib/hal/e_hal_util.c @@ -0,0 +1,106 @@ +#include <E_Hal.h> +#include <string.h> +#include "e_hal_private.h" + +/** + * @internal + * @brief free a property structure + * @param prop the property to free + */ +EAPI void +e_hal_property_free(E_Hal_Property *prop) +{ + if (prop->type == E_HAL_PROPERTY_TYPE_STRLIST) + { + const char *str; + EINA_LIST_FREE(prop->val.strlist, str) + eina_stringshare_del(str); + } + else if (prop->type == E_HAL_PROPERTY_TYPE_STRING) + eina_stringshare_del(prop->val.s); + free(prop); +} + +/** + * @brief Retrive a string from an element of a property hash + * @param properties the E_Hal_Properties structure + * @param key the key of the property to retrieve + * @param err a pointer to an int, which if supplied, will be set to 0 on success and 1 on an error + */ +EAPI const char * +e_hal_property_string_get(E_Hal_Properties *properties, const char *key, int *err) +{ + E_Hal_Property *prop; + if (err) *err = 0; + if (!properties->properties) return NULL; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.s; + + if (err) *err = 1; + return NULL; +} + +EAPI Eina_Bool +e_hal_property_bool_get(E_Hal_Properties *properties, const char *key, int *err) +{ + E_Hal_Property *prop; + if (err) *err = 0; + if (!properties->properties) return 0; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.b; + + if (err) *err = 1; + return 0; +} + +EAPI int +e_hal_property_int_get(E_Hal_Properties *properties, const char *key, int *err) +{ + E_Hal_Property *prop; + if (err) *err = 0; + if (!properties->properties) return 0; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.i; + + if (err) *err = 1; + return 0; +} + +EAPI uint64_t +e_hal_property_uint64_get(E_Hal_Properties *properties, const char *key, int *err) +{ + E_Hal_Property *prop; + if (err) *err = 0; + if (!properties->properties) return 0; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.u64; + + if (err) *err = 1; + return 0; +} + +EAPI double +e_hal_property_double_get(E_Hal_Properties *properties, const char *key, int *err) +{ + E_Hal_Property *prop; + if (err) *err = 0; + if (!properties->properties) return 0; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.d; + + if (err) *err = 1; + return 0; +} + +EAPI const Eina_List * +e_hal_property_strlist_get(E_Hal_Properties *properties, const char *key, int *err) +{ + E_Hal_Property *prop; + if (err) *err = 0; + if (!properties->properties) return NULL; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.strlist; + + if (err) *err = 1; + return NULL; +} diff --git a/src/lib/hal/e_hal_util.h b/src/lib/hal/e_hal_util.h new file mode 100644 index 0000000..0413510 --- /dev/null +++ b/src/lib/hal/e_hal_util.h @@ -0,0 +1,14 @@ +#ifndef E_HAL_UTIL_H +#define E_HAL_UTIL_H + +#include "E_Hal.h" + +void e_hal_property_free(E_Hal_Property *prop); +const char *e_hal_property_string_get(E_Hal_Properties *properties, const char *key, int *err); +char e_hal_property_bool_get(E_Hal_Properties *properties, const char *key, int *err); +int e_hal_property_int_get(E_Hal_Properties *properties, const char *key, int *err); +uint64_t e_hal_property_uint64_get(E_Hal_Properties *properties, const char *key, int *err); +double e_hal_property_double_get(E_Hal_Properties *properties, const char *key, int *err); +const Eina_List *e_hal_property_strlist_get(E_Hal_Properties *properties, const char *key, int *err); + +#endif diff --git a/src/lib/notification/.cvsignore b/src/lib/notification/.cvsignore new file mode 100644 index 0000000..09980ae --- /dev/null +++ b/src/lib/notification/.cvsignore @@ -0,0 +1,6 @@ +.deps +.libs +Makefile +Makefile.in +*.lo +*.la diff --git a/src/lib/notification/E_Notification_Daemon.h b/src/lib/notification/E_Notification_Daemon.h new file mode 100644 index 0000000..9285373 --- /dev/null +++ b/src/lib/notification/E_Notification_Daemon.h @@ -0,0 +1,95 @@ +#ifndef E_NOTIFICATION_DAEMON_H +#define E_NOTIFICATION_DAEMON_H + +#define E_NOTIFICATION_DAEMON_VERSION "0.9" + +#include <E_Notify.h> + +#ifdef EAPI +#undef EAPI +#endif +#ifdef _MSC_VER +# ifdef BUILDING_DLL +# define EAPI __declspec(dllexport) +# else +# define EAPI __declspec(dllimport) +# endif +#else +# ifdef __GNUC__ +# if __GNUC__ >= 4 +# define EAPI __attribute__ ((visibility("default"))) +# else +# define EAPI +# endif +# else +# define EAPI +# endif +#endif + + +typedef struct E_Notification_Daemon E_Notification_Daemon; + +/* daemon callbacks */ +typedef int (*E_Notification_Daemon_Callback_Notify) (E_Notification_Daemon *daemon, E_Notification *notification); +typedef void (*E_Notification_Daemon_Callback_Close_Notification) (E_Notification_Daemon *daemon, unsigned int notification_id); + +/* gui */ +typedef struct E_Notification_View E_Notification_View; + +struct E_Notification_Daemon +{ + E_DBus_Connection *conn; + E_DBus_Interface *iface; + E_DBus_Object *obj; + + char *name; + char *vendor; + + struct + { + E_Notification_Daemon_Callback_Notify notify; + E_Notification_Daemon_Callback_Close_Notification close_notification; + } func; + void *data; + + int state; +}; + +#ifdef __cplusplus +extern "C" { +#endif + + EAPI int e_notification_daemon_init(void); + EAPI int e_notification_daemon_shutdown(void); + +/* daemon */ + EAPI E_Notification_Daemon *e_notification_daemon_add(const char *name, const char *vendor); + EAPI void e_notification_daemon_free(E_Notification_Daemon *d); +/* TODO + void e_notification_daemon_close(E_Notification_Daemon *d, + E_Notification *n, unsigned int reason); + void e_notification_daemon_action_invoke(E_Notification_Daemon *d, + E_Notification *n, const char *action_id); +*/ + + EAPI void e_notification_daemon_data_set(E_Notification_Daemon *daemon, void *data); + EAPI void *e_notification_daemon_data_get(E_Notification_Daemon *daemon); + + EAPI void e_notification_daemon_callback_notify_set(E_Notification_Daemon *daemon, E_Notification_Daemon_Callback_Notify func); + EAPI void e_notification_daemon_callback_close_notification_set(E_Notification_Daemon *daemon, E_Notification_Daemon_Callback_Close_Notification func); + + EAPI void e_notification_daemon_signal_notification_closed(E_Notification_Daemon *daemon, unsigned int id, E_Notification_Closed_Reason reason); + EAPI void e_notification_daemon_signal_action_invoked(E_Notification_Daemon *daemon, unsigned int notification_id, const char *action_id); + +/***** gui *****/ +/* TODO + E_Notification_View *e_notification_view_add(E_Notification_Daemon *d, E_Notification *n); + void e_notification_view_close(E_Notification_View *nv); + Evas_Object * e_notification_view_icon_get(Evas *evas, E_Notification *n); +*/ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lib/notification/E_Notify.h b/src/lib/notification/E_Notify.h new file mode 100644 index 0000000..5d708ac --- /dev/null +++ b/src/lib/notification/E_Notify.h @@ -0,0 +1,187 @@ +#ifndef E_NOTIFY_H +#define E_NOTIFY_H + +#include <Evas.h> +#include <E_DBus.h> + +#ifdef EAPI +#undef EAPI +#endif +#ifdef _MSC_VER +# ifdef BUILDING_DLL +# define EAPI __declspec(dllexport) +# else +# define EAPI __declspec(dllimport) +# endif +#else +# ifdef __GNUC__ +# if __GNUC__ >= 4 +# define EAPI __attribute__ ((visibility("default"))) +# else +# define EAPI +# endif +# else +# define EAPI +# endif +#endif + + +/* notifications */ +typedef struct E_Notification_Image E_Notification_Image; +typedef struct E_Notification E_Notification; +typedef struct E_Notification_Action E_Notification_Action; + +typedef enum E_Notification_Urgency E_Notification_Urgency; +typedef enum E_Notification_Hint_Type E_Notification_Hint_Type; +typedef enum E_Notification_Closed_Reason E_Notification_Closed_Reason; + +/* method returns */ +typedef struct E_Notification_Return_Notify E_Notification_Return_Notify; +typedef struct E_Notification_Return_Get_Capabilities E_Notification_Return_Get_Capabilities; +typedef struct E_Notification_Return_Get_Server_Information E_Notification_Return_Get_Server_Information; + + +/* signal events */ +typedef struct E_Notification_Event_Action_Invoked E_Notification_Event_Action_Invoked; +typedef struct E_Notification_Event_Notification_Closed E_Notification_Event_Notification_Closed; + +/* enums */ + +enum E_Notification_Urgency +{ + E_NOTIFICATION_URGENCY_LOW, + E_NOTIFICATION_URGENCY_NORMAL, + E_NOTIFICATION_URGENCY_CRITICAL +}; + +enum E_Notification_Closed_Reason +{ + E_NOTIFICATION_CLOSED_EXPIRED, + E_NOTIFICATION_CLOSED_DISMISSED, + E_NOTIFICATION_CLOSED_REQUESTED, + E_NOTIFICATION_CLOSED_UNDEFINED +}; + +enum E_Notification_Hint_Type +{ + E_NOTIFICATION_HINT_URGENCY = 0x1, + E_NOTIFICATION_HINT_CATEGORY = 0x2, + E_NOTIFICATION_HINT_DESKTOP = 0x4, + E_NOTIFICATION_HINT_SOUND_FILE = 0x8, + E_NOTIFICATION_HINT_SUPPRESS_SOUND = 0x10, + E_NOTIFICATION_HINT_XY = 0x20, + E_NOTIFICATION_HINT_IMAGE_DATA = 0x40 +}; + +/* client method returns */ +struct E_Notification_Return_Notify +{ + unsigned int notification_id; + E_Notification *notification; +}; + +struct E_Notification_Return_Get_Capabilities +{ + Eina_List *capabilities; +}; + +struct E_Notification_Return_Get_Server_Information +{ + const char *name; + const char *vendor; + const char *version; +}; + +/* signals */ +struct E_Notification_Event_Notification_Closed +{ + unsigned int notification_id; + E_Notification_Closed_Reason reason; +}; + +struct E_Notification_Event_Action_Invoked +{ + unsigned int notification_id; + char *action_id; +}; + +#ifdef __cplusplus +extern "C" { +#endif + + EAPI int e_notification_init(); + EAPI int e_notification_shutdown(); + +/* client */ + EAPI void e_notification_send(E_Notification *n, E_DBus_Callback_Func func, void *data); + EAPI void e_notification_get_capabilities(E_DBus_Callback_Func func, void *data); + EAPI void e_notification_get_server_information(E_DBus_Callback_Func func, void *data); + + +/* Notifications */ + + EAPI E_Notification *e_notification_new(); + EAPI void e_notification_ref(E_Notification *n); + EAPI void e_notification_unref(E_Notification *n); + EAPI void e_notification_free(E_Notification *n); + + EAPI E_Notification *e_notification_full_new(const char *app_name, + unsigned int replaces_id, + const char *app_icon, + const char *summary, + const char *body, + int expire_timeout); + +/* notification mutators */ + EAPI void e_notification_id_set(E_Notification *note, unsigned int id); + EAPI void e_notification_app_name_set(E_Notification *n, const char *app_name); + EAPI void e_notification_app_icon_set(E_Notification *n, const char *app_icon); + EAPI void e_notification_summary_set(E_Notification *n, const char *summary); + EAPI void e_notification_body_set(E_Notification *n, const char *body); + EAPI void e_notification_replaces_id_set(E_Notification *n, int replaces_id); + EAPI void e_notification_timeout_set(E_Notification *n, int timeout); + EAPI void e_notification_closed_set(E_Notification *note, unsigned char closed); + +/* notification accessors */ + EAPI unsigned int e_notification_id_get(E_Notification *note); + EAPI const char *e_notification_app_name_get(E_Notification *n); + EAPI const char *e_notification_app_icon_get(E_Notification *n); + EAPI const char *e_notification_summary_get(E_Notification *n); + EAPI const char *e_notification_body_get(E_Notification *n); + EAPI int e_notification_replaces_id_get(E_Notification *note); + EAPI int e_notification_timeout_get(E_Notification *note); + EAPI unsigned char e_notification_closed_get(E_Notification *note); + +/* actions */ + EAPI void e_notification_action_add(E_Notification *n, const char *action_id, const char *action_name); + EAPI Eina_List *e_notification_actions_get(E_Notification *n); + +/* hint mutators */ + EAPI void e_notification_hint_urgency_set(E_Notification *n, char urgency); + EAPI void e_notification_hint_category_set(E_Notification *n, const char *category); + EAPI void e_notification_hint_desktop_set(E_Notification *n, const char *desktop); + EAPI void e_notification_hint_sound_file_set(E_Notification *n, const char *sound_file); + EAPI void e_notification_hint_suppress_sound_set(E_Notification *n, char suppress_sound); + EAPI void e_notification_hint_xy_set(E_Notification *n, int x, int y); + EAPI void e_notification_hint_image_data_set(E_Notification *n, E_Notification_Image *image); + +/* hint accessors */ + EAPI char e_notification_hint_urgency_get(E_Notification *n); + EAPI const char *e_notification_hint_category_get(E_Notification *n); + EAPI const char *e_notification_hint_desktop_get(E_Notification *n); + EAPI const char *e_notification_hint_sound_file_get(E_Notification *n); + EAPI char e_notification_hint_suppress_sound_get(E_Notification *n); + EAPI int e_notification_hint_xy_get(E_Notification *n, int *x, int *y); + EAPI E_Notification_Image *e_notification_hint_image_data_get(E_Notification *n); + EAPI E_Notification_Image *e_notification_hint_icon_data_get(E_Notification *n); + +/* image hint */ + EAPI E_Notification_Image *e_notification_image_new(); + EAPI void e_notification_image_free(E_Notification_Image *img); + EAPI Evas_Object *e_notification_image_evas_object_add(Evas *evas, E_Notification_Image *img); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lib/notification/Makefile.am b/src/lib/notification/Makefile.am new file mode 100644 index 0000000..cc9684c --- /dev/null +++ b/src/lib/notification/Makefile.am @@ -0,0 +1,29 @@ +MAINTAINERCLEANFILES = Makefile.in + +AM_CPPFLAGS = \ +-I $(top_srcdir)/src/lib/dbus \ +@EDBUS_CFLAGS@ @EVAS_CFLAGS@ @EINA_CFLAGS@ + +if BUILD_ENOTIFY + +lib_LTLIBRARIES = libenotify.la +include_HEADERS = E_Notify.h E_Notification_Daemon.h + +noinst_HEADERS = e_notify_private.h + +libenotify_la_SOURCES = \ +E_Notify.h \ +E_Notification_Daemon.h \ +e_notify_private.h \ +notification.c \ +marshal.c \ +client.c \ +daemon.c + +libenotify_la_LIBADD = \ +@EDBUS_LIBS@ @EVAS_LIBS@ \ +$(top_builddir)/src/lib/dbus/libedbus.la \ +@EINA_LIBS@ +libenotify_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @enotify_release_info@ + +endif diff --git a/src/lib/notification/client.c b/src/lib/notification/client.c new file mode 100644 index 0000000..d2cc2d6 --- /dev/null +++ b/src/lib/notification/client.c @@ -0,0 +1,62 @@ +#include "E_Notify.h" +#include "e_notify_private.h" + +static E_DBus_Connection *client_conn; +static int init_count = 0; + +EAPI int +e_notification_init(void) +{ + if (init_count) return ++init_count; + + if (!e_dbus_init()) return 0; + client_conn = e_dbus_bus_get(DBUS_BUS_SESSION); + if (!client_conn) + { + e_dbus_shutdown(); + return 0; + } + + return ++init_count; +} + +EAPI int +e_notification_shutdown(void) +{ + if (--init_count) return init_count; + e_dbus_connection_close(client_conn); + client_conn = NULL; + e_dbus_shutdown(); + return 0; +} + +/**** client api ****/ +EAPI void +e_notification_send(E_Notification *n, E_DBus_Callback_Func func, void *data) +{ + DBusMessage *msg; + + msg = e_notify_marshal_notify(n); + e_dbus_method_call_send(client_conn, msg, e_notify_unmarshal_notify_return, func, e_notify_free_notify_return, -1, data); + dbus_message_unref(msg); +} + +EAPI void +e_notification_get_capabilities(E_DBus_Callback_Func func, void *data) +{ + DBusMessage *msg; + + msg = e_notify_marshal_get_capabilities(); + e_dbus_method_call_send(client_conn, msg, e_notify_unmarshal_get_capabilities_return, func, e_notify_free_get_capabilities_return, -1, data); + dbus_message_unref(msg); +} + +EAPI void +e_notification_get_server_information(E_DBus_Callback_Func func, void *data) +{ + DBusMessage *msg; + + msg = e_notify_marshal_get_server_information(); + e_dbus_method_call_send(client_conn, msg, e_notify_unmarshal_get_server_information_return, func, e_notify_free_get_server_information_return, -1, data); + dbus_message_unref(msg); +} diff --git a/src/lib/notification/daemon.c b/src/lib/notification/daemon.c new file mode 100644 index 0000000..2e4127b --- /dev/null +++ b/src/lib/notification/daemon.c @@ -0,0 +1,260 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "E_Notify.h" +#include "E_Notification_Daemon.h" +#include "e_notify_private.h" +#include <string.h> + +#define DBG(...) EINA_LOG_DOM_DBG(log_dom, __VA_ARGS__) +#define INF(...) EINA_LOG_DOM_INFO(log_dom, __VA_ARGS__) +#define WRN(...) EINA_LOG_DOM_WARN(log_dom, __VA_ARGS__) +#define ERR(...) EINA_LOG_DOM_ERR(log_dom, __VA_ARGS__) +#define CRIT(...) EINA_LOG_DOM_CRITICAL(log_dom, __VA_ARGS__) +static int log_dom = -1; +static int init_count = 0; +static E_DBus_Interface *daemon_iface = NULL; + +static int e_notification_daemon_bus_init(E_Notification_Daemon *daemon); +static int e_notification_daemon_object_init(E_Notification_Daemon *daemon); + +DBusMessage * +method_get_capabilities(E_DBus_Object *obj __UNUSED__, DBusMessage *message) +{ + const char *capabilities[] = { + "body", + "actions", + NULL + }; + return e_notify_marshal_get_capabilities_return(message, capabilities); +} + +DBusMessage * +method_notify(E_DBus_Object *obj, DBusMessage *message) +{ + E_Notification *n; + E_Notification_Daemon *daemon; + int id = -1; + + daemon = e_dbus_object_data_get(obj); + n = e_notify_unmarshal_notify(message, NULL); + if (daemon->func.notify) + id = daemon->func.notify(daemon, n); + else + return dbus_message_new_error(message, E_NOTIFICATION_INTERFACE".Unimplemented", "This functionality has not yet been implemented"); + + e_notification_unref(n); + return e_notify_marshal_notify_return(message, id); +} + +DBusMessage * +method_close_notification(E_DBus_Object *obj, DBusMessage *message) +{ + E_Notification_Daemon *daemon; + dbus_uint32_t id; + + daemon = e_dbus_object_data_get(obj); + id = e_notify_unmarshal_close_notification(message, NULL); + if (daemon->func.close_notification) + daemon->func.close_notification(daemon, id); + return dbus_message_new_method_return(message); +} + +DBusMessage * +method_get_server_information(E_DBus_Object *obj, DBusMessage *message) +{ + E_Notification_Daemon *daemon; + + daemon = e_dbus_object_data_get(obj); + + return e_notify_marshal_get_server_information_return(message, daemon->name, daemon->vendor, E_NOTIFICATION_DAEMON_VERSION); +} + + +/**** daemon api ****/ + +EAPI int +e_notification_daemon_init(void) +{ + if (init_count) return ++init_count; + if (!e_dbus_init()) return 0; + log_dom = eina_log_domain_register + ("e_dbus_notification_daemon", E_DBUS_COLOR_DEFAULT); + if(log_dom < 0) + { + ERR("Impossible to create e_dbus_notification_daemon domain"); + e_dbus_shutdown(); + return 0; + } + + daemon_iface = e_dbus_interface_new(E_NOTIFICATION_INTERFACE); + + return ++init_count; +} + +EAPI int +e_notification_daemon_shutdown(void) +{ + if (--init_count) return init_count; + eina_log_domain_unregister(log_dom); + e_dbus_shutdown(); + return 0; +} + +EAPI E_Notification_Daemon * +e_notification_daemon_add(const char *name, const char *vendor) +{ + E_Notification_Daemon *daemon; + + daemon = calloc(1, sizeof(E_Notification_Daemon)); + if (daemon) + e_notification_daemon_bus_init(daemon); + + if (!daemon || !daemon->conn) + { + if (daemon) free(daemon); + e_dbus_shutdown(); + return NULL; + } + + daemon->name = strdup(name); + daemon->vendor = strdup(vendor); + + e_dbus_interface_ref(daemon_iface); + daemon->iface = daemon_iface; + e_dbus_interface_method_add(daemon->iface, "GetCapabilities", "", "as", method_get_capabilities); + e_dbus_interface_method_add(daemon->iface, "Notify", "susssasa{sv}i", "u", method_notify); + e_dbus_interface_method_add(daemon->iface, "CloseNotification", "u", "u", method_close_notification); + e_dbus_interface_method_add(daemon->iface, "GetServerInformation", "", "sss", method_get_server_information); + + return daemon; +} + + +EAPI void +e_notification_daemon_free(E_Notification_Daemon *daemon) +{ + e_dbus_release_name(daemon->conn, E_NOTIFICATION_BUS_NAME, NULL, NULL); + if (daemon->obj) + { + e_dbus_object_interface_detach(daemon->obj, daemon->iface); + e_dbus_object_free(daemon->obj); + } + if (daemon->conn) e_dbus_connection_close(daemon->conn); + if (daemon->name) free(daemon->name); + if (daemon->vendor) free(daemon->vendor); + if (daemon->iface) e_dbus_interface_unref(daemon->iface); + free(daemon); +} + +EAPI void +e_notification_daemon_data_set(E_Notification_Daemon *daemon, void *data) +{ + daemon->data = data; +} + +EAPI void * +e_notification_daemon_data_get(E_Notification_Daemon *daemon) +{ + return daemon->data; +} + +EAPI void +e_notification_daemon_callback_notify_set(E_Notification_Daemon *daemon, E_Notification_Daemon_Callback_Notify func) +{ + daemon->func.notify = func; +} + +EAPI void +e_notification_daemon_callback_close_notification_set(E_Notification_Daemon *daemon, E_Notification_Daemon_Callback_Close_Notification func) +{ + daemon->func.close_notification = func; +} + + +static void +cb_request_name(void *data, DBusMessage *msg, DBusError *err) +{ + E_Notification_Daemon *daemon = data; + dbus_uint32_t ret; + DBusError new_err; + + if (dbus_error_is_set(err)) + { + ERR("request_name: %s", err->message); + dbus_error_free(err); + return; + } + + INF("received response with signature: '%s'", + dbus_message_get_signature(msg)); + dbus_error_init(&new_err); + dbus_message_get_args + (msg, &new_err, DBUS_TYPE_UINT32, &ret, DBUS_TYPE_INVALID); + if (dbus_error_is_set(&new_err)) + { + ERR("req name unmarshal: %s", new_err.message); + dbus_error_free(&new_err); + return; + } + + switch(ret) + { + case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER: + case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER: + e_notification_daemon_object_init(daemon); + break; + case DBUS_REQUEST_NAME_REPLY_IN_QUEUE: + //XXX mark daemon as queued? + break; + case DBUS_REQUEST_NAME_REPLY_EXISTS: + //XXX exit? + break; + } +} + +static int +e_notification_daemon_bus_init(E_Notification_Daemon *daemon) +{ + daemon->conn = e_dbus_bus_get(DBUS_BUS_SESSION); + if (!daemon->conn) return 0; + + // this blocks... make it async, and handle failure, etc + e_dbus_request_name(daemon->conn, E_NOTIFICATION_BUS_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING, cb_request_name, daemon); + + return 1; +} + +static int +e_notification_daemon_object_init(E_Notification_Daemon *daemon) +{ + if (!daemon || !daemon->conn) return 0; + daemon->obj = e_dbus_object_add(daemon->conn, E_NOTIFICATION_PATH, daemon); + if (!daemon->obj) return 0; + + e_dbus_object_interface_attach(daemon->obj, daemon->iface); + + return 1; +} + + +EAPI void +e_notification_daemon_signal_notification_closed(E_Notification_Daemon *daemon, unsigned int id, E_Notification_Closed_Reason reason) +{ + DBusMessage *msg = e_notify_marshal_notification_closed_signal(id, reason); + e_dbus_message_send(daemon->conn, + msg, + NULL, -1, NULL); + dbus_message_unref(msg); +} + +EAPI void +e_notification_daemon_signal_action_invoked(E_Notification_Daemon *daemon, unsigned int notification_id, const char *action_id) +{ + DBusMessage *msg = e_notify_marshal_action_invoked_signal(notification_id, action_id); + e_dbus_message_send(daemon->conn, + msg, + NULL, -1, NULL); + dbus_message_unref(msg); +} diff --git a/src/lib/notification/e_notify_private.h b/src/lib/notification/e_notify_private.h new file mode 100644 index 0000000..250f6d5 --- /dev/null +++ b/src/lib/notification/e_notify_private.h @@ -0,0 +1,97 @@ +#ifndef E_NOTIFY_PRIVATE_H +#define E_NOTIFY_PRIVATE_H + +#define E_NOTIFICATION_BUS_NAME "org.freedesktop.Notifications" +#define E_NOTIFICATION_INTERFACE "org.freedesktop.Notifications" +#define E_NOTIFICATION_PATH "/org/freedesktop/Notifications" + +#define e_notification_call_new(member) dbus_message_new_method_call(E_NOTIFICATION_BUS_NAME, E_NOTIFICATION_PATH, E_NOTIFICATION_INTERFACE, member) + +typedef void (*E_DBus_Variant_Marshaller) (DBusMessageIter *iter, void *data); +#define E_DBUS_VARIANT_MARSHALLER(x) ((E_DBus_Variant_Marshaller)(x)) + +void e_notify_marshal_dict_variant(DBusMessageIter *iter, const char *key, char *type_str, E_DBus_Variant_Marshaller func, void *data); +void e_notify_marshal_dict_string(DBusMessageIter *iter, const char *key, const char *value); +void e_notify_marshal_dict_byte(DBusMessageIter *iter, const char *key, char value); +void e_notify_marshal_dict_int(DBusMessageIter *iter, const char *key, int value); + +void e_notify_marshal_string_array(DBusMessageIter *iter, const char **strings); +void e_notify_marshal_string_list_as_array(DBusMessageIter *iter, Eina_List *strings); +Eina_List * e_notify_unmarshal_string_array_as_list(DBusMessageIter *iter, DBusError *err); +DBusMessage * e_notify_marshal_get_capabilities(); +DBusMessage * e_notify_marshal_get_capabilities_return(DBusMessage *method_call, const char **capabilities); +void * e_notify_unmarshal_get_capabilities_return(DBusMessage *msg, DBusError *err); +void e_notify_free_get_capabilities_return(void *data); +DBusMessage * e_notify_marshal_get_server_information(); +DBusMessage * e_notify_marshal_get_server_information_return(DBusMessage *method_call, const char *name, const char *vendor, const char *version); +void * e_notify_unmarshal_get_server_information_return(DBusMessage *msg, DBusError *err); +void e_notify_free_get_server_information_return(void *data); +DBusMessage * e_notify_marshal_close_notification(dbus_uint32_t id); +dbus_uint32_t e_notify_unmarshal_close_notification(DBusMessage *msg, DBusError *err); +DBusMessage * e_notify_marshal_notification_closed_signal(dbus_uint32_t id, dbus_uint32_t reason); +E_Notification_Event_Notification_Closed * e_notify_unmarshal_notification_closed_signal(DBusMessage *msg, DBusError *err); +DBusMessage * e_notify_marshal_action_invoked_signal(dbus_uint32_t id, const char *action_id); +E_Notification_Event_Action_Invoked * e_notify_unmarshal_action_invoked_signal(DBusMessage *msg, DBusError *err); +DBusMessage * e_notify_marshal_notify(E_Notification *n); +E_Notification * e_notify_unmarshal_notify(DBusMessage *msg, DBusError *err); +DBusMessage * e_notify_marshal_notify_return(DBusMessage *method_call, dbus_uint32_t notification_id); +void * e_notify_unmarshal_notify_return(DBusMessage *msg, DBusError *err); +void e_notify_free_notify_return(void *data); +void e_notify_unmarshal_notify_actions(E_Notification *n, DBusMessageIter *iter); +void e_notify_unmarshal_notify_hints(E_Notification *n, DBusMessageIter *iter); +void e_notify_marshal_hint_image(DBusMessageIter *iter, E_Notification_Image *img); +E_Notification_Image * e_notify_unmarshal_hint_image(DBusMessageIter *iter); + + +#ifndef E_DBUS_COLOR_DEFAULT +#define E_DBUS_COLOR_DEFAULT EINA_COLOR_CYAN +#endif + +struct E_Notification_Image +{ + int width; + int height; + int rowstride; + char has_alpha; + int bits_per_sample; + int channels; + unsigned char *data; +}; + +struct E_Notification +{ + int id; + char *app_name; + unsigned int replaces_id; + char *app_icon; + char *summary; + char *body; + int expire_timeout; + + Eina_List *actions; + + struct + { + char urgency; + char *category; + char *desktop; + char *sound_file; + char suppress_sound; + int x, y; + E_Notification_Image *image_data; + E_Notification_Image *icon_data; + } hints; + + int hint_flags; + unsigned char closed; + + int refcount; +}; + +struct E_Notification_Action +{ + char *id; + char *name; +}; + +#endif diff --git a/src/lib/notification/marshal.c b/src/lib/notification/marshal.c new file mode 100644 index 0000000..91b9389 --- /dev/null +++ b/src/lib/notification/marshal.c @@ -0,0 +1,595 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <string.h> + +#include "E_Notify.h" +#include "e_notify_private.h" + +void +e_notify_marshal_dict_variant(DBusMessageIter *iter, const char *key, char *type_str, E_DBus_Variant_Marshaller func, void *data) +{ + DBusMessageIter entry, variant; + + dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, "sv", &entry); + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); + func(&entry, data); + dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, type_str, &variant); + func(&variant, data); + dbus_message_iter_close_container(&entry, &variant); + dbus_message_iter_close_container(iter, &entry); +} + +void +e_notify_marshal_dict_string(DBusMessageIter *iter, const char *key, const char *value) +{ + DBusMessageIter entry, variant; + + dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, "sv", &entry); + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); + dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, "s", &variant); + dbus_message_iter_append_basic(&variant, DBUS_TYPE_STRING, &value); + dbus_message_iter_close_container(&entry, &variant); + dbus_message_iter_close_container(iter, &entry); +} + +void +e_notify_marshal_dict_byte(DBusMessageIter *iter, const char *key, char value) +{ + DBusMessageIter entry, variant; + + if (!key || !value) return; + + dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, NULL, &entry); + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); + dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, "y", &variant); + dbus_message_iter_append_basic(&variant, DBUS_TYPE_BYTE, &value); + dbus_message_iter_close_container(&entry, &variant); + dbus_message_iter_close_container(iter, &entry); +} + +void +e_notify_marshal_dict_int(DBusMessageIter *iter, const char *key, int value) +{ + DBusMessageIter entry, variant; + + if (!key || !value) return; + + dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, "sv", &entry); + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); + dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, "i", &variant); + dbus_message_iter_append_basic(&variant, DBUS_TYPE_INT32, &value); + dbus_message_iter_close_container(&entry, &variant); + dbus_message_iter_close_container(iter, &entry); +} + +void +e_notify_marshal_string_array(DBusMessageIter *iter, const char **strings) +{ + const char **str; + DBusMessageIter arr; + + dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, "s", &arr); + + for (str = strings; *str; str++) + dbus_message_iter_append_basic(&arr, DBUS_TYPE_STRING, str); + + dbus_message_iter_close_container(iter, &arr); +} + +void +e_notify_marshal_string_list_as_array(DBusMessageIter *iter, Eina_List *strings) +{ + const char *str; + DBusMessageIter arr; + Eina_List *l; + + dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, "s", &arr); + + EINA_LIST_FOREACH(strings, l, str) + dbus_message_iter_append_basic(&arr, DBUS_TYPE_STRING, &str); + + dbus_message_iter_close_container(iter, &arr); +} + +Eina_List * +e_notify_unmarshal_string_array_as_list(DBusMessageIter *iter, DBusError *err __UNUSED__) +{ + Eina_List *strings; + char *sig; + int ret; + DBusMessageIter arr; + + sig = dbus_message_iter_get_signature(iter); + ret = !strcmp(sig, "as"); + dbus_free(sig); + if (!ret) return NULL; + + strings = NULL; + + dbus_message_iter_recurse(iter, &arr); + while(dbus_message_iter_has_next(&arr)) + { + const char *str; + dbus_message_iter_get_basic(&arr, &str); + strings = eina_list_append(strings, strdup(str)); //XXX use eina_stringshare_instance? + dbus_message_iter_next(&arr); + } + return strings; +} + + + +DBusMessage * +e_notify_marshal_get_capabilities() +{ + DBusMessage *msg; + + msg = e_notification_call_new("GetCapabilities"); + return msg; +} + +DBusMessage * +e_notify_marshal_get_capabilities_return(DBusMessage *method_call, const char **capabilities) +{ + DBusMessage *msg; + DBusMessageIter iter; + + msg = dbus_message_new_method_return(method_call); + dbus_message_iter_init_append(msg, &iter); + e_notify_marshal_string_array(&iter, capabilities); + + return msg; +} + +void * +e_notify_unmarshal_get_capabilities_return(DBusMessage *msg, DBusError *err) +{ + DBusMessageIter iter; + E_Notification_Return_Get_Capabilities *ret; + + if (!dbus_message_has_signature(msg, "as")) return NULL; + + ret = calloc(1, sizeof(E_Notification_Return_Get_Capabilities)); + dbus_message_iter_init(msg, &iter); + ret->capabilities = e_notify_unmarshal_string_array_as_list(&iter, err); + + return ret; +} + +void +e_notify_free_get_capabilities_return(void *data) +{ + E_Notification_Return_Get_Capabilities *ret = data; + + if (!ret) return; + eina_list_free(ret->capabilities); + free(ret); +} + +DBusMessage * +e_notify_marshal_get_server_information() +{ + DBusMessage *msg; + + msg = e_notification_call_new("GetServerInformation"); + return msg; +} + +DBusMessage * +e_notify_marshal_get_server_information_return(DBusMessage *method_call, const char *name, const char *vendor, const char *version) +{ + DBusMessage *msg; + msg = dbus_message_new_method_return(method_call); + dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &vendor, DBUS_TYPE_STRING, &version, DBUS_TYPE_INVALID); + return msg; +} + +void * +e_notify_unmarshal_get_server_information_return(DBusMessage *msg, DBusError *err) +{ + E_Notification_Return_Get_Server_Information *info; + if (!dbus_message_has_signature(msg, "sss")) return NULL; + + info = calloc(1, sizeof(E_Notification_Return_Get_Server_Information)); + dbus_message_get_args(msg, err, + DBUS_TYPE_STRING, &(info->name), + DBUS_TYPE_STRING, &(info->vendor), + DBUS_TYPE_STRING, &(info->version), + DBUS_TYPE_INVALID + ); + if (dbus_error_is_set(err)) + { + free(info); + return NULL; + } + + return info; +} + +void +e_notify_free_get_server_information_return(void *data) +{ + E_Notification_Return_Get_Server_Information *info = data; + + if (!info) return; + free(info); +} + +DBusMessage * +e_notify_marshal_close_notification(dbus_uint32_t id) +{ + DBusMessage *msg; + + msg = e_notification_call_new("CloseNotification"); + dbus_message_append_args(msg, DBUS_TYPE_UINT32, &id, DBUS_TYPE_INVALID); + return msg; +} + +dbus_uint32_t +e_notify_unmarshal_close_notification(DBusMessage *msg, DBusError *err) +{ + dbus_uint32_t id; + if (!dbus_message_has_signature(msg, "u")) return 0; + dbus_message_get_args(msg, err, DBUS_TYPE_UINT32, &id, DBUS_TYPE_INVALID); + if (err && dbus_error_is_set(err)) + return 0; + + return id; +} + +DBusMessage * +e_notify_marshal_notification_closed_signal(dbus_uint32_t id, dbus_uint32_t reason) +{ + DBusMessage *msg; + msg = dbus_message_new_signal(E_NOTIFICATION_PATH, E_NOTIFICATION_INTERFACE, "NotificationClosed"); + dbus_message_append_args(msg, DBUS_TYPE_UINT32, &id, DBUS_TYPE_UINT32, &reason, DBUS_TYPE_INVALID); + return msg; +} + +E_Notification_Event_Notification_Closed * +e_notify_unmarshal_notification_closed_signal(DBusMessage *msg, DBusError *err) +{ + E_Notification_Event_Notification_Closed *ev; + + if (!dbus_message_has_signature(msg, "uu")) + { + dbus_set_error(err, DBUS_ERROR_INVALID_SIGNATURE, ""); + return NULL; + } + ev = calloc(1, sizeof(E_Notification_Event_Notification_Closed)); + dbus_message_get_args(msg, err, DBUS_TYPE_UINT32, &(ev->notification_id), DBUS_TYPE_UINT32, &(ev->reason), DBUS_TYPE_INVALID); + if (dbus_error_is_set(err)) + { + free(ev); + return NULL; + } + return ev; +} + +DBusMessage * +e_notify_marshal_action_invoked_signal(dbus_uint32_t id, const char *action_id) +{ + DBusMessage *msg; + msg = dbus_message_new_signal(E_NOTIFICATION_PATH, E_NOTIFICATION_INTERFACE, "ActionInvoked"); + dbus_message_append_args(msg, DBUS_TYPE_UINT32, &id, DBUS_TYPE_STRING, &action_id, DBUS_TYPE_INVALID); + return msg; +} + +E_Notification_Event_Action_Invoked * +e_notify_unmarshal_action_invoked_signal(DBusMessage *msg, DBusError *err) +{ + E_Notification_Event_Action_Invoked *ev; + + if (!dbus_message_has_signature(msg, "us")) + { + dbus_set_error(err, DBUS_ERROR_INVALID_SIGNATURE, ""); + return NULL; + } + ev = calloc(1, sizeof(E_Notification_Event_Action_Invoked)); + dbus_message_get_args(msg, err, DBUS_TYPE_UINT32, &(ev->notification_id), DBUS_TYPE_STRING, &(ev->action_id), DBUS_TYPE_INVALID); + if (dbus_error_is_set(err)) + { + free(ev); + return NULL; + } + return ev; +} + +DBusMessage * +e_notify_marshal_notify(E_Notification *n) +{ + DBusMessage *msg; + DBusMessageIter iter, sub; + Eina_List *l; + + if (!n->app_name) n->app_name = strdup(""); + if (!n->app_icon) n->app_icon = strdup(""); + if (!n->summary) n->summary = strdup(""); + if (!n->body) n->body = strdup(""); + + msg = e_notification_call_new("Notify"); + dbus_message_append_args(msg, + DBUS_TYPE_STRING, &(n->app_name), + DBUS_TYPE_UINT32, &(n->replaces_id), + DBUS_TYPE_STRING, &(n->app_icon), + DBUS_TYPE_STRING, &(n->summary), + DBUS_TYPE_STRING, &(n->body), + DBUS_TYPE_INVALID + ); + + dbus_message_iter_init_append(msg, &iter); + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub); + if (n->actions) + { + E_Notification_Action *action; + EINA_LIST_FOREACH(n->actions, l, action) + { + dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &(action->id)); + dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &(action->name)); + } + } + dbus_message_iter_close_container(&iter, &sub); + + /* hints */ + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub); + if (n->hints.urgency) /* we only need to send this if its non-zero*/ + e_notify_marshal_dict_byte(&sub, "urgency", n->hints.urgency); + if (n->hints.category) + e_notify_marshal_dict_string(&sub, "category", n->hints.category); + if (n->hints.desktop) + e_notify_marshal_dict_string(&sub, "desktop_entry", n->hints.desktop); + if (n->hints.image_data) + e_notify_marshal_dict_variant(&sub, "image_data", "(iiibiiay)", E_DBUS_VARIANT_MARSHALLER(e_notify_marshal_hint_image), n->hints.image_data); + if (n->hints.icon_data) + e_notify_marshal_dict_variant(&sub, "icon_data", "(iiibiiay)", E_DBUS_VARIANT_MARSHALLER(e_notify_marshal_hint_image), n->hints.icon_data); + if (n->hints.sound_file) + e_notify_marshal_dict_string(&sub, "sound_file", n->hints.sound_file); + if (n->hints.suppress_sound) /* we only need to send this if its true */ + e_notify_marshal_dict_byte(&sub, "suppress_sound", n->hints.suppress_sound); + if (n->hints.x > -1 && n->hints.y > -1) + { + e_notify_marshal_dict_int(&sub, "x", n->hints.x); + e_notify_marshal_dict_int(&sub, "y", n->hints.y); + } + + dbus_message_iter_close_container(&iter, &sub); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &(n->expire_timeout)); + return msg; +} + +E_Notification * +e_notify_unmarshal_notify(DBusMessage *msg, DBusError *err __UNUSED__) +{ + E_Notification *n; + const char *s_val; + dbus_uint32_t u_val; + dbus_int32_t i_val; + DBusMessageIter iter; + if (!dbus_message_has_signature(msg, "susssasa{sv}i")) return NULL; + + n = e_notification_new(); + if (!n) return NULL; + dbus_message_iter_init(msg, &iter); + + dbus_message_iter_get_basic(&iter, &s_val); + e_notification_app_name_set(n, s_val); + dbus_message_iter_next(&iter); + + dbus_message_iter_get_basic(&iter, &u_val); + e_notification_replaces_id_set(n, u_val); + dbus_message_iter_next(&iter); + + dbus_message_iter_get_basic(&iter, &s_val); + e_notification_app_icon_set(n, s_val); + dbus_message_iter_next(&iter); + + dbus_message_iter_get_basic(&iter, &s_val); + e_notification_summary_set(n, s_val); + dbus_message_iter_next(&iter); + + dbus_message_iter_get_basic(&iter, &s_val); + e_notification_body_set(n, s_val); + dbus_message_iter_next(&iter); + + e_notify_unmarshal_notify_actions(n, &iter); + dbus_message_iter_next(&iter); + + e_notify_unmarshal_notify_hints(n, &iter); + dbus_message_iter_next(&iter); + + dbus_message_iter_get_basic(&iter, &i_val); + e_notification_timeout_set(n, i_val); + + return n; +} + +DBusMessage * +e_notify_marshal_notify_return(DBusMessage *method_call, dbus_uint32_t notification_id) +{ + DBusMessage *msg; + msg = dbus_message_new_method_return(method_call); + dbus_message_append_args(msg, DBUS_TYPE_UINT32, ¬ification_id, DBUS_TYPE_INVALID); + return msg; +} + +void * +e_notify_unmarshal_notify_return(DBusMessage *msg, DBusError *err) +{ + E_Notification_Return_Notify *ret; + ret = calloc(1, sizeof(E_Notification_Return_Notify)); + dbus_message_get_args(msg, err, DBUS_TYPE_UINT32, &(ret->notification_id), DBUS_TYPE_INVALID); + if (dbus_error_is_set(err)) + { + free(ret); + return NULL; + } + return ret; +} + +void +e_notify_free_notify_return(void *data) +{ + E_Notification_Return_Notify *ret = data; + + if (!ret) return; + free(ret); +} + +void +e_notify_unmarshal_notify_actions(E_Notification *n, DBusMessageIter *iter) +{ + DBusMessageIter arr; + const char *id, *name; + dbus_message_iter_recurse(iter, &arr); + while (dbus_message_iter_has_next(&arr)) + { + dbus_message_iter_get_basic(&arr, &id); + dbus_message_iter_next(&arr); + dbus_message_iter_get_basic(&arr, &name); + dbus_message_iter_next(&arr); + e_notification_action_add(n, id, name); + } +} + +void +e_notify_unmarshal_notify_hints(E_Notification *n, DBusMessageIter *iter) +{ + DBusMessageIter arr; + const char *key; + int x_set = 0, y_set = 0; + int x, y; + dbus_message_iter_recurse(iter, &arr); + + if (dbus_message_iter_get_arg_type(&arr) == DBUS_TYPE_INVALID) + return; + + do + { + DBusMessageIter dict; + dbus_message_iter_recurse(&arr, &dict); + do + { + DBusMessageIter variant; + const char *s_val; + char y_val; + dbus_bool_t b_val; + + dbus_message_iter_get_basic(&dict, &key); + dbus_message_iter_next(&dict); + dbus_message_iter_recurse(&dict, &variant); + + if (!strcmp(key, "urgency")) + { + dbus_message_iter_get_basic(&variant, &y_val); + e_notification_hint_urgency_set(n, y_val); + } + else if (!strcmp(key, "category")) + { + dbus_message_iter_get_basic(&variant, &s_val); + e_notification_hint_category_set(n, s_val); + } + else if (!strcmp(key, "desktop-entry")) + { + dbus_message_iter_get_basic(&variant, &s_val); + e_notification_hint_desktop_set(n, s_val); + } + else if (!strcmp(key, "sound-file")) + { + dbus_message_iter_get_basic(&variant, &s_val); + e_notification_hint_sound_file_set(n, s_val); + } + else if (!strcmp(key, "suppress-sound")) + { + dbus_message_iter_get_basic(&variant, &b_val); + e_notification_hint_suppress_sound_set(n, b_val); + } + else if (!strcmp(key, "x")) + { + dbus_message_iter_get_basic(&variant, &x); + x_set = 1; + } + else if (!strcmp(key, "y")) + { + dbus_message_iter_get_basic(&variant, &y); + y_set = 1; + } + else if (!strcmp(key, "image_data")) + { + dbus_message_iter_recurse(&dict, &variant); + n->hints.image_data = e_notify_unmarshal_hint_image(&variant); + } + else if (!strcmp(key, "icon_data")) + { + dbus_message_iter_recurse(&dict, &variant); + n->hints.icon_data = e_notify_unmarshal_hint_image(&variant); + } + } + while (dbus_message_iter_next(&dict)); + } + while (dbus_message_iter_next(&arr)); + + if (x_set && y_set) + e_notification_hint_xy_set(n, x, y); +} + +void +e_notify_marshal_hint_image(DBusMessageIter *iter, E_Notification_Image *img) +{ + DBusMessageIter sub, arr; + int data_len = 0; + + data_len = ((img->height - 1) * img->rowstride) + (img->width * ((img->channels * (img->bits_per_sample + 7)) / 8)); + dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &sub); + dbus_message_iter_append_basic(&sub, DBUS_TYPE_INT32, &(img->width)); + dbus_message_iter_append_basic(&sub, DBUS_TYPE_INT32, &(img->height)); + dbus_message_iter_append_basic(&sub, DBUS_TYPE_INT32, &(img->rowstride)); + dbus_message_iter_append_basic(&sub, DBUS_TYPE_BOOLEAN, &(img->has_alpha)); + dbus_message_iter_append_basic(&sub, DBUS_TYPE_INT32, &(img->bits_per_sample)); + dbus_message_iter_append_basic(&sub, DBUS_TYPE_INT32, &(img->channels)); + dbus_message_iter_open_container(&sub, DBUS_TYPE_ARRAY, NULL, &arr); + dbus_message_iter_append_fixed_array(&arr, DBUS_TYPE_BYTE, &(img->data), data_len); + dbus_message_iter_close_container(&sub, &arr); +} + +E_Notification_Image * +e_notify_unmarshal_hint_image(DBusMessageIter *iter) +{ + DBusMessageIter sub, arr; + char *byte_array; + int array_len; + E_Notification_Image *img; + char *sig; + int sig_matches; + + sig = dbus_message_iter_get_signature(iter); + sig_matches = strcmp(sig, "(iiibiiay)"); + dbus_free(sig); + if (sig_matches) return NULL; + + img = e_notification_image_new(); + if (!img) return NULL; + + dbus_message_iter_recurse(iter, &sub); + dbus_message_iter_get_basic(&sub, &(img->width)); + dbus_message_iter_next(&sub); + dbus_message_iter_get_basic(&sub, &(img->height)); + dbus_message_iter_next(&sub); + dbus_message_iter_get_basic(&sub, &(img->rowstride)); + dbus_message_iter_next(&sub); + dbus_message_iter_get_basic(&sub, &(img->has_alpha)); + dbus_message_iter_next(&sub); + dbus_message_iter_get_basic(&sub, &(img->bits_per_sample)); + dbus_message_iter_next(&sub); + dbus_message_iter_get_basic(&sub, &(img->channels)); + dbus_message_iter_next(&sub); + + dbus_message_iter_recurse(&sub, &arr); + dbus_message_iter_get_fixed_array(&arr, &(byte_array), &array_len); + img->data = malloc(array_len); + memcpy(img->data, byte_array, array_len); + + return img; +} + diff --git a/src/lib/notification/notification-spec-0.9.txt b/src/lib/notification/notification-spec-0.9.txt new file mode 100644 index 0000000..f392c8c --- /dev/null +++ b/src/lib/notification/notification-spec-0.9.txt @@ -0,0 +1,827 @@ + Desktop Notifications Specification + + Mike Hearn + + <[1]mike@navi.cx> + + + Christian Hammond + + <[2]chipx86@chipx86.com> + + + Version 0.9 + + Revision History + Revision 0.9 15 January 2006 Revised by: cdh + Clarify the naming for the application IDs. Put back a number of things + that probably shouldn't have been removed from the spec. + Revision 0.8 23 September 2005 Revised by: J5 + Major overhaul of spec to work with the newer D-Bus recursive type system. + Simplify protocol. Changed the verbage notification type to category + Revision 0.7 28 July 2005 Revised by: cdh + Added "x" and "y" hints. Talk about the variant type for hint values. + Revision 0.6 1 April 2005 Revised by: cdh + Updated to work with D-BUS 0.31+. + Revision 0.5 2 October 2004 Revised by: cdh + Added a "suppress-sound" hint. Added a "sound" capability. Renamed the + "soundfile" hint to sound-file". + Revision 0.4 29 September 2004 Revised by: cdh + Added image support in markup, and made the restrictions on markup more + clear. Removed the High urgency. Added new notification types. Fixed + notification expiration. + Revision 0.3 15 September 2004 Revised by: cdh + Added hint and notification type sections + Revision 0.2 foo Revised by: mh + Added replaces field to protocol + Revision 0.1 foo Revised by: mh + Initial version + + -------------------------------------------------------------------------- + + Table of Contents + + 1. [3]Introduction + + 2. [4]Basic Design + + 3. [5]Backwards Compatibility + + 4. [6]Markup + + 4.1. [7]Hyperlinks + + 4.2. [8]Images + + 5. [9]Icons + + 6. [10]Categories + + 7. [11]Urgency Levels + + 8. [12]Hints + + 9. [13]D-BUS Protocol + + 9.1. [14]Message commands + + 9.1.1. + [15]org.freedesktop.Notifications.GetCapabilities + + 9.1.2. [16]org.freedesktop.Notifications.Notify + + 9.1.3. + [17]org.freedesktop.Notifications.CloseNotification + + 9.1.4. + [18]org.freedesktop.Notifications.GetServerInformation + + 9.2. [19]Signals + + 9.2.1. + [20]org.freedesktop.Notifications.NotificationClosed + + 9.2.2. + [21]org.freedesktop.Notifications.ActionInvoked + +1. Introduction + + This is a draft standard for a desktop notifications service, through + which applications can generate passive popups (sometimes known as + "poptarts") to notify the user in an asynchronous manner of events. + + This specification explicitly does not include other types of + notification presentation such as modal message boxes, window manager + decorations or window list annotations. + + Example use cases include: + + * Presence changes in IM programs: for instance, MSN Messenger on + Windows pioneered the use of passive popups to indicate presence + changes. + + * Scheduled alarm + + * Completed file transfer + + * New mail notification + + * Low disk space/battery warnings + + -------------------------------------------------------------------------- + +2. Basic Design + + In order to ensure that multiple notifications can easily be displayed + at once, and to provide a convenient implementation, all notifications are + controlled by a single session-scoped service which exposes a D-BUS + interface. + + On startup, a conforming implementation should take the + org.freedesktop.Notifications service on the session bus. This service + will be referred to as the "notification server" or just "the server" in + this document. It can optionally be activated automatically by the bus + process, however this is not required and notification server clients must + not assume that it is available. + + The server should implement the org.freedesktop.Notifications interface + on an object with the path "/org/freedesktop/Notifications". This is the + only interface required by this version of the specification. + + A notification has the following components: + + Table 1. Notification Components + + +------------------------------------------------------------------------+ + | Component | Description | + |--------------------+---------------------------------------------------| + | | This is the optional name of the application | + | | sending the notification. This should be the | + | Application Name | application's formal name, rather than some sort | + | | of ID. An example would be "FredApp E-Mail | + | | Client," rather than "fredapp-email-client." | + |--------------------+---------------------------------------------------| + | Replaces ID | An optional ID of an existing notification that | + | | this notification is intended to replace. | + |--------------------+---------------------------------------------------| + | | The notification icon. This is represented | + | | either as a URI (file:// is the only URI schema | + | Notification Icon | supported right now) or a name in a | + | | freedesktop.org-compliant icon theme (not a GTK+ | + | | stock ID). | + |--------------------+---------------------------------------------------| + | | This is a single line overview of the | + | | notification. For instance, "You have mail" or "A | + | | friend has come online". It should generally not | + | Summary | be longer than 40 characters, though this is not | + | | a requirement, and server implementations should | + | | word wrap if necessary. The summary must be | + | | encoded using UTF-8. | + |--------------------+---------------------------------------------------| + | | | + | | | + | | This is a multi-line body of text. Each line is | + | | a paragraph, server implementations are free to | + | | word wrap them as they see fit. | + | Body | | + | | The body may contain simple markup as specified | + | | in [22]Markup. It must be encoded using UTF-8. | + | | | + | | If the body is omitted, just the summary is | + | | displayed. | + |--------------------+---------------------------------------------------| + | | | + | | | + | | The actions send a request message back to the | + | | notification client when invoked. This | + | | functionality may not be implemented by the | + | | notification server, conforming clients should | + | | check if it is available before using it (see the | + | | GetCapabilities message in [23]Protocol). An | + | | implementation is free to ignore any requested by | + | | the client. As an example one possible rendering | + | | of actions would be as buttons in the | + | Actions | notification popup. | + | | | + | | Actions are sent over as a list of pairs. Each | + | | even element in the list (starting at index 0) | + | | represents the identifier for the action. Each | + | | odd element in the list is the localized string | + | | that will be displayed to the user. | + | | | + | | The default action (usually invoked my clicking | + | | the notification) should have a key named | + | | "default". The name can be anything, though | + | | implementations are free not to display it. | + |--------------------+---------------------------------------------------| + | | | + | | | + | | See [24]Hints. | + | | | + | | Beyond the core protocol is the hints table. A | + | | couple of core elements have been moved to hints | + | | mostly because in a huge number of cases their | + | | default values would be sufficent. The elements | + | | moved to hints are: | + | | | + | | Elements Moved to Hints | + | | | + | | Element: Category ID | + | | | + | Hints | Description: An optional ID representing the type | + | | of notification (the name has been changed from | + | | Notification Type ID in pervious versions). See | + | | [25]Categories. | + | | | + | | Element: Urgency Level | + | | | + | | Description: The urgency of the notification. See | + | | [26]Urgency Levels. (Defaults to 1 - Normal) | + | | | + | | Element: Icon Data | + | | | + | | Description: Instead of overloading the icon | + | | field we now have an icon_data field that is used | + | | when icon is blank. | + |--------------------+---------------------------------------------------| + | | | + | | | + | | The timeout time in milliseconds since the | + | | display of the notification at which the | + | | notification should automatically close. | + | Expiration Timeout | | + | | If -1, the notification's expiration time is | + | | dependent on the notification server's settings, | + | | and may vary for the type of notification. | + | | | + | | If 0, the notification never expires. | + +------------------------------------------------------------------------+ + + Each notification displayed is allocated a unique ID by the server. This + is unique within the session. While the notification server is running, + the ID will not be recycled unless the capacity of a uint32 is exceeded. + + This can be used to hide the notification before the expiration timeout + is reached. It can also be used to atomically replace the notification + with another. This allows you to (for instance) modify the contents of a + notification while it's on-screen. + + -------------------------------------------------------------------------- + +3. Backwards Compatibility + + Clients should try and avoid making assumptions about the presentation + and abilities of the notification server. The message content is the most + important thing. + + Clients can check with the server what capabilities are supported using + the GetCapabilities message. See [27]Protocol. + + If a client requires a response from a passive popup, it should be coded + such that a non-focus-stealing message box can be used in the case that + the notification server does not support this feature. + + -------------------------------------------------------------------------- + +4. Markup + + Body text may contain markup. The markup is XML-based, and consists of a + small subset of HTML along with a few additional tags. + + The following tags should be supported by the notification server. + Though it is optional, it is recommended. Notification servers that do not + support these tags should filter them out. + + +------------------------------------------+ + | <b> ... </b> | Bold | + |------------------------------+-----------| + | <i> ... </i> | Italic | + |------------------------------+-----------| + | <u> ... </u> | Underline | + |------------------------------+-----------| + | <a href="..."> ... </a> | Hyperlink | + |------------------------------+-----------| + | <img src="..." alt="..."/> | Image | + +------------------------------------------+ + + A full-blown HTML implementation is not required of this spec, and + notifications should never take advantage of tags that are not listed + above. As notifications are not a substitute for web browsers or complex + dialogs, advanced layout is not necessary, and may in fact limit the + number of systems that notification services can run on, due to memory + usage and screen space. Such examples are PDAs, certain cell phones, and + slow PCs or laptops with little memory. + + For the same reason, a full XML or XHTML implementation using XSLT or + CSS stylesheets is not part of this specification. Information that must + be presented in a more complex form should use an application-specific + dialog, a web browser, or some other display mechanism. + + The tags specified above mark up the content in a way that allows them + to be stripped out on some implementations without impacting the actual + content. + + -------------------------------------------------------------------------- + + 4.1. Hyperlinks + + Hyperlinks allow for linking one or more words to a URI. There is no + requirement to allow for images to be linked, and it is highly suggested + that implementations do not allow this, as there is no clean-looking, + standard visual indicator for a hyperlinked image. + + Hyperlinked text should appear in the standard blue underline format. + + Hyperlinks cannot function as a replacement for actions. They are used + to link to local directories or remote sites using standard URI schemes. + + Implementations are not required to support hyperlinks. + + -------------------------------------------------------------------------- + + 4.2. Images + + Images may be placed in the notification, but this should be done with + caution. The image should never exceed 200x100, but this should be thought + of as a maximum size. Images should always have alternative text provided + through the alt="..." attribute. + + Image data cannot be embedded in the message itself. Images referenced + must always be local files. + + Implementations are not required to support images. + + -------------------------------------------------------------------------- + +5. Icons + + A notification can optionally have an icon specified by the Notification + Icon field or by the icon_data hint. + + The icon_data field should be a raw image data structure of signature + (iiibiiay) which describes the width, height, rowstride, has alpha, bits + per sample, channels and image data respectively. + + -------------------------------------------------------------------------- + +6. Categories + + Notifications can optionally have a type indicator. Although neither + client or nor server must support this, some may choose to. Those servers + implementing categories may use them to intelligently display the + notification in a certain way, or group notifications of similar types. + + Categories are in class.specific form. class specifies the generic type + of notification, and specific specifies the more specific type of + notification. + + If a specific type of notification does not exist for your notification, + but the generic kind does, a notification of type class is acceptable. + + Third parties, when defining their own categories, should discuss the + possibility of standardizing on the hint with other parties, preferably in + a place such as the [28]xdg mailing list at [29]freedesktop.org. If it + warrants a standard, it will be added to the table above. If no consensus + is reached, the category should be in the form of "x-vendor.class.name." + + The following table lists standard notifications as defined by this + spec. More will be added in time. + + Table 2. Categories + + +------------------------------------------------------------------------+ + | Type | Description | + |------------------------+-----------------------------------------------| + | "device" | A generic device-related notification that | + | | doesn't fit into any other category. | + |------------------------+-----------------------------------------------| + | "device.added" | A device, such as a USB device, was added to | + | | the system. | + |------------------------+-----------------------------------------------| + | "device.error" | A device had some kind of error. | + |------------------------+-----------------------------------------------| + | "device.removed" | A device, such as a USB device, was removed | + | | from the system. | + |------------------------+-----------------------------------------------| + | "email" | A generic e-mail-related notification that | + | | doesn't fit into any other category. | + |------------------------+-----------------------------------------------| + | "email.arrived" | A new e-mail notification. | + |------------------------+-----------------------------------------------| + | "email.bounced" | A notification stating that an e-mail has | + | | bounced. | + |------------------------+-----------------------------------------------| + | | A generic instant message-related | + | "im" | notification that doesn't fit into any other | + | | category. | + |------------------------+-----------------------------------------------| + | "im.error" | An instant message error notification. | + |------------------------+-----------------------------------------------| + | "im.received" | A received instant message notification. | + |------------------------+-----------------------------------------------| + | "network" | A generic network notification that doesn't | + | | fit into any other category. | + |------------------------+-----------------------------------------------| + | | A network connection notification, such as | + | "network.connected" | successful sign-on to a network service. This | + | | should not be confused with device.added for | + | | new network devices. | + |------------------------+-----------------------------------------------| + | | A network disconnected notification. This | + | "network.disconnected" | should not be confused with device.removed | + | | for disconnected network devices. | + |------------------------+-----------------------------------------------| + | "network.error" | A network-related or connection-related | + | | error. | + |------------------------+-----------------------------------------------| + | | A generic presence change notification that | + | "presence" | doesn't fit into any other category, such as | + | | going away or idle. | + |------------------------+-----------------------------------------------| + | "presence.offline" | An offline presence change notification. | + |------------------------+-----------------------------------------------| + | "presence.online" | An online presence change notification. | + |------------------------+-----------------------------------------------| + | | A generic file transfer or download | + | "transfer" | notification that doesn't fit into any other | + | | category. | + |------------------------+-----------------------------------------------| + | "transfer.complete" | A file transfer or download complete | + | | notification. | + |------------------------+-----------------------------------------------| + | "transfer.error" | A file transfer or download error. | + +------------------------------------------------------------------------+ + + -------------------------------------------------------------------------- + +7. Urgency Levels + + Notifications have an urgency level associated with them. This defines + the importance of the notification. For example, "Joe Bob signed on" would + be a low urgency. "You have new mail" or "A USB device was unplugged" + would be a normal urgency. "Your computer is on fire" would be a critical + urgency. + + Urgency levels are defined as follows: + + Table 3. Urgency Levels + + +--------------------+ + | Type | Description | + |------+-------------| + | 0 | Low | + |------+-------------| + | 1 | Normal | + |------+-------------| + | 2 | Critical | + +--------------------+ + + Developers must use their own judgement when deciding the urgency of a + notification. Typically, if the majority of programs are using the same + level for a specific type of urgency, other applications should follow + them. + + For low and normal urgencies, server implementations may display the + notifications how they choose. They should, however, have a sane + expiration timeout dependent on the urgency level. + + Critical notifications should not automatically expire, as they are + things that the user will most likely want to know about. They should only + be closed when the user dismisses them, for example, by clicking on the + notification. + + -------------------------------------------------------------------------- + +8. Hints + + Hints are a way to provide extra data to a notification server that the + server may be able to make use of. + + Neither clients nor notification servers are required to support any + hints. Both sides should assume that hints are not passed, and should + ignore any hints they do not understand. + + Third parties, when defining their own hints, should discuss the + possibility of standardizing on the hint with other parties, preferably in + a place such as the [30]xdg mailing list at [31]freedesktop.org. If it + warrants a standard, it will be added to the table above. If no consensus + is reached, the hint name should be in the form of "x-vendor-name." + + The value type for the hint dictionary in D-BUS is of the + DBUS_TYPE_VARIANT container type. This allows different data types + (string, integer, boolean, etc.) to be used for hints. When adding a + dictionary of hints, this type must be used, rather than putting the + actual hint value in as the dictionary value. + + The following table lists the standard hints as defined by this + specification. Future hints may be proposed and added to this list over + time. Once again, implementations are not required to support these. + + Table 4. Standard Hints + + +------------------------------------------------------------------------+ + | Name | Value Type | Description | + |------------------+------------+----------------------------------------| + | "urgency" | byte | The urgency level. | + |------------------+------------+----------------------------------------| + | "category" | string | The type of notification this is. | + |------------------+------------+----------------------------------------| + | | | This specifies the name of the | + | | | desktop filename representing the | + | | | calling program. This should be the | + | | | same as the prefix used for the | + | "desktop-entry"> | string | application's .desktop file. An | + | | | example would be "rhythmbox" from | + | | | "rhythmbox.desktop". This can be used | + | | | by the daemon to retrieve the correct | + | | | icon for the application, for logging | + | | | purposes, etc. | + |------------------+------------+----------------------------------------| + | | | This is a raw data image format | + | | | which describes the width, height, | + | "image_data" | (iiibiiay) | rowstride, has alpha, bits per sample, | + | | | channels and image data respectively. | + | | | We use this value if the icon field is | + | | | left blank. | + |------------------+------------+----------------------------------------| + | "sound-file" | string | The path to a sound file to play | + | | | when the notification pops up. | + |------------------+------------+----------------------------------------| + | | | Causes the server to suppress | + | | | playing any sounds, if it has that | + | "suppress-sound" | boolean | ability. This is usually set when the | + | | | client itself is going to play its own | + | | | sound. | + |------------------+------------+----------------------------------------| + | | | Specifies the X location on the | + | "x" | int | screen that the notification should | + | | | point to. The "y" hint must also be | + | | | specified. | + |------------------+------------+----------------------------------------| + | | | Specifies the Y location on the | + | "y" | int | screen that the notification should | + | | | point to. The "x" hint must also be | + | | | specified. | + +------------------------------------------------------------------------+ + + -------------------------------------------------------------------------- + +9. D-BUS Protocol + + The following messages must be supported by all implementations. + + -------------------------------------------------------------------------- + + 9.1. Message commands + + 9.1.1. org.freedesktop.Notifications.GetCapabilities + + STRING_ARRAY org.freedesktop.Notifications.GetCapabilities (void); + + This message takes no parameters. + + It returns an array of strings. Each string describes an optional + capability implemented by the server. The following values are defined by + this spec: + + Table 5. Server Capabilities + + +------------------------------------------------------------------------+ + | | The server will provide the specified actions to | + | "actions" | the user. Even if this cap is missing, actions may | + | | still be specified by the client, however the | + | | server is free to ignore them. | + |-------------------+----------------------------------------------------| + | | Supports body text. Some implementations may | + | "body" | only show the summary (for instance, onscreen | + | | displays, marquee/scrollers) | + |-------------------+----------------------------------------------------| + | "body-hyperlinks" | The server supports hyperlinks in the | + | | notifications. | + |-------------------+----------------------------------------------------| + | "body-images" | The server supports images in the notifications. | + |-------------------+----------------------------------------------------| + | | Supports markup in the body text. If marked up | + | "body-markup" | text is sent to a server that does not give this | + | | cap, the markup will show through as regular text | + | | so must be stripped clientside. | + |-------------------+----------------------------------------------------| + | | The server will render an animation of all the | + | | frames in a given image array. The client may | + | "icon-multi" | still specify multiple frames even if this cap | + | | and/or "icon-static" is missing, however the | + | | server is free to ignore them and use only the | + | | primary frame. | + |-------------------+----------------------------------------------------| + | | Supports display of exactly 1 frame of any given | + | "icon-static" | image array. This value is mutually exclusive with | + | | "icon-multi", it is a protocol error for the | + | | server to specify both. | + |-------------------+----------------------------------------------------| + | | The server supports sounds on notifications. If | + | "sound" | returned, the server must support the "sound-file" | + | | and "suppress-sound" hints. | + +------------------------------------------------------------------------+ + + New vendor-specific caps may be specified as long as they start with + "x-vendor". For instance, "x-gnome-foo-cap". Capability names must not + contain spaces. They are limited to alpha-numeric characters and dashes + ("-"). + + -------------------------------------------------------------------------- + + 9.1.2. org.freedesktop.Notifications.Notify + + UINT32 org.freedesktop.Notifications.Notify (STRING app_name, UINT32 + replaces_id, STRING app_icon, STRING summary, STRING body, ARRAY actions, + DICT hints, INT32 expire_timeout); + + Sends a notification to the notification server. + + Table 6. Notify Parameters + + +------------------------------------------------------------------------+ + | Name | Type | Description | + |----------------+--------+----------------------------------------------| + | app_name | STRING | The optional name of the application | + | | | sending the notification. Can be blank. | + |----------------+--------+----------------------------------------------| + | | | The optional notification ID that this | + | | | notification replaces. The server must | + | | | atomically (ie with no flicker or other | + | | | visual cues) replace the given notification | + | replaces_id | UINT32 | with this one. This allows clients to | + | | | effectively modify the notification while | + | | | it's active. A value of value of 0 means | + | | | that this notification won't replace any | + | | | existing notifications. | + |----------------+--------+----------------------------------------------| + | | | The optional program icon of the calling | + | app_icon | STRING | application. See [32]Icons. Can be an empty | + | | | string, indicating no icon. | + |----------------+--------+----------------------------------------------| + | summary | STRING | The summary text briefly describing the | + | | | notification. | + |----------------+--------+----------------------------------------------| + | body | STRING | The optional detailed body text. Can be | + | | | empty. | + |----------------+--------+----------------------------------------------| + | | | Actions are sent over as a list of pairs. | + | | | Each even element in the list (starting at | + | actions | ARRAY | index 0) represents the identifier for the | + | | | action. Each odd element in the list is the | + | | | localized string that will be displayed to | + | | | the user. | + |----------------+--------+----------------------------------------------| + | | | Optional hints that can be passed to the | + | | | server from the client program. Although | + | | | clients and servers should never assume each | + | hints | DICT | other supports any specific hints, they can | + | | | be used to pass along information, such as | + | | | the process PID or window ID, that the | + | | | server may be able to make use of. See | + | | | [33]Hints. Can be empty. | + |----------------+--------+----------------------------------------------| + | | | | + | | | | + | | | The timeout time in milliseconds since the | + | | | display of the notification at which the | + | expire_timeout | INT32 | notification should automatically close. | + | | | | + | | | If -1, the notification's expiration time | + | | | is dependent on the notification server's | + | | | settings, and may vary for the type of | + | | | notification. If 0, never expire. | + +------------------------------------------------------------------------+ + + If replaces_id is 0, the return value is a UINT32 that represent the + notification. It is unique, and will not be reused unless a MAXINT number + of notifications have been generated. An acceptable implementation may + just use an incrementing counter for the ID. The returned ID is always + greater than zero. Servers must make sure not to return zero as an ID. + + If replaces_id is not 0, the returned value is the same value as + replaces_id. + + -------------------------------------------------------------------------- + + 9.1.3. org.freedesktop.Notifications.CloseNotification + + void org.freedesktop.Notifications.CloseNotification (UINT32 id); + + Causes a notification to be forcefully closed and removed from the + user's view. It can be used, for example, in the event that what the + notification pertains to is no longer relevant, or to cancel a + notification with no expiration time. + + The NotificationClosed signal is emitted by this method. + + If the notification no longer exists, an empty D-BUS Error message is + sent back. + + -------------------------------------------------------------------------- + + 9.1.4. org.freedesktop.Notifications.GetServerInformation + + void org.freedesktop.Notifications.GetServerInformation (out STRING + name, out STRING vendor, out STRING version); + + This message returns the information on the server. Specifically, the + server name, vendor, and version number. + + Table 7. GetServerInformation Return Values + + +------------------------------------------------------------------------+ + | Name | Type | Description | + |---------+--------+-----------------------------------------------------| + | name | STRING | The product name of the server. | + |---------+--------+-----------------------------------------------------| + | vendor | STRING | The vendor name. For example, "KDE," "GNOME," | + | | | "freedesktop.org," or "Microsoft." | + |---------+--------+-----------------------------------------------------| + | version | STRING | The server's version number. | + +------------------------------------------------------------------------+ + + -------------------------------------------------------------------------- + + 9.2. Signals + + 9.2.1. org.freedesktop.Notifications.NotificationClosed + + org.freedesktop.Notifications.NotificationClosed (UINT32 id, UINT32 + reason); + + A completed notification is one that has timed out, or has been + dismissed by the user. + + Table 8. NotificationClosed Parameters + + +------------------------------------------------------------------------+ + | Name | Type | Description | + |--------+--------+------------------------------------------------------| + | id | UINT32 | The ID of the notification that was closed. | + |--------+--------+------------------------------------------------------| + | | | | + | | | | + | | | The reason the notification was closed. | + | | | | + | | | 1 - The notification expired. | + | reason | UINT32 | | + | | | 2 - The notification was dismissed by the user. | + | | | | + | | | 3 - The notification was closed by a call to | + | | | CloseNotification. | + | | | | + | | | 4 - Undefined/reserved reasons. | + +------------------------------------------------------------------------+ + + The ID specified in the signal is invalidated before the signal is sent + and may not be used in any further communications with the server. + + -------------------------------------------------------------------------- + + 9.2.2. org.freedesktop.Notifications.ActionInvoked + + org.freedesktop.Notifications.ActionInvoked (UINT32 id, STRING + action_key); + + This signal is emitted when one of the following occurs: + + * The user performs some global "invoking" action upon a notification. + For instance, clicking somewhere on the notification itself. + + * The user invokes a specific action as specified in the original + Notify request. For example, clicking on an action button. + + Table 9. ActionInvoked Parameters + + +------------------------------------------------------------------------+ + | Name | Type | Description | + |------------+--------+--------------------------------------------------| + | id | UINT32 | The ID of the notification emitting the | + | | | ActionInvoked signal. | + |------------+--------+--------------------------------------------------| + | action_key | STRING | The key of the action invoked. These match the | + | | | keys sent over in the list of actions. | + +------------------------------------------------------------------------+ + + [34]Note Clients should not assume the server will generate this signal. + Some servers may not support user interaction at all, or may not + support the concept of being able to "invoke" a notification. + +References + + Visible links + 1. mailto:mike@navi.cx + 2. mailto:chipx86@chipx86.com + 3. file:///tmp/html-A2Tahl#introduction + 4. file:///tmp/html-A2Tahl#basic-design + 5. file:///tmp/html-A2Tahl#backwards-compat + 6. file:///tmp/html-A2Tahl#markup + 7. file:///tmp/html-A2Tahl#hyperlinks + 8. file:///tmp/html-A2Tahl#images + 9. file:///tmp/html-A2Tahl#icons + 10. file:///tmp/html-A2Tahl#categories + 11. file:///tmp/html-A2Tahl#urgency-levels + 12. file:///tmp/html-A2Tahl#hints + 13. file:///tmp/html-A2Tahl#protocol + 14. file:///tmp/html-A2Tahl#commands + 15. file:///tmp/html-A2Tahl#command-get-capabilities + 16. file:///tmp/html-A2Tahl#command-notify + 17. file:///tmp/html-A2Tahl#command-close-notification + 18. file:///tmp/html-A2Tahl#command-get-server-information + 19. file:///tmp/html-A2Tahl#signals + 20. file:///tmp/html-A2Tahl#signal-notification-closed + 21. file:///tmp/html-A2Tahl#signal-action-invoked + 22. file:///tmp/html-A2Tahl#markup + 23. file:///tmp/html-A2Tahl#protocol + 24. file:///tmp/html-A2Tahl#hints + 25. file:///tmp/html-A2Tahl#categories + 26. file:///tmp/html-A2Tahl#urgency-levels + 27. file:///tmp/html-A2Tahl#protocol + 28. http://freedesktop.org/mailman/listinfo/xdg + 29. http://freedesktop.org/ + 30. http://freedesktop.org/mailman/listinfo/xdg + 31. http://freedesktop.org/ + 32. file:///tmp/html-A2Tahl#icons + 33. file:///tmp/html-A2Tahl#hints diff --git a/src/lib/notification/notification.c b/src/lib/notification/notification.c new file mode 100644 index 0000000..5326bcf --- /dev/null +++ b/src/lib/notification/notification.c @@ -0,0 +1,390 @@ +#include "E_Notify.h" +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <inttypes.h> +#include "e_notify_private.h" + +/* private functions */ +static Eina_List * e_notification_action_list_new(); +static E_Notification_Action *e_notification_action_new(const char *id, const char *name); + +/* (con|de)structor */ + +EAPI E_Notification * +e_notification_full_new(const char *app_name, unsigned int replaces_id, const char *app_icon, const char *summary, const char *body, int expire_timeout) +{ + E_Notification *n; + + n = e_notification_new(); + if (!n) return NULL; + + if (app_name) n->app_name = strdup(app_name); + n->replaces_id = replaces_id; + if (app_icon) n->app_icon = strdup(app_icon); + if (summary) n->summary = strdup(summary); + if (body) n->body = strdup(body); + n->expire_timeout = expire_timeout; + + + return n; +} + +EAPI E_Notification * +e_notification_new() +{ + E_Notification *n; + n = calloc(1, sizeof(E_Notification)); + if (!n) return NULL; + n->refcount = 1; + + return n; +} + +EAPI void +e_notification_ref(E_Notification *n) +{ + n->refcount++; +} + +EAPI void +e_notification_unref(E_Notification *n) +{ + if (--n->refcount == 0) e_notification_free(n); +} + +EAPI void +e_notification_free(E_Notification *n) +{ + if (!n) return; + + if (n->app_name) free(n->app_name); + if (n->app_icon) free(n->app_icon); + if (n->summary) free(n->summary); + if (n->body) free(n->body); + + eina_list_free(n->actions); + + if (n->hints.category) free(n->hints.category); + if (n->hints.desktop) free(n->hints.desktop); + if (n->hints.sound_file) free(n->hints.sound_file); + if (n->hints.image_data) e_notification_image_free(n->hints.image_data); + if (n->hints.icon_data) e_notification_image_free(n->hints.icon_data); + free(n); +} + +/* mutators */ +EAPI void +e_notification_id_set(E_Notification *note, unsigned int id) +{ + note->id = id; +} + +EAPI void +e_notification_app_name_set(E_Notification *note, const char *app_name) +{ + if (note->app_name) free(note->app_name); + if (app_name) note->app_name = strdup(app_name); +} + +EAPI void +e_notification_app_icon_set(E_Notification *note, const char *app_icon) +{ + if (note->app_icon) free(note->app_icon); + if (app_icon) note->app_icon = strdup(app_icon); +} + +EAPI void +e_notification_summary_set(E_Notification *note, const char *summary) +{ + if (note->summary) free(note->summary); + if (summary) note->summary = strdup(summary); +} + +EAPI void +e_notification_body_set(E_Notification *note, const char *body) +{ + if (note->body) free(note->body); + if (body) note->body = strdup(body); +} + +EAPI void +e_notification_action_add(E_Notification *n, const char *action_id, const char *action_name) +{ + E_Notification_Action *a; + + if (!n->actions) + n->actions = e_notification_action_list_new(); + + a = e_notification_action_new(action_id, action_name); + n->actions = eina_list_append(n->actions, a); +} + + +EAPI void +e_notification_replaces_id_set(E_Notification *note, int replaces_id) +{ + note->replaces_id = replaces_id; +} + +EAPI void +e_notification_timeout_set(E_Notification *note, int timeout) +{ + note->expire_timeout = timeout; +} + +EAPI void +e_notification_closed_set(E_Notification *note, unsigned char closed) +{ + note->closed = closed; +} + + +/* accessors */ +EAPI unsigned int +e_notification_id_get(E_Notification *note) +{ + return note->id; +} + +EAPI const char * +e_notification_app_name_get(E_Notification *note) +{ + return note->app_name; +} + +EAPI const char * +e_notification_app_icon_get(E_Notification *note) +{ + return note->app_icon; +} + +EAPI const char * +e_notification_summary_get(E_Notification *note) +{ + return note->summary; +} + +EAPI const char * +e_notification_body_get(E_Notification *note) +{ + return note->body; +} + +EAPI Eina_List * +e_notification_actions_get(E_Notification *note) +{ + return note->actions; +} + +EAPI int +e_notification_replaces_id_get(E_Notification *note) +{ + return note->replaces_id; +} + +EAPI int +e_notification_timeout_get(E_Notification *note) +{ + return note->expire_timeout; +} + +EAPI unsigned char +e_notification_closed_get(E_Notification *note) +{ + return note->closed; +} + +/***** actions *****/ + +static Eina_List * +e_notification_action_list_new() +{ + Eina_List *alist; + + alist = NULL; + return alist; +} + +static E_Notification_Action * +e_notification_action_new(const char *id, const char *name) +{ + E_Notification_Action *act; + act = malloc(sizeof(E_Notification_Action)); + act->id = strdup(id); + act->name = strdup(name); + return act; +} + + +/********* hints *******/ + + +EAPI void +e_notification_hint_urgency_set(E_Notification *n, char urgency) +{ + n->hints.urgency = urgency; + n->hint_flags |= E_NOTIFICATION_HINT_URGENCY; +} + +EAPI void +e_notification_hint_category_set(E_Notification *n, const char *category) +{ + if (n->hints.category) free(n->hints.category); + n->hints.category = strdup(category); + n->hint_flags |= E_NOTIFICATION_HINT_CATEGORY; +} + +EAPI void +e_notification_hint_desktop_set(E_Notification *n, const char *desktop) +{ + if (n->hints.desktop) free(n->hints.desktop); + n->hints.desktop = strdup(desktop); + n->hint_flags |= E_NOTIFICATION_HINT_DESKTOP; +} + +EAPI void +e_notification_hint_sound_file_set(E_Notification *n, const char *sound_file) +{ + if (n->hints.sound_file) free(n->hints.sound_file); + n->hints.sound_file = strdup(sound_file); + n->hint_flags |= E_NOTIFICATION_HINT_SOUND_FILE; +} + +EAPI void +e_notification_hint_suppress_sound_set(E_Notification *n, char suppress_sound) +{ + n->hints.suppress_sound = suppress_sound; + n->hint_flags |= E_NOTIFICATION_HINT_SUPPRESS_SOUND; +} + +EAPI void +e_notification_hint_xy_set(E_Notification *n, int x, int y) +{ + n->hints.x = x; + n->hints.y = y; + n->hint_flags |= E_NOTIFICATION_HINT_XY; +} + +EAPI void +e_notification_hint_image_data_set(E_Notification *n, E_Notification_Image *image) +{ + n->hints.image_data = image; +} + + +EAPI char +e_notification_hint_urgency_get(E_Notification *n) +{ + return (n->hint_flags & E_NOTIFICATION_HINT_URGENCY ? n->hints.urgency : 1); +} + +EAPI const char * +e_notification_hint_category_get(E_Notification *n) +{ + return n->hints.category; +} + +EAPI const char * +e_notification_hint_desktop_get(E_Notification *n) +{ + return n->hints.desktop; +} + +EAPI const char * +e_notification_hint_sound_file_get(E_Notification *n) +{ + return n->hints.sound_file; +} + +EAPI char +e_notification_hint_suppress_sound_get(E_Notification *n) +{ + return n->hints.suppress_sound; +} + +EAPI int +e_notification_hint_xy_get(E_Notification *n, int *x, int *y) +{ + if (x) *x = n->hints.x; + if (y) *y = n->hints.y; + + return (n->hint_flags & E_NOTIFICATION_HINT_XY ? 1 : 0); +} + +EAPI E_Notification_Image * +e_notification_hint_image_data_get(E_Notification *n) +{ + return n->hints.image_data; +} + + +EAPI E_Notification_Image * +e_notification_hint_icon_data_get(E_Notification *n) +{ + return n->hints.icon_data; +} + +EAPI E_Notification_Image * +e_notification_image_new() +{ + E_Notification_Image *img; + + img = calloc(1, sizeof(E_Notification_Image)); + return img; +} + +EAPI void +e_notification_image_free(E_Notification_Image *img) +{ + if (img->data) free(img->data); + if (img) free(img); +} + + +EAPI Evas_Object * +e_notification_image_evas_object_add(Evas *evas, E_Notification_Image *img) +{ + int *imgdata; + Evas_Object *o = NULL; + + if (!evas || !img) return NULL; + + o = evas_object_image_add(evas); + evas_object_resize(o, img->width, img->height); + evas_object_image_alpha_set(o, img->has_alpha); + evas_object_image_size_set(o, img->width, img->height); + evas_object_image_fill_set(o, 0, 0, img->width, img->height); + imgdata = evas_object_image_data_get(o, 1); + + if (img->bits_per_sample == 8) + { + /* Although not specified. + * The data are very likely to come from a GdkPixbuf + * which align each row on a 4-bytes boundary when using RGB. + * And is RGBA otherwise. + */ + int x, y; + int32_t *dest; + unsigned char *src; + for (y = 0; y < img->height; y++) + { + src = img->data + y * img->rowstride; + dest = imgdata + y * img->width; + + for (x = 0; x < img->width; x++, src += img->channels, dest++) + { + *dest = *(src + 2); + *dest += *(src + 1) << 8; + *dest += *(src + 0) << 16; + if (img->has_alpha) + *dest += *(src + 3) << 24; + else + *dest += 255 << 24; + } + } + } + evas_object_image_data_update_add(o, 0, 0, img->width, img->height); + evas_object_image_data_set(o, imgdata); + return o; +} diff --git a/src/lib/ofono/E_Ofono.h b/src/lib/ofono/E_Ofono.h new file mode 100644 index 0000000..1b9d3ef --- /dev/null +++ b/src/lib/ofono/E_Ofono.h @@ -0,0 +1,131 @@ +#ifndef E_OFONO_H +#define E_OFONO_H + +#include <stdint.h> +#include <stdio.h> + +#include <Eina.h> +#include <Ecore.h> +#include <E_DBus.h> + +#ifdef EAPI +#undef EAPI +#endif +#ifdef _MSC_VER +# ifdef BUILDING_DLL +# define EAPI __declspec(dllexport) +# else +# define EAPI __declspec(dllimport) +# endif +#else +# ifdef __GNUC__ +# if __GNUC__ >= 4 +# define EAPI __attribute__ ((visibility("default"))) +# else +# define EAPI +# endif +# else +# define EAPI +# endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + + /* Ecore Events */ + extern int E_OFONO_EVENT_MANAGER_IN; + extern int E_OFONO_EVENT_MANAGER_OUT; + extern int E_OFONO_EVENT_ELEMENT_ADD; + extern int E_OFONO_EVENT_ELEMENT_DEL; + extern int E_OFONO_EVENT_ELEMENT_UPDATED; + + typedef struct _E_Ofono_Element E_Ofono_Element; + + struct _E_Ofono_Element + { + const char *path; + const char *interface; + E_DBus_Signal_Handler *signal_handler; + Eina_Inlist *props; + + /* private */ + struct { + Eina_Inlist *properties_get; + Eina_Inlist *property_set; + Eina_Inlist *send_sms; + } _pending; + struct { + Ecore_Idler *changed; + } _idler; + Eina_Inlist *_listeners; + int _references; + }; + + /* General Public API */ + EAPI unsigned int e_ofono_system_init(E_DBus_Connection *edbus_conn) EINA_ARG_NONNULL(1); + EAPI unsigned int e_ofono_system_shutdown(void); + + /* Manager Methods */ + EAPI E_Ofono_Element *e_ofono_manager_get(void) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_manager_modems_get(Eina_Array **array); + + /* Modem Methods */ + EAPI Eina_Bool e_ofono_modem_powered_get(const E_Ofono_Element *element, Eina_Bool *powered) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_modem_powered_set(E_Ofono_Element *element, Eina_Bool powered, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_modem_name_get(const E_Ofono_Element *element, const char **name) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + /* NetworkRegistration Methods */ + EAPI Eina_Bool e_ofono_netreg_mode_get(const E_Ofono_Element *element, const char **mode) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_netreg_status_get(const E_Ofono_Element *element, const char **status) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_netreg_operator_get(const E_Ofono_Element *element, const char **op) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_netreg_strength_get(const E_Ofono_Element *element, uint8_t *strength) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + /* SMS Methods */ + EAPI Eina_Bool e_ofono_sms_sca_get(const E_Ofono_Element *element, const char **sca) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_sms_sca_set(E_Ofono_Element *element, const char *sca, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_sms_send_message(E_Ofono_Element *element, const char *number, const char *message, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + + /* Low-Level API: + * + * Should just be used to work around problems until proper solution + * is made into e_ofono. + */ + EAPI Eina_Bool e_ofono_manager_sync_elements(void); + + EAPI Eina_Bool e_ofono_elements_get_all(unsigned int *count, E_Ofono_Element ***p_elements) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_elements_get_all_type(const char *type, unsigned int *count, E_Ofono_Element ***p_elements) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + EAPI E_Ofono_Element *e_ofono_element_get(const char *path, const char *interface) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + + EAPI void e_ofono_element_listener_add(E_Ofono_Element *element, void (*cb)(void *data, const E_Ofono_Element *element), const void *data, void (*free_data)(void *data)) EINA_ARG_NONNULL(1, 2); + EAPI void e_ofono_element_listener_del(E_Ofono_Element *element, void (*cb)(void *data, const E_Ofono_Element *element), const void *data) EINA_ARG_NONNULL(1, 2); + + EAPI int e_ofono_element_ref(E_Ofono_Element *element) EINA_ARG_NONNULL(1); + EAPI int e_ofono_element_unref(E_Ofono_Element *element) EINA_ARG_NONNULL(1); + + EAPI void e_ofono_element_print(FILE *fp, const E_Ofono_Element *element) EINA_ARG_NONNULL(1, 2); + + + EAPI Eina_Bool e_ofono_element_properties_sync(E_Ofono_Element *element) EINA_ARG_NONNULL(1); + EAPI Eina_Bool e_ofono_element_properties_sync_full(E_Ofono_Element *element, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1); + + EAPI Eina_Bool e_ofono_element_property_set(E_Ofono_Element *element, const char *prop, int type, const void *value) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_element_property_set_full(E_Ofono_Element *element, const char *prop, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_element_property_dict_set_full(E_Ofono_Element *element, const char *prop, const char *key, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + + EAPI void e_ofono_element_properties_list(const E_Ofono_Element *element, Eina_Bool (*cb)(void *data, const E_Ofono_Element *element, const char *name, int type, const void *value), const void *data) EINA_ARG_NONNULL(1, 2); + + EAPI Eina_Bool e_ofono_element_property_type_get_stringshared(const E_Ofono_Element *element, const char *name, int *type) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_element_property_type_get(const E_Ofono_Element *element, const char *name, int *type) EINA_ARG_NONNULL(1, 2, 3) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_element_property_dict_get_stringshared(const E_Ofono_Element *element, const char *dict_name, const char *key_name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_element_property_get_stringshared(const E_Ofono_Element *element, const char *name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_element_property_get(const E_Ofono_Element *element, const char *name, int *type, void *value) EINA_ARG_NONNULL(1, 2, 4) EINA_WARN_UNUSED_RESULT; + + EAPI Eina_Bool e_ofono_element_is_manager(const E_Ofono_Element *element) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_element_is_modem(const E_Ofono_Element *element) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + EAPI Eina_Bool e_ofono_element_is_netreg(const E_Ofono_Element *element) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; + +#ifdef __cplusplus +} +#endif +#endif /* E_OFONO_H */ diff --git a/src/lib/ofono/Makefile.am b/src/lib/ofono/Makefile.am new file mode 100644 index 0000000..715d1db --- /dev/null +++ b/src/lib/ofono/Makefile.am @@ -0,0 +1,29 @@ +MAINTAINERCLEANFILES = Makefile.in + +AM_CPPFLAGS = \ +-I $(top_srcdir)/src/lib/dbus \ +@EDBUS_CFLAGS@ @EVAS_CFLAGS@ @EINA_CFLAGS@ + +if BUILD_EOFONO + +lib_LTLIBRARIES = libeofono.la +include_HEADERS = E_Ofono.h + +libeofono_la_SOURCES = \ +E_Ofono.h \ +e_ofono_private.h \ +e_ofono.c \ +e_ofono_element.c \ +e_ofono_manager.c \ +e_ofono_modem.c \ +e_ofono_network_reg.c \ +e_ofono_sms.c + +libeofono_la_LIBADD = \ +@EDBUS_LIBS@ @EVAS_LIBS@ \ +$(top_builddir)/src/lib/dbus/libedbus.la \ +@EINA_LIBS@ + +libeofono_la_LDFLAGS = -version-info @version_info@ @eofono_release_info@ + +endif diff --git a/src/lib/ofono/e_ofono.c b/src/lib/ofono/e_ofono.c new file mode 100644 index 0000000..8ca58b3 --- /dev/null +++ b/src/lib/ofono/e_ofono.c @@ -0,0 +1,319 @@ +#include "e_ofono_private.h" +#include <stdlib.h> +#include <string.h> + +static E_DBus_Signal_Handler *cb_name_owner_changed = NULL; +static DBusPendingCall *pending_get_name_owner = NULL; +static unsigned int init_count = 0; +static char *unique_name = NULL; + +static const char bus_name[] = "org.ofono"; +static const char fdo_bus_name[] = "org.freedesktop.DBus"; +static const char fdo_interface[] = "org.freedesktop.DBus"; +static const char fdo_path[] = "/org/freedesktop/DBus"; + +E_DBus_Connection *e_ofono_conn = NULL; + +EAPI int E_OFONO_EVENT_MANAGER_IN = 0; +EAPI int E_OFONO_EVENT_MANAGER_OUT = 0; +EAPI int E_OFONO_EVENT_ELEMENT_ADD = 0; +EAPI int E_OFONO_EVENT_ELEMENT_DEL = 0; +EAPI int E_OFONO_EVENT_ELEMENT_UPDATED = 0; + +const char *e_ofono_iface_manager = NULL; +const char *e_ofono_prop_modems = NULL; +const char *e_ofono_iface_modem = NULL; +const char *e_ofono_prop_name = NULL; +const char *e_ofono_prop_powered = NULL; +const char *e_ofono_prop_interfaces = NULL; +const char *e_ofono_iface_netreg = NULL; +const char *e_ofono_prop_mode = NULL; +const char *e_ofono_prop_status = NULL; +const char *e_ofono_prop_operator = NULL; +const char *e_ofono_prop_strength = NULL; +const char *e_ofono_iface_sms = NULL; +const char *e_ofono_prop_sca = NULL; +const char *e_ofono_method_send_sms = NULL; + +int _e_dbus_ofono_log_dom = -1; + +const char * +e_ofono_system_bus_name_get(void) +{ + return unique_name ? unique_name : bus_name; +} + +/*********************************************************************** + * Manager + ***********************************************************************/ + +/* + * FIXME: Do we really need to call Manager.GetProperties()? + */ + +/** + * Synchronize elements with server. + * + * This will call Manager.GetProperties() on server, retrieve properties + * and some element paths and then request their properties. + * + * This call will add events E_OFONO_EVENT_ELEMENT_ADD and + * E_OFONO_EVENT_ELEMENT_UPDATED to the main loop. + * + * This will not remove stale elements. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_manager_sync_elements(void) +{ + E_Ofono_Element *manager; + + if (!unique_name) + return FALSE; + manager = e_ofono_element_register(manager_path, e_ofono_iface_manager); + if (manager) + e_ofono_element_properties_sync(manager); + else + return FALSE; + + DBG("sync_manager: %s (%s)", unique_name, bus_name); + + return TRUE; +} + +static void +_e_ofono_system_name_owner_exit(void) +{ + e_ofono_manager_clear_elements(); + ecore_event_add(E_OFONO_EVENT_MANAGER_OUT, NULL, NULL, NULL); + + free(unique_name); + unique_name = NULL; +} + +static void +_e_ofono_system_name_owner_enter(const char *uid) +{ + DBG("enter ofono at %s (old was %s)", uid, unique_name); + if (unique_name && strcmp(unique_name, uid) == 0) + { + DBG("same unique_name for ofono, ignore."); + return; + } + + if (unique_name) + _e_ofono_system_name_owner_exit(); + + unique_name = strdup(uid); + + ecore_event_add(E_OFONO_EVENT_MANAGER_IN, NULL, NULL, NULL); + e_ofono_manager_sync_elements(); +} + + +static void +_e_ofono_system_name_owner_changed(void *data __UNUSED__, DBusMessage *msg) +{ + DBusError err; + const char *name, *from, *to; + + dbus_error_init(&err); + if (!dbus_message_get_args(msg, &err, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_STRING, &from, + DBUS_TYPE_STRING, &to, + DBUS_TYPE_INVALID)) + { + ERR("could not get NameOwnerChanged arguments: %s: %s", + err.name, err.message); + dbus_error_free(&err); + return; + } + + if (strcmp(name, bus_name) != 0) + return; + + DBG("NameOwnerChanged from=[%s] to=[%s]", from, to); + + if (from[0] == '\0' && to[0] != '\0') + _e_ofono_system_name_owner_enter(to); + else if (from[0] != '\0' && to[0] == '\0') + { + DBG("exit ofono at %s", from); + if (strcmp(unique_name, from) != 0) + DBG("%s was not the known name %s, ignored.", from, unique_name); + else + _e_ofono_system_name_owner_exit(); + } + else + DBG("unknow change from %s to %s", from, to); +} + +static void +_e_ofono_get_name_owner(void *data __UNUSED__, DBusMessage *msg, DBusError *err) +{ + DBusMessageIter itr; + int t; + const char *uid; + + pending_get_name_owner = NULL; + + if (!_dbus_callback_check_and_init(msg, &itr, err)) + return; + + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING)) + return; + + dbus_message_iter_get_basic(&itr, &uid); + if (!uid) + { + ERR("no name owner!"); + return; + } + + _e_ofono_system_name_owner_enter(uid); + return; +} + +/** + * Initialize E oFono (E_Ofono) system. + * + * This will connect and watch org.ofono.Manager and Element + * events and translate to Ecore main loop events, also provide a + * proxy for method invocation on server. + * + * Interesting events are: + * - E_OFONO_EVENT_MANAGER_IN: issued when ofono is avaiable. + * - E_OFONO_EVENT_MANAGER_OUT: issued when ofono connection is lost. + * - E_OFONO_EVENT_ELEMENT_ADD: element was added. + * - E_OFONO_EVENT_ELEMENT_DEL: element was deleted. + * - E_OFONO_EVENT_ELEMENT_UPDATED: element was updated (properties + * or state changed). + * + * Manager IN/OUT events do not provide any event information, just + * tells you that system is usable or not. After manager is out, all + * elements will be removed, so after this event do not use the system anymore. + * + * Element events will give you an element object. After DEL event callback + * returns, that element will not be valid anymore. + */ +unsigned int +e_ofono_system_init(E_DBus_Connection *edbus_conn) +{ + init_count++; + + if (init_count > 1) + return init_count; + + _e_dbus_ofono_log_dom = eina_log_domain_register + ("e_dbus_ofono", EINA_LOG_DEFAULT_COLOR); + + if(_e_dbus_ofono_log_dom < 0) + { + EINA_LOG_ERR + ("impossible to create a log domain for edbus_ofono module"); + return -1; + } + + if (E_OFONO_EVENT_MANAGER_IN == 0) + E_OFONO_EVENT_MANAGER_IN = ecore_event_type_new(); + if (E_OFONO_EVENT_MANAGER_OUT == 0) + E_OFONO_EVENT_MANAGER_OUT = ecore_event_type_new(); + if (E_OFONO_EVENT_ELEMENT_ADD == 0) + E_OFONO_EVENT_ELEMENT_ADD = ecore_event_type_new(); + if (E_OFONO_EVENT_ELEMENT_DEL == 0) + E_OFONO_EVENT_ELEMENT_DEL = ecore_event_type_new(); + if (E_OFONO_EVENT_ELEMENT_UPDATED == 0) + E_OFONO_EVENT_ELEMENT_UPDATED = ecore_event_type_new(); + + if (e_ofono_iface_manager == NULL) + e_ofono_iface_manager = eina_stringshare_add("org.ofono.Manager"); + if (e_ofono_prop_modems == NULL) + e_ofono_prop_modems = eina_stringshare_add("Modems"); + if (e_ofono_iface_modem == NULL) + e_ofono_iface_modem = eina_stringshare_add("org.ofono.Modem"); + if (e_ofono_prop_name == NULL) + e_ofono_prop_name = eina_stringshare_add("Name"); + if (e_ofono_prop_powered == NULL) + e_ofono_prop_powered = eina_stringshare_add("Powered"); + if (e_ofono_prop_interfaces == NULL) + e_ofono_prop_interfaces = eina_stringshare_add("Interfaces"); + if (e_ofono_iface_netreg == NULL) + e_ofono_iface_netreg = eina_stringshare_add("org.ofono.NetworkRegistration"); + if (e_ofono_prop_mode == NULL) + e_ofono_prop_mode = eina_stringshare_add("Mode"); + if (e_ofono_prop_status == NULL) + e_ofono_prop_status = eina_stringshare_add("Status"); + if (e_ofono_prop_operator == NULL) + e_ofono_prop_operator = eina_stringshare_add("Operator"); + if (e_ofono_prop_strength == NULL) + e_ofono_prop_strength = eina_stringshare_add("Strength"); + if (e_ofono_iface_sms == NULL) + e_ofono_iface_sms = eina_stringshare_add("org.ofono.SmsManager"); + if (e_ofono_prop_sca == NULL) + e_ofono_prop_sca = eina_stringshare_add("ServiceCenterAddress"); + if (e_ofono_method_send_sms == NULL) + e_ofono_method_send_sms = eina_stringshare_add("SendMessage"); + + e_ofono_conn = edbus_conn; + cb_name_owner_changed = e_dbus_signal_handler_add + (e_ofono_conn, fdo_bus_name, fdo_path, fdo_interface, "NameOwnerChanged", + _e_ofono_system_name_owner_changed, NULL); + + if (pending_get_name_owner) + dbus_pending_call_cancel(pending_get_name_owner); + + pending_get_name_owner = e_dbus_get_name_owner + (e_ofono_conn, bus_name, _e_ofono_get_name_owner, NULL); + + e_ofono_elements_init(); + + return init_count; +} + + +static inline void +_stringshare_del(const char **str) +{ + if (!*str) + return; + eina_stringshare_del(*str); + *str = NULL; +} + +/** + * Shutdown ofono system. + * + * When count drops to 0 resources will be released and no calls should be + * made anymore. + */ +unsigned int +e_ofono_system_shutdown(void) +{ + if (init_count == 0) + { + ERR("ofono system already shut down."); + return 0; + } + init_count--; + if (init_count > 0) + return init_count; + + _stringshare_del(&e_ofono_iface_manager); + _stringshare_del(&e_ofono_prop_modems); + _stringshare_del(&e_ofono_iface_modem); + _stringshare_del(&e_ofono_prop_name); + _stringshare_del(&e_ofono_prop_powered); + _stringshare_del(&e_ofono_prop_interfaces); + _stringshare_del(&e_ofono_iface_netreg); + _stringshare_del(&e_ofono_prop_mode); + _stringshare_del(&e_ofono_prop_status); + _stringshare_del(&e_ofono_prop_operator); + _stringshare_del(&e_ofono_prop_strength); + _stringshare_del(&e_ofono_iface_sms); + _stringshare_del(&e_ofono_prop_sca); + _stringshare_del(&e_ofono_method_send_sms); + return 0; +} diff --git a/src/lib/ofono/e_ofono_element.c b/src/lib/ofono/e_ofono_element.c new file mode 100644 index 0000000..c57fe24 --- /dev/null +++ b/src/lib/ofono/e_ofono_element.c @@ -0,0 +1,2338 @@ +#include "e_ofono_private.h" +#include <string.h> +#include <errno.h> + +/* + * Maximum size for elements hash key. + * + * The elements hash key is contructed by concatenating the object path and the + * interface for the element (with a colon separating the two strings). D-Bus + * interfaces have a maximum size of 255 but object paths have unlimited size. + * We're assuming a maximum key size of 4k here, but this might need to be + * increased if oFono object paths grows bigger than that. + */ +#define MAX_KEY_SIZE 4096 +static Eina_Hash *elements = NULL; + +typedef struct _E_Ofono_Element_Pending E_Ofono_Element_Pending; +typedef struct _E_Ofono_Element_Call_Data E_Ofono_Element_Call_Data; +typedef struct _E_Ofono_Element_Property E_Ofono_Element_Property; +typedef struct _E_Ofono_Element_Listener E_Ofono_Element_Listener; +typedef struct _E_Ofono_Element_Dict_Entry E_Ofono_Element_Dict_Entry; + +struct _E_Ofono_Element_Pending +{ + EINA_INLIST; + DBusPendingCall *pending; + void *data; + E_DBus_Method_Return_Cb user_cb; + void *user_data; +}; + +struct _E_Ofono_Element_Call_Data +{ + E_Ofono_Element *element; + E_DBus_Method_Return_Cb cb; + E_Ofono_Element_Pending *pending; + Eina_Inlist **p_list; +}; + +struct _E_Ofono_Element_Property +{ + EINA_INLIST; + const char *name; + int type; + union { + Eina_Bool boolean; + const char *str; + unsigned short u16; + unsigned int u32; + unsigned char byte; + const char *path; + void *variant; + E_Ofono_Array *array; + } value; +}; + +struct _E_Ofono_Element_Dict_Entry +{ + const char *name; + int type; + union { + Eina_Bool boolean; + const char *str; + unsigned short u16; + unsigned int u32; + unsigned char byte; + const char *path; + } value; +}; + +struct _E_Ofono_Element_Listener +{ + EINA_INLIST; + void (*cb)(void *data, const E_Ofono_Element *element); + void *data; + void (*free_data)(void *data); +}; + +static void +_e_ofono_element_event_no_free(void *data __UNUSED__, void *ev) +{ + E_Ofono_Element *element = ev; + e_ofono_element_unref(element); +} + +static void +e_ofono_element_event_add(int event_type, E_Ofono_Element *element) +{ + e_ofono_element_ref(element); + ecore_event_add + (event_type, element, _e_ofono_element_event_no_free, element); +} + +static void +e_ofono_element_call_dispatch_and_free(void *d, DBusMessage *msg, DBusError *err) +{ + E_Ofono_Element_Call_Data *data = d; + E_Ofono_Element_Pending *pending; + + pending = data->pending; + pending->pending = NULL; + + if (data->cb) + data->cb(data->element, msg, err); + + if (pending->user_cb) + pending->user_cb(pending->user_data, msg, err); + + pending->data = NULL; + *data->p_list = eina_inlist_remove(*data->p_list, EINA_INLIST_GET(pending)); + free(pending); + free(data); +} + +static void +e_ofono_element_pending_cancel_and_free(Eina_Inlist **pending) +{ + while (*pending) + { + E_Ofono_Element_Pending *p = (E_Ofono_Element_Pending *)*pending; + DBusError err; + + dbus_pending_call_cancel(p->pending); + + dbus_error_init(&err); + dbus_set_error(&err, "Canceled", "Pending method call was canceled."); + e_ofono_element_call_dispatch_and_free(p->data, NULL, &err); + dbus_error_free(&err); + } +} + +void +e_ofono_element_listener_add(E_Ofono_Element *element, void (*cb)(void *data, const E_Ofono_Element *element), const void *data, void (*free_data)(void *data)) +{ + E_Ofono_Element_Listener *l; + + if (!element) + { + ERR("safety check failed: element == NULL"); + goto error; + } + if (!cb) + { + ERR("safety check failed: cb == NULL"); + goto error; + } + + l = malloc(sizeof(*l)); + if (!l) + { + ERR("could not allocate E_Ofono_Element_Listener"); + goto error; + } + + l->cb = cb; + l->data = (void *)data; + l->free_data = free_data; + + element->_listeners = eina_inlist_append + (element->_listeners, EINA_INLIST_GET(l)); + + return; + + error: + if (free_data) + free_data((void *)data); +} + +void +e_ofono_element_listener_del(E_Ofono_Element *element, void (*cb)(void *data, const E_Ofono_Element *element), const void *data) +{ + E_Ofono_Element_Listener *l; + + EINA_SAFETY_ON_NULL_RETURN(element); + EINA_SAFETY_ON_NULL_RETURN(cb); + + EINA_INLIST_FOREACH(element->_listeners, l) + if ((l->cb == cb) && (l->data == data)) + { + element->_listeners = eina_inlist_remove + (element->_listeners, EINA_INLIST_GET(l)); + if (l->free_data) l->free_data(l->data); + free(l); + return; + } +} + +static void +_e_ofono_element_listeners_call_do(E_Ofono_Element *element) +{ + E_Ofono_Element_Listener *l, **shadow; + unsigned int i, count; + + /* NB: iterate on a copy in order to allow listeners to be deleted + * from callbacks. number of listeners should be small, so the + * following should do fine. + */ + count = eina_inlist_count(element->_listeners); + if (count < 1) + goto end; + + shadow = alloca(sizeof(*shadow) * count); + if (!shadow) + goto end; + + i = 0; + EINA_INLIST_FOREACH(element->_listeners, l) + shadow[i++] = l; + + for (i = 0; i < count; i++) + shadow[i]->cb(shadow[i]->data, element); + + end: + e_ofono_element_event_add(E_OFONO_EVENT_ELEMENT_UPDATED, element); +} + +static int +_e_ofono_element_listeners_call_idler(void *data) +{ + E_Ofono_Element *element = data; + _e_ofono_element_listeners_call_do(element); + element->_idler.changed = NULL; + return 0; +} + +static void +_e_ofono_element_listeners_call(E_Ofono_Element *element) +{ + if (element->_idler.changed) + return; + element->_idler.changed = ecore_idler_add + (_e_ofono_element_listeners_call_idler, element); +} + +/*********************************************************************** + * Property + ***********************************************************************/ + +static void +_e_ofono_element_dict_entry_free(E_Ofono_Element_Dict_Entry *entry) +{ + switch (entry->type) + { + case DBUS_TYPE_BOOLEAN: + case DBUS_TYPE_BYTE: + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + break; + case DBUS_TYPE_OBJECT_PATH: + eina_stringshare_del(entry->value.path); + break; + case DBUS_TYPE_STRING: + eina_stringshare_del(entry->value.str); + break; + default: + ERR("don't know how to free dict entry '%s' of type %c (%d)", + entry->name, entry->type, entry->type); + } + + eina_stringshare_del(entry->name); + free(entry); +} + +static E_Ofono_Element_Dict_Entry * +_e_ofono_element_dict_entry_new(DBusMessageIter *itr) +{ + E_Ofono_Element_Dict_Entry *entry; + DBusMessageIter e_itr, v_itr; + int t; + const char *key = NULL; + void *value = NULL; + + dbus_message_iter_recurse(itr, &e_itr); + + t = dbus_message_iter_get_arg_type(&e_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING)) + { + ERR("invalid format for dict entry. first type not a string: %c (%d)", + t, t); + return NULL; + } + + dbus_message_iter_get_basic(&e_itr, &key); + if (!key || !key[0]) + { + ERR("invalid format for dict entry. no key."); + return NULL; + } + + dbus_message_iter_next(&e_itr); + t = dbus_message_iter_get_arg_type(&e_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_VARIANT)) + { + ERR("invalid format for dict entry '%s'. " + "second type not a variant: %c (%d)", + key, t, t); + return NULL; + } + + dbus_message_iter_recurse(&e_itr, &v_itr); + + t = dbus_message_iter_get_arg_type(&v_itr); + if ((t == DBUS_TYPE_INVALID) || (t == DBUS_TYPE_ARRAY)) + { + ERR("invalid type for dict value for entry '%s': %c (%d)", + key, t, t); + return NULL; + } + + entry = calloc(1, sizeof(*entry)); + if (!entry) + { + ERR("could not allocate memory for dict entry."); + return NULL; + } + + dbus_message_iter_get_basic(&v_itr, &value); + switch (t) + { + case DBUS_TYPE_BOOLEAN: + entry->value.boolean = (Eina_Bool)(long)value; + break; + case DBUS_TYPE_BYTE: + entry->value.byte = (unsigned char)(long)value; + break; + case DBUS_TYPE_UINT16: + entry->value.u16 = (unsigned short)(long)value; + break; + case DBUS_TYPE_UINT32: + entry->value.u32 = (unsigned int)(long)value; + break; + case DBUS_TYPE_STRING: + entry->value.str = eina_stringshare_add(value); + break; + case DBUS_TYPE_OBJECT_PATH: + entry->value.path = eina_stringshare_add(value); + break; + default: + ERR("don't know how to create dict entry '%s' for of type %c (%d)", + key, t, t); + free(entry); + return NULL; + } + + entry->name = eina_stringshare_add(key); + entry->type = t; + return entry; +} + +static E_Ofono_Element_Dict_Entry * +_e_ofono_element_array_dict_find_stringshared(const E_Ofono_Array *array, const char *key) +{ + E_Ofono_Element_Dict_Entry *entry; + Eina_Array_Iterator iterator; + unsigned int i; + + EINA_ARRAY_ITER_NEXT(array->array, i, entry, iterator) + if (entry->name == key) + return entry; + + return NULL; +} + +static void +_e_ofono_element_array_free(E_Ofono_Array *array, E_Ofono_Array *new __UNUSED__) +{ + Eina_Array_Iterator iterator; + unsigned int i; + void *item; + + if (!array) + return; + + switch (array->type) + { + case DBUS_TYPE_BOOLEAN: + case DBUS_TYPE_BYTE: + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + break; + case DBUS_TYPE_OBJECT_PATH: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + eina_stringshare_del(item); + break; + case DBUS_TYPE_STRING: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + eina_stringshare_del(item); + break; + case DBUS_TYPE_DICT_ENTRY: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + _e_ofono_element_dict_entry_free(item); + break; + default: + ERR("don't know how to free array of values of type %c (%d)", + array->type, array->type); + break; + } + eina_array_free(array->array); + free(array); +} + +static void +_e_ofono_element_property_value_free(E_Ofono_Element_Property *property) +{ + switch (property->type) + { + case 0: + return; + case DBUS_TYPE_BOOLEAN: + case DBUS_TYPE_BYTE: + case DBUS_TYPE_UINT16: + case DBUS_TYPE_UINT32: + break; + case DBUS_TYPE_STRING: + eina_stringshare_del(property->value.str); + break; + case DBUS_TYPE_OBJECT_PATH: + eina_stringshare_del(property->value.path); + break; + case DBUS_TYPE_ARRAY: + _e_ofono_element_array_free(property->value.array, NULL); + break; + default: + ERR("don't know how to free value of property type %c (%d)", + property->type, property->type); + } +} + +static const char * +_e_ofono_element_get_interface(const char *key) +{ + const char *interface = NULL, *tail; + char head; + + head = key[0]; + tail = key + 1; + + switch (head) + { + case 'M': + if (strcmp(tail, "odems") == 0) + interface = e_ofono_iface_modem; + break; + default: + break; + } + + if (!interface) + ERR("failed to find interface for property \"%s\"", key); + + return interface; +} + +static E_Ofono_Element * +_e_ofono_element_item_register(const char *key, const char *item) +{ + E_Ofono_Element *element; + const char *interface; + + interface = _e_ofono_element_get_interface(key); + if (!interface) + return NULL; + element = e_ofono_element_register(item, interface); + if ((element) && (!e_ofono_element_properties_sync(element))) + WRN("could not get properties of %s", element->path); + return element; +} + +/* Match 2 arrays to find which are new and which are old elements + * For new elements, register them under prop_name property + * For old elements, unregister them, sending proper DEL event + */ +static void +_e_ofono_element_array_match(E_Ofono_Array *old, E_Ofono_Array *new, const char *prop_name, E_Ofono_Element *element) +{ + Eina_List *deleted = NULL; + Eina_Array_Iterator iter_old, iter_new; + unsigned int i_old = 0, i_new = 0; + void *item_old, *item_new; + Eina_List *l; + void *data; + Eina_Bool interfaces = 0; + + if (!old) + return; + if ((old->type != DBUS_TYPE_OBJECT_PATH) && + (old->type != DBUS_TYPE_STRING)) + return; + + /* is this a list of interfaces? */ + interfaces = !strcmp(prop_name, "Interfaces"); + + if ((!new) || (!new->array) || eina_array_count_get(new->array) == 0) + { + if ((!old) || (!old->array) || eina_array_count_get(old->array) == 0) + return; + else + { + iter_old = old->array->data; + goto out_remove_remaining; + } + } + + iter_new = new->array->data; + item_new = *iter_new; + EINA_ARRAY_ITER_NEXT(old->array, i_old, item_old, iter_old) + { + if (item_old == item_new) + { + i_new++; + if (i_new >= eina_array_count_get(new->array)) + { + i_old++; + break; + } + + iter_new++; + item_new = *iter_new; + } + else + deleted = eina_list_append(deleted, item_old); + } + + for(; i_new < eina_array_count_get(new->array); iter_new++, i_new++) + { + Eina_Bool found = 0; + item_new = *iter_new; + if (!item_new) + break; + + EINA_LIST_FOREACH(deleted, l, data) + { + if (data == item_new) + { + deleted = eina_list_remove_list(deleted, l); + found = 1; + break; + } + } + if (!found) + { + E_Ofono_Element *e = NULL; + + if (interfaces) + e = e_ofono_element_register(item_new, element->path); + else + e = _e_ofono_element_item_register(prop_name, item_new); + + if (e) + DBG("Add element %s (%s)\n", e->path, e->interface); + } + } + + /* everybody after i_old on old->array + everybody from deleted list + will be removed + */ + EINA_LIST_FREE(deleted, data) + { + E_Ofono_Element *e; + if (interfaces) + e = e_ofono_element_get(element->path, item_old); + else + e = e_ofono_element_get(data, + _e_ofono_element_get_interface(prop_name)); + + if (e) + { + e_ofono_element_unregister(e); + DBG("Deleted element %s %s\n", e->path, e->interface); + } + } + + out_remove_remaining: + for(; i_old < eina_array_count_get(old->array); iter_old++, i_old++) + { + E_Ofono_Element *e; + item_old = *iter_old; + if (!item_old) + break; + + if (interfaces) + e = e_ofono_element_get(element->path, item_old); + else + e = e_ofono_element_get(item_old, + _e_ofono_element_get_interface(prop_name)); + + if (e) + { + e_ofono_element_unregister(e); + DBG("Deleted element %s %s\n", e->path, e->interface); + } + } +} + +static Eina_Bool +_e_ofono_element_property_update(E_Ofono_Element_Property *property, int type, void *data, E_Ofono_Element *element) +{ + int changed = 0; + + if ((type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) && data) + data = (char *)eina_stringshare_add(data); + + if (property->type != type) + { + if (property->type) + DBG("property type changed from '%c' to '%c'", + property->type, type); + _e_ofono_element_property_value_free(property); + memset(&property->value, 0, sizeof(property->value)); + property->type = type; + changed = 1; + } + + switch (type) + { + case DBUS_TYPE_BOOLEAN: + if (changed || property->value.boolean != (Eina_Bool)(long)data) + { + property->value.boolean = (Eina_Bool)(long)data; + changed = 1; + } + break; + case DBUS_TYPE_BYTE: + if (changed || property->value.byte != (unsigned char)(long)data) + { + property->value.byte = (unsigned char)(long)data; + changed = 1; + } + break; + case DBUS_TYPE_UINT16: + if (changed || property->value.u16 != (unsigned short)(long)data) + { + property->value.u16 = (unsigned short)(long)data; + changed = 1; + } + break; + case DBUS_TYPE_UINT32: + if (changed || property->value.u32 != (unsigned int)(long)data) + { + property->value.u32 = (unsigned int)(long)data; + changed = 1; + } + break; + case DBUS_TYPE_STRING: + if (changed) + property->value.str = data; + else + { + if (property->value.str) + eina_stringshare_del(property->value.str); + if (property->value.str != data) + { + property->value.str = data; + changed = 1; + } + } + break; + case DBUS_TYPE_OBJECT_PATH: + if (changed) + property->value.path = data; + else + { + if (property->value.path) + eina_stringshare_del(property->value.path); + if (property->value.path != data) + { + property->value.path = data; + changed = 1; + } + } + break; + case DBUS_TYPE_ARRAY: + if (!changed) + if (property->value.array) + { + _e_ofono_element_array_match(property->value.array, data, + property->name, element); + _e_ofono_element_array_free(property->value.array, data); + } + property->value.array = data; + changed = 1; + break; + default: + ERR("don't know how to update property type %c (%d)", type, type); + } + + return changed; +} + +static E_Ofono_Element_Property * +_e_ofono_element_property_new(const char *name, int type, void *data, E_Ofono_Element *element) +{ + E_Ofono_Element_Property *property; + + property = calloc(1, sizeof(*property)); + if (!property) + { + eina_stringshare_del(name); + ERR("could not allocate property: %s", strerror(errno)); + return NULL; + } + + property->name = name; + _e_ofono_element_property_update(property, type, data, element); + return property; +} + +static void +_e_ofono_element_property_free(E_Ofono_Element_Property *property) +{ + _e_ofono_element_property_value_free(property); + eina_stringshare_del(property->name); + free(property); +} + +/*********************************************************************** + * Element + ***********************************************************************/ +unsigned char * +e_ofono_element_bytes_array_get_stringshared(const E_Ofono_Element *element, const char *property, unsigned int *count) +{ + Eina_Array_Iterator iterator; + E_Ofono_Array *array; + unsigned char *ret, *p; + unsigned int i; + void *item; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(property, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, NULL); + + *count = 0; + + if (!e_ofono_element_property_get_stringshared + (element, property, NULL, &array)) + return NULL; + + if ((!array) || (!(array->array))) + return NULL; + + *count = eina_array_count_get(array->array); + ret = malloc(*count * sizeof(unsigned char)); + if (!ret) + { + ERR("could not allocate return array of %d bytes: %s", + *count, strerror(errno)); + return NULL; + } + p = ret; + + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + { + *p = (unsigned char)(long)item; + p++; + } + return ret; +} + +Eina_Bool +e_ofono_element_objects_array_get_stringshared(const E_Ofono_Element *element, const char *property, unsigned int *count, E_Ofono_Element ***elements) +{ + E_Ofono_Element **ret, **p; + Eina_Array_Iterator iterator; + E_Ofono_Array *array; + unsigned int i; + int type; + void *item; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(property, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(elements, 0); + + *count = 0; + *elements = NULL; + + if (!e_ofono_element_property_get_stringshared + (element, property, &type, &array)) + return 0; + + if (type != DBUS_TYPE_ARRAY) + { + ERR("property %s is not an array!", property); + return 0; + } + + if ((!array) || (!array->array) || (array->type == DBUS_TYPE_INVALID)) + return 0; + + if (array->type != DBUS_TYPE_OBJECT_PATH) + { + ERR("property %s is not an array of object paths!", property); + return 0; + } + + *count = eina_array_count_get(array->array); + ret = malloc(*count * sizeof(E_Ofono_Element *)); + if (!ret) + { + ERR("could not allocate return array of %d elements: %s", + *count, strerror(errno)); + *count = 0; + return 0; + } + p = ret; + + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + { + E_Ofono_Element *e = e_ofono_element_get(item, property); + if (!e) + continue; + *p = e; + p++; + } + *count = p - ret; + *elements = ret; + return 1; +} + +/* strings are just pointers (references), no strdup or stringshare_add/ref */ +Eina_Bool +e_ofono_element_strings_array_get_stringshared(const E_Ofono_Element *element, const char *property, unsigned int *count, const char ***strings) +{ + const char **ret, **p; + Eina_Array_Iterator iterator; + E_Ofono_Array *array; + unsigned int i; + int type; + void *item; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(property, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(strings, 0); + + *count = 0; + *strings = NULL; + + if (!e_ofono_element_property_get_stringshared + (element, property, &type, &array)) + return 0; + + if (type != DBUS_TYPE_ARRAY) + { + ERR("property %s is not an array!", property); + return 0; + } + + if ((!array) || (!array->array) || (array->type == DBUS_TYPE_INVALID)) + return 0; + + if (array->type != DBUS_TYPE_STRING) + { + ERR("property %s is not an array of strings!", property); + return 0; + } + + *count = eina_array_count_get(array->array); + ret = malloc(*count * sizeof(char *)); + if (!ret) + { + ERR("could not allocate return array of %d strings: %s", + *count, strerror(errno)); + *count = 0; + return 0; + } + p = ret; + + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + { + if (!item) + continue; + *p = item; + p++; + } + *count = p - ret; + *strings = ret; + return 1; +} + +static void +_e_ofono_element_array_print(FILE *fp, E_Ofono_Array *array) +{ + Eina_Array_Iterator iterator; + unsigned int i; + void *item; + + if (!array) + return; + + switch (array->type) + { + case DBUS_TYPE_OBJECT_PATH: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "\"%s\", ", (const char *)item); + break; + case DBUS_TYPE_STRING: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "\"%s\", ", (const char *)item); + break; + case DBUS_TYPE_BYTE: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "%#02hhx (\"%c\"), ", (unsigned char)(long)item, + (unsigned char)(long)item); + break; + case DBUS_TYPE_UINT16: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "%#04hx (%hu), ", (unsigned short)(long)item, + (unsigned short)(long)item); + break; + case DBUS_TYPE_UINT32: + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + fprintf(fp, "%#08x (%u), ", (unsigned int)(long)item, + (unsigned int)(long)item); + break; + case DBUS_TYPE_DICT_ENTRY: + fputs("{ ", fp); + EINA_ARRAY_ITER_NEXT(array->array, i, item, iterator) + { + E_Ofono_Element_Dict_Entry *entry = item; + fprintf(fp, "%s: ", entry->name); + switch (entry->type) + { + case DBUS_TYPE_OBJECT_PATH: + fprintf(fp, "\"%s\", ", entry->value.path); + break; + case DBUS_TYPE_STRING: + fprintf(fp, "\"%s\", ", entry->value.str); + break; + case DBUS_TYPE_BYTE: + fprintf(fp, "%#02hhx (\"%c\"), ", + entry->value.byte, entry->value.byte); + break; + case DBUS_TYPE_UINT16: + fprintf(fp, "%#04hx (%hu), ", + entry->value.u16, entry->value.u16); + break; + case DBUS_TYPE_UINT32: + fprintf(fp, "%#08x (%u), ", + entry->value.u32, entry->value.u32); + break; + default: + fprintf(fp, "<UNKNOWN TYPE '%c'>", entry->type); + } + } + fputs("}", fp); + break; + default: + fprintf(fp, "<UNKNOWN ARRAY TYPE '%c'>", array->type); + } +} + +/** + * Print element to file descriptor. + */ +void +e_ofono_element_print(FILE *fp, const E_Ofono_Element *element) +{ + const E_Ofono_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN(fp); + if (!element) + { + fputs("Error: no element to print\n", fp); + return; + } + + fprintf(fp, + "Element %p: %s [%s]\n" + "\tProperties:\n", + element, element->path, element->interface); + + EINA_INLIST_FOREACH(element->props, p) + { + fprintf(fp, "\t\t%s (%c) = ", p->name, p->type); + + switch (p->type) + { + case DBUS_TYPE_STRING: + fprintf(fp, "\"%s\"", p->value.str); + break; + case DBUS_TYPE_OBJECT_PATH: + fprintf(fp, "\"%s\"", p->value.path); + break; + case DBUS_TYPE_BOOLEAN: + fprintf(fp, "%hhu", p->value.boolean); + break; + case DBUS_TYPE_BYTE: + fprintf(fp, "%#02hhx (%d), ", p->value.byte, p->value.byte); + break; + case DBUS_TYPE_UINT16: + fprintf(fp, "%hu", p->value.u16); + break; + case DBUS_TYPE_UINT32: + fprintf(fp, "%u", p->value.u32); + break; + case DBUS_TYPE_ARRAY: + _e_ofono_element_array_print(fp, p->value.array); + break; + default: + fputs("don't know how to print type", fp); + } + + fputc('\n', fp); + } +} + +static E_Ofono_Element * +e_ofono_element_new(const char *path, const char *interface) +{ + E_Ofono_Element *element; + + element = calloc(1, sizeof(*element)); + if (!element) + { + ERR("could not allocate element: %s", strerror(errno)); + return NULL; + } + + element->path = eina_stringshare_add(path); + element->interface = eina_stringshare_ref(interface); + element->_references = 1; + + return element; +} + +static void +e_ofono_element_extra_properties_free(E_Ofono_Element *element) +{ + while (element->props) + { + E_Ofono_Element_Property *prop; + prop = (E_Ofono_Element_Property *)element->props; + element->props = element->props->next; + _e_ofono_element_property_free(prop); + } +} + +static void +e_ofono_element_free(E_Ofono_Element *element) +{ + if (element->_idler.changed) + ecore_idler_del(element->_idler.changed); + + while (element->_listeners) + { + E_Ofono_Element_Listener *l = (void *)element->_listeners; + element->_listeners = eina_inlist_remove + (element->_listeners, element->_listeners); + + if (l->free_data) l->free_data(l->data); + free(l); + } + + e_ofono_element_pending_cancel_and_free(&element->_pending.properties_get); + e_ofono_element_pending_cancel_and_free(&element->_pending.property_set); + e_ofono_element_pending_cancel_and_free(&element->_pending.send_sms); + + e_ofono_element_extra_properties_free(element); + eina_stringshare_del(element->interface); + eina_stringshare_del(element->path); + free(element); +} + +/** + * Add reference to element. + */ +int +e_ofono_element_ref(E_Ofono_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return ++element->_references; +} + +/** + * Remove reference from element. + * + * If reference count drops to 0 element will be freed. + */ +int +e_ofono_element_unref(E_Ofono_Element *element) +{ + int i; + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + + i = --element->_references; + if (i == 0) + e_ofono_element_free(element); + else if (i < 0) + ERR("element %p references %d < 0", element, i); + return i; +} + +/** + * Send message with callbacks set to work with ofono elements. + * + * If this call fails (returns 0), pending callbacks will not be called, + * not even with error messages. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_element_message_send(E_Ofono_Element *element, const char *method_name, const char *interface, E_DBus_Method_Return_Cb cb, DBusMessage *msg, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + E_Ofono_Element_Call_Data *data; + E_Ofono_Element_Pending *p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(msg, 0); + + interface = interface ? : element->interface; + + data = malloc(sizeof(*data)); + if (!data) + { + ERR("could not alloc e_ofono_element_call_data: %s", + strerror(errno)); + dbus_message_unref(msg); + return 0; + } + + p = malloc(sizeof(*p)); + if (!p) + { + ERR("could not alloc E_Ofono_Element_Pending: %s", + strerror(errno)); + free(data); + dbus_message_unref(msg); + return 0; + } + + data->element = element; + data->cb = cb; + data->pending = p; + data->p_list = pending; + p->user_cb = user_cb; + p->user_data = (void *)user_data; + p->data = data; + p->pending = e_dbus_message_send + (e_ofono_conn, msg, e_ofono_element_call_dispatch_and_free, -1, data); + dbus_message_unref(msg); + + if (p->pending) + { + *pending = eina_inlist_append(*pending, EINA_INLIST_GET(p)); + return 1; + } + else + { + ERR("failed to call %s (obj=%s, path=%s, iface=%s)", + method_name, e_ofono_system_bus_name_get(), + element->path, interface); + free(data); + free(p); + return 0; + } +} + +Eina_Bool +e_ofono_element_call_full(E_Ofono_Element *element, const char *method_name, const char *interface, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + + interface = interface ? : element->interface; + + msg = dbus_message_new_method_call + (e_ofono_system_bus_name_get(), element->path, interface, + method_name); + + return e_ofono_element_message_send + (element, method_name, interface, cb, msg, pending, user_cb, user_data); +} + +static Eina_Bool +_e_ofono_element_property_value_add(E_Ofono_Element *element, const char *name, int type, void *value) +{ + E_Ofono_Element_Property *p; + + name = eina_stringshare_add(name); + EINA_INLIST_FOREACH(element->props, p) + { + if (p->name == name) + { + eina_stringshare_del(name); + return _e_ofono_element_property_update(p, type, value, element); + } + } + + p = _e_ofono_element_property_new(name, type, value, element); + if (!p) + { + ERR("could not create property %s (%c)", name, type); + return 0; + } + + element->props = eina_inlist_append(element->props, EINA_INLIST_GET(p)); + return 1; +} + +static E_Ofono_Array * +_e_ofono_element_iter_get_array(DBusMessageIter *itr, const char *key) +{ + E_Ofono_Array *array; + DBusMessageIter e_itr; + + array = malloc(sizeof(E_Ofono_Array)); + if (!array) + { + ERR("could not create new e_ofono array."); + return NULL; + } + array->array = eina_array_new(16); + if (!(array->array)) + { + ERR("could not create new eina array."); + free(array); + return NULL; + } + + dbus_message_iter_recurse(itr, &e_itr); + array->type = dbus_message_iter_get_arg_type(&e_itr); + if (array->type == DBUS_TYPE_INVALID) + { + DBG("array %s is of type 'invalid' (empty?)", key); + eina_array_free(array->array); + free(array); + return NULL; + } + + do + { + switch (array->type) + { + case DBUS_TYPE_OBJECT_PATH: + { + const char *path; + + dbus_message_iter_get_basic(&e_itr, &path); + path = eina_stringshare_add(path); + eina_array_push(array->array, path); + _e_ofono_element_item_register(key, path); + } + break; + case DBUS_TYPE_STRING: + { + const char *str; + + dbus_message_iter_get_basic(&e_itr, &str); + str = eina_stringshare_add(str); + eina_array_push(array->array, str); + } + break; + case DBUS_TYPE_BYTE: + { + unsigned char byte; + dbus_message_iter_get_basic(&e_itr, &byte); + eina_array_push(array->array, (void *)(long)byte); + } + break; + case DBUS_TYPE_DICT_ENTRY: + { + E_Ofono_Element_Dict_Entry *entry; + entry = _e_ofono_element_dict_entry_new(&e_itr); + if (entry) + eina_array_push(array->array, entry); + } + break; + default: + ERR("don't know how to build array '%s' of type %c (%d)", + key, array->type, array->type); + eina_array_free(array->array); + free(array); + return NULL; + } + } + while (dbus_message_iter_next(&e_itr)); + return array; +} + +static void +_e_ofono_element_get_properties_callback(void *user_data, DBusMessage *msg, DBusError *err) +{ + E_Ofono_Element *element = user_data; + DBusMessageIter itr, s_itr; + int t, changed; + + DBG("get_properties msg=%p", msg); + + if (!_dbus_callback_check_and_init(msg, &itr, err)) + return; + + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_ARRAY)) + return; + + changed = 0; + dbus_message_iter_recurse(&itr, &s_itr); + do + { + DBusMessageIter e_itr, v_itr; + const char *key; + void *value = NULL; + int r; + + t = dbus_message_iter_get_arg_type(&s_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_DICT_ENTRY)) + continue; + + dbus_message_iter_recurse(&s_itr, &e_itr); + + t = dbus_message_iter_get_arg_type(&e_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING)) + continue; + + dbus_message_iter_get_basic(&e_itr, &key); + dbus_message_iter_next(&e_itr); + t = dbus_message_iter_get_arg_type(&e_itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_VARIANT)) + continue; + + dbus_message_iter_recurse(&e_itr, &v_itr); + t = dbus_message_iter_get_arg_type(&v_itr); + if (t == DBUS_TYPE_ARRAY) + value = _e_ofono_element_iter_get_array(&v_itr, key); + else if (t != DBUS_TYPE_INVALID) { + dbus_message_iter_get_basic(&v_itr, &value); + } else { + ERR("property has invalid type %s", key); + continue; + } + + r = _e_ofono_element_property_value_add(element, key, t, value); + if (r < 0) + ERR("failed to add property value %s (%c)", key, t); + else if (r == 1) + { + INF("property value changed %s (%c)", key, t); + changed = 1; + if ((strcmp(key, "Interfaces") == 0) && value) + { + char *interface; + Eina_Array_Iterator iterator; + unsigned int i; + E_Ofono_Element *e; + + EINA_ARRAY_ITER_NEXT(((E_Ofono_Array*)value)->array, i, + interface, iterator) + { + DBG("Found interface %s on %s", interface, element->path); + e = e_ofono_element_register(element->path, interface); + if ((e) && (!e_ofono_element_properties_sync(e))) + WRN("could not get properties of %s", e->path); + } + } + } + } + while (dbus_message_iter_next(&s_itr)); + + if (changed) + _e_ofono_element_listeners_call(element); +} + +/** + * Sync element properties with server. + * + * Call method GetProperties() at the given element on server in order to sync + * them. + * + * @param element to call method on server. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_element_sync_properties_full(E_Ofono_Element *element, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "GetProperties"; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return e_ofono_element_call_full + (element, name, element->interface, + _e_ofono_element_get_properties_callback, + &element->_pending.properties_get, cb, data); +} + +/** + * Sync element properties with server, simple version. + * + * Call method GetProperties() at the given element on server in order to sync + * them. This is the simple version and there is no check of server reply + * for errors. + * + * @param element to call method on server. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_element_properties_sync(E_Ofono_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return e_ofono_element_sync_properties_full(element, NULL, NULL); +} + +/** + * Call method SetProperty(prop, {key: value}) at the given element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_OFONO_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * @param element to call method on server. + * @param prop property name. + * @param key dict key name. + * @param type DBus type to use for value. + * @param value pointer to value, just like regular DBus, see + * dbus_message_iter_append_basic(). + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_element_property_dict_set_full(E_Ofono_Element *element, const char *prop, const char *key, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "SetProperty"; + DBusMessage *msg; + DBusMessageIter itr, variant, dict, entry; + char typestr[32]; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(prop, 0); + + msg = dbus_message_new_method_call + (e_ofono_system_bus_name_get(), element->path, element->interface, name); + + if (!msg) + return 0; + + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &prop); + + if ((size_t)snprintf(typestr, sizeof(typestr), + (DBUS_TYPE_ARRAY_AS_STRING + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + "%c" + DBUS_DICT_ENTRY_END_CHAR_AS_STRING), + type) >= sizeof(typestr)) + { + ERR("sizeof(typestr) is too small!"); + return 0; + } + + dbus_message_iter_open_container(&itr, DBUS_TYPE_VARIANT, typestr, &variant); + + snprintf(typestr, sizeof(typestr), + (DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + "%c" + DBUS_DICT_ENTRY_END_CHAR_AS_STRING), + type); + + dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY, typestr, &dict); + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry); + + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); + + if ((type == DBUS_TYPE_STRING) || (type == DBUS_TYPE_OBJECT_PATH)) + dbus_message_iter_append_basic(&entry, type, &value); + else + dbus_message_iter_append_basic(&entry, type, value); + + dbus_message_iter_close_container(&dict, &entry); + dbus_message_iter_close_container(&variant, &dict); + dbus_message_iter_close_container(&itr, &variant); + + return e_ofono_element_message_send + (element, name, NULL, NULL, msg, + &element->_pending.property_set, cb, data); +} + +/** + * Call method SetProperty(prop, value) at the given element on server. + * + * This is a server call, not local, so it may fail and in that case + * no property is updated locally. If the value was set the event + * E_OFONO_EVENT_ELEMENT_UPDATED will be added to main loop. + * + * @param element to call method on server. + * @param prop property name. + * @param type DBus type to use for value. + * @param value pointer to value, just like regular DBus, see + * dbus_message_iter_append_basic(). + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_element_property_set_full(E_Ofono_Element *element, const char *prop, int type, const void *value, E_DBus_Method_Return_Cb cb, const void *data) +{ + const char name[] = "SetProperty"; + char typestr[2]; + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(prop, 0); + + msg = dbus_message_new_method_call + (e_ofono_system_bus_name_get(), element->path, element->interface, name); + + if (!msg) + return 0; + + DBusMessageIter itr, v; + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &prop); + + typestr[0] = type; + typestr[1] = '\0'; + dbus_message_iter_open_container(&itr, DBUS_TYPE_VARIANT, typestr, &v); + if ((type == DBUS_TYPE_STRING) || (type == DBUS_TYPE_OBJECT_PATH)) + dbus_message_iter_append_basic(&v, type, &value); + else if (type == DBUS_TYPE_BOOLEAN) + { + unsigned int b = *(Eina_Bool *)value; + dbus_message_iter_append_basic(&v, type, &b); + } + else + dbus_message_iter_append_basic(&v, type, value); + dbus_message_iter_close_container(&itr, &v); + + return e_ofono_element_message_send + (element, name, NULL, NULL, msg, + &element->_pending.property_set, cb, data); +} + +/** + * Call method SetProperty(prop, value) at the given element on server. + * + * This is the simple version and there is no check of server reply + * for errors. + * + * @param element to call method on server. + * @param prop property name. + * @param type DBus type to use for value. + * @param value pointer to value, just like regular DBus, see + * dbus_message_iter_append_basic(). + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_element_property_set(E_Ofono_Element *element, const char *prop, int type, const void *value) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(prop, 0); + return e_ofono_element_property_set_full + (element, prop, type, value, NULL, NULL); +} + +Eina_Bool +e_ofono_element_call_with_path(E_Ofono_Element *element, const char *method_name, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + DBusMessageIter itr; + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(string, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + + msg = dbus_message_new_method_call + (e_ofono_system_bus_name_get(), element->path, element->interface, + method_name); + + if (!msg) + return 0; + + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_OBJECT_PATH, &string); + + return e_ofono_element_message_send + (element, method_name, NULL, cb, msg, pending, user_cb, user_data); +} + +Eina_Bool +e_ofono_element_call_with_string(E_Ofono_Element *element, const char *method_name, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + DBusMessageIter itr; + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(string, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + + msg = dbus_message_new_method_call + (e_ofono_system_bus_name_get(), element->path, element->interface, + method_name); + + if (!msg) + return 0; + + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &string); + + return e_ofono_element_message_send + (element, method_name, NULL, cb, msg, pending, user_cb, user_data); +} + +Eina_Bool +e_ofono_element_call_with_path_and_string(E_Ofono_Element *element, const char *method_name, const char *path, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data) +{ + DBusMessageIter itr; + DBusMessage *msg; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(method_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(path, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(string, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(pending, 0); + + msg = dbus_message_new_method_call + (e_ofono_system_bus_name_get(), element->path, element->interface, + method_name); + + if (!msg) + return 0; + + dbus_message_iter_init_append(msg, &itr); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_OBJECT_PATH, &path); + dbus_message_iter_append_basic(&itr, DBUS_TYPE_STRING, &string); + + return e_ofono_element_message_send + (element, method_name, NULL, cb, msg, pending, user_cb, user_data); +} + +/** + * Get property type. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param name property name, must be previously stringshared + * @param type will contain the value type. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_element_property_type_get_stringshared(const E_Ofono_Element *element, const char *name, int *type) +{ + const E_Ofono_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(type, 0); + + EINA_INLIST_FOREACH(element->props, p) + { + if (p->name == name) + { + *type = p->type; + return 1; + } + } + + WRN("element %s (%p) has no property with name \"%s\".", + element->path, element, name); + return 0; +} + +/** + * Get property type. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param name property name + * @param type will contain the value type. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_element_property_type_get(const E_Ofono_Element *element, const char *name, int *type) +{ + Eina_Bool ret; + name = eina_stringshare_add(name); + ret = e_ofono_element_property_type_get_stringshared(element, name, type); + eina_stringshare_del(name); + return ret; +} + +void +e_ofono_element_list_properties(const E_Ofono_Element *element, Eina_Bool (*cb)(void *data, const E_Ofono_Element *element, const char *name, int type, const void *value), const void *data) +{ + const E_Ofono_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN(element); + EINA_SAFETY_ON_NULL_RETURN(cb); + + EINA_INLIST_FOREACH(element->props, p) + { + const void *value = NULL; + + switch (p->type) + { + case DBUS_TYPE_STRING: + value = &p->value.str; + break; + case DBUS_TYPE_OBJECT_PATH: + value = &p->value.path; + break; + case DBUS_TYPE_BOOLEAN: + value = (void *)(unsigned long)p->value.boolean; + break; + case DBUS_TYPE_UINT16: + value = &p->value.u16; + break; + case DBUS_TYPE_UINT32: + value = &p->value.u32; + break; + default: + ERR("unsupported type %c", p->type); + } + + if (!cb((void *)data, element, p->name, p->type, value)) + return; + } +} + +/** + * Get dict value given its key inside a dict property. + * + * This will look into properties for one of type dict that contains + * the given key, to find the property. If no property is found then + * 0 is returned. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param dict_name property name, must be previously stringshared + * @param key key inside dict, must be previously stringshared + * @param type if provided it will contain the value type. + * @param value where to store the property value, must be a pointer to the + * exact type, (Eina_Bool *) for booleans, (char **) for strings, and so on. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_element_property_dict_get_stringshared(const E_Ofono_Element *element, const char *dict_name, const char *key, int *type, void *value) +{ + const E_Ofono_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(dict_name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(key, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(value, 0); + + EINA_INLIST_FOREACH(element->props, p) + { + E_Ofono_Element_Dict_Entry *entry; + E_Ofono_Array *array; + + if (p->name != dict_name) + continue; + if (p->type != DBUS_TYPE_ARRAY) + { + WRN("element %s (%p) has property \"%s\" is not an array: %c (%d)", + element->path, element, dict_name, p->type, p->type); + return 0; + } + array = p->value.array; + if ((!array) || (array->type != DBUS_TYPE_DICT_ENTRY)) + { + int t = array ? array->type : DBUS_TYPE_INVALID; + WRN("element %s (%p) has property \"%s\" is not a dict: %c (%d)", + element->path, element, dict_name, t, t); + return 0; + } + entry = _e_ofono_element_array_dict_find_stringshared(array, key); + if (!entry) + { + WRN("element %s (%p) has no dict property with name \"%s\" with " + "key \"%s\".", + element->path, element, dict_name, key); + return 0; + } + + if (type) *type = entry->type; + + switch (entry->type) + { + case DBUS_TYPE_BOOLEAN: + *(Eina_Bool *)value = entry->value.boolean; + return 1; + case DBUS_TYPE_BYTE: + *(unsigned char *)value = entry->value.byte; + return 1; + case DBUS_TYPE_UINT16: + *(unsigned short *)value = entry->value.u16; + return 1; + case DBUS_TYPE_UINT32: + *(unsigned int *)value = entry->value.u32; + return 1; + case DBUS_TYPE_STRING: + *(const char **)value = entry->value.str; + return 1; + case DBUS_TYPE_OBJECT_PATH: + *(const char **)value = entry->value.path; + return 1; + default: + ERR("don't know how to get property %s, key %s type %c (%d)", + dict_name, key, entry->type, entry->type); + return 0; + } + } + + WRN("element %s (%p) has no property with name \"%s\".", + element->path, element, dict_name); + return 0; +} + +/** + * Get property value given its name. + * + * This will look into properties, to find the property. + * If no property is found then 0 is returned. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param name property name, must be previously stringshared + * @param type if provided it will contain the value type. + * @param value where to store the property value, must be a pointer to the + * exact type, (Eina_Bool *) for booleans, (char **) for strings, and so on. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_element_property_get_stringshared(const E_Ofono_Element *element, const char *name, int *type, void *value) +{ + const E_Ofono_Element_Property *p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(value, 0); + + EINA_INLIST_FOREACH(element->props, p) + { + if (p->name != name) + continue; + + if (type) *type = p->type; + + switch (p->type) + { + case DBUS_TYPE_BOOLEAN: + *(Eina_Bool *)value = p->value.boolean; + return 1; + case DBUS_TYPE_BYTE: + *(unsigned char *)value = p->value.byte; + return 1; + case DBUS_TYPE_UINT16: + *(unsigned short *)value = p->value.u16; + return 1; + case DBUS_TYPE_UINT32: + *(unsigned int *)value = p->value.u32; + return 1; + case DBUS_TYPE_STRING: + *(const char **)value = p->value.str; + return 1; + case DBUS_TYPE_OBJECT_PATH: + *(const char **)value = p->value.path; + return 1; + case DBUS_TYPE_ARRAY: + *(E_Ofono_Array **)value = p->value.array; + return 1; + default: + ERR("don't know how to get property type %c (%d)", + p->type, p->type); + return 0; + } + } + + WRN("element %s (%p) has no property with name \"%s\".", + element->path, element, name); + return 0; +} + +/** + * Get property value given its name. + * + * This will look into properties, to find the property. + * If no property is found then 0 is returned. + * + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param element which element to get the property + * @param name property name + * @param type if provided it will contain the value type. + * @param value where to store the property value, must be a pointer to the + * exact type, (Eina_Bool *) for booleans, (char **) for strings, and so on. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_element_property_get(const E_Ofono_Element *element, const char *name, int *type, void *value) +{ + Eina_Bool ret; + name = eina_stringshare_add(name); + ret = e_ofono_element_property_get_stringshared + (element, name, type, value); + eina_stringshare_del(name); + return ret; +} + + +struct e_ofono_elements_for_each_data +{ + Eina_Hash_Foreach cb; + void *data; +}; + +Eina_Bool +_e_ofono_elements_for_each(Eina_Hash *hash __UNUSED__, const char *key, void *data, void *fdata) +{ + struct e_ofono_elements_for_each_data *each_data = fdata; + + each_data->cb(elements, key, data, each_data->data); + return 1; +} + +/** + * Call the given function for each existing element. + * + * @param cb function to call for each element. It will get as parameters, + * in order: the element pointer and the given @a user_data. + * @param user_data data to give to @a cb for each element. + */ +void +e_ofono_elements_for_each(Eina_Hash_Foreach cb, const void *user_data) +{ + struct e_ofono_elements_for_each_data data = {cb, (void *)user_data}; + + EINA_SAFETY_ON_NULL_RETURN(cb); + + eina_hash_foreach + (elements, (Eina_Hash_Foreach) _e_ofono_elements_for_each, &data); +} + +static Eina_Bool +_e_ofono_elements_get_allocate(unsigned int *count, E_Ofono_Element ***p_elements) +{ + *count = eina_hash_population(elements); + if (*count == 0) + { + *p_elements = NULL; + return 1; + } + + *p_elements = malloc(*count * sizeof(E_Ofono_Element *)); + if (!*p_elements) + { + ERR("could not allocate return array of %d elements: %s", + *count, strerror(errno)); + *count = 0; + return 0; + } + return 1; +} + +Eina_Bool +_e_ofono_elements_get_all(Eina_Hash *hash __UNUSED__, const char *key __UNUSED__, void *data, void *fdata) +{ + E_Ofono_Element *element = data; + E_Ofono_Element ***p_ret = fdata; + + **p_ret = element; + (*p_ret)++; + return 1; +} + +/** + * Get all known elements. + * + * No reference is added to these elements, since there are no threads + * in the system, you are free to add references yourself right after + * the return of this call without race condition, elements by the + * system (ie: elementRemoved signal)could only be touched on the next + * main loop iteration. + * + * @param count return the number of elements in array. + * @param p_elements array with all elements, these are not referenced + * and in no particular order, just set if return is 1. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_elements_get_all(unsigned int *count, E_Ofono_Element ***p_elements) +{ + E_Ofono_Element **p; + + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(p_elements, 0); + + if (!_e_ofono_elements_get_allocate(count, p_elements)) + return 0; + p = *p_elements; + eina_hash_foreach + (elements, (Eina_Hash_Foreach) _e_ofono_elements_get_all, &p); + return 1; +} + +struct e_ofono_elements_get_all_str_data +{ + E_Ofono_Element **elements; + int count; + const char *str; +}; + +Eina_Bool +_e_ofono_elements_get_all_type(Eina_Hash *hash __UNUSED__, const char *key __UNUSED__, void *e, void *user_data) +{ + struct e_ofono_elements_get_all_str_data *data = user_data; + E_Ofono_Element *element = e; + + if ((data->str) && (element->interface != data->str)) + return 1; + + data->elements[data->count] = element; + data->count++; + return 1; +} + +/** + * Get all known elements of type. + * + * No reference is added to these elements, since there are no threads + * in the system, you are free to add references yourself right after + * the return of this call without race condition, elements by the + * system (ie: ElementRemoved signal) could only be touched on the next + * main loop iteration. + * + * @param type type to filter, or NULL to get all. + * @param count return the number of elements in array. + * @param p_elements array with all elements, these are not referenced + * and in no particular order, just set if return is 1. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + * + * @see e_ofono_elements_get_all() + */ +Eina_Bool +e_ofono_elements_get_all_type(const char *type, unsigned int *count, E_Ofono_Element ***p_elements) +{ + struct e_ofono_elements_get_all_str_data data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(count, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(p_elements, 0); + + if (!_e_ofono_elements_get_allocate(count, p_elements)) + return 0; + + data.elements = *p_elements; + data.count = 0; + data.str = eina_stringshare_add(type); + eina_hash_foreach(elements, + (Eina_Hash_Foreach) _e_ofono_elements_get_all_type, + &data); + + eina_stringshare_del(data.str); + *count = data.count; + return 1; +} + +/** + * Get the element registered at given path. + * + * @param path the path to query for registered object. + * + * @return element pointer if found, NULL otherwise. No references are added. + */ +E_Ofono_Element * +e_ofono_element_get(const char *path, const char *interface) +{ + E_Ofono_Element *element; + char key[MAX_KEY_SIZE]; + + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(interface, NULL); + + snprintf(key, MAX_KEY_SIZE, "%s:%s", path, interface); + element = eina_hash_find(elements, key); + + return element; +} + +static void +_e_ofono_element_property_changed_callback(void *data, DBusMessage *msg) +{ + E_Ofono_Element *element = (E_Ofono_Element *)data; + DBusMessageIter itr, v_itr; + int t, r, changed = 0; + const char *name = NULL; + void *value = NULL; + + DBG("Property changed in element %s %s", element->path, element->interface); + + if (!_dbus_callback_check_and_init(msg, &itr, NULL)) + return; + + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING)) + { + ERR("missing name in property changed signal"); + return; + } + dbus_message_iter_get_basic(&itr, &name); + + dbus_message_iter_next(&itr); + t = dbus_message_iter_get_arg_type(&itr); + if (!_dbus_iter_type_check(t, DBUS_TYPE_VARIANT)) + { + ERR("missing value in property changed signal"); + return; + } + dbus_message_iter_recurse(&itr, &v_itr); + t = dbus_message_iter_get_arg_type(&v_itr); + + if (t == DBUS_TYPE_ARRAY) + value = _e_ofono_element_iter_get_array(&v_itr, name); + else if (t != DBUS_TYPE_INVALID) + dbus_message_iter_get_basic(&v_itr, &value); + else + { + ERR("property has invalid type %s", name); + return; + } + + r = _e_ofono_element_property_value_add(element, name, t, value); + if (r < 0) + ERR("failed to add property value %s (%c)", name, t); + else if (r == 1) + { + INF("property value changed %s (%c)", name, t); + changed = 1; + if ((strcmp(name, "Interfaces") == 0) && value) + { + char *interface; + Eina_Array_Iterator iterator; + unsigned int i; + E_Ofono_Element *e; + + EINA_ARRAY_ITER_NEXT(((E_Ofono_Array*)value)->array, i, + interface, iterator) + { + DBG("Found interface %s on %s", interface, element->path); + e_ofono_element_register(element->path, interface); + e = e_ofono_element_register(element->path, interface); + if ((e) && (!e_ofono_element_properties_sync(e))) + WRN("could not get properties of %s", e->path); + } + } + } + if (changed) + _e_ofono_element_listeners_call(element); +} + +/** + * Register the given pair (path, interface), possibly creating an + * element and return it. + * + * This will check if (path, interface) is already registered, in + * that case the exiting element is returned. If it was not registered + * yet, a new element is created, registered and returned. + * + * This call will not add extra references to the object. + * + * @param path the path to register the element + * + * @return the registered object, no references are added. + */ +E_Ofono_Element * +e_ofono_element_register(const char *path, const char *interface) +{ + E_Ofono_Element *element; + char key[MAX_KEY_SIZE]; + + EINA_SAFETY_ON_NULL_RETURN_VAL(path, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(interface, NULL); + + snprintf(key, MAX_KEY_SIZE, "%s:%s", path, interface); + element = eina_hash_find(elements, key); + if (element) + return element; + + element = e_ofono_element_new(path, interface); + if (!element) + return NULL; + + if (!eina_hash_add(elements, key, element)) + { + ERR("could not add element %s to hash, delete it.", path); + e_ofono_element_free(element); + return NULL; + } + + element->signal_handler = + e_dbus_signal_handler_add + (e_ofono_conn, e_ofono_system_bus_name_get(), + element->path, element->interface, "PropertyChanged", + _e_ofono_element_property_changed_callback, element); + + e_ofono_element_event_add(E_OFONO_EVENT_ELEMENT_ADD, element); + + return element; +} + +static void +_e_ofono_element_event_unregister_and_free(void *data __UNUSED__, void *ev) +{ + E_Ofono_Element *element = ev; + e_ofono_element_unref(element); +} + +static void +_e_ofono_element_unregister_internal(E_Ofono_Element *element) +{ + if (element->signal_handler) + { + e_dbus_signal_handler_del(e_ofono_conn, element->signal_handler); + element->signal_handler = NULL; + } + + ecore_event_add(E_OFONO_EVENT_ELEMENT_DEL, element, + _e_ofono_element_event_unregister_and_free, NULL); +} + +/** + * Forget about the given element. + * + * This will remove the element from the pool of known objects, then + * add an E_OFONO_EVENT_ELEMENT_DEL and after that will unreference it, + * possible freeing it. + * + * @param element element to forget about. Its reference will be removed. + */ +void +e_ofono_element_unregister(E_Ofono_Element *element) +{ + char key[MAX_KEY_SIZE]; + + if (!element) + return; + + snprintf(key, MAX_KEY_SIZE, "%s:%s", element->path, element->interface); + if (elements) + eina_hash_del_by_key(elements, key); +} + +/** + * Remove all known elements. + * + * This will remove all known elements but will NOT add any + * E_OFONO_EVENT_ELEMENT_DEL to main loop. + * + * This is just useful to make sure next e_ofono_manager_sync_elements() + * will not leave any stale elements. This is unlikely to happen, as + * E_Ofono is supposed to catch all required events to avoid stale elements. + */ +void +e_ofono_manager_clear_elements(void) +{ + e_ofono_elements_shutdown(); + e_ofono_elements_init(); +} + +/** + * Creates elements hash. + * + * This has no init counter since its already guarded by other code. + * @internal + */ +void +e_ofono_elements_init(void) +{ + EINA_SAFETY_ON_FALSE_RETURN(elements == NULL); + elements = + eina_hash_string_superfast_new + (EINA_FREE_CB(_e_ofono_element_unregister_internal)); +} + +void +e_ofono_elements_shutdown(void) +{ + EINA_SAFETY_ON_FALSE_RETURN(elements != NULL); + eina_hash_free(elements); + elements = NULL; +} + +static inline Eina_Bool +_e_ofono_element_is(const E_Ofono_Element *element, const char *interface) +{ + return element->interface == interface; +} + +Eina_Bool +e_ofono_element_is_manager(const E_Ofono_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return _e_ofono_element_is(element, e_ofono_iface_manager); +} + +Eina_Bool +e_ofono_element_is_modem(const E_Ofono_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return _e_ofono_element_is(element, e_ofono_iface_modem); +} + +Eina_Bool +e_ofono_element_is_netreg(const E_Ofono_Element *element) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + return _e_ofono_element_is(element, e_ofono_iface_netreg); +} diff --git a/src/lib/ofono/e_ofono_manager.c b/src/lib/ofono/e_ofono_manager.c new file mode 100644 index 0000000..a39d0fe --- /dev/null +++ b/src/lib/ofono/e_ofono_manager.c @@ -0,0 +1,43 @@ +#include "e_ofono_private.h" + +/** + * Get the element manager. + * + * @return element pointer if found, NULL otherwise. + */ +E_Ofono_Element * +e_ofono_manager_get(void) +{ + return e_ofono_element_get(manager_path, e_ofono_iface_manager); +} + +/** + * Get array of modem object paths. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param array where to store the property value, must be a pointer + * to Eina_Array (Eina_Array **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_manager_modems_get(Eina_Array **array) +{ + E_Ofono_Element *element; + E_Ofono_Array *a = NULL; + Eina_Bool r; + + EINA_SAFETY_ON_NULL_RETURN_VAL(array, 0); + + element = e_ofono_element_get(manager_path, e_ofono_iface_manager); + r = e_ofono_element_property_get_stringshared + (element, e_ofono_prop_modems, NULL, &a); + if (a) + *array = a->array; + return r; +} diff --git a/src/lib/ofono/e_ofono_modem.c b/src/lib/ofono/e_ofono_modem.c new file mode 100644 index 0000000..196f4f0 --- /dev/null +++ b/src/lib/ofono/e_ofono_modem.c @@ -0,0 +1,67 @@ +#include "e_ofono_private.h" + +/* TODO: add a getter for Interfaces property */ + +/** + * Get property "Powered" value. + * + * @param powered where to store the property value, must be a pointer + * to Eina_Bool (Eina_Bool *), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_modem_powered_get(const E_Ofono_Element *element, Eina_Bool *powered) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(powered, 0); + + return e_ofono_element_property_get_stringshared + (element, e_ofono_prop_powered, NULL, powered); +} + +/** + * Call method SetProperty("Powered", powered) at the given element on server. + * + * + * @param powered value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_modem_powered_set(E_Ofono_Element *element, Eina_Bool powered, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + + return e_ofono_element_property_set_full + (element, e_ofono_prop_powered, DBUS_TYPE_BOOLEAN, + &powered, cb, data); +} + +/** + * Get property "Name" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param address where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_modem_name_get(const E_Ofono_Element *element, const char **name) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(name, 0); + + return e_ofono_element_property_get_stringshared + (element, e_ofono_prop_name, NULL, name); +} diff --git a/src/lib/ofono/e_ofono_network_reg.c b/src/lib/ofono/e_ofono_network_reg.c new file mode 100644 index 0000000..3719173 --- /dev/null +++ b/src/lib/ofono/e_ofono_network_reg.c @@ -0,0 +1,93 @@ +#include "e_ofono_private.h" + +/** + * Get property "Mode" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param mode where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_netreg_mode_get(const E_Ofono_Element *element, const char **mode) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(mode, 0); + + return e_ofono_element_property_get_stringshared + (element, e_ofono_prop_mode, NULL, mode); +} + +/** + * Get property "Status" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param status where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_netreg_status_get(const E_Ofono_Element *element, const char **status) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(status, 0); + + return e_ofono_element_property_get_stringshared + (element, e_ofono_prop_status, NULL, status); +} + +/** + * Get property "Operator" value. + * + * If this property isn't found then 0 is returned. + * If zero is returned, then this call failed and parameter-returned + * values shall be considered invalid. + * + * @param operator where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_netreg_operator_get(const E_Ofono_Element *element, const char **op) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(op, 0); + + return e_ofono_element_property_get_stringshared + (element, e_ofono_prop_operator, NULL, op); +} + +/** + * Get property "Strength" value. + * + * @param strength where to store the property value, must be a pointer + * to char (char *), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_netreg_strength_get(const E_Ofono_Element *element, uint8_t *strength) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(strength, 0); + + return e_ofono_element_property_get_stringshared + (element, e_ofono_prop_strength, NULL, strength); +} diff --git a/src/lib/ofono/e_ofono_private.h b/src/lib/ofono/e_ofono_private.h new file mode 100644 index 0000000..bbe7366 --- /dev/null +++ b/src/lib/ofono/e_ofono_private.h @@ -0,0 +1,135 @@ + #ifdef HAVE_CONFIG_H + #include "config.h" + #endif + + #ifdef HAVE_ALLOCA_H + # include <alloca.h> + #elif defined __GNUC__ + # define alloca __builtin_alloca + #elif defined _AIX + # define alloca __alloca + #elif defined _MSC_VER + # include <malloc.h> + # define alloca _alloca + #else + # include <stddef.h> + # ifdef __cplusplus + extern "C" + # endif + void *alloca (size_t); + #endif + + #include <stdio.h> + + #include <Eina.h> + #include <eina_safety_checks.h> + + #include "E_Ofono.h" + + static const char manager_path[] = "/"; + + extern const char *e_ofono_iface_manager; + extern const char *e_ofono_prop_modems; + extern const char *e_ofono_iface_modem; + extern const char *e_ofono_prop_name; + extern const char *e_ofono_prop_powered; + extern const char *e_ofono_prop_interfaces; + extern const char *e_ofono_iface_netreg; + extern const char *e_ofono_prop_mode; + extern const char *e_ofono_prop_status; + extern const char *e_ofono_prop_operator; + extern const char *e_ofono_prop_strength; + extern const char *e_ofono_iface_sms; + extern const char *e_ofono_prop_sca; + extern const char *e_ofono_method_send_sms; + + extern int _e_dbus_ofono_log_dom; + + #ifndef EINA_LOG_DEFAULT_COLOR + #define EINA_LOG_DEFAULT_COLOR EINA_COLOR_CYAN + #endif + + #undef DBG + #undef INF + #undef WRN + #undef ERR + + #define DBG(...) EINA_LOG_DOM_DBG(_e_dbus_ofono_log_dom , __VA_ARGS__) + #define INF(...) EINA_LOG_DOM_INFO(_e_dbus_ofono_log_dom , __VA_ARGS__) + #define WRN(...) EINA_LOG_DOM_WARN(_e_dbus_ofono_log_dom , __VA_ARGS__) + #define ERR(...) EINA_LOG_DOM_ERR(_e_dbus_ofono_log_dom , __VA_ARGS__) + + typedef struct _E_Ofono_Array E_Ofono_Array; + + struct _E_Ofono_Array + { + int type; + Eina_Array *array; + }; + + static inline Eina_Bool + __dbus_callback_check_and_init(const char *file, int line, const char *function, DBusMessage *msg, DBusMessageIter *itr, DBusError *err) + { + if (!msg) + { + if (err) + eina_log_print(_e_dbus_ofono_log_dom, EINA_LOG_LEVEL_ERR, + file, function, line, + "an error was reported by server: " + "name=\"%s\", message=\"%s\"", + err->name, err->message); + else + eina_log_print(_e_dbus_ofono_log_dom, EINA_LOG_LEVEL_ERR, + file, function, line, + "callback without message arguments!"); + + return 0; + } + + if (!dbus_message_iter_init(msg, itr)) + { + eina_log_print(_e_dbus_ofono_log_dom, EINA_LOG_LEVEL_ERR, + file, function, line, + "could not init iterator."); + return 0; + } + + return 1; + } + + #define _dbus_callback_check_and_init(msg, itr, err) \ + __dbus_callback_check_and_init(__FILE__, __LINE__, __FUNCTION__, \ + msg, itr, err) + + static inline Eina_Bool + __dbus_iter_type_check(const char *file, int line, const char *function, int type, int expected, const char *expected_name) + { + if (type == expected) + return 1; + + ERR(file, function, line, + "expected type %s (%c) but got %c instead!", + expected_name, expected, type); + + return 0; + } + #define _dbus_iter_type_check(t, e) __dbus_iter_type_check(__FILE__, __LINE__, __FUNCTION__, t, e, #e) + + extern E_DBus_Connection *e_ofono_conn; + + const char *e_ofono_system_bus_name_get(void); + + void e_ofono_manager_clear_elements(void); + + void e_ofono_elements_init(void); + void e_ofono_elements_shutdown(void); + + E_Ofono_Element *e_ofono_element_register(const char *path, const char *interface); + void e_ofono_element_unregister(E_Ofono_Element *element); + + Eina_Bool e_ofono_element_message_send(E_Ofono_Element *element, const char *method_name, const char *interface, E_DBus_Method_Return_Cb cb, DBusMessage *msg, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); + + Eina_Bool e_ofono_element_call_full(E_Ofono_Element *element, const char *method_name, const char *interface, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); + Eina_Bool e_ofono_element_call_with_path(E_Ofono_Element *element, const char *method_name, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); + Eina_Bool e_ofono_element_call_with_string(E_Ofono_Element *element, const char *method_name, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); + Eina_Bool e_ofono_element_call_with_path_and_string(E_Ofono_Element *element, const char *method_name, const char *path, const char *string, E_DBus_Method_Return_Cb cb, Eina_Inlist **pending, E_DBus_Method_Return_Cb user_cb, const void *user_data); diff --git a/src/lib/ofono/e_ofono_sms.c b/src/lib/ofono/e_ofono_sms.c new file mode 100644 index 0000000..38b8062 --- /dev/null +++ b/src/lib/ofono/e_ofono_sms.c @@ -0,0 +1,77 @@ +#include "e_ofono_private.h" + +/** + * Get property "ServiceCenterAddress" value. + * + * @param sca where to store the property value, must be a pointer + * to string (const char **), it will not be allocated or + * copied and references will be valid until element changes, + * so copy it if you want to use it later. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_sms_sca_get(const E_Ofono_Element *element, const char **sca) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(sca, 0); + + return e_ofono_element_property_get_stringshared + (element, e_ofono_prop_sca, NULL, sca); +} + +/** + * Call method SetProperty("ServiceCenterAddress", powered) at the given + * element on server. + * + * + * @param sca value to set. + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_sms_sca_set(E_Ofono_Element *element, const char *sca, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + + return e_ofono_element_property_set_full + (element, e_ofono_prop_sca, DBUS_TYPE_STRING, sca, cb, data); +} + +/** + * Send SMS message. + * + * Call method SendMessage(number, text) to send a new SMS message. + * + * @param number the destination of the message + * @param message text of message body + * @param cb function to call when server replies or some error happens. + * @param data data to give to cb when it is called. + * + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise. + */ +Eina_Bool +e_ofono_sms_send_message(E_Ofono_Element *element, const char *number, const char *message, E_DBus_Method_Return_Cb cb, const void *data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(number, 0); + EINA_SAFETY_ON_NULL_RETURN_VAL(message, 0); + + DBusMessage *m; + DBusMessageIter i; + + if (!(m = dbus_message_new_method_call(e_ofono_system_bus_name_get(), + element->path, element->interface, + e_ofono_method_send_sms))) + return EINA_FALSE; + + dbus_message_iter_init_append(m, &i); + dbus_message_iter_append_basic(&i, DBUS_TYPE_STRING, &number); + dbus_message_iter_append_basic(&i, DBUS_TYPE_STRING, &message); + + return e_ofono_element_message_send(element, e_ofono_method_send_sms, + e_ofono_iface_sms, NULL, m, + &element->_pending.send_sms, cb, data); +} diff --git a/src/lib/ukit/E_Ukit.h b/src/lib/ukit/E_Ukit.h new file mode 100644 index 0000000..d9117b3 --- /dev/null +++ b/src/lib/ukit/E_Ukit.h @@ -0,0 +1,176 @@ +#ifndef E_UKIT_H +#define E_UKIT_H +#include <E_DBus.h> +#include <eina_stringshare.h> + +#ifdef EAPI +#undef EAPI +#endif +#ifdef _MSC_VER +# ifdef BUILDING_DLL +# define EAPI __declspec(dllexport) +# else +# define EAPI __declspec(dllimport) +# endif +#else +# ifdef __GNUC__ +# if __GNUC__ >= 4 +# define EAPI __attribute__ ((visibility("default"))) +# else +# define EAPI +# endif +# else +# define EAPI +# endif +#endif + +#define E_UKIT_PROP_INTERFACE "org.freedesktop.DBus.Properties" + +#define E_UDISKS_BUS "org.freedesktop.UDisks" +#define E_UDISKS_PATH "/org/freedesktop/UDisks" +#define E_UDISKS_INTERFACE "org.freedesktop.UDisks.Device" + +#define E_UPOWER_BUS "org.freedesktop.UPower" +#define E_UPOWER_PATH "/org/freedesktop/UPower" +#define E_UPOWER_INTERFACE "org.freedesktop.UPower.Device" + +/* message return types */ + +typedef struct E_Ukit_Property E_Ukit_Property; +typedef struct E_Ukit_Properties E_Ukit_Properties; + +struct E_Ukit_String_List_Return +{ + Eina_List *strings; /* list of const char * */ +}; + +struct E_Ukit_Bool_Return +{ + Eina_Bool boolean; +}; + +struct E_Ukit_UDI_Return +{ + const char *udi; +}; + +struct E_Ukit_Capability +{ + const char *udi; + const char *capability; +}; + +typedef enum +{ + E_UKIT_PROPERTY_TYPE_STRING, + E_UKIT_PROPERTY_TYPE_INT, + E_UKIT_PROPERTY_TYPE_UINT32, + E_UKIT_PROPERTY_TYPE_UINT64, + E_UKIT_PROPERTY_TYPE_INT64, + E_UKIT_PROPERTY_TYPE_BOOL, + E_UKIT_PROPERTY_TYPE_DOUBLE, + E_UKIT_PROPERTY_TYPE_STRLIST +} E_Ukit_Property_Type; + +struct E_Ukit_Property +{ + E_Ukit_Property_Type type; + union + { + const char *s; + int i; + Eina_Bool b; + double d; + uint32_t u; + uint64_t t; + int64_t x; + Eina_List *strlist; + } val; +}; + +struct E_Ukit_Properties +{ + Eina_Hash *properties; +}; + +typedef enum +{ + E_UPOWER_BATTERY_UNKNOWN, + E_UPOWER_BATTERY_LION, + E_UPOWER_BATTERY_LPOLYMER, + E_UPOWER_BATTERY_LIRONPHOS, + E_UPOWER_BATTERY_LEAD, + E_UPOWER_BATTERY_NICAD, + E_UPOWER_BATTERY_METALHYDRYDE +} E_UPower_Battery_Type; + +typedef enum +{ + E_UPOWER_STATE_UNKNOWN, + E_UPOWER_STATE_CHARGING, + E_UPOWER_STATE_DISCHARGING, + E_UPOWER_STATE_EMPTY, + E_UPOWER_STATE_FULL, + E_UPOWER_STATE_PENDINGCHARGE, + E_UPOWER_STATE_PENDINGDISCHARGE +} E_Upower_State; + +typedef enum +{ + E_UPOWER_SOURCE_UNKNOWN, + E_UPOWER_SOURCE_AC, + E_UPOWER_SOURCE_BATTERY, + E_UPOWER_SOURCE_UPS, + E_UPOWER_SOURCE_MONITOR, + E_UPOWER_SOURCE_MOUSE, + E_UPOWER_SOURCE_KEYBOARD, + E_UPOWER_SOURCE_PDA, + E_UPOWER_SOURCE_PHONE +} E_Upower_Source; + + +typedef struct E_Ukit_Properties E_Ukit_Get_All_Properties_Return; +typedef struct E_Ukit_Property E_Ukit_Get_Property_Return; +typedef struct E_Ukit_String_List_Return E_Ukit_String_List_Return; +typedef struct E_Ukit_String_List_Return E_Ukit_Get_All_Devices_Return; + +typedef struct E_Ukit_UDI_Return E_Ukit_Device_Added; +typedef struct E_Ukit_UDI_Return E_Ukit_Device_Removed; +typedef struct E_Ukit_Capability E_Ukit_New_Capability; + +#ifdef __cplusplus +extern "C" { +#endif + + EAPI int e_ukit_init(void); + EAPI int e_ukit_shutdown(void); + + EAPI DBusPendingCall *e_udisks_get_property(E_DBus_Connection *conn, const char *udi, const char *property, E_DBus_Callback_Func cb_func, void *data); + EAPI DBusPendingCall *e_udisks_get_all_properties(E_DBus_Connection *conn, const char *udi, E_DBus_Callback_Func cb_func, void *data); + EAPI DBusPendingCall *e_udisks_get_all_devices(E_DBus_Connection *conn, E_DBus_Callback_Func cb_func, void *data); + + EAPI DBusPendingCall *e_upower_get_property(E_DBus_Connection *conn, const char *udi, const char *property, E_DBus_Callback_Func cb_func, void *data); + EAPI DBusPendingCall *e_upower_get_all_properties(E_DBus_Connection *conn, const char *udi, E_DBus_Callback_Func cb_func, void *data); + EAPI DBusPendingCall *e_upower_get_all_devices(E_DBus_Connection *conn, E_DBus_Callback_Func cb_func, void *data); + +/* utility functions */ + EAPI void e_ukit_property_free(E_Ukit_Property *prop); + EAPI const char *e_ukit_property_string_get(E_Ukit_Properties *properties, const char *key, int *err); + EAPI Eina_Bool e_ukit_property_bool_get(E_Ukit_Properties *properties, const char *key, int *err); + EAPI int e_ukit_property_int_get(E_Ukit_Properties *properties, const char *key, int *err); + EAPI uint32_t e_ukit_property_uint32_get(E_Ukit_Properties *properties, const char *key, int *err); + EAPI uint64_t e_ukit_property_uint64_get(E_Ukit_Properties *properties, const char *key, int *err); + EAPI int64_t e_ukit_property_int64_get(E_Ukit_Properties *properties, const char *key, int *err); + EAPI double e_ukit_property_double_get(E_Ukit_Properties *properties, const char *key, int *err); + EAPI const Eina_List *e_ukit_property_strlist_get(E_Ukit_Properties *properties, const char *key, int *err); + +/* (un)mount */ + EAPI DBusPendingCall *e_udisks_volume_mount(E_DBus_Connection *conn, const char *udi, const char *fstype, Eina_List *options, E_DBus_Callback_Func cb_func, void *data); + EAPI DBusPendingCall *e_udisks_volume_unmount(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data); + EAPI DBusPendingCall *e_udisks_volume_eject(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lib/ukit/Makefile.am b/src/lib/ukit/Makefile.am new file mode 100644 index 0000000..2e093e2 --- /dev/null +++ b/src/lib/ukit/Makefile.am @@ -0,0 +1,26 @@ +MAINTAINERCLEANFILES = Makefile.in + +AM_CPPFLAGS = \ +-I $(top_srcdir)/src/lib/dbus \ +@EDBUS_CFLAGS@ @EINA_CFLAGS@ + +if BUILD_EUKIT + +lib_LTLIBRARIES = libeukit.la +include_HEADERS = E_Ukit.h + +libeukit_la_SOURCES = \ +e_udisks.c \ +e_upower.c \ +e_ukit_util.c \ +e_ukit_main.c \ +e_ukit_private_util.c + +libeukit_la_LIBADD = \ +$(top_builddir)/src/lib/dbus/libedbus.la \ +@EINA_LIBS@ +libeukit_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ @eukit_release_info@ + +endif + +EXTRA_DIST = e_ukit_private.h diff --git a/src/lib/ukit/e_udisks.c b/src/lib/ukit/e_udisks.c new file mode 100644 index 0000000..70363f8 --- /dev/null +++ b/src/lib/ukit/e_udisks.c @@ -0,0 +1,194 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <E_Ukit.h> +#include "e_ukit_private.h" + +#define E_UKIT_BUS E_UDISKS_BUS +#define E_UKIT_PATH E_UDISKS_PATH +#define E_UKIT_INTERFACE E_UDISKS_INTERFACE + +const char *e_udisks_iface="org.freedesktop.UDisks.Device"; + +#if 0 +static void cb_device_get_property(void *data, DBusMessage *msg, DBusError *err); +static void cb_device_get_all_properties(void *data, DBusMessage *msg, DBusError *err); +static void cb_device_query_capability(void *data, DBusMessage *msg, DBusError *err); +#endif + +/* Properties.Get */ +EAPI DBusPendingCall * +e_udisks_get_property(E_DBus_Connection *conn, const char *udi, const char *property, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_ukit_property_call_new(udi, "Get"); + dbus_message_append_args(msg, DBUS_TYPE_STRING, &e_udisks_iface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID); + ret = e_dbus_method_call_send(conn, msg, unmarshal_property, cb_func, free_property, -1, data); + dbus_message_unref(msg); + return ret; +} + +/* Properties.GetAll */ +EAPI DBusPendingCall * +e_udisks_get_all_properties(E_DBus_Connection *conn, const char *udi, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_ukit_property_call_new(udi, "GetAll"); + dbus_message_append_args(msg, DBUS_TYPE_STRING, &e_udisks_iface, DBUS_TYPE_INVALID); + ret = e_dbus_method_call_send(conn, msg, unmarshal_device_get_all_properties, cb_func, free_device_get_all_properties, -1, data); + dbus_message_unref(msg); + return ret; +} + + + +/* void FilesystemMount(string fstype, array{string}options) */ + +/** + * @brief Mount a Filesystem + * + * @param conn the E_DBus_Connection + * @param udi the udi of the device object + * @param fstype the fstype of the device (e.g. volume.fstype property) + * @param options a list of additional options (not sure... fstype dependant?) + * @param cb_func an optional callback to call when the mount is done + * @param data custom data pointer for the callback function + * + * @return mount point of fs or error + */ +EAPI DBusPendingCall * +e_udisks_volume_mount(E_DBus_Connection *conn, const char *udi, const char *fstype, Eina_List *options, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusMessageIter iter, subiter; + Eina_List *l; + DBusPendingCall *ret; + + msg = e_ukit_device_call_new(udi, "FilesystemMount"); + + dbus_message_iter_init_append(msg, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &fstype); + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); + + if (options) + { + const char *opt; + + EINA_LIST_FOREACH(options, l, opt) + dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt); + } + dbus_message_iter_close_container(&iter, &subiter) ; + + ret = e_dbus_method_call_send(conn, msg, unmarshal_property, cb_func, free_property, -1, data); + dbus_message_unref(msg); + return ret; +} + +/* void Unmount(array{string} options) */ + +/** + * @brief Unmount a Volume + * + * @param conn the E_DBus_Connection + * @param udi the udi of the device object + * @param options a list of additional options (currently only 'force' is supported) + * @param cb_func an optional callback to call when the unmount is done + * @param data custom data pointer for the callback function + */ +EAPI DBusPendingCall * +e_udisks_volume_unmount(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusMessageIter iter, subiter; + Eina_List *l; + DBusPendingCall *ret; + + msg = e_ukit_device_call_new(udi, "FilesystemUnmount"); + + dbus_message_iter_init_append(msg, &iter); + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); + if (options) + { + const char *opt; + + EINA_LIST_FOREACH(options, l, opt) + dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt); + } + dbus_message_iter_close_container(&iter, &subiter) ; + + ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data); + dbus_message_unref(msg); + return ret; +} + +/** + * @brief Eject a Volume + * + * @param conn the E_DBus_Connection + * @param udi the udi of the device object + * @param options a list of additional options (none currently supported) + * @param cb_func an optional callback to call when the eject is done + * @param data cuatom data pointer for the callback function + */ +EAPI DBusPendingCall * +e_udisks_volume_eject(E_DBus_Connection *conn, const char *udi, Eina_List *options, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusMessageIter iter, subiter; + Eina_List *l; + DBusPendingCall *ret; + + msg = e_ukit_device_call_new(udi, "DriveEject"); + + dbus_message_iter_init_append(msg, &iter); + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &subiter); + if (options) + { + const char *opt; + + EINA_LIST_FOREACH(options, l, opt) + dbus_message_iter_append_basic(&subiter, DBUS_TYPE_STRING, &opt); + } + dbus_message_iter_close_container(&iter, &subiter) ; + + ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data); + dbus_message_unref(msg); + return ret; +} + +/* EnumerateDevices */ +EAPI DBusPendingCall * +e_udisks_get_all_devices(E_DBus_Connection *conn, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_ukit_call_new(E_UKIT_PATH, "EnumerateDevices"); + ret = e_dbus_method_call_send(conn, msg, unmarshal_string_list, cb_func, free_string_list, -1, data); + dbus_message_unref(msg); + return ret; +} + + +/* Manager.FindDeviceByCapability */ +/* + * not implemented in udisks yet... + * +EAPI DBusPendingCall * +e_udisks_find_device_by_capability(E_DBus_Connection *conn, const char *capability, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_udisks_call_new("FindDeviceByCapability"); + dbus_message_append_args(msg, DBUS_TYPE_STRING, &capability, DBUS_TYPE_INVALID); + ret = e_dbus_method_call_send(conn, msg, unmarshal_string_list, cb_func, free_string_list, -1, data); + dbus_message_unref(msg); + return ret; +} +*/ diff --git a/src/lib/ukit/e_ukit_main.c b/src/lib/ukit/e_ukit_main.c new file mode 100644 index 0000000..c541e3d --- /dev/null +++ b/src/lib/ukit/e_ukit_main.c @@ -0,0 +1,58 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <E_Ukit.h> +#include "e_ukit_private.h" + +int _e_dbus_ukit_log_dom = -1; +int _e_dbus_ukit_init_count = 0; + +EAPI int +e_ukit_init(void) +{ + if (++_e_dbus_ukit_init_count != 1) + return _e_dbus_ukit_init_count; + + if (!eina_init()) + return --_e_dbus_ukit_init_count; + + _e_dbus_ukit_log_dom = eina_log_domain_register + ("e_ukit", E_DBUS_COLOR_DEFAULT); + if (_e_dbus_ukit_log_dom < 0) + { + EINA_LOG_ERR("Could not register 'e_ukit' log domain."); + goto shutdown_eina; + } + + if (!e_dbus_init()) + { + ERR("Could not initialize E_DBus."); + goto unregister_log_domain; + } + + return _e_dbus_ukit_init_count; + + unregister_log_domain: + eina_log_domain_unregister(_e_dbus_ukit_log_dom); + _e_dbus_ukit_log_dom = -1; + shutdown_eina: + eina_shutdown(); + + return _e_dbus_ukit_init_count; +} + +EAPI int +e_ukit_shutdown(void) +{ + if (--_e_dbus_ukit_init_count != 0) + return _e_dbus_ukit_init_count; + + e_dbus_shutdown(); + + eina_log_domain_unregister(_e_dbus_ukit_log_dom); + _e_dbus_ukit_log_dom = -1; + eina_shutdown(); + + return _e_dbus_ukit_init_count; +} diff --git a/src/lib/ukit/e_ukit_private.h b/src/lib/ukit/e_ukit_private.h new file mode 100644 index 0000000..c4763de --- /dev/null +++ b/src/lib/ukit/e_ukit_private.h @@ -0,0 +1,43 @@ +#ifndef E_UKIT_PRIVATE_H +#define E_UKIT_PRIVATE_H + +#ifndef E_DBUS_COLOR_DEFAULT +# define E_DBUS_COLOR_DEFAULT EINA_COLOR_CYAN +#endif + +extern int _e_dbus_ukit_log_dom; + +#ifdef ERR +# undef ERR +#endif + +#ifdef INF +# undef INF +#endif + +#ifdef WARN +# undef WARN +#endif + +#ifdef DBG +# undef DBG +#endif + +#define e_ukit_call_new(udi, member) dbus_message_new_method_call(E_UKIT_BUS, udi, E_UKIT_BUS, member) +#define e_ukit_device_call_new(udi, member) dbus_message_new_method_call(E_UKIT_BUS, udi, E_UKIT_INTERFACE, member) +#define e_ukit_property_call_new(udi, member) dbus_message_new_method_call(E_UKIT_BUS, udi, E_UKIT_PROP_INTERFACE, member) + +#define DBG(...) EINA_LOG_DOM_DBG(_e_dbus_ukit_log_dom, __VA_ARGS__) +#define INFO(...) EINA_LOG_DOM_INFO(_e_dbus_ukit_log_dom, __VA_ARGS__) +#define WARN(...) EINA_LOG_DOM_WARN(_e_dbus_ukit_log_dom, __VA_ARGS__) +#define ERR(...) EINA_LOG_DOM_ERR(_e_dbus_ukit_log_dom, __VA_ARGS__) + +void *unmarshal_property(DBusMessage *msg, DBusError *err); +void free_property(void *data); +void *unmarshal_device_get_all_properties(DBusMessage *msg, DBusError *err); +void free_device_get_all_properties(void *data); +void *unmarshal_string_list(DBusMessage *msg, DBusError *err); +void free_string_list(void *data); + + +#endif diff --git a/src/lib/ukit/e_ukit_private_util.c b/src/lib/ukit/e_ukit_private_util.c new file mode 100644 index 0000000..1d14605 --- /dev/null +++ b/src/lib/ukit/e_ukit_private_util.c @@ -0,0 +1,254 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <E_Ukit.h> +#include "e_ukit_private.h" + +void * +unmarshal_property(DBusMessage *msg, DBusError *err) +{ + E_Ukit_Get_Property_Return *ret = NULL; + DBusMessageIter iter, a_iter; + int type; + char *tmp; + + ret = calloc(1, sizeof(E_Ukit_Get_Property_Return)); + if (!ret) + { + dbus_set_error(err, DBUS_ERROR_NO_MEMORY, ""); + return NULL; + } + + dbus_message_iter_init(msg, &iter); + dbus_message_iter_recurse(&iter, &a_iter); + if (dbus_message_iter_get_arg_type(&a_iter) != DBUS_TYPE_INVALID) + { + type = dbus_message_iter_get_arg_type(&a_iter); + + switch(type) + { + case DBUS_TYPE_STRING: + ret->type = E_UKIT_PROPERTY_TYPE_STRING; + dbus_message_iter_get_basic(&a_iter, &tmp); + ret->val.s = eina_stringshare_add(tmp); + break; + case DBUS_TYPE_INT32: + ret->type = E_UKIT_PROPERTY_TYPE_INT; + dbus_message_iter_get_basic(&a_iter, &(ret->val.i)); + break; + case DBUS_TYPE_UINT32: + ret->type = E_UKIT_PROPERTY_TYPE_UINT32; + dbus_message_iter_get_basic(&a_iter, &(ret->val.u)); + break; + case DBUS_TYPE_UINT64: + ret->type = E_UKIT_PROPERTY_TYPE_UINT64; + dbus_message_iter_get_basic(&a_iter, &(ret->val.t)); + break; + case DBUS_TYPE_INT64: + ret->type = E_UKIT_PROPERTY_TYPE_INT64; + dbus_message_iter_get_basic(&a_iter, &(ret->val.x)); + break; + case DBUS_TYPE_BOOLEAN: + ret->type = E_UKIT_PROPERTY_TYPE_BOOL; + dbus_message_iter_get_basic(&a_iter, &(ret->val.b)); + break; + case DBUS_TYPE_DOUBLE: + ret->type = E_UKIT_PROPERTY_TYPE_DOUBLE; + dbus_message_iter_get_basic(&a_iter, &(ret->val.d)); + break; + case DBUS_TYPE_ARRAY: + ret->type = E_UKIT_PROPERTY_TYPE_STRLIST; + { + DBusMessageIter list_iter; + ret->val.strlist = NULL; + dbus_message_iter_recurse(&a_iter, &list_iter); + while (dbus_message_iter_get_arg_type(&list_iter) != DBUS_TYPE_INVALID) + { + char *str; + dbus_message_iter_get_basic(&list_iter, &str); + tmp = (char*)eina_stringshare_add(str); + ret->val.strlist = eina_list_append(ret->val.strlist, tmp); + dbus_message_iter_next(&list_iter); + } + } + break; + default: + break; + } + } + + return ret; +} + +void +free_property(void *data) +{ + E_Ukit_Get_Property_Return *ret = data; + + if (!ret) return; + if (ret->type == E_UKIT_PROPERTY_TYPE_STRLIST) + { + const char *s; + EINA_LIST_FREE(ret->val.strlist, s) + eina_stringshare_del(s); + } + else if (ret->type == E_UKIT_PROPERTY_TYPE_STRING) + eina_stringshare_del(ret->val.s); + free(ret); +} + +void * +unmarshal_device_get_all_properties(DBusMessage *msg, DBusError *err) +{ + E_Ukit_Get_All_Properties_Return *ret = NULL; + DBusMessageIter iter, a_iter, s_iter, v_iter; + int type; + char *tmp; + + /* a{sv} = array of string+variants */ + if (!dbus_message_has_signature(msg, "a{sv}")) + { + dbus_set_error(err, DBUS_ERROR_INVALID_SIGNATURE, ""); + return NULL; + } + + ret = calloc(1, sizeof(E_Ukit_Get_All_Properties_Return)); + if (!ret) + { + dbus_set_error(err, DBUS_ERROR_NO_MEMORY, ""); + return NULL; + } + + ret->properties = eina_hash_string_small_new(EINA_FREE_CB(e_ukit_property_free)); + + dbus_message_iter_init(msg, &iter); + dbus_message_iter_recurse(&iter, &a_iter); + while (dbus_message_iter_get_arg_type(&a_iter) != DBUS_TYPE_INVALID) + { + const char *name; + E_Ukit_Property *prop = calloc(1, sizeof(E_Ukit_Property)); + dbus_message_iter_recurse(&a_iter, &s_iter); + dbus_message_iter_get_basic(&s_iter, &name); + dbus_message_iter_next(&s_iter); + dbus_message_iter_recurse(&s_iter, &v_iter); + + type = dbus_message_iter_get_arg_type(&v_iter); + switch(type) + { + case DBUS_TYPE_STRING: + prop->type = E_UKIT_PROPERTY_TYPE_STRING; + dbus_message_iter_get_basic(&v_iter, &tmp); + prop->val.s = eina_stringshare_add(tmp); + break; + case DBUS_TYPE_INT32: + prop->type = E_UKIT_PROPERTY_TYPE_INT; + dbus_message_iter_get_basic(&v_iter, &(prop->val.i)); + break; + case DBUS_TYPE_UINT32: + prop->type = E_UKIT_PROPERTY_TYPE_UINT32; + dbus_message_iter_get_basic(&v_iter, &(prop->val.u)); + break; + case DBUS_TYPE_UINT64: + prop->type = E_UKIT_PROPERTY_TYPE_UINT64; + dbus_message_iter_get_basic(&v_iter, &(prop->val.t)); + break; + case DBUS_TYPE_INT64: + prop->type = E_UKIT_PROPERTY_TYPE_INT64; + dbus_message_iter_get_basic(&v_iter, &(prop->val.x)); + break; + case DBUS_TYPE_BOOLEAN: + prop->type = E_UKIT_PROPERTY_TYPE_BOOL; + dbus_message_iter_get_basic(&v_iter, &(prop->val.b)); + break; + case DBUS_TYPE_DOUBLE: + prop->type = E_UKIT_PROPERTY_TYPE_DOUBLE; + dbus_message_iter_get_basic(&v_iter, &(prop->val.d)); + break; + case DBUS_TYPE_ARRAY: + prop->type = E_UKIT_PROPERTY_TYPE_STRLIST; + { + DBusMessageIter list_iter; + prop->val.strlist = NULL; + dbus_message_iter_recurse(&v_iter, &list_iter); + while (dbus_message_iter_get_arg_type(&list_iter) != DBUS_TYPE_INVALID) + { + char *str; + dbus_message_iter_get_basic(&list_iter, &str); + tmp = (char*)eina_stringshare_add(str); + prop->val.strlist = eina_list_append(prop->val.strlist, tmp); + dbus_message_iter_next(&list_iter); + } + } + break; + default: + WARN("EUkit Error: unexpected property type (%s): %c", name, dbus_message_iter_get_arg_type(&v_iter)); + break; + } + eina_hash_add(ret->properties, name, prop); + + dbus_message_iter_next(&a_iter); + } + + return ret; +} + +void +free_device_get_all_properties(void *data) +{ + E_Ukit_Get_All_Properties_Return *ret = data; + + if (!ret) return; + eina_hash_free(ret->properties); + free(ret); +} + +void * +unmarshal_string_list(DBusMessage *msg, DBusError *err) +{ + E_Ukit_String_List_Return *ret = NULL; + DBusMessageIter iter, sub; + char *tmp; + + /* ao = array of object strings */ + if (!dbus_message_has_signature(msg, "ao")) + { + dbus_set_error(err, DBUS_ERROR_INVALID_SIGNATURE, ""); + return NULL; + } + + ret = calloc(1, sizeof(E_Ukit_String_List_Return)); + if (!ret) + { + dbus_set_error(err, DBUS_ERROR_NO_MEMORY, ""); + return NULL; + } + + ret->strings = NULL; + + dbus_message_iter_init(msg, &iter); + dbus_message_iter_recurse(&iter, &sub); + while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) + { + char *dev = NULL; + + dbus_message_iter_get_basic(&sub, &dev); + tmp = (char*)eina_stringshare_add(dev); + if (dev) ret->strings = eina_list_append(ret->strings, tmp); + dbus_message_iter_next(&sub); + } + + return ret; +} + +void +free_string_list(void *data) +{ + E_Ukit_String_List_Return *ret = data; + const char *x; + + if (!ret) return; + EINA_LIST_FREE(ret->strings, x) + eina_stringshare_del(x); + free(ret); +} diff --git a/src/lib/ukit/e_ukit_util.c b/src/lib/ukit/e_ukit_util.c new file mode 100644 index 0000000..3067b75 --- /dev/null +++ b/src/lib/ukit/e_ukit_util.c @@ -0,0 +1,129 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <E_Ukit.h> +#include "e_ukit_private.h" + +/** + * @internal + * @brief free a property structure + * @param prop the property to free + */ +EAPI void +e_ukit_property_free(E_Ukit_Property *prop) +{ + if (prop->type == E_UKIT_PROPERTY_TYPE_STRLIST) + eina_list_free(prop->val.strlist); + free(prop); +} + +/** + * @brief Retrive a string from an element of a property hash + * @param properties the E_Ukit_Properties structure + * @param key the key of the property to retrieve + * @param err a pointer to an int, which if supplied, will be set to 0 on success and 1 on an error + */ +EAPI const char * +e_ukit_property_string_get(E_Ukit_Properties *properties, const char *key, int *err) +{ + E_Ukit_Property *prop; + if (err) *err = 0; + if (!properties->properties) return NULL; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.s; + + if (err) *err = 1; + return NULL; +} + +EAPI Eina_Bool +e_ukit_property_bool_get(E_Ukit_Properties *properties, const char *key, int *err) +{ + E_Ukit_Property *prop; + if (err) *err = 0; + if (!properties->properties) return 0; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.b; + + if (err) *err = 1; + return 0; +} + +EAPI int +e_ukit_property_int_get(E_Ukit_Properties *properties, const char *key, int *err) +{ + E_Ukit_Property *prop; + if (err) *err = 0; + if (!properties->properties) return 0; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.i; + + if (err) *err = 1; + return 0; +} + +EAPI uint32_t +e_ukit_property_uint32_get(E_Ukit_Properties *properties, const char *key, int *err) +{ + E_Ukit_Property *prop; + if (err) *err = 0; + if (!properties->properties) return 0; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.u; + + if (err) *err = 1; + return 0; +} + +EAPI uint64_t +e_ukit_property_uint64_get(E_Ukit_Properties *properties, const char *key, int *err) +{ + E_Ukit_Property *prop; + if (err) *err = 0; + if (!properties->properties) return 0; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.t; + + if (err) *err = 1; + return 0; +} + +EAPI int64_t +e_ukit_property_int64_get(E_Ukit_Properties *properties, const char *key, int *err) +{ + E_Ukit_Property *prop; + if (err) *err = 0; + if (!properties->properties) return 0; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.x; + + if (err) *err = 1; + return 0; +} + +EAPI double +e_ukit_property_double_get(E_Ukit_Properties *properties, const char *key, int *err) +{ + E_Ukit_Property *prop; + if (err) *err = 0; + if (!properties->properties) return 0; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.d; + + if (err) *err = 1; + return 0; +} + +EAPI const Eina_List * +e_ukit_property_strlist_get(E_Ukit_Properties *properties, const char *key, int *err) +{ + E_Ukit_Property *prop; + if (err) *err = 0; + if (!properties->properties) return NULL; + prop = eina_hash_find(properties->properties, key); + if (prop) return prop->val.strlist; + + if (err) *err = 1; + return NULL; +} diff --git a/src/lib/ukit/e_upower.c b/src/lib/ukit/e_upower.c new file mode 100644 index 0000000..af6de36 --- /dev/null +++ b/src/lib/ukit/e_upower.c @@ -0,0 +1,112 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <E_Ukit.h> +#include "e_ukit_private.h" + +#define E_UKIT_BUS E_UPOWER_BUS +#define E_UKIT_PATH E_UPOWER_PATH +#define E_UKIT_INTERFACE E_UPOWER_INTERFACE + +const char *e_upower_iface="org.freedesktop.UPower.Device"; + +#if 0 +static void cb_device_get_property(void *data, DBusMessage *msg, DBusError *err); +static void cb_device_get_all_properties(void *data, DBusMessage *msg, DBusError *err); +static void cb_device_query_capability(void *data, DBusMessage *msg, DBusError *err); +#endif + +/* Properties.Get */ +EAPI DBusPendingCall * +e_upower_get_property(E_DBus_Connection *conn, const char *udi, const char *property, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_ukit_property_call_new(udi, "Get"); + dbus_message_append_args(msg, DBUS_TYPE_STRING, &e_upower_iface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID); + ret = e_dbus_method_call_send(conn, msg, unmarshal_property, cb_func, free_property, -1, data); + dbus_message_unref(msg); + return ret; +} + +/* Properties.GetAll */ +EAPI DBusPendingCall * +e_upower_get_all_properties(E_DBus_Connection *conn, const char *udi, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_ukit_property_call_new(udi, "GetAll"); + dbus_message_append_args(msg, DBUS_TYPE_STRING, &e_upower_iface, DBUS_TYPE_INVALID); + ret = e_dbus_method_call_send(conn, msg, unmarshal_device_get_all_properties, cb_func, free_device_get_all_properties, -1, data); + dbus_message_unref(msg); + return ret; +} + + +EAPI DBusPendingCall * +e_upower_hibernate(E_DBus_Connection *conn, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_ukit_call_new(E_UKIT_PATH, "Hibernate"); + + ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data); + dbus_message_unref(msg); + return ret; +} + +EAPI DBusPendingCall * +e_upower_suspend(E_DBus_Connection *conn, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_ukit_call_new(E_UKIT_PATH, "Suspend"); + + ret = e_dbus_method_call_send(conn, msg, NULL, cb_func, NULL, -1, data); + dbus_message_unref(msg); + return ret; +} + +EAPI DBusPendingCall * +e_upower_hibernate_allowed(E_DBus_Connection *conn, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_ukit_call_new(E_UKIT_PATH, "HibernateAllowed"); + + ret = e_dbus_method_call_send(conn, msg, unmarshal_property, cb_func, free_property, -1, data); + dbus_message_unref(msg); + return ret; +} + +EAPI DBusPendingCall * +e_upower_suspend_allowed(E_DBus_Connection *conn, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_ukit_call_new(E_UKIT_PATH, "SuspendAllowed"); + + ret = e_dbus_method_call_send(conn, msg, unmarshal_property, cb_func, free_property, -1, data); + dbus_message_unref(msg); + return ret; +} + +/* EnumerateDevices */ +EAPI DBusPendingCall * +e_upower_get_all_devices(E_DBus_Connection *conn, E_DBus_Callback_Func cb_func, void *data) +{ + DBusMessage *msg; + DBusPendingCall *ret; + + msg = e_ukit_call_new(E_UKIT_PATH, "EnumerateDevices"); + ret = e_dbus_method_call_send(conn, msg, unmarshal_string_list, cb_func, free_string_list, -1, data); + dbus_message_unref(msg); + return ret; +} |