File feedbackd-0.5.0.obscpio of Package feedbackd

07070100000000000081A400000000000000000000000166F7A513000001B8000000000000000000000000000000000000001F00000000feedbackd-0.5.0/.dir-locals.el(
 (c-mode . (
            (c-file-style . "linux")
            (indent-tabs-mode . nil)
            (c-basic-offset . 2)
            ))
 (setq auto-mode-alist (cons '("\\.ui$" . nxml-mode) auto-mode-alist))
 (nxml-mode . (
            (indent-tabs-mode . nil)
            ))
 (css-mode . (
            (css-indent-offset . 2)
            ))
 (js-mode . (
	     (indent-tabs-mode . nil)
             (js-indent-level . 2)
            ))
)

07070100000001000081A400000000000000000000000166F7A513000001B5000000000000000000000000000000000000001E00000000feedbackd-0.5.0/.editorconfigroot = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true

[meson.build]
indent_size = 2
tab_size = 2
indent_style = space

[*.{c,h,h.in}]
indent_size = 2
tab_size = 2
indent_style = space
max_line_length = 80

[*.css]
indent_size = 2
tab_size = 2
indent_style = space

[*.xml]
indent_size = 2
tab_size = 2
indent_style = space

[*.json]
indent_size = 2
tab_size = 2
indent_style = space

[NEWS]
max_line_length = 72
07070100000002000081A400000000000000000000000166F7A5130000019B000000000000000000000000000000000000001B00000000feedbackd-0.5.0/.gitignore_build
debian/.debhelper/
debian/debhelper-build-stamp
debian/files
debian/gir1.2-feedback-0.0.substvars
debian/gir1.2-feedback-0.0/
debian/*.debhelper
debian/*.debhelper.log
debian/*.substvars
debian/feedbackd/
debian/feedbackd-common/
debian/gir1.2-lfb-0.0/
debian/libfeedback-0.0-0.substvars
debian/libfeedback-0.0-0/
debian/libfeedback-dev.substvars
debian/libfeedback-dev/
debian/tmp/
subprojects/gmobile/
07070100000003000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001B00000000feedbackd-0.5.0/.gitlab-ci07070100000004000081A400000000000000000000000166F7A51300000DB8000000000000000000000000000000000000001F00000000feedbackd-0.5.0/.gitlab-ci.ymlinclude:
 - remote: 'https://gitlab.freedesktop.org/freedesktop/ci-templates/-/raw/34039cd573a2df832d465bc9e4c5f543571f5241/templates/ci-fairy.yml'
 - remote: 'https://gitlab.gnome.org/guidog/meta-phosh/-/raw/f3c92e90dcc0d65322888217429b75dd101bd0d3/ci/phosh-common-jobs.yml'

stages:
 - build
 - test
 - style-checks
 - package

workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
    # Don't trigger a branch pipeline if there is an open MR
    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
      when: never
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH

.before_script: &before_script
  before_script:
    - export DEBIAN_FRONTEND=noninteractive
    - apt-get -y update
    - apt-get -y upgrade
    - apt-get -y build-dep .
    - '[ -z "${EXTRA_PKGS}" ] || echo "Extra packages: ${EXTRA_PKGS}"'
    - apt-get -y install gcovr git build-essential ${EXTRA_PKGS}

.image: &image
  image:
    name: debian:trixie

.tags: &tags
  tags:
    - librem5:arm64

# Regular, full build
build:gcc:native-debian-trixie:full:
  <<: *tags
  <<: *image
  <<: *before_script
  stage: build
  artifacts:
    paths:
      - _build
  script:
    - meson setup -Db_coverage=true --werror _build
    - meson compile -C _build
  except:
    variables:
      - $PKG_ONLY == "1"

# Minimal build for e.g. submodule usage
build:gcc:native-debian-trixie:lib:
  <<: *tags
  <<: *image
  <<: *before_script
  stage: build
  script:
    - meson setup --werror -Ddaemon=false -Dgtk_doc=false _build
    - meson compile -C _build
  except:
    variables:
      - $PKG_ONLY == "1"

# Build using clang
build:clang:native-debian-trixie:full:
  variables:
    EXTRA_PKGS: clang
  <<: *tags
  <<: *image
  <<: *before_script
  stage: build
  artifacts:
    paths:
      - _build
  script:
    - CC=clang meson setup --werror _build
    - meson compile -C _build
  except:
    variables:
      - $PKG_ONLY == "1"
  allow_failure: true

test:native-debian-trixie:
  <<: *tags
  <<: *image
  <<: *before_script
  stage: test
  needs:
    - build:gcc:native-debian-trixie:full
  coverage: '/^\s+lines\.+:\s+([\d.]+\%)\s+/'
  script:
    - dbus-run-session ninja -C _build test coverage
  except:
    variables:
      - $PKG_ONLY == "1"

format-check:
  <<: *tags
  <<: *image
  before_script:
    - export DEBIAN_FRONTEND=noninteractive
    - apt-get -y update
    - apt-get -y install uncrustify git python3
  stage: style-checks
  needs: []
  script:
    - |
      if [ -n "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" ]; then
        git remote add target $CI_MERGE_REQUEST_PROJECT_URL.git
        echo "Fetching MR target branch $CI_MERGE_REQUEST_TARGET_BRANCH_NAME from $CI_MERGE_REQUEST_PROJECT_URL"
        git fetch target "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
        git fetch --deepen=100 origin HEAD
        merge_base=$(git merge-base "target/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" HEAD)
        if [ -z "$merge_base" ]; then
          echo "Could't determine merge base"
          exit 1
        fi
        echo "Merge base: $merge_base"
        ./.gitlab-ci/check-style.py --dry-run --sha $merge_base
      else
        echo "Not a merge request"
      fi
  allow_failure: true
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME'

format-check:
  <<: *tags
  stage: style-checks
  extends: .phosh-format-check
  allow_failure: true

package:deb-debian-trixie:arm64:
  tags:
    - librem5:arm64
  stage: package
  variables:
    PHOSH_DOCKER_IMAGE: debian:trixie
  extends: .phosh-build-debian-package
07070100000005000081ED00000000000000000000000166F7A513000001DE000000000000000000000000000000000000002400000000feedbackd-0.5.0/.gitlab-ci/check-po#!/bin/bash

cd po/ || exit 1
# barf on untranslated C files. Seems intltool
# can't be told to exit with non-zero exit status
# in this case

if intltool-update -m 2>&1 | grep -E -qs '/.*\.(c|ui)'; then
  intltool-update -m
  exit 1
fi

# Check for broken po files
for file in *.po; do
  echo -n "Checking ${file}: "
  msgfmt -v -c "${file}"
  # Check for errors, msgfmt returns 0 on errors too
  if msgfmt -c "${file}" 2>&1 | grep -qs 'fatal error'; then
    exit 1
  fi
done
07070100000006000081ED00000000000000000000000166F7A5130000153B000000000000000000000000000000000000002A00000000feedbackd-0.5.0/.gitlab-ci/check-style.py#!/bin/env python3
#
# Based on check-style.py by
# Carlos Garnacho <carlosg@gnome.org>

import argparse
import os
import re
import subprocess
import sys
import tempfile

# Path relative to this script
uncrustify_cfg = ".gitlab-ci/uncrustify.cfg"


def run_diff(sha):
    proc = subprocess.run(
        ["git", "diff", "-U0", "--function-context", sha, "HEAD"],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        encoding="utf-8",
    )
    return proc.stdout.strip().splitlines()


def find_chunks(diff):
    file_entry_re = re.compile(r"^\+\+\+ b/(.*)$")
    diff_chunk_re = re.compile(r"^@@ -\d+,\d+ \+(\d+),(\d+)")
    file = None
    chunks = []

    for line in diff:
        match = file_entry_re.match(line)
        if match:
            file = match.group(1)

        match = diff_chunk_re.match(line)
        if match:
            start = int(match.group(1))
            len = int(match.group(2))
            end = start + len

            if len > 0 and (
                file.endswith(".c") or file.endswith(".h") or file.endswith(".vala")
            ):
                chunks.append({"file": file, "start": start, "end": end})

    return chunks


def reformat_chunks(chunks, rewrite, dry_run):
    # Creates temp file with INDENT-ON/OFF comments
    def create_temp_file(file, start, end):
        with open(file) as f:
            tmp = tempfile.NamedTemporaryFile()
            if start > 1:
                tmp.write(b"/** *INDENT-OFF* **/\n")
            for i, line in enumerate(f, start=1):
                if i == start - 1:
                    tmp.write(b"/** *INDENT-ON* **/\n")

                tmp.write(bytes(line, "utf-8"))
                if i == end - 1:
                    tmp.write(b"/** *INDENT-OFF* **/\n")
            tmp.seek(0)
        return tmp

    # Removes uncrustify INDENT-ON/OFF helper comments
    def remove_indent_comments(output):
        tmp = tempfile.NamedTemporaryFile()
        for line in output:
            if line != b"/** *INDENT-OFF* **/\n" and line != b"/** *INDENT-ON* **/\n":
                tmp.write(line)

        tmp.seek(0)
        return tmp

    changed = None
    for chunk in chunks:
        # Add INDENT-ON/OFF comments
        tmp = create_temp_file(chunk["file"], chunk["start"], chunk["end"])

        # uncrustify chunk
        proc = subprocess.run(
            ["uncrustify", "-c", uncrustify_cfg, "-f", tmp.name],
            stdout=subprocess.PIPE,
        )
        reindented = proc.stdout.splitlines(keepends=True)
        if proc.returncode != 0:
            continue

        tmp.close()

        # Remove INDENT-ON/OFF comments
        formatted = remove_indent_comments(reindented)

        if dry_run is True:
            # Show changes
            proc = subprocess.run(
                ["diff", "-up", "--color=always", chunk["file"], formatted.name],
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                encoding="utf-8",
            )
            diff = proc.stdout
            if diff != "":
                output = re.sub("\t", "↦\t", diff)
                print(output)
                changed = True
        else:
            # Apply changes
            diff = subprocess.run(
                ["diff", "-up", chunk["file"], formatted.name],
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
            )
            subprocess.run(["patch", chunk["file"]], input=diff.stdout)

        formatted.close()

    return changed


def main(argv):
    parser = argparse.ArgumentParser(
        description="Check code style. Needs uncrustify installed."
    )
    parser.add_argument(
        "--sha", metavar="SHA", type=str, help="SHA for the commit to compare HEAD with"
    )
    parser.add_argument(
        "--dry-run",
        "-d",
        type=bool,
        action=argparse.BooleanOptionalAction,
        help="Only print changes to stdout, do not change code",
    )
    parser.add_argument(
        "--rewrite",
        "-r",
        type=bool,
        action=argparse.BooleanOptionalAction,
        help="Whether to amend the result to the last commit (e.g. 'git rebase --exec \"%(prog)s -r\"')",
    )

    if not os.path.exists(".git"):
        print("Not in toplevel of a git repository", fille=sys.stderr)
        return 1

    args = parser.parse_args(argv)
    sha = args.sha or "HEAD^"

    diff = run_diff(sha)
    chunks = find_chunks(diff)
    changed = reformat_chunks(chunks, args.rewrite, args.dry_run)

    if args.dry_run is not True and args.rewrite is True:
        proc = subprocess.run(["git", "add", "-p"])
        if proc.returncode == 0:
            # Commit the added changes as a squash commit
            subprocess.run(
                ["git", "commit", "--squash", "HEAD", "-C", "HEAD"],
                stdout=subprocess.DEVNULL,
            )
            # Delete the unapplied changes
            subprocess.run(["git", "reset", "--hard"], stdout=subprocess.DEVNULL)
            return 0
    elif args.dry_run is True and changed is True:
        print(
            f"""
Issue the following commands in your local tree to apply the suggested changes:

    $ git rebase {sha} --exec "./.gitlab-ci/check-style.py -r"
    $ git rebase --autosquash {sha}

Don't trust uncrustify unconditionally.
"""
        )
        return 1
    return 0


if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))
07070100000007000081A400000000000000000000000166F7A513000003BA000000000000000000000000000000000000002C00000000feedbackd-0.5.0/.gitlab-ci/commit-rules.ymlpatterns:
  deny:
    - regex: '^$CI_MERGE_REQUEST_PROJECT_URL/(-/)?merge_requests/$CI_MERGE_REQUEST_IID$'
      message: Commit message must not contain a link to its own merge request
    - regex: '^[^:]+: [a-z]'
      message: "Commit description in commit message subject should be properly Capitalized. E.g. 'monitor: Avoid crash on unplug'"
      where: subject
    - regex: '^\S*\.(c|h|ui):'
      message: Commit message subject prefix should not include .c, .h etc.
      where: subject
    - regex: '([^.]\.|[:,;])\s*$'
      message: Commit message subject should not end with punctuation
      where: subject
    - regex: '^[A-Z]\S*:'
      message: "Identifier in commit message subject should start lowercase 'monitor: Avoid crash on unplug'"
      where: subject
  require:
    - regex: '^[a-z0-9,\.\+\-/#=_]+:'
      message: "Commit message should start with a lowercase identifier 'monitor: Avoid crash on unplug'"
      where: subject
07070100000008000081A400000000000000000000000166F7A5130000141D000000000000000000000000000000000000002A00000000feedbackd-0.5.0/.gitlab-ci/uncrustify.cfg#
# Uncrustify config for phosh and related projects
#

# A span is the number of lines considered
# A threshold is the maximum number of columns an item is moved

# Indent by two spaces
indent_columns                  = 2
# No tabs
indent_with_tabs                = 0
# Line length
code_width                      = 100
# Whether to remove superfluous semicolons
mod_remove_extra_semicolon      = true
# indent goto by 1 (or -1 brace level)
indent_label                    = -1
# don't indent case after switch
indent_switch_case              = 0

#
# Keywords and operators
#
# Add between 'do' and '{'.
sp_do_brace_open                = add
# Add space between '}' and 'while'.
sp_brace_close_while            = add
# Add 'while' and '('.
sp_while_paren_open             = add
# Add or remove space around boolean operators '&&' and '||'.
sp_bool                         = add
# Ternary operator
sp_cond_ternary_short           = remove
# Remove newline between 'struct and '{'.
nl_struct_brace                 = remove
# Remove newline between 'if' and '{'.
nl_if_brace                     = remove
# Remove newline between '}' and 'else'.
nl_brace_else                   = remove
# Remove newline between 'else' and '{'.
nl_else_brace                   = remove
# Remove newline between 'else' and 'if'.
nl_else_if                      = remove
# Add or remove newline between 'for' and '{'.
nl_for_brace                    = remove
# Add or remove newline between 'while' and '{'.
nl_while_brace                  = remove
# Treat iterators as for loops:
set FOR wl_list_for_each wl_list_for_each_reverse wl_list_for_each_safe
# Remove braces on single line if/for/while statements
mod_full_brace_if               = remove
mod_full_brace_for              = remove
mod_full_brace_while            = remove
# If any must be braced, they are all braced.  If all can be unbraced, then the braces are removed.
mod_full_brace_if_chain         = 1
# Remove braces around case (when there are no variables declarations)
mod_case_brace                  = remove
# Don't remove branches if the statement has more than one line
mod_full_brace_nl               = 2

#
# Function declarations, definitions and calls
#
# Add space between function name and '(' on function declaration.
sp_func_proto_paren             = add
# Add or remove space between function name and '()' on function declaration
# without parameters.
sp_func_proto_paren_empty       = add
# Add space between function name and '(' on function definition.
sp_func_def_paren               = add
# Add or remove space between function name and '(' on function calls.
sp_func_call_paren              = add
# Specialcase i18n macros
set func_call_user               _ N_ C_
sp_func_call_user_paren         = remove

# Whether to force indentation of function definitions to start in column 1.
indent_func_def_force_col1      = true
# Add newline between return type and function name in a function definition.
nl_func_type_name               = add
# Add newline between function signature and '{'.
nl_fdef_brace                   = add
# Whether to align variable definitions in prototypes and functions.
align_func_params               = true
# The span for aligning function prototypes.
align_func_proto_span           = 8
# Add space between 'decltype(...)' and word.
sp_after_decltype               = add
# Add or remove space after a pointer star '*', if followed by a function
# prototype or function definition.
sp_after_ptr_star_func          = remove
# Add or remove newline between a function call's ')' and '{', as in
# 'list_for_each(item, &list) { }'.
nl_fcall_brace                  = add

#
# Typedefs
#
# Add space between '}' and the name of a typedef on the same line.
sp_brace_typedef                = add

#
# Comments
#
# Add space after the opening of a C++ comment, i.e. '// A' vs. '//A'.
sp_cmt_cpp_start                = add

#
# Preprocessor
#
# Add or remove space between #else or #endif and a trailing comment.
sp_endif_cmt                    = add

# Newlines at the start and end of the file.
nl_start_of_file                = remove
nl_end_of_file                  = add
nl_end_of_file_min              = 1

#
# Variable definitions
#
# How to align the '*' in variable definitions.
#
# 0: Part of the type     'void *   foo;' (default)
# 1: Part of the variable 'void     *foo;'
# 2: Dangling             'void    *foo;'
# Dangling: the '*' will not be taken into account when aligning.
align_var_def_star_style        = 2
# Same for typedefs
align_typedef_star_style        = 2
# The gap for aligning struct/union member definitions.
align_var_struct_gap            = 1
# The span for aligning struct/union member definitions.
align_var_struct_span           = 4
# The threshold for aligning struct/union member definitions.
align_var_struct_thresh         = 8

# Remove space between pointer stars '*'.
sp_between_ptr_star             = remove
# Add space before '(' of control statements ('if', 'for', 'switch', 'while', etc.)
sp_before_sparen                = add

# Add spaces around assignments and arithmethic operators
sp_assign = add
sp_arith = add
07070100000009000081A400000000000000000000000166F7A51300000076000000000000000000000000000000000000001C00000000feedbackd-0.5.0/.gitmodules[submodule "subprojects/gmobile"]
	path = subprojects/gmobile
	url = https://gitlab.gnome.org/World/Phosh/gmobile.git
0707010000000A000081A400000000000000000000000166F7A5130000894B000000000000000000000000000000000000001800000000feedbackd-0.5.0/COPYING                    GNU GENERAL PUBLIC LICENSE
                       Version 3, 29 June 2007

 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

                            Preamble

  The GNU General Public License is a free, copyleft license for
software and other kinds of works.

  The licenses for most software and other practical works are designed
to take away your freedom to share and change the works.  By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.  We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors.  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.

  To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights.  Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received.  You must make sure that they, too, receive
or can get the source code.  And you must show them these terms so they
know their rights.

  Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.

  For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software.  For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.

  Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so.  This is fundamentally incompatible with the aim of
protecting users' freedom to change the software.  The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable.  Therefore, we
have designed this version of the GPL to prohibit the practice for those
products.  If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.

  Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary.  To prevent this, the GPL assures that
patents cannot be used to render the program non-free.

  The precise terms and conditions for copying, distribution and
modification follow.

                       TERMS AND CONDITIONS

  0. Definitions.

  "This License" refers to version 3 of the GNU General Public License.

  "Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.

  "The Program" refers to any copyrightable work licensed under this
License.  Each licensee is addressed as "you".  "Licensees" and
"recipients" may be individuals or organizations.

  To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy.  The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.

  A "covered work" means either the unmodified Program or a work based
on the Program.

  To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy.  Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.

  To "convey" a work means any kind of propagation that enables other
parties to make or receive copies.  Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.

  An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License.  If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.

  1. Source Code.

  The "source code" for a work means the preferred form of the work
for making modifications to it.  "Object code" means any non-source
form of a work.

  A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.

  The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form.  A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.

  The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities.  However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work.  For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.

  The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.

  The Corresponding Source for a work in source code form is that
same work.

  2. Basic Permissions.

  All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met.  This License explicitly affirms your unlimited
permission to run the unmodified Program.  The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work.  This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.

  You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force.  You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright.  Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.

  Conveying under any other circumstances is permitted solely under
the conditions stated below.  Sublicensing is not allowed; section 10
makes it unnecessary.

  3. Protecting Users' Legal Rights From Anti-Circumvention Law.

  No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.

  When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.

  4. Conveying Verbatim Copies.

  You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.

  You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.

  5. Conveying Modified Source Versions.

  You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:

    a) The work must carry prominent notices stating that you modified
    it, and giving a relevant date.

    b) The work must carry prominent notices stating that it is
    released under this License and any conditions added under section
    7.  This requirement modifies the requirement in section 4 to
    "keep intact all notices".

    c) You must license the entire work, as a whole, under this
    License to anyone who comes into possession of a copy.  This
    License will therefore apply, along with any applicable section 7
    additional terms, to the whole of the work, and all its parts,
    regardless of how they are packaged.  This License gives no
    permission to license the work in any other way, but it does not
    invalidate such permission if you have separately received it.

    d) If the work has interactive user interfaces, each must display
    Appropriate Legal Notices; however, if the Program has interactive
    interfaces that do not display Appropriate Legal Notices, your
    work need not make them do so.

  A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit.  Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.

  6. Conveying Non-Source Forms.

  You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:

    a) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by the
    Corresponding Source fixed on a durable physical medium
    customarily used for software interchange.

    b) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by a
    written offer, valid for at least three years and valid for as
    long as you offer spare parts or customer support for that product
    model, to give anyone who possesses the object code either (1) a
    copy of the Corresponding Source for all the software in the
    product that is covered by this License, on a durable physical
    medium customarily used for software interchange, for a price no
    more than your reasonable cost of physically performing this
    conveying of source, or (2) access to copy the
    Corresponding Source from a network server at no charge.

    c) Convey individual copies of the object code with a copy of the
    written offer to provide the Corresponding Source.  This
    alternative is allowed only occasionally and noncommercially, and
    only if you received the object code with such an offer, in accord
    with subsection 6b.

    d) Convey the object code by offering access from a designated
    place (gratis or for a charge), and offer equivalent access to the
    Corresponding Source in the same way through the same place at no
    further charge.  You need not require recipients to copy the
    Corresponding Source along with the object code.  If the place to
    copy the object code is a network server, the Corresponding Source
    may be on a different server (operated by you or a third party)
    that supports equivalent copying facilities, provided you maintain
    clear directions next to the object code saying where to find the
    Corresponding Source.  Regardless of what server hosts the
    Corresponding Source, you remain obligated to ensure that it is
    available for as long as needed to satisfy these requirements.

    e) Convey the object code using peer-to-peer transmission, provided
    you inform other peers where the object code and Corresponding
    Source of the work are being offered to the general public at no
    charge under subsection 6d.

  A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.

  A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling.  In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage.  For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product.  A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.

  "Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source.  The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.

  If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information.  But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).

  The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed.  Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.

  Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.

  7. Additional Terms.

  "Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law.  If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.

  When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it.  (Additional permissions may be written to require their own
removal in certain cases when you modify the work.)  You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.

  Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:

    a) Disclaiming warranty or limiting liability differently from the
    terms of sections 15 and 16 of this License; or

    b) Requiring preservation of specified reasonable legal notices or
    author attributions in that material or in the Appropriate Legal
    Notices displayed by works containing it; or

    c) Prohibiting misrepresentation of the origin of that material, or
    requiring that modified versions of such material be marked in
    reasonable ways as different from the original version; or

    d) Limiting the use for publicity purposes of names of licensors or
    authors of the material; or

    e) Declining to grant rights under trademark law for use of some
    trade names, trademarks, or service marks; or

    f) Requiring indemnification of licensors and authors of that
    material by anyone who conveys the material (or modified versions of
    it) with contractual assumptions of liability to the recipient, for
    any liability that these contractual assumptions directly impose on
    those licensors and authors.

  All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10.  If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term.  If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.

  If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.

  Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.

  8. Termination.

  You may not propagate or modify a covered work except as expressly
provided under this License.  Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).

  However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.

  Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.

  Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License.  If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.

  9. Acceptance Not Required for Having Copies.

  You are not required to accept this License in order to receive or
run a copy of the Program.  Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance.  However,
nothing other than this License grants you permission to propagate or
modify any covered work.  These actions infringe copyright if you do
not accept this License.  Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.

  10. Automatic Licensing of Downstream Recipients.

  Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License.  You are not responsible
for enforcing compliance by third parties with this License.

  An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations.  If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.

  You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License.  For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.

  11. Patents.

  A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based.  The
work thus licensed is called the contributor's "contributor version".

  A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version.  For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.

  Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.

  In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement).  To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.

  If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients.  "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.

  If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.

  A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License.  You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.

  Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.

  12. No Surrender of Others' Freedom.

  If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all.  For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.

  13. Use with the GNU Affero General Public License.

  Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work.  The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.

  14. Revised Versions of this License.

  The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

  Each version is given a distinguishing version number.  If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation.  If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.

  If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.

  Later license versions may give you additional or different
permissions.  However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.

  15. Disclaimer of Warranty.

  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

  16. Limitation of Liability.

  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.

  17. Interpretation of Sections 15 and 16.

  If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.

                     END OF TERMS AND CONDITIONS

            How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

  If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

    <program>  Copyright (C) <year>  <name of author>
    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".

  You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.

  The GNU General Public License does not permit incorporating your program
into proprietary programs.  If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library.  If this is what you want to do, use the GNU Lesser General
Public License instead of this License.  But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
0707010000000B000081A400000000000000000000000166F7A513000067A2000000000000000000000000000000000000001C00000000feedbackd-0.5.0/COPYING.LIB                  GNU LESSER GENERAL PUBLIC LICENSE
                       Version 2.1, February 1999

 Copyright (C) 1991, 1999 Free Software Foundation, Inc.
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

[This is the first released version of the Lesser GPL.  It also counts
 as the successor of the GNU Library Public License, version 2, hence
 the version number 2.1.]

                            Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.

  This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it.  You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.

  When we speak of free software, we are referring to freedom of use,
not price.  Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.

  To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights.  These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.

  For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you.  You must make sure that they, too, receive or can get the source
code.  If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it.  And you must show them these terms so they know their rights.

  We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.

  To protect each distributor, we want to make it very clear that
there is no warranty for the free library.  Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.

  Finally, software patents pose a constant threat to the existence of
any free program.  We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder.  Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.

  Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License.  This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License.  We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.

  When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library.  The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom.  The Lesser General
Public License permits more lax criteria for linking other code with
the library.

  We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License.  It also provides other free software developers Less
of an advantage over competing non-free programs.  These disadvantages
are the reason we use the ordinary General Public License for many
libraries.  However, the Lesser license provides advantages in certain
special circumstances.

  For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard.  To achieve this, non-free programs must be
allowed to use the library.  A more frequent case is that a free
library does the same job as widely used non-free libraries.  In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.

  In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software.  For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.

  Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.

  The precise terms and conditions for copying, distribution and
modification follow.  Pay close attention to the difference between a
"work based on the library" and a "work that uses the library".  The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.

                  GNU LESSER GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".

  A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.

  The "Library", below, refers to any such software library or work
which has been distributed under these terms.  A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language.  (Hereinafter, translation is
included without limitation in the term "modification".)

  "Source code" for a work means the preferred form of the work for
making modifications to it.  For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.

  Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it).  Whether that is true depends on what the Library does
and what the program that uses the Library does.

  1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.

  You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.

  2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) The modified work must itself be a software library.

    b) You must cause the files modified to carry prominent notices
    stating that you changed the files and the date of any change.

    c) You must cause the whole of the work to be licensed at no
    charge to all third parties under the terms of this License.

    d) If a facility in the modified Library refers to a function or a
    table of data to be supplied by an application program that uses
    the facility, other than as an argument passed when the facility
    is invoked, then you must make a good faith effort to ensure that,
    in the event an application does not supply such function or
    table, the facility still operates, and performs whatever part of
    its purpose remains meaningful.

    (For example, a function in a library to compute square roots has
    a purpose that is entirely well-defined independent of the
    application.  Therefore, Subsection 2d requires that any
    application-supplied function or table used by this function must
    be optional: if the application does not supply it, the square
    root function must still compute square roots.)

These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.

In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

  3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library.  To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License.  (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.)  Do not make any other change in
these notices.

  Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.

  This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.

  4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.

  If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.

  5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library".  Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.

  However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library".  The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.

  When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library.  The
threshold for this to be true is not precisely defined by law.

  If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work.  (Executables containing this object code plus portions of the
Library will still fall under Section 6.)

  Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.

  6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.

  You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License.  You must supply a copy of this License.  If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License.  Also, you must do one
of these things:

    a) Accompany the work with the complete corresponding
    machine-readable source code for the Library including whatever
    changes were used in the work (which must be distributed under
    Sections 1 and 2 above); and, if the work is an executable linked
    with the Library, with the complete machine-readable "work that
    uses the Library", as object code and/or source code, so that the
    user can modify the Library and then relink to produce a modified
    executable containing the modified Library.  (It is understood
    that the user who changes the contents of definitions files in the
    Library will not necessarily be able to recompile the application
    to use the modified definitions.)

    b) Use a suitable shared library mechanism for linking with the
    Library.  A suitable mechanism is one that (1) uses at run time a
    copy of the library already present on the user's computer system,
    rather than copying library functions into the executable, and (2)
    will operate properly with a modified version of the library, if
    the user installs one, as long as the modified version is
    interface-compatible with the version that the work was made with.

    c) Accompany the work with a written offer, valid for at
    least three years, to give the same user the materials
    specified in Subsection 6a, above, for a charge no more
    than the cost of performing this distribution.

    d) If distribution of the work is made by offering access to copy
    from a designated place, offer equivalent access to copy the above
    specified materials from the same place.

    e) Verify that the user has already received a copy of these
    materials or that you have already sent this user a copy.

  For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it.  However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.

  It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system.  Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.

  7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:

    a) Accompany the combined library with a copy of the same work
    based on the Library, uncombined with any other library
    facilities.  This must be distributed under the terms of the
    Sections above.

    b) Give prominent notice with the combined library of the fact
    that part of it is a work based on the Library, and explaining
    where to find the accompanying uncombined form of the same work.

  8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License.  Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License.  However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.

  9. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Library or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.

  10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.

  11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all.  For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.

If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

  12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded.  In such case, this License incorporates the limitation as if
written in the body of this License.

  13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.

Each version is given a distinguishing version number.  If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation.  If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.

  14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission.  For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this.  Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.

                            NO WARRANTY

  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.

                     END OF TERMS AND CONDITIONS

           How to Apply These Terms to Your New Libraries

  If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change.  You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).

  To apply these terms, attach the following notices to the library.  It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.

    <one line to give the library's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Also add information on how to contact you by electronic and paper mail.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary.  Here is a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  library `Frob' (a library for tweaking knobs) written by James Random Hacker.

  <signature of Ty Coon>, 1 April 1990
  Ty Coon, President of Vice

That's all there is to it!
0707010000000C000081A400000000000000000000000166F7A51300000B10000000000000000000000000000000000000001500000000feedbackd-0.5.0/NEWSfeedbackd 0.5.0
---------------
Released September 2024
* Detect haptic on Google Sargo and Oneplus Enchilada/Fachita
* Handle "alert slider" on Oneplus Enchilada/Fachita
* Contributors:
    * Evangelos Ribeiro Tzaras
    * isyourbrain foss
    * Guido Günther
    * Robert Mader

feedbackd 0.4.1
---------------
Released August 2024
* Simplify udev rule installation
* Dont' fail tests with newer json-glib
* Issues fixed:
    * https://source.puri.sm/Librem5/feedbackd/-/issues/79
* Contributors:
    * Guido Günther

feedbackd 0.4.0
---------------
Released June 2024
* Support `hw_pattern` on devices using qcom-lpg. This allows
  to keep LEDs on in suspend.
* Internal cleanups and restructuring to cater for different
  LED types.
* Support RGB color mixing for multicolor leds
* Allow to use (camera) flash LEDs as notificaton LED
* Immediately end "too noisy" feedbacks when switching profile levels
* Issues fixed:
    * https://source.puri.sm/Librem5/feedbackd/-/issues/77
    * https://source.puri.sm/Librem5/feedbackd/-/issues/76
    * https://source.puri.sm/Librem5/feedbackd/-/issues/13
    * https://source.puri.sm/Librem5/feedbackd/-/issues/55
* Contributors:
    * Dylan Van Assche
    * Guido Günther

feedbackd 0.3.0
---------------
Released April 2024
* Allow blessed apps (e.g. alarm clocks) to override the global
  feedback level
* Documentation, CI and packaging updates
* Make it simpler to add new led types
* Contributors:
    * Guido Günther

feedbackd 0.2.1
---------------
Released August 2023
* Minor documentation updates
* Contributors:
    * Guido Günther

feedbackd 0.2.0
---------------
Released April 2023
* lfbevent: Add api to set app-id
* lfbevent: Change signature of get_feedback_profile().
  (API change but no known users)
* Contributors:
    * Guido Günther

feedbackd 0.1.1
---------------
Released March 2023
* Fix test failure exposed by glib 2.76
* Leak fixes
* Contributors:
    * Guido Günther

feedbackd 0.1.0
---------------
Released February 2023
* Make LED class more flexible. This will
  allow e.g. hw based implementations
* Trigger module load via udev. This avoids
  shipping another conf file
* Contributors:
    * Dylan Van Assche
    * Guido Günther

feedbackd 0.0.3
---------------
Released February 2023
* spec: Separate system and application events
* theme: add screen-shot event
* Build and doc fixes
* Update gmobile to 0.0.1
* Contributors:
    * Guido Günther

feedbackd 0.0.2
---------------
Released December 2022
* Support theme merging
* Support user themes (`theme` gsetting)
* Add theme validator
* Doc updates
* Switch documentation to gi-docgen
* Switch manpages to reStructuredText
* Contributors:
	Chris Vogel
	Guido Günther

feedbackd 0.0.1
---------------
Released November 2022
* Initial release (all version before were
  git snapshots)
0707010000000D000081A400000000000000000000000166F7A51300002313000000000000000000000000000000000000001A00000000feedbackd-0.5.0/README.mdHaptic/visual/audio feedback for GNOME
======================================
[![Code coverage](https://source.puri.sm/Librem5/feedbackd/badges/master/coverage.svg)](https://source.puri.sm/guido.gunther/feedbackd/commits/master)

feedbackd provides a DBus daemon (feedbackd) to act on events to provide
haptic, visual and audio feedback. It offers a library (libfeedback) and
GObject introspection bindings to ease using it from applications.

## License

feedbackd is licensed under the GPLv3+ while the libfeedback library is
licensed under LGPL 2.1+.

## Getting the source

```sh
git clone https://source.puri.sm/Librem5/feedbackd
cd feedbackd
```

The master branch has the current development version.

## Dependencies
On a Debian based system run

```sh
sudo apt-get -y install build-essential
sudo apt-get -y build-dep .
```

For an explicit list of dependencies check the `Build-Depends` entry in the
[debian/control][] file.

## Building

We use the meson (and thereby Ninja) build system for feedbackd.  The quickest
way to get going is to do the following:

    meson . _build
    ninja -C _build
    ninja -C _build test
    ninja -C _build install

## Running
### Running from the source tree
To run the daemon use

```sh
_build/run _build/src/feedbackd
```

To run under gdb use

``` sh
FBD_GDB=1 _build/run _build/src/feedbackd
```

You can introspect and get the current theme with

```sh
gdbus introspect --session --dest org.sigxcpu.Feedback --object-path /org/sigxcpu/Feedback
```

To run feedback for an event, use [fbcli](#fbcli)

See `examples/` for a simple python example using GObject introspection.

# How it works

We're using a [event naming spec](./doc/Event-naming-spec-0.0.0.md)
similar to http://0pointer.de/public/sound-naming-spec.html to name
events. This will allow us to act as a system sound library so
applications only need to call into this library and things like
the quiet and silent profile work out of the box.

Any feedback triggered by a client via an event will be stopped latest when the
client disconnects from DBus. This makes sure all feedbacks get canceled if the
app that triggered it crashes.

## Feedback theme
Events are then mapped to a specific type of feedback (sound, led, vibra) via a
device specific theme - since devices have different capabilities and
different users different needs.

Feedbackd is shipped with a default theme `default.json`.
You can add your own themes in multiple ways:

1. By exporting an environment variable `FEEDBACK_THEME` with a path to a
   valid theme file (not recommended, use for testing only), or
2. By creating a theme file under `$XDG_CONFIG_HOME/feedbackd/themes/default.json`.
   If `XDG_CONFIG_HOME` environment variable is not set or empty, it will
   default to `$HOME/.config`, or
3. By creating a theme file under `$XDG_CONFIG_HOME/feedbackd/themes/custom.json`.
   You only specify the values you want to change in that theme and add an entry
   ```json
   {
      "name: "custom"
      "parent-theme": "default"
	  "profiles" : [
	   ...(entries you want to change go here)...
	   ]
   }
   ```
   next to the `name` entry in. This has the upside that your theme
   gets way smaller and that new entries added to the default theme
   will automatically be used by your theme too. See
   [here](./tests/data/user-config/feedbackd/themes/custom.json) for
   an example. Once you have the file in place, tell feedbackd the
   them you want to use:

        gsettings set org.sigxcpu.feedbackd theme custom

   When you want to go back to the default theme just do:

        gsettings reset org.sigxcpu.feedbackd theme

   Note that you can name your theme as you wish but avoid theme names
   starting with `__` or `$` as this namespace is reserved. This is the
   preferred way to specify a custom theme.

4. By adding your theme file to one of the folders in the `XDG_DATA_DIRS`
   environment variable, appended with `feedbackd/themes/`. This folder isn't
   created automatically, so you have to create it yourself. Here's an example:
   ```bash
   # Check which folders are "valid"
   $ echo $XDG_DATA_DIRS
   [ ... ]:/usr/local/share:/usr/share
   
   # Pick a folder that suits you. Note that you shouldn't place themes in
   # /usr/share, because they would be overwritten by updates!
   # Create missing directories
   $ sudo mkdir -p /usr/local/share/feedbackd/themes
   
   # Add your theme file!
   $ sudo cp my_awesome_theme.json /usr/local/share/feedbackd/themes/
   ```

Upon reception of `SIGHUP` signal, the daemon process will proceed to retrigger
the above logic to find the themes, and reload the corresponding one. This can
be used to avoid having to restart the daemon in case of configuration changes.

Check out the companion [feedbackd-device-themes][1] repository for a
selection of device-specific themes. In order for your theme to be recognized
it must be named properly. Currently, theme names are based on the `compatible`
device-tree attribute. You can run the following command to get a list of valid
filenames for your custom theme (**Note**: You must run this command on the
device you want to create the theme for!):

```bash
$ cat /sys/firmware/devicetree/base/compatible | tr '\0' "\n"
```

Example output (for a Pine64 PinePhone):

```bash
$ cat /sys/firmware/devicetree/base/compatible | tr '\0' "\n"
pine64,pinephone-1.2
pine64,pinephone
allwinner,sun50i-a64
```

Thus you could create a custom feedbackd theme for the Pinephone by placing a
modified theme file in
`/usr/local/share/feedbackd/themes/pine64,pinephone.json`

If multiple theme files exist, the selection logic follows these steps:

1. It picks an identifier from the devicetree, until none are left
2. It searches through the folders in `XDG_DATA_DIRS` in order of appearence,
   until none are left
3. If a theme file is found in the current location with the current name,
   **it will be chosen** and other themes are ignored.

If no theme file can be found this way (i.e. there are no identifiers and
folders left to check), `default.json` is chosen instead. Given the above
examples:

- `/usr/local/share/feedbackd/themes/pine64,pinephone-1.2.json` takes
  precedence over `/usr/local/share/feedbackd/themes/pine64-pinephone.json`
- `/usr/local/share/feedbackd/themes/pine64-pinephone.json` takes precedence
  over `/usr/share/feedbackd/themes/pine64-pinephone-1.2.json`
- etc...

For available feeddback types see the [feedback-themes][](5) manpage.

You can check the feedback theme and the classes (prefixed with Fbd)
for available properties. Note that the feedback theme API (including
the theme file format) is not stable but considered internal to the
daemon.

## Profiles
The profile determines which parts of the theme are in use:

- `full`: Use configured events from the `full`, `quiet` and `silent` parts of
  the feedback them.
- `quiet`: Use `quiet` and `silent` part from of the feedback theme. This usually
  means no audio feedback.
- `silent`: Only use the `silent` part from the feedback theme. This usually means
  to not use audio or vibra.

It can be set via a GSetting

```sh
  gsettings set org.sigxcpu.feedbackd profile full
```
## fbcli

`fbcli` can be used to trigger feedback for different events. Here are some examples:

### Phone call
Run feedbacks for event `phone-incoming-call` until explicitly stopped:

```
_build/cli/fbcli -t 0 -E phone-incoming-call
```

### New instant message
Run feedbacks for event `message-new-instant` just once:

```
_build/cli/fbcli -t -1 -E message-new-instant
```

### Alarm clock
Run feedbacks for event `message-new-instant` for 10 seconds:

```
_build/cli/fbcli -t 10 -E alarm-clock-elapsed
```

## Examples

Here's some examples that show how to use libfeedback in your application:

### C

The command line tool [`fbcli`](./cli/fbcli.c) can be used as example
on how to use libfeedback from C.

### Python

There's an [`example.py`](./examples/example.py) script demonstrating
how to use the introspection bindings and how to trigger feedback via
an event.

### Rust

The [libfeedback-rs](https://gitlab.gnome.org/guidog/libfeedback-rs) Rust
bindings ship an [example](https://gitlab.gnome.org/guidog/libfeedback-rs/-/blob/main/libfeedback/examples/hello-world.rs?ref_type=heads)
to demo the usage.

## Per app profiles
One can set the feedback profile of an individual application
via `GSettings`. E.g. for an app with app id `sm.puri.Phosh`
to set the profile to `quiet` do:

```
GSETTINGS_SCHEMA_DIR=_build/data/ gsettings set org.sigxcpu.feedbackd.application:/org/sigxcpu/feedbackd/application/sm-puri-phosh/ profile quiet
```

# Documentation

- [Libfeedback API](https://honk.sigxcpu.org/projects/feedbackd/doc/)
- [Event naming spec draft](./doc/Event-naming-spec-0.0.0.md)
- [Feedback-theme-spec draft](./doc/Feedback-theme-spec-0.0.0.md)

[debian/control]: ./debian/control#L5
[1]: https://source.puri.sm/Librem5/feedbackd-device-themes
[feedback-themes]: ./doc/feedback-themes.rst
0707010000000E000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001A00000000feedbackd-0.5.0/build-aux0707010000000F000081A400000000000000000000000166F7A5130000012F000000000000000000000000000000000000002A00000000feedbackd-0.5.0/build-aux/post_install.py#!/usr/bin/python3

import os
import subprocess
import sys

destdir = os.environ.get('DESTDIR', '')

if not destdir and len(sys.argv) > 1:
    datadir = sys.argv[1]

    print('Compiling gsettings schemas...')
    subprocess.call(['glib-compile-schemas', os.path.join(datadir, 'glib-2.0', 'schemas')])

07070100000010000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001400000000feedbackd-0.5.0/cli07070100000011000081A400000000000000000000000166F7A51300001487000000000000000000000000000000000000001C00000000feedbackd-0.5.0/cli/fbcli.c/*
 * Copyright (C) 2020 Purism SPC
 *               2023-2024 The Phosh Developers
 *
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */
#define LIBFEEDBACK_USE_UNSTABLE_API
#include "libfeedback.h"

#include <glib.h>
#include <gio/gio.h>
#include <glib-unix.h>

#include <locale.h>

#define DEFAULT_EVENT "phone-incoming-call"

static GMainLoop *loop;

static gboolean
on_shutdown_signal (gpointer unused)
{
  /* End right away, lfb_uninit will end running feedback */
  g_main_loop_quit (loop);

  return FALSE;
}

static gboolean
on_watch_expired (gpointer unused)
{
  g_warning ("Watch expired waiting for all feedbacks to finish");
  g_main_loop_quit (loop);

  return G_SOURCE_REMOVE;
}

static void
on_feedback_ended (LfbEvent *event, int *data)
{
  g_return_if_fail (LFB_IS_EVENT (event));

  g_debug  ("Feedback ended for event");
  *data = TRUE;
  g_main_loop_quit (loop);
}

static gboolean
on_user_input (GIOChannel *channel, GIOCondition cond, LfbEvent *event)
{
  g_autoptr (GError) err = NULL;

  if (cond == G_IO_IN) {
    g_print ("Ending feedback\n");
    if (!lfb_event_end_feedback (event, &err))
      g_warning ("Failed to end feedback: %s", err->message);
  }
  return FALSE;
}

static gboolean
trigger_event (const char *name, const gchar *profile, gboolean important, gint timeout)
{
  g_autoptr (GError) err = NULL;
  g_autoptr (LfbEvent) event = NULL;
  g_autoptr (GIOChannel) input = NULL;
  int success = FALSE;

  g_unix_signal_add (SIGTERM, on_shutdown_signal, NULL);
  g_unix_signal_add (SIGINT, on_shutdown_signal, NULL);

  g_print ("Triggering feedback for event '%s'\n", name);
  event = lfb_event_new (name);
  lfb_event_set_timeout (event, timeout);
  if (profile)
    lfb_event_set_feedback_profile (event, profile);

  if (important)
    lfb_event_set_important (event, TRUE);

  g_signal_connect (event, "feedback-ended", (GCallback)on_feedback_ended, &success);
  if (!lfb_event_trigger_feedback (event, &err)) {
    g_print ("Failed to report event: %s\n", err->message);
    return FALSE;
  }

  input = g_io_channel_unix_new (STDIN_FILENO);
  g_io_add_watch (input, G_IO_IN, (GIOFunc)on_user_input, event);
  g_print ("Press <RETURN> to end feedback right away.\n");

  loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (loop);
  g_main_loop_unref (loop);

  if (lfb_event_get_end_reason (event) == LFB_EVENT_END_REASON_NOT_FOUND)
    g_print ("No feedback found for '%s' at level '%s'\n", name, lfb_get_feedback_profile ());

  return success;
}

static void
on_profile_changed (LfbGdbusFeedback *proxy, GParamSpec *psepc, gpointer unused)
{
  g_print ("Set feedback profile to: '%s'\n",
           lfb_get_feedback_profile ());
  g_main_loop_quit (loop);
}

static gboolean
set_profile (const gchar *profile)
{
  LfbGdbusFeedback *proxy;
  const gchar *current;

  current = lfb_get_feedback_profile ();
  g_debug ("Current profile is %s", current);
  if (!g_strcmp0 (current, profile)) {
    g_print ("Profile is already set to %s\n", profile);
    return TRUE;
  }

  g_debug ("Setting profile to %s", profile);
  proxy = lfb_get_proxy ();

  /* Set profile and wait until we got notified about the profile change */
  loop = g_main_loop_new (NULL, FALSE);
  lfb_set_feedback_profile (profile);
  g_signal_connect (proxy, "notify::profile", (GCallback)on_profile_changed, NULL);
  g_main_loop_run (loop);
  g_print ("Current feedback profile is: '%s'\n",
           lfb_get_feedback_profile ());
  return TRUE;
}

int
main (int argc, char *argv[0])
{
  g_autoptr (GOptionContext) opt_context = NULL;
  g_autoptr (GError) err = NULL;
  g_autofree char *profile = NULL;
  g_autofree char *app_id = NULL;
  const char *name = NULL;
  gboolean success, important = FALSE;
  int watch = 30;
  int timeout = -1;
  const GOptionEntry options [] = {
    {"event", 'E', 0, G_OPTION_ARG_STRING, &name,
     "Event name. (default: " DEFAULT_EVENT ").", NULL},
    {"important", 'I', 0, G_OPTION_ARG_NONE, &important,
     "Whether to set the important hint", NULL},
    {"timeout", 't', 0, G_OPTION_ARG_INT, &timeout,
     "Run feedback for timeout seconds", NULL},
    {"profile", 'P', 0, G_OPTION_ARG_STRING, &profile,
     "Profile name to set", NULL},
    {"watch", 'w', 0, G_OPTION_ARG_INT, &watch,
     "How long to watch for feedback longest", NULL},
    {"app-id", 'A', 0, G_OPTION_ARG_STRING, &app_id,
     "Override used application id"},
    { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
  };

  setlocale (LC_ALL, "");
  opt_context = g_option_context_new ("- A cli for feedbackd");
  g_option_context_add_main_entries (opt_context, options, NULL);
  if (!g_option_context_parse (opt_context, &argc, &argv, &err)) {
    g_warning ("%s", err->message);
    return 1;
  }

  if (!app_id)
    app_id = g_strdup ("org.sigxcpu.fbcli");

  if (!lfb_init (app_id, &err)) {
    g_print ("Failed to init libfeedback: %s\n", err->message);
    return 1;
  }

  if (profile && !name) {
    success = set_profile (profile);
  } else {
    if (!name)
      name = g_strdup (DEFAULT_EVENT);

    g_timeout_add_seconds (watch, (GSourceFunc)on_watch_expired, NULL);
    success = trigger_event (name, profile, important, timeout);
  }

  lfb_uninit ();
  return !success;
}
07070100000012000081A400000000000000000000000166F7A513000000B1000000000000000000000000000000000000002000000000feedbackd-0.5.0/cli/meson.buildfbcli_sources = [
  'fbcli.c',
]

fbcli_deps = [
  libfeedback_dep,
  gio,
  gio_unix,
]

executable(
  'fbcli',
  fbcli_sources,
  dependencies: fbcli_deps,
  install: true,
)
07070100000013000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001500000000feedbackd-0.5.0/data07070100000014000081A400000000000000000000000166F7A513000006A6000000000000000000000000000000000000002800000000feedbackd-0.5.0/data/90-feedbackd.rules#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of feedbackd.

ACTION=="remove", GOTO="feedbackd_end"

#
# Haptic
#
# Librem 5, PinePhone
SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT}=="1", ENV{ID_PATH}=="platform-vibrator", TAG+="uaccess", ENV{FEEDBACKD_TYPE}="vibra"
# Google Sargo (not mainline)
SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT}=="1", SUBSYSTEMS=="input", ATTRS{name}=="drv2624:haptics", TAG+="uaccess", ENV{FEEDBACKD_TYPE}="vibra"
# Oneplus Enchilada, Fajita (not mainline)
SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT}=="1", SUBSYSTEMS=="input", ATTRS{name}=="spmi_haptics", TAG+="uaccess", ENV{FEEDBACKD_TYPE}="vibra"


#
# See include/dt-bindings/leds/common.h in the linux kernel
#
# Status LEDs
SUBSYSTEM=="leds", DEVPATH=="*/*:status", ENV{FEEDBACKD_TYPE}="led", RUN{builtin}+="kmod load ledtrig-pattern", RUN+="/usr/libexec/fbd-ledctrl -p %S%p -t pattern -G feedbackd"
SUBSYSTEM=="leds", DEVPATH=="*/*:indicator", ENV{FEEDBACKD_TYPE}="led", RUN{builtin}+="kmod load ledtrig-pattern", RUN+="/usr/libexec/fbd-ledctrl -p %S%p -t pattern -G feedbackd"
# Camera Flash
SUBSYSTEM=="leds", DEVPATH=="*/*:flash", ENV{FEEDBACKD_TYPE}="led", RUN{builtin}+="kmod load ledtrig-pattern", RUN+="/usr/libexec/fbd-ledctrl -p %S%p -t pattern -G feedbackd"
SUBSYSTEM=="leds", DEVPATH=="*/*:torch", ENV{FEEDBACKD_TYPE}="led", RUN{builtin}+="kmod load ledtrig-pattern", RUN+="/usr/libexec/fbd-ledctrl -p %S%p -t pattern -G feedbackd"

#
# Alert sliders
#
# OnePlus 6,6T (DT bits not yet upstream)
SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT}=="1", ENV{ID_PATH}=="platform-alert-slider", TAG+="uaccess", ENV{FEEDBACKD_TYPE}="alert-slider"

LABEL="feedbackd_end"
07070100000015000081A400000000000000000000000166F7A51300001652000000000000000000000000000000000000002200000000feedbackd-0.5.0/data/default.json{
  "name" : "default",
  "profiles" : [
    {
      "name" : "full",
      "feedbacks" : [
        {
          "event-name" : "alarm-clock-elapsed",
          "type"       : "Sound",
          "effect"     : "alarm-clock-elapsed"
        },
        {
          "event-name" : "button-pressed",
          "type"       : "Sound",
          "effect"     : "button-pressed"
        },
        {
          "event-name" : "button-released",
          "type"       : "Sound",
          "effect"     : "button-released"
        },
        {
          "event-name" : "camera-focus",
          "type"       : "Sound",
          "effect"     : "camera-focus"
        },
        {
          "event-name" : "camera-shutter",
          "type"       : "Sound",
          "effect"     : "camera-shutter"
        },
        {
          "event-name" : "message-new-cellbroadcast",
          "type"       : "Sound",
          "effect"     : "cellbroadcast"
        },
        {
          "event-name" : "message-new-email",
          "type"       : "Sound",
          "effect"     : "message-new-email"
        },
        {
          "event-name" : "message-new-instant",
          "type"       : "Sound",
          "effect"     : "message-new-instant"
        },
        {
          "event-name" : "message-new-sms",
          "type"       : "Sound",
          "effect"     : "message-new-instant"
        },
        {
          "event-name" : "phone-incoming-call",
          "type"       : "Sound",
          "effect"     : "phone-incoming-call"
        },
        {
          "event-name" : "phone-hangup",
          "type"       : "Sound",
          "effect"     : "phone-hangup"
        },
        {
          "event-name" : "phone-failure",
          "type"       : "Sound",
          "effect"     : "phone-failure"
        },
        {
          "event-name" : "phone-outgoing-busy",
          "type"       : "Sound",
          "effect"     : "phone-outgoing-busy"
        },
        {
          "event-name" : "screen-capture",
          "type"       : "Sound",
          "effect"     : "screen-capture"
        },
        {
          "event-name" : "timeout-completed",
          "type"       : "Sound",
          "effect"     : "complete"
        },
        {
          "event-name" : "theme-demo",
          "type"       : "Sound",
          "effect"     : "theme-demo"
        },
        {
          "event-name" : "window-close",
          "type"       : "Sound",
          "effect"     : "theme-demo"
        }
      ]
    },
    {
      "name" : "quiet",
      "feedbacks" : [
        {
          "event-name"   : "alarm-clock-elapsed",
          "type"         : "VibraPeriodic",
          "magnitude"    : 32767,
          "duration"     : 10000,
          "fade-in-time" : 10000,
          "fade-in-level": 4096
        },
        {
          "event-name" : "bell-terminal",
          "type"       : "VibraRumble",
          "duration"   : 100
        },
        {
          "event-name" : "button-pressed",
          "type"       : "VibraRumble",
          "duration"   : 15
        },
        {
          "event-name" : "button-released",
          "type"       : "VibraRumble",
          "duration"   : 12
        },
        {
          "event-name" : "message-new-cellbroadcast",
          "type"       : "VibraPeriodic",
          "magnitude"  : 10000,
          "duration"   : 3000
        },
        {
          "event-name" : "message-new-email",
          "type"       : "VibraRumble",
          "duration"   : 750,
          "count"      : 3,
          "pause"      : 100
        },
        {
          "event-name" : "message-new-instant",
          "type"       : "VibraRumble",
          "duration"   : 150
        },
        {
          "event-name" : "message-new-sms",
          "type"       : "VibraRumble",
          "duration"   : 500,
          "count"      : 2,
          "pause"      : 100
        },
        {
          "event-name" : "message-sent-instant",
          "type"       : "VibraRumble",
          "duration"   : 150
        },
        {
          "event-name" : "phone-incoming-call",
          "type"       : "VibraPeriodic",
          "duration"   : 10000
        },
        {
          "event-name" : "timeout-completed",
          "type"       : "VibraRumble",
          "duration"   : 100
        },
        {
          "event-name" : "theme-demo",
          "type"       : "VibraPeriodic",
          "magnitude"  : 32767,
          "duration"   : 5000
        },
        {
          "event-name" : "window-close",
          "type"       : "VibraRumble",
          "duration"   : 25
        }
      ]
    },
    {
      "name" : "silent",
      "feedbacks" : [
        {
          "event-name" : "battery-caution",
          "type"       : "Led",
          "color"      : "red",
          "frequency"  : 5000
        },
        {
          "event-name" : "message-missed-email",
          "type"       : "Led",
          "color"      : "#800080",
          "frequency"  : 2000
        },
        {
          "event-name" : "message-missed-instant",
          "type"       : "Led",
          "color"      : "blue",
          "frequency"  : 1000
        },
        {
          "event-name" : "message-missed-notification",
          "type"       : "Led",
          "color"      : "blue",
          "frequency"  : 500
        },
        {
          "event-name" : "message-missed-sms",
          "type"       : "Led",
          "color"      : "blue",
          "frequency"  : 2000
        },
        {
          "event-name" : "phone-missed-call",
          "type"       : "Led",
          "color"      : "#00FFFF",
          "frequency"  : 3000
        }
      ]
    }
  ]
}
07070100000016000081A400000000000000000000000166F7A513000000D5000000000000000000000000000000000000003100000000feedbackd-0.5.0/data/fbd-alert-slider.service.in[Unit]
Description=Feedbackd Alert Slider Handler
PartOf=graphical-session.target

[Service]
ExecStart=@libexecdir@/fbd-alert-slider
Restart=on-abnormal
RestartSec=10s

[Install]
WantedBy=graphical-session.target
07070100000017000081A400000000000000000000000166F7A5130000098F000000000000000000000000000000000000002100000000feedbackd-0.5.0/data/meson.build# DBus server interface
prefix = 'org.sigxcpu.'
namespace = 'LfbGdbus'

generated_dbus_sources = []

dbus_interfaces = [ 'org.sigxcpu.Feedback.xml' ]

generated_dbus_sources += gnome.gdbus_codegen('lfb-gdbus',
      sources          : dbus_interfaces,
      object_manager   : false,
      docbook          : 'libfeedback',
      interface_prefix : prefix,
      install_header   : true,
      install_dir      : join_paths(get_option('includedir'), libname),
      namespace        : namespace)

dbus_header_dir = meson.current_build_dir()
dbus_inc = include_directories('.')
install_data(dbus_interfaces, install_dir: ifacedir)

schemas = ['org.sigxcpu.feedbackd.gschema.xml']
compiled = gnome.compile_schemas(
  build_by_default: true
)

compile_schemas = find_program('glib-compile-schemas', required: false)
if compile_schemas.found()
  test('Validate schema file', compile_schemas,
       args: ['--strict', '--dry-run', meson.current_source_dir()])
endif

install_data(
  schemas,
  install_dir: 'share/glib-2.0/schemas'
)


if get_option('daemon')

service_data = configuration_data()
service_data.set('libexecdir', libexecdir)
service_file = 'org.sigxcpu.Feedback.service'

configure_file(
  input : service_file + '.in',
  output : service_file,
  configuration : service_data,
  install : true,
  install_dir: servicedir,
)

theme_json = ['default.json']
install_data(
  theme_json,
  install_dir: feedbackd_theme_dir,
)

if json_glib_validate.found()
  jsons = []
  foreach theme : theme_json
    jsons += (join_paths(meson.current_source_dir(), theme))
  endforeach
  custom_target('validate-json',
		build_by_default: true,
		input: theme_json,
		output: 'json_validate_stamp',
		command: [json_glib_validate.full_path()] + jsons)
endif

if get_option('udev')
  install_data('90-feedbackd.rules', install_dir: udevdir)
endif

systemd_user_unit_dir = get_option('systemd_user_unit_dir')
systemd_dep = dependency('systemd', required: false)
if systemd_user_unit_dir == ''
  if systemd_dep.found()
    systemd_user_unit_dir = systemd_dep.get_variable('systemd_user_unit_dir')
  else
    systemd_user_unit_dir = prefix / libdir / 'systemd' / 'user'
  endif
endif

# Alert slider Systemd user service
alert_slider_unit = 'fbd-alert-slider.service'
configure_file(
  input : alert_slider_unit + '.in',
  output : alert_slider_unit,
  configuration : service_data,
  install : true,
  install_dir : systemd_user_unit_dir,
)

endif # daemon
07070100000018000081A400000000000000000000000166F7A51300000047000000000000000000000000000000000000003500000000feedbackd-0.5.0/data/org.sigxcpu.Feedback.service.in[D-BUS Service]
Name=org.sigxcpu.Feedback
Exec=@libexecdir@/feedbackd

07070100000019000081A400000000000000000000000166F7A51300000A74000000000000000000000000000000000000002E00000000feedbackd-0.5.0/data/org.sigxcpu.Feedback.xml<?xml version="1.0" encoding="UTF-8" ?>

<node>
  <!-- org.sigxcpu.Feedback
       @short_description: haptic/audio/visual feedback interface

       This D-Bus interface is used to get the current feedback theme
       and to give feedback on events.
   -->
  <interface name="org.sigxcpu.Feedback">
    <!--
         Profile: The currently used profile.

         The currently used feedback profile name. Applications should
         usually not change this value.
    -->
    <property name="Profile" type="s" access="readwrite" />

    <!--
        TriggerFeedback:
        @app_id: The application id usually in "reverse DNS" format
        @event: The event name from the Event naming spec
        @hints: Additional hints. Currently known hints
          - profile: Override the profile used for this event with the given profile name
          - important: Override the current global feedback level.
            Together with the 'profile' hint this allows to trigger feedback for events
            that would otherwise be disabled. A typical use case is an alarm clock. Note
            that the feedback daemon (depending on it's configuration) might ignore this flag.
        @timeout: When the feedbacks for this event should end latest in seconds. The special values '-1' (just run each feedback once) and '0' (endless loop) are also supported.
	@id: Event id for future reference

        Give user feedback for an event by triggering feedbacks
        defined in the daemon. The method call returns an event id
        that can be used later on to e.g. cancel the triggered
        feedbacks early.

        Depending on the event, theme and profile several forms of
        feedback will be triggered such as an audio ring tone and a
        haptic motor.
    -->
    <method name="TriggerFeedback">
      <arg direction="in" name="app_id" type="s"/>
      <arg direction="in" name="event" type="s"/>
      <arg direction="in" name="hints" type="a{sv}"/>
      <arg direction="in" name="timeout" type="i"/>
      <arg direction="out" name="id" type="u"/>
    </method>

    <!--
         EndFeedback:
         @id: The id of the event

         End all feedbacks triggered by the event with the given id.
     -->
    <method name="EndFeedback">
      <arg direction="in" name="id" type="u"/>
    </method>

    <!--
         FeedbackEnded:
         @id: The id of the event
         @reason: The reason why feedback was ended (currently unused).

         Emitted when all feedbacks for an event have ended.
    -->
    <signal name="FeedbackEnded">
      <arg name="id" type="u"/>
      <arg name="reason" type="u"/>
    </signal>
  </interface>

</node>
0707010000001A000081A400000000000000000000000166F7A51300000783000000000000000000000000000000000000003700000000feedbackd-0.5.0/data/org.sigxcpu.feedbackd.gschema.xml<schemalist>
  <schema id="org.sigxcpu.feedbackd"
          path="/org/sigxcpu/feedbackd/">
    <key name="profile" type="s">
      <choices>
        <choice value='full'/>
        <choice value='quiet'/>
        <choice value='silent'/>
      </choices>
      <default>'full'</default>
    <summary>Feedack profile to use</summary>
    <description>
      The feedback profile determines the audio and haptical feedback
      level given on events to the user.
    </description>
    </key>

    <key name="theme" type="s">
      <default>'default'</default>
      <summary>The feedback theme to use</summary>
      <description>
        The feedback theme determines which feedbacks are triggered when
        feedbackd receives an event.
      </description>
    </key>

    <key name="prefer-flash" type="b">
      <default>false</default>
      <summary>Prefer camera flash LED over notification LED</summary>
      <description>
        Prefer the (camera) flash LED over other notifiction LEDs.
      </description>
    </key>

    <key name="allow-important" type="as">
      <default>['org.sigxcpu.FbdAlertSlider',
                'org.sigxcpu.FbdAlertSlider']</default>
      <summary>List of apps that can override the feedback level</summary>
      <description>
        Apps listed here can override the configured feedack level by
        setting the 'important' hint on the submitted event.
      </description>
    </key>
  </schema>

  <schema id="org.sigxcpu.feedbackd.application">
    <key name="profile" type="s">
      <choices>
        <choice value='full'/>
        <choice value='quiet'/>
        <choice value='silent'/>
      </choices>
      <default>'full'</default>
      <summary>Feedack profile to use</summary>
      <description>
	The feedback profile determines the audio and haptical feedback
	level given on events to the user.
      </description>
    </key>
  </schema>
</schemalist>
0707010000001B000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001700000000feedbackd-0.5.0/debian0707010000001C000081A400000000000000000000000166F7A5130000043E000000000000000000000000000000000000002500000000feedbackd-0.5.0/debian/README.sourceThis package is maintained with git-buildpackage(1). It follows DEP-14
for branch naming (e.g. using debian/sid for the current version
in Debian unstable).

It uses pristine-tar(1) to store enough information in git to generate
bit identical tarballs when building the package without having
downloaded an upstream tarball first.

When working with patches it is recommended to use "gbp pq import" to
import the patches, modify the source and then use "gbp pq export
--commit" to commit the modifications.

The changelog is generated using "gbp dch" so if you submit any
changes don't bother to add changelog entries but rather provide
a nice git commit message that can then end up in the changelog.

It is recommended to build the package with pbuilder using:

    gbp buildpackage --git-pbuilder

For information on how to set up a pbuilder environment see the
git-pbuilder(1) manpage. In short:

    DIST=sid git-pbuilder create
    gbp clone <project-url>
    cd <project>
    gbp buildpackage --git-pbuilder

 -- Guido Günther <agx@sigxcpu.org>, Wed,  2 Dec 2015 18:51:15 +0100
0707010000001D000081A400000000000000000000000166F7A51300009910000000000000000000000000000000000000002100000000feedbackd-0.5.0/debian/changelogfeedbackd (0.5.0) experimental; urgency=medium

  [ Guido Günther ]
  * packaging: Update lintian overrides
  * packaging: Install NEWS and README. They contain useful information
  * packaging: Use pkgconf. It's prefered over pkg-config in Debian
  * doc: Document gsettings used by feedbackd
  * udev: Add support for haptics on Oneplus Enchilada / Fajita.
    The spmi_haptics driver isn't in mainline Linux as of Linux 6.11.
  * theme: Add events for cellbroadcast
  * data: Allow logged in users to access the alert slider
  * fbd-alert-slider: Small service to track alert sliders.
    This tracks the alert slider on OnePlus 6/6T devices
    and adjusts the profile level accordingly.
    This is based on a script by "isyourbrain foss" in the Phosh matrix
    channel.
  * data: Add systemd unit to start alert slider service
  * data: Allow alert-slider to override the feedback level.
    This allows the alert-slider to also emit feedback when phone is in
    silent mode.
  * data: Add gnome-clocks to allow-important list.
    This will allow us to drop the override from phosh
  * packaging: Better handle RC version when updating changelog.
    This allows us to switch from RCs to releases without manual
    effort.

  [ Robert Mader ]
  * udev-rules: Add support for haptics on Google Sargo.
    The drv2624 driver isn't in mainline Linux as of Linux 6.11.
    Taken from

 -- Guido Günther <agx@sigxcpu.org>  Fri, 27 Sep 2024 13:46:42 +0200

feedbackd (0.4.1) experimental; urgency=medium

  * not-intalled: Avoid gmobile on all arches.
    This only matters for the case where we use the embedded
    gmobile but better to be correct.
  * tests: Use decimal values.
    We don't rely on that anywhere anyway.
    Co-authored-by: Tomi Lähteenmäki <lihis@lihis.net>
    Closes: https://source.puri.sm/Librem5/feedbackd/-/issues/79
  * build: Install udev rule.
    Don't hide it in the packaging as that makes it easier to miss.
    This makes debian/ really only carry packaging information.

 -- Guido Günther <agx@sigxcpu.org>  Mon, 12 Aug 2024 22:54:48 +0200

feedbackd (0.4.0) experimental; urgency=medium

  [ Guido Günther ]
  * docs: Expand the examples section a bit
  * led: Add doc strings
  * led: Drop unused variable
  * led: Don't forget to init variable
  * fbd-dev-led-multicolor: Drop unused variable
  * fbd-theme-validate: Use G_NORETURN
  * Build: Use meson instead of ninja
  * ci: Add clang build
  * tests: Add umockdev based tests for leds.
    This ensures we can probe the different led types correctly
    The umockdev data was recoreded on an Librem 5 and Librem 14
  * led-qcom: Use char instead of gchar.
    We prefer the C types in new code.
  * led-qcom-multicolor: Drop unused defines
  * led-qcom-multicolor: Don't leak qcom_led
  * led-qcom: Check for LED driver.
    The hw_pattern attribute is driver specific. Ensure we don't apply the
    LED pattern to unknown drivers.
    Closes: https://source.puri.sm/Librem5/feedbackd/-/issues/77
  * ci: Update common files from meta-phosh.
    This updates to commit f3c92e90dcc0d65322888217429b75dd101bd0d3
  * ci: Use common jobs from meta-phosh
  * build: Let daemon dependency depend on generated enum headers.
    Otherwise it might not be available in the tests
  * dev-led-multicolor: Use correct format specifier.
    The values are unsigned int
  * doc: Document feedback types.
    This allows us to remove the list from the README
  * doc: Fix URLs.
    Don't use Markdown markup as it looks odd in the generated page.
  * fbd-feedback-led: Modernize property definitions.
    Adapt current phosh coding style before making other changes
  * feedback-led: Support colors as strings.
    The FbdDevLedColor enum defines the hardware color of the LED. We used
    it for the feedbacks color value as long as the kernel mostly had
    single color LEDs. As multicolor LEDs are common nowadays switch the
    color to a string which will allow us to use RGB values later on.
  * feedbackd: Pass GMOBILE_USE_UNSTABLE_API to all files.
    No need to ack that individually
  * feedback-led: Document hw LED types
  * led: Parse color values and pass them down the chain.
    We parse RGB color values as HEX ('#RRGGBB') and use those when a RGB
    LED is available. Single color LEDs won't see a change.
  * theme: Use different colors for emails and calls.
    This makes them a bit simpler to distinguish
  * manager: Move schema name to header.
    This makes it available to other compilation units
  * led: Drop FBD_FEEDBACK_LED_COLOR_LAST.
    With new led types we might not loop over all of them. This makes
    it a bit more obvious.
  * feedback-led: Check if at least one LED is available.
    So far we didn't create any FbdDevLeds if there wasn't at least one
    usable LED. Once we introduce flash LEDs we might probe the LED but the
    LED might not be usable as the user hasn't enabled using it. Prepare for
    that scenario.
  * led: Add flash LED type.
    Camera flashes are also exported via the LED subsystem. We use a
    separate LED type so they're not picked by default.
    We don't use them as fallbacks either.
  * leds: Probe flash LED
  * feedback-led: Allow to prefer flash LEDs over notification LEDs
  * udev: Allow to use flash devices
  * packaging: Don't require root for building.
    This helps the nightly builds
  * packaging: Build-depend on shared gmobile.
    This ensures we don't use the subproject in packaging builds
  * cli: Inform user when no feedback was found.
    This might either be because the event doesn't exist or when the profile
    doesn't have any feedback on the current level.
    Closes: https://source.puri.sm/Librem5/feedbackd/-/issues/76
  * tests/fbd-event: Check if objects are finalized.
    This gives us more info than just using automatic cleanup
  * event: Make removing feedbacks more self contained.
    If the feedback is in our list of feedbacks disconnect signals
    and drop the reference we hold.
    As we have removed the signal handler that would invoke `check_ended()`
    we invoke this manually when the list becomes empty.
  * event: Allow to end events by level.
    The level here is an abstract value but in fact matches the profile
    level. Well make this a property when fixing #35.
  * feedback-manager: End too noisy feedbacks on profile level change.
    When the profile gets lowered from e.g. quiet to silent we want to end
    all ongoing feedbacks that belong to the quiet level.
    This allows to e.g. silence an incoming phone call by switching the
    feedback level via phosh's quick setting.
    Closes: https://source.puri.sm/Librem5/feedbackd/-/issues/13
    Closes: https://source.puri.sm/Librem5/feedbackd/-/issues/55

  [ Dylan Van Assche ]
  * fbd-dev-led-multicolor: Use separate log domain.
    Debugging driver probing is much easier when each driver has its own log domain.
  * fbd-dev-led-multicolor: Fix typo in error message
    multicololo -> multicolor LED
  * fbd-dev-led: Scan for RGB color as well.
    Multicolor LEDs have the color 'rgb', we should also scan it
    as they are also a FbdDevLed.
  * fbd-dev-led-*: Adjust to method convention
    fbd_dev_led_ is the convention for methods, adjust them all.
  * fbd-dev-led: Rework color API.
    Drop has_color API since supported colors are set during probing
    and can be handled completely separately from the classes for
    each type of hardware.
  * fbd-ledctrl: Set permissions for hw_pattern.
    Allow access to hw_pattern sysfs node for feedbackd, similar to other nodes.
  * fbd-dev-led: Check max_brightness_percentage range.
    Percentages are always between 0.0 and 100.0.
    Also fix a typo along the way.
  * fbd-dev-led-multicolor: Support red, green, blue and white LED colors.
    Provide our own supports_color method to specify which colors are
    actually implemented by the driver. RGB LEDs could provide different
    colors as well such as orange, purple, etc. but those are not supported
    yet.
  * fbd-dev-led-qcom: Support QCOM LPG LED single color.
    QCOM LPG LEDs expose a hw_pattern sysfs entry which accepts a limited
    set of patterns but allows to use dedicated hardware for blinking the
    LED. This way, battery life can be improved and the LED still blinks,
    even if the device is suspended.
  * fbd-dev-led-qcom-multicolor: Support QCOM LPG LED multicolor.
    QCOM LPG LEDs can also operate in a multicolor fashion.
    Re-use the probing sequence of multicolor LEDs and the hw_pattern
    configuration of single color QCOM LPG LEDs.
  * fbd-dev-leds: Probe QCOM HW LED types.
    Try first the QCOM hardware LED types which require the most features of
    LED drivers. Try until we have a single color GPIO LED which is the
    minimal LED driver support we require. If the LED does not meet that
    expectation either, we ignore the LED.

 -- Guido Günther <agx@sigxcpu.org>  Tue, 11 Jun 2024 09:49:20 +0200

feedbackd (0.3.0) experimental; urgency=medium

  * feedback-themes: Improve wording
  * manpages: Improve references
  * manpages: Fix whatis entry
  * debian: Update from the current packaging in Debian
    - Validate fbd-theme-validate
    - Add Build-dep to symbols file
    - Add doc-base registration
    - Use dh_installman to fix nodoc build
    - Update debian/copyright
    - Improve Recommends: and multi arch annotations
    - Add lintian overrides
  * debian: Fix nodoc build.
    Don't try to install the dev docs in that case.
  * debian: Install NEWS
  * packaging: Use meson's default wrap mode
    ci should be allowed to download gmobile
  * build: Switch gmobile to 0.0.4.
    We switch to a wrap which helps us to avoid the submodule
  * ci: Switch to trixie
  * ci: Add uncrustify config and checker.
    Based on what we added to phoc recently
  * ci: Run style checks on merge requests
  * fbd-dev-led-multicolor: Fix indentation
  * fbd-dev-led-multicolor: Drop unused variable
  * fbd-dev-led-multicolor: Make it a derivable type.
    This will allow hw-pattern classes to derive from it.
  * Draft: ci: Add rules for format-check
  * build: Switch to gmobile 0.1.0
  * build: Allow to use shared gmobile
  * packaging: Add libgirepository1.0-dev
  * README: Note what's the preferred way to specify a theme
  * build: Validate schema file
  * data/dbus: Document current flags
  * data/dbus: Document important hint.
    The important hint can be used by apps to override the current per app
    or system wide feedback level (if the feedback server allows it).
  * data/schema: Add 'allow-override' gsetting.
    This allows to list apps that can override the currently
    effective feedback level by setting the 'impotant' hint in
    the event.
  * fbcli: Allow to override app-id.
    Useful for testing
  * feedback-manager: Use MIN()
    A bit easier to read
  * libfeedback: Allow to set important hint
  * feedback-manager: Parse important hint
  * cli: Allow to set important hint
  * feedback-manager: Handle important hint.
    This allows blessed apps to override the per-app as well as the global
    feedback level. This can e.g. be useful for alarm clocks.

 -- Guido Günther <agx@sigxcpu.org>  Sun, 21 Apr 2024 12:15:01 +0200

feedbackd (0.2.1) experimental; urgency=medium

  * Update NEWS
  * event: Fix doc link
  * treewide: Drop superfluous '()' after functions in doc strings.
    Otherwise we have that doubled in the docs
  * doc: Better cross reference manpages
  * doc: Add manpage for feedback themes.
    This should direct users to the documentation.

 -- Guido Günther <agx@sigxcpu.org>  Tue, 29 Aug 2023 18:32:09 +0200

feedbackd (0.2.0) experimental; urgency=medium

  * build: Bump version to 0.2.0. We have a slight api change.
  * lfb-event: Avoid allocation when getting profile.
    We can return the const *. This makes it consistent with other getters.
    This is an API change we didn't find any users and the API is declared
    unstable.
  * tests: Get properties all at once
  * lfb-event: Add getter and setter for app-id.
    For applications this is figured out automatically but notification
    daemons and portal implementations might want to override it to have the
    per-app feedback profile picked up automatically.

 -- Guido Günther <agx@sigxcpu.org>  Mon, 17 Apr 2023 12:14:14 +0200

feedbackd (0.1.1) experimental; urgency=medium

  * build: Avoid meson deprecation warning
  * fbd-event: Make sure we iterate the list safely.
    When all feedbacks are done the event signals "feedbacks-ended" which
    lets the manager dispose the feedback. When all feedbacks end instantly
    and synchronously (as is the case with the dummy feedback) this triggers
    the disposal of the event within the loop leading to a crash.
    Make sure the object doesn't go away be referencing it during the loop
    iteration.
    We didn't see this before as glib's slice allocator for lists papered
    over this for us.
    Closes: https://source.puri.sm/Librem5/feedbackd/-/issues/69
  * tests: Don't leak json string
  * tests: Don't leak profiles and test that.
    We finalize the theme first so the last reference is dropped when
    finalizing the profiles.
  * feedback-profile: Don't leak json array when serializing profile
    json_array_add_element doesn't transfer ownership
  * feedback-theme: Don't leak json array when serializing profile
    json_array_add_element doesn't transfer ownership.
  * feedback-theme: Don't leak parent name
  * tests/profile: Don't leak json node

 -- Guido Günther <agx@sigxcpu.org>  Thu, 23 Mar 2023 10:35:01 +0100

feedbackd (0.1.0) experimental; urgency=medium

  [ Dylan Van Assche ]
  * udev: load the required kernel modules.
    Loading the required kernel modules such as ledtrig-pattern via
    /etc/modules-load.d may introduce a race condition on some systems such
    as non-systemd based distros. Load the kernel modules using the builtin
    'kmod load' udev command instead.

  [ Guido Günther ]
  * debian: Drop obsolete conf file.
    As this is now handled via udev's kmod builtin we can drop this.
  * theme: Fix some indentation
  * fbd-dev-leds: Use gi-docgen compatible format.
    We don't document the server classes via gi-docgen atm but
    as we use it for the lib update classes we touch.
  * Move LED device to separate file.
    We separate out the led as different LED types have different
    ways to set patterns, etc
  * fbd-dev-leds: Move led creation into fbd-dev-led.
    This will allow us to separate the different led types
  * fbd-dev-leds: Move pattern trigger into fbd-dev-led
  * fbd-dev-led: Allow to lookup color.
    This allows us to make the led structure into an opaque in
    the next commit
  * fbd-dev-led: Make structure opaque.
    This will allow us to turn it into a GObject
  * fbd-dev-led: Turn into a GObject.
    This is just the minimal changes to switch to a derivable GObject
  * fbd-dev-led: Use GInitable.
    Use default GObject patterns instead of stuffing things into the
    fbd_dev_led_new () so derived classes can override it.
  * fbd-dev-led: Add class methods so derived classes can override functionality
  * fbd-dev-led: Move multicolor handling to separate class.
    Everything related to multicolor moves into the new class and we add the
    necessary getters and setters so derived classes can access the parent
    classes attributes where needed.
  * d/gbp.conf: Be less strict when matching the meson version field

 -- Guido Günther <agx@sigxcpu.org>  Sat, 25 Feb 2023 14:04:43 +0100

feedbackd (0.0.3) experimental; urgency=medium

  * build: Add dbus sources to the lib dependency.  Otherwise we might fail to
    generate it for the executables
  * event-naming-spec: Separate application and system events.
    Make it obvious which events are meant to be used by "normal" GUI
    applications in contrast to system components like desktop shells or
    components monitoring the battery, etc.
    This was prompted by
    https://github.com/flatpak/xdg-desktop-portal/issues/929
  * feedback-theme: Add screen-shot event.
    Used to indicate that a screen shot is being taken.
  * lfb-event: Fix docstring.
    This allows gi-docgen to pick it up
  * doc: Fix link to spec in manpage
  * libfeedback: Fix link to specs.
    Since we now have them as part of the API docs we can avoid any remote
    URLs
  * Update gmobile to 0.0.1

 -- Guido Günther <agx@sigxcpu.org>  Thu, 02 Feb 2023 12:10:51 +0100

feedbackd (0.0.2) experimental; urgency=medium

  [ Chris Vogel ]
  * docs: Update references to documentation from branch master to branch main.
  * README: Mention python example
  * doc: feedback stops when client disconnects
  * run: Export GI_TYPELIB_PATH as well.
    This is needed for programs needing GObject introspection data
  * run: Don't hardcode feedbackd.
    This allows arbitrary executables from the source tree with
    a well defined environment.
  * example: Document usage

  [ Guido Günther ]
  * run: Fix daemon name.
    Fixes: 99fc8c2 ("run: Make it easy to run under gdb and document usage")
  * example: Wait a bit before ending
    feedbackd terminates feedback when clients disconnect from DBus so
    we need to wait a bit before quitting as otherwise no feedback will
    be played. (Closes: #65)
  * d/gbp.conf: Update branch.
    Missed that one when switching to 'main'
  * ci: Switch build to bookworm / byzantium.
    Use Debian bookworm for the tests and PureOS byzantium for the
    package build
    We use the arm64 builder as the amd64 one fails to find a shell in the
    bookworm image.
  * d/control: Add settings schema for the tests
  * d/control: Drop Breaks/Replaces on packages long gone
  * d/rules: Support nodoc build profile
  * build: Bump required meson version
  * Switch library documentation to gi-docgen.
    Switch from gtk-doc to gi-docgen for the library documentation and
    adjust the source files accordingly.
    We don't bother about the daemon doc headers as they're not built into
    any docs atm. (Closes: #56)
  * Include specifications in the documentation.
    Now that we can use markdown easily add them as they provide
    help to the developer what events exist, etc.
  * dir-locals: Simlify consistent JS indenting
  * feedback-vibra: Fix indentation
  * tests: Test feedback theme name
  * feedback-theme: No need for constructed.
    We can do all that in init
  * feedback-theme: Fix indentation
  * feedback-theme: Use getter.
    Ensures we stay consistent with future changes
  * feedback-theme: Allow to set name
  * feedback-profile: Document hash types
  * feedback-dummy: Add getter for duration.
    Useful in tests
  * feedback-profile: Allow to update profiles.
    Allow to add feedbacks from a profile to another one
  * feedback-theme: Allow to update theme.
    New profiles are added, existing profiles updated. This will
    allow to merge themes.
  * feedback-theme: Allow to get and set parent theme name.
    If set the parent theme's feedbackd and profiles should be merged into
    this theme.
  * ci: Install git.
    Needed for the submodule
  * Add gmobile library
  * build: Don't include main in lib.
    For that move the error quark to a separate file.
  * Recursively load themes.
    Themes (other than the default theme) can specify a `parent-name` in the
    json file. This theme will be used as a base for the theme. Events and
    profiles of the children override those in the parents.
    For this we move the lookup code into it's separate class and also add
    tests. (Closes: #38)
  * theme-expander: Allow to set the theme to expand
  * data: Allow to set feedback theme
  * manager: Don't load theme in constructor.
    Loading the theme can trigger calls to
    fbd_feedback_manager_get_default() which then results in an endless look
    as the object isn't fully initialized in constructed. Instead do
    the setup in main() which has the advantage that the manager's life
    cycle becomes more obvious too.
  * feedback-manager: Handle theme gsetting.
    Update the theme when the gsetting changes
  * README: Document custom themes
  * tests: Help old glib on PureOS along
  * theme-expander: Also log initial theme file
  * Add theme validator.
    Recursively loads a given theme file.
  * ci: Use bookworm image for package build too.
    No need to fight against old glib and friends in PureOS
  * doc: Convert manpages to rst.
    This will make it more fun to add details and more manpages.
  * doc: Add manual page for fbd-theme-validate
  * d/rules: Don't build tests with nocheck

 -- Guido Günther <agx@sigxcpu.org>  Tue, 13 Dec 2022 13:53:57 +0100

feedbackd (0.0.1) byzantium; urgency=medium

  [ Evangelos Ribeiro Tzaras ]
  * spec: Clarify feedback noisiness.
    The old wording could be interpreted as the feedback being discarded if
    it's noisier than the currently selected profile which is not the case.
    Also take the new per application settings into account.
  * lfb-event: Fix SPDX identifier.
    The library is LGPL-2.1+, not GPL-3.0+
  * test-lfb-integration: Test event state in async callback
  * lfb-event: Notify state change before completing async task
    lfb_event_trigger_feedback_async() internally uses a GTask to handle
    invocation of the user provided callback when g_task_return_*() is
    called.
    Currently GTask is completed first and only afterwards is the state of
    the event being updated which can lead to surprising behaviour.
  * feedback-manager: Use guint for event id.
    The ID is inserted into a hashtable below with GUINT_TO_POINTER
    and is set using self->next_id++ with next_id also being a guint,
    so change the type accordingly.
  * run: Make it easy to run under gdb and document usage.
    Having a fast and easy way to run the daemon under gdb can be beneficial
    for debugging. For that start the run script with FBD_GDB=1.
  * tests/integration: Indicate that callback quits main loop
    on_event_triggered() is renamed to on_event_triggered_quit()
    as we will shortly introduce a variant that does not quit.
  * tests/integration: Fix whitespace.
    Remove all tabs in favour of spaces and align function arguments.
  * tests/integration: Test that "feedback-ended" is propagated through
    LfbEvent.
    When no feedbacks are available (either because the requested event does
    not exist in the theme or because the system does not have required
    capabilities, e.g. no vibration motor or LED) feedbackd will emit a
    "feedback-ended" signal (with reason LFB_EVENT_STATE_REASON_NOT_FOUND)
    on DBus _before_ completing the event triggering DBus call.
    Since the DBus call was not completed yet, LfbEvent will not have
    learned it's ID yet and therefore not emit it's own "feedback-ended"
    GObject signal.
    In this case the test will timeout since the main loop is never quit.
  * feedback-manager: Complete DBus call before emitting "feedback-ended"
    See previous commit adding the test (that now passes) for the reasoning.
    Fixes: #62

  [ Guido Günther ]
  * data: Drop outdated comment.
    We use the hints since some time, see lfb_event_set_feedback_profile().
  * lfb-event: Fix typo. It's LfbEvent
  * lfb-event: Use consistent prefix.
    Make async data use the same prefix.
  * Use g_error() when library is not initialized.
    This makes sure it still works when asserts are disabled.
  * lfb-event: Untabify
  * tests: Drop unused variable
  * tests/integration: Check the state of the ended event
  * manager: Use FEEDBACKD_UDEV_ATTR.
    It was introduced in
    a5b4f99 ("feedbackd: Support visual feedback via LEDs")
  * fbd: Fix indentation

 -- Guido Günther <agx@sigxcpu.org>  Thu, 10 Nov 2022 13:53:19 +0100

feedbackd (0.0.0+git20220520) byzantium; urgency=medium

  [ Guido Günther ]
  * udev: Drop pre L5 pre 5.9 workaround.
    Not neeed in 2022.
  * udev: Use more generic comment.
    Make it more obvious that this isn't device specific

  [ Dylan Van Assche ]
  * fbd-dev-leds: use define for max_brightness.
    All other attributes use a define, let's do the same for max_brightness.
  * fbd-dev-leds: rename var to max_brightness_percentage.
    Improve readability of the code.

  [ Luca Weiss ]
  * fbd-dev-leds: support for multicolor LEDs.
    Add support for multicolor LEDs as supported by the kernel.
    Used by Qualcomm devices such as SHIFT 6mq, OnePlus 6, etc.
    Co-Developed-by: Dylan Van Assche <me@dylanvanassche.be>

 -- Guido Günther <agx@sigxcpu.org>  Fri, 20 May 2022 10:55:13 +0200

feedbackd (0.0.0+git20220208) byzantium; urgency=medium

  [ Pablo Correa Gómez ]
  * Reload theme on SIGHUP signal.
    Allows for users/applications to request a theme reload
    by sending SIGHUP signal to the daemon.

  [ Evangelos Ribeiro Tzaras ]
  * lfb-event: Clarify docstring on lfb_event_set_feedback_profile
  * fbd-event: Fix return value for fbd_event_get_sender
  * doc: Clarify that the timeout is in seconds

  [ Guido Günther ]
  * libfeedback: Remove unused variables
  * tests: Remove unused variables
  * manager: Set initial profile to unknown.
    This makes sure we sync the profile with the DBus property after
    fetching it from GSettings.
  * manager: Sync profile with setting on startup.
    On startup the GSetting is the relevant input for selecting the profle.
    (Closes: #52)
  * manager: Don't sync DBus profile property.
    This will happen in on_feedbackd_setting_changed() once the
    profile was adjusted.

 -- Guido Günther <agx@sigxcpu.org>  Tue, 08 Feb 2022 11:29:41 +0100

feedbackd (0.0.0+git20211018) byzantium; urgency=medium

  [ Evangelos Ribeiro Tzaras ]
  * fbd-dev-sound: Honour sound theme name for all GNOME based desktops.
  * d/control: Add json-glib-tools as build dependency.
    This will make sure that the json theme file gets validated in CI.
  * feedback-theme: Add phone-{hangup,failure,outgoing-busy} events.
  * naming-spec: Fix upper cases, whitespaces and punctuation.

  [ Andreas Hartmann ]
  * fbd-feedback-manager: Make sure theme path components are '/' separated.
  * README: Add explanation on custom theme paths.

  [ Pablo Correa Gómez ]
  * feedback-manager: Search for default theme under XDG_CONFIG_HOME first.
    This would allow users to create their own feedback profiles
  * Fix typos in documentation
  * README: dbus calls not usable to trigger feedback.
    Fixes #45

  [ Guido Günther ]
  * examples: Unbreak python example.
  * docs: Fix --profile short option. It's '-P', not '-p'.
  * cli: Fix changing global profile.
  * feedback-theme: Add camera related events
  * gitlab-ci: Switch to bullseye.
  * fbd-dev-sound: Delay sending `ended` signal. This makes sure
    we properly end the feedback even when looping.

 -- Guido Günther <agx@sigxcpu.org>  Tue, 19 Oct 2021 13:13:43 +0200

feedbackd (0.0.0+git20210426) byzantium; urgency=medium

  [ Martin Bürgmann ]
  * implement fbd_dev_sound_stop
    tracks the FdbFeedbackSounds in a GHashTable in the FdbDevSound
    (Closes: #10)

  [ Guido Günther ]
  * fbd-dev-sound: Don't leak GError
  * fbd-dev-sound: Don't warn when sound was cancelled.
    This is not an error per se.
  * lfb-event: Don't leak error.
    Don't leak the error values in the success case
  * tests: Run lfb_event_{get,set}_timeout
  * test-lfb-integration: Test invocation error
  * event: Make log-domain match source file name
  * tests: Run event tests too
  * event: Remove 'g' prefix from common C types.
    This matchs phosh's style.
  * fbd-event: Add sender property.
    This allows us to store the DBus sender
  * fbd-manager: Keep DBus sender around
  * feedback-manager: Track DBus clients and end feedbacks if they go away.
    When the client goes away we build up a list of events to end feedback
    for to make sure the hash table isn't modified in place. tThe alternative
    approach would be to disconnect the on_event_feedbacks_ended handler,
    duplicate the DBus signal emission and use g_hash_table_foreach_remove
    but that looks less robust than using the same code path. (Closes: #25)
  * Help emacs to indent properly
  * fbd-feedback-theme: Don't leak JSON node
  * fbd-dev-leds: Free actual FbdDevLed as well.
    So far we only unref'ed the device.
  * fbd-dev-leds: Don't leak enum_name
    g_enum_to_string() is transfer full.
  * fbd-dev-leds: Don't leak color
    g_ascii_strdown() creates a copy already.
  * fbd-dev-leds: Use automatic deep cleanup for device list.
    The current logic was fragile and failed e.g. when the
    FEEDBACKD_UDEV_VAL_LED would not match leaking the dev since the
    g_object_unref() at the end of the loop was never hit.
    Prevent that with automatic cleanup and explicitly ref'ing the
    devs we want to use.
  * fbd-dev-sound: Use correct cleanup for hash table.
    This went unnoticed since the manager forgot to cleanup
    this at all (see follow up commit).
  * fbd-feedback-manager: Make sure to dispose sound device as well.
    Fixes another leak.
  * fbd-feedback-manager: Don't leak config_path.
    It's assigned multiple times.
  * fbd-feedback-manager: Don't leak device list

  [ Clayton Craft ]
  * fbd-ledctrl: fix matching of trigger in list of triggers.
    If the trigger is the last thing in sysfs_path/LED_TRIGGER_ATTR, then
    the new-line at the end of the output causes g_strv_contains to fail to
    find the trigger in the list. This strips the new-line before splitting
    the output into a list for searching.

  [ Sebastian Spaeth ]
  * README: Fix gdbus test command.
    It is TriggerFeedback and not Feedback (anymore). Also add a note how to
    end the feedback in order to prevent loss of hearing :-).

 -- Guido Günther <agx@sigxcpu.org>  Mon, 26 Apr 2021 12:34:38 +0200

feedbackd (0.0.0+git20210125) amber-phone; urgency=medium

  [ Dylan Van Assche ]
  * meson.build: compile GLib schemas on install.
    Run a script as a post install to make sure that all GLib schemas are compiled
  * fbd-feedback-manager: Allow device-specific feedbackd themes.

  [ Guido Günther ]
  * feedback-manager: Fix formatting.

 -- Guido Günther <agx@sigxcpu.org>  Mon, 25 Jan 2021 10:50:15 +0100

feedbackd (0.0.0+git20201114) amber-phone; urgency=high

  [ Guido Günther ]
  * sound: Set 'event' media role.  This allows pa to cork, duck, etc.
  * gitlab-ci: Honor PKG_ONLY.  This allow us to get debs quicker
  * udev: Update led maching for the librem5.  The names changed in device
    tree which tickles up into userspace.
  * debian: Don't abuse the video group.  Use a separate group for users that
    should be able to access the LED devices.

  [ Luca Weiss ]
  * fbd-dev-leds: fix brightness parameter.
    The fbd_dev_led_set_brightness function is only getting called with
    parameter 0 at the moment so this was never noticed.
  * Fix typos

 -- Guido Günther <agx@sigxcpu.org>  Sat, 14 Nov 2020 15:54:23 +0100

feedbackd (0.0.0+git20200726) amber-phone; urgency=medium

  [ Arnaud Ferraris ]
  * debian: udev: add support for PinePhone front LEDs
  * fbd-dev-leds: store LED color when parsing devices.
    Failing to do so will always select the first recognized LED (the blue 
    one for the PinePhone).

  [ Guido Günther ]
  * Release new git snapshot
  * fbd-dev-sound: Be less verbose on missing sound files.
    This is quite common so don't fill the logs at normal debug levels
    but be more specific about what is missing.
  * fbd-feedback-base: Add fbd_feedback_is_available ()
    This allows to check if a feedback type is available
    at all.
  * feedback-manager: Fix indentation
  * fbd-feedback-manager: Check if feedback is usable.
    If we don't find any usable feedbacks for an event return
    FBD_EVENT_END_REASON_NOT_FOUND.
  * fbd-feedback-led: Implement is_available ()
    This avoids criticals when there's no Leds available.
  * feedback-vibra-rumble: Implement is_available.
    This avoids criticals when there's no rumble vibra available.
  * feedback-vibra-periodic: Implement is_available.
    This avoids criticals when there's no periodic vibra available.
  * feedback-sound: Implement is_available.
    This avoids criticals when there's sound device available. We
    can also be more precise about the reason why feedback ended.
  * feedback-theme: Avoid warning when feedback is not found.
    We tell the caller so debug level is enough
  * tests: Don't check end reason in feedback handler.
    This allows to reuse the feedback handler and we check the
    reason in the actual test function anyway.
  * tests: Test event not found case too
  * feedback-manager: Deeply free the feedback list.
    Instead of freeing each element after each iteration and then the list
    itself at the very end just fully free the list. g_autoslist does
    not work well on oder glib so do that manually.
    This is just cosmetics.
  * feedback-manager: Don't forget to remove not found events from the hash table.
    This plugs a leak.
  * feedback-manager: Dispose leds too
  * feedback-led: Stop the correct led color
  * feedback-led: Don't try to stop led when there's no led device.
    This is not a critical since we prevented submitting initially
    but daemon cleanup processes all entries in the theme.
  * fbd: Dispose manager at the very end

 -- Guido Günther <agx@sigxcpu.org>  Sun, 26 Jul 2020 13:05:59 +0200

feedbackd (0.0.0+git20200714) amber-phone; urgency=medium

  [ Arnaud Ferraris ]
  * doc: fix typos
  * doc: feedbackd: add short description.
    Lintian issues a warning if short description is empty.
  * fbd-ledctrl: fix typo

  [ Guido Günther ]
  * lfb-event: Clarify return values of `finished` functions.
    They just inidicate that we talked to feedbackd successfully.
  * lfb-event: Connect done handler in async case too.
    Otherwise the event state is not updated properly
  * tests: Don't quit mainloop on event end.
    This is needed to properly test aync where we have the
    finished async event handler and the signal.
  * tests: Use async feedback as the test name implies

 -- Guido Günther <agx@sigxcpu.org>  Tue, 14 Jul 2020 10:30:45 +0200

feedbackd (0.0.0+git20200707) amber-phone; urgency=medium

  [ Sebastian Krzyszkowiak ]
  * data: Lower rumble time for window-close and button-pressed even more.
    Haptic feedback for touchscreen input should be as subtle as possible
    to not make it distracting.
  * data: Add button-released event

  [ Guido Günther ]
  * feedback-sound: Plug a leak.
    We did not free the effect name
  * Doc cleanups
  * feedback-manager: Only act on add.
    We would otherwise ignore the action when no vibra device was yet found.
    Make sure we release the old device when updating.
  * libfeedback: Unset _initted early.
    This make sure a client does not end up in our shutdown phase and sees a
    half initted library.
  * libfeedback: Cancel all running feedbacks on uninit.
    We keep track of the active ids and end them on uninit. This
    make sure feedbacks don't continue to run if the application quits
    and forgets to end a feedback.
  * fbcli: Quit main loop on CTRL-C / SIGTERM.
    This makes sure we invoke the cleanup function correctly and allows
    to test running event handling.
  * docs: Add manpages (Closes: #12)
  * data: Drop phone-missed-call in 'quiet' profile.  Only want LEDs there.
  * feedbackd: Add helper to set up permissions for LEDs.
    This helper knows about the triggers and necessary permission.
    It's intended to be run via udev.
  * debian: Setup leds via udev.
    This allows feedbackd to set periodic feedback and makes usable
    LED devices identifiable by feedbackd.
  * feedbackd: Support visual feedback via LEDs.
    later on by using the 'repeat' attribute of the LED pattern
    trigger.
  * data: Use LED feedback for missed calls, IMs and SMS
  * Add generic missed notification.
    This can be used e.g. by the shell for general purpose notifictions
    but also for in app notifications of the foreground app.
  * feedback-manager: Add hint to select feedback profile per event.
    This e.g. allows events that are meant for haptic only to avoid
    emitting a sound by omitting the 'full' level and using "quiet"
    instead. (Closes: #7)
  * LfbEvent: Add feedback-profile property.
    This allows to specify the feedback profile to use for
    this particular event.
  * cli: Allow to set profile per event.
    We allowed set the global profile via `-P` use it as per event
    profile when used with `-E`.

  [ Dorota Czaplejewicz ]
  * build: Remove feedback dependencies from libfeedback builds

 -- Guido Günther <agx@sigxcpu.org>  Fri, 10 Jul 2020 11:52:07 +0200

feedbackd (0.0.0+git20200527) amber; urgency=medium

  [ Rasmus Thomsen ]
  * build: add proper dependencies on gdbus-codgen-generated headers.
    Without this it was possible that ninja built a target that needs
    the generated header before the header was generated

  [ Guido Günther ]
  * Release another git snapshot
  * Honor sound theme on GNOME.
    We don't set this for other DEs since they might want to pick a good
    default from elsewhere.

 -- Guido Günther <agx@sigxcpu.org>  Wed, 27 May 2020 10:00:08 +0200

feedbackd (0.0.0+git20200420) amber; urgency=medium

  [ Guido Günther ]
  * Release another git snapshot
  * Add symbols file
  * theme: order feedbacks alphabetically.
  * theme: Add feedbacks for window-close and button-press
  * Allow to lower the feedback level per application.

  [ Arnaud Ferraris ]
  * d/control: customize short descriptions per binary package
  * d/control: change feedbackd-common architecture to 'all'
  * debian: rename gir package to match typelib name

 -- Guido Günther <agx@sigxcpu.org>  Mon, 20 Apr 2020 09:55:33 +0200

feedbackd (0.0.0+git20200305) amber-phone; urgency=medium

  * feedbackd-common: Add proper Breaks/Replaces.
    This handles partial upgrades with newer schema but old feebackd.

 -- Guido Günther <agx@sigxcpu.org>  Mon, 23 Mar 2020 10:21:14 +0100

feedbackd (0.0.0+git20200304) amber-phone; urgency=medium

  [ Guido Günther ]
  * libfeedback: Drop trailing semicolon.
    Trips up some compilers.
    Thanks to Andrea Schaefer
  * build: Don't add lfb-enums.c to list of generated sources.
    Otherwise when used as a subproject the master project will try
    to rebuild with it's own set of flags. These lack
    LIBFEEDBACK_COMPILATION which does not end well.
  * Fix typos
  * theme: Add timeout-completed event for alarms and stop watches
  * Update docs (Closes: #4, #8)
  * debian: Split out shared files.
    This allows other programs (like gnome-control-center) to consume the
    settings schema without having to depend on the daemon itself.

  [ Rasmus Thomsen ]
  * fbd-feedback-profile: use G_GSIZE_FORMAT instead of hardcoding lu.
    On 32-bit platforms lu doesn't apply since GType is defined as a gsize
    fixes #15

 -- Guido Günther <agx@sigxcpu.org>  Wed, 04 Mar 2020 16:46:36 +0100

feedbackd (0.0.0+git20200214) amber-phone; urgency=medium

  * Initial git snapshot

 -- Guido Günther <agx@sigxcpu.org>  Wed, 16 Oct 2019 21:22:33 +0200
0707010000001E000081A400000000000000000000000166F7A51300000B3F000000000000000000000000000000000000001F00000000feedbackd-0.5.0/debian/controlSource: feedbackd
Section: x11
Priority: optional
Maintainer: Guido Günther <agx@sigxcpu.org>
Build-Depends:
 dbus,
 debhelper-compat (= 13),
 dh-sequence-gir,
 gsettings-desktop-schemas <!nocheck>,
 gi-docgen <!nodoc>,
 gir1.2-gio-2.0-dev <!nogir>,
 json-glib-tools,
 libgirepository1.0-dev <!nogir>,
 libglib2.0-dev,
 libgmobile-dev,
 libgudev-1.0-dev,
 libgsound-dev,
 libjson-glib-dev,
 libumockdev-dev,
 meson,
 pkgconf,
 python3-docutils <!nodoc>,
 systemd-dev,
 umockdev,
 valac,
Standards-Version: 4.6.2
Homepage: https://source.puri.sm/Librem5/feedbackd
Rules-Requires-Root: no

Package: feedbackd
Architecture: any
Depends:
 ${misc:Depends},
 ${shlibs:Depends},
 feedbackd-common (>= ${source:Version}),
 sound-theme-freedesktop,
Recommends:
 gsettings-desktop-schemas,
Description: DBus service for haptic/visual/audio feedback
 Feedbackd is a DBus activated daemon that provides haptic/
 visual/audio feedback based on events selected from configurable
 profiles.
 .
 This package contains the daemon.

Package: feedbackd-common
Architecture: all
Depends:
 ${misc:Depends},
 ${shlibs:Depends},
Breaks:
 feedbackd (<< 0.0.0+git20200304),
Replaces:
 feedbackd (<< 0.0.0+git20200304),
Description: Shared files for feedbackd
 Feedbackd is a DBus activated daemon that provides haptic/
 visual/audio feedback based on events selected from configurable
 profiles.
 .
 This package contains the architecture-independent shared files.

Package: libfeedback-0.0-0
Architecture: any
Multi-Arch: same
Section: libs
Depends:
 ${misc:Depends},
 ${shlibs:Depends},
Recommends: feedbackd (>= ${binary:Version})
Description: Library for managing haptic/visual/audio feedback
 Feedbackd is a DBus activated daemon that provides haptic/
 visual/audio feedback based on events selected from configurable
 profiles.
 .
 This package contains the shared libraries for applications
 interfacing with Feedbackd and the API documentation.

Package: libfeedback-dev
Architecture: any
Multi-Arch: same
Section: libdevel
Depends:
 gir1.2-lfb-0.0 (= ${binary:Version}),
 libfeedback-0.0-0 (= ${binary:Version}),
 libglib2.0-dev,
 ${misc:Depends},
 ${shlibs:Depends},
Description: Development files for libfeedback
 Feedbackd is a DBus activated daemon that provides haptic/
 visual/audio feedback based on events selected from configurable
 profiles.
 .
 This package contains development files and Vala bindings to use when
 writing applications that interface with feedbackd.

Package: gir1.2-lfb-0.0
Architecture: any
Multi-Arch: same
Section: introspection
Depends:
 ${gir:Depends},
 ${misc:Depends},
 ${shlibs:Depends},
Description: GObject introspection data for libfeedback
 Feedbackd is a DBus activated daemon that provides haptic/
 visual/audio feedback based on events selected from configurable
 profiles.
 .
 This package contains introspection data for the libfeedback library.

0707010000001F000081A400000000000000000000000166F7A51300000835000000000000000000000000000000000000002100000000feedbackd-0.5.0/debian/copyrightFormat: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: feedbackd
Upstream-Contact: Guido Günther <agx@debian.org>
Source: https://source.puri.sm/Librem5/feedbackd

Files: *
Copyright: 2020 Purism SPC
License: GPL-3+

Files: debian/*
Copyright:
 2020 Purism SPC
 2020 Arnaud Ferraris <arnaud.ferraris@gmail.com>
License: GPL-3+

Files: debian/feedbackd.udev
Copyright: 2020 Purism SPC
License: LGPL-2.1+

Files: libfeedback/*
Copyright: 2020 Purism SPC
License: LGPL-2.1+

License: GPL-3+
 This package is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 .
 This package is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 .
 You should have received a copy of the GNU General Public License
 along with this program. If not, see <https://www.gnu.org/licenses/>
 .
 On Debian systems, the complete text of the GNU General
 Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".

License: LGPL-2.1+
 This package is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 .
 This package is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Lesser General Public License for more details.
 .
 You should have received a copy of the GNU Lesser General Public License
 along with this program. If not, see <https://www.gnu.org/licenses/>
 .
 On Debian systems, the complete text of the GNU Lesser General
 Public License version 3 can be found in "/usr/share/common-licenses/LGPL-2.1".
07070100000020000081A400000000000000000000000166F7A5130000001B000000000000000000000000000000000000003000000000feedbackd-0.5.0/debian/feedbackd-common.installusr/share/glib-2.0/schemas
07070100000021000081A400000000000000000000000166F7A5130000000F000000000000000000000000000000000000002600000000feedbackd-0.5.0/debian/feedbackd.docsNEWS
README.md
07070100000022000081A400000000000000000000000166F7A51300000060000000000000000000000000000000000000002900000000feedbackd-0.5.0/debian/feedbackd.installusr/bin/
usr/lib/systemd/user
usr/lib/udev/
usr/libexec/
usr/share/dbus-1/
usr/share/feedbackd/
07070100000023000081A400000000000000000000000166F7A5130000005F000000000000000000000000000000000000003300000000feedbackd-0.5.0/debian/feedbackd.lintian-overridesfeedbackd: appstream-metadata-missing-modalias-provide usr/lib/udev/rules.d/90-feedbackd.rules
07070100000024000081A400000000000000000000000166F7A51300000035000000000000000000000000000000000000002D00000000feedbackd-0.5.0/debian/feedbackd.maintscriptrm_conffile /etc/modules-load.d/feedbackd.conf 0.0.4
07070100000025000081A400000000000000000000000166F7A5130000008B000000000000000000000000000000000000002A00000000feedbackd-0.5.0/debian/feedbackd.manpages/usr/share/man/man1/fbcli.1
/usr/share/man/man1/fbd-theme-validate.1
/usr/share/man/man5/feedback-themes.5
/usr/share/man/man8/feedbackd.8
07070100000026000081A400000000000000000000000166F7A513000004AB000000000000000000000000000000000000002A00000000feedbackd-0.5.0/debian/feedbackd.postinst#!/bin/sh
# postinst script for feedbackd
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package

case "$1" in
    configure)
        if ! getent group feedbackd >/dev/null; then
            addgroup --quiet --system feedbackd
        fi

        # we ship udev rules, so trigger an update
        udevadm trigger --subsystem-match=leds --action=change || true
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

07070100000027000081A400000000000000000000000166F7A513000000C7000000000000000000000000000000000000002000000000feedbackd-0.5.0/debian/gbp.conf[DEFAULT]
debian-branch = main
debian-tag = v%(version)s
debian-tag-msg = %(pkg)s v%(version)s

[dch]
postedit = sed -i s"@^\( \+version *: '\)[0-9][^']\+\(',\)@\1$GBP_DEBIAN_VERSION\2@" meson.build
07070100000028000081A400000000000000000000000166F7A5130000001C000000000000000000000000000000000000002E00000000feedbackd-0.5.0/debian/gir1.2-lfb-0.0.install/usr/lib/*/girepository-1.0
07070100000029000081A400000000000000000000000166F7A51300000005000000000000000000000000000000000000002E00000000feedbackd-0.5.0/debian/libfeedback-0.0-0.docsNEWS
0707010000002A000081A400000000000000000000000166F7A5130000001E000000000000000000000000000000000000003100000000feedbackd-0.5.0/debian/libfeedback-0.0-0.install/usr/lib/*/libfeedback-*.so.0
0707010000002B000081A400000000000000000000000166F7A51300000BC5000000000000000000000000000000000000003100000000feedbackd-0.5.0/debian/libfeedback-0.0-0.symbolslibfeedback-0.0.so.0 libfeedback-0.0-0 #MINVER#
* Build-Depends-Package: libfeedback-dev
 LIBFEEDBACK_0_0_0@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_end_feedback@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_end_feedback_async@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_end_feedback_finish@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_end_reason_get_type@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_get_app_id@LIBFEEDBACK_0_0_0 0.2.0
 lfb_event_get_end_reason@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_get_event@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_get_feedback_profile@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_get_important@LIBFEEDBACK_0_0_0 0.2.1
 lfb_event_get_state@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_get_timeout@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_get_type@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_new@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_set_app_id@LIBFEEDBACK_0_0_0 0.2.0
 lfb_event_set_feedback_profile@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_set_important@LIBFEEDBACK_0_0_0 0.2.1
 lfb_event_set_timeout@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_state_get_type@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_trigger_feedback@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_trigger_feedback_async@LIBFEEDBACK_0_0_0 0.1.1
 lfb_event_trigger_feedback_finish@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_call_end_feedback@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_call_end_feedback_finish@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_call_end_feedback_sync@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_call_trigger_feedback@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_call_trigger_feedback_finish@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_call_trigger_feedback_sync@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_complete_end_feedback@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_complete_trigger_feedback@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_dup_profile@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_emit_feedback_ended@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_get_profile@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_get_type@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_interface_info@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_override_properties@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_proxy_get_type@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_proxy_new@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_proxy_new_finish@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_proxy_new_for_bus@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_proxy_new_for_bus_finish@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_proxy_new_for_bus_sync@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_proxy_new_sync@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_set_profile@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_skeleton_get_type@LIBFEEDBACK_0_0_0 0.1.1
 lfb_gdbus_feedback_skeleton_new@LIBFEEDBACK_0_0_0 0.1.1
 lfb_get_app_id@LIBFEEDBACK_0_0_0 0.1.1
 lfb_get_feedback_profile@LIBFEEDBACK_0_0_0 0.1.1
 lfb_get_proxy@LIBFEEDBACK_0_0_0 0.1.1
 lfb_init@LIBFEEDBACK_0_0_0 0.1.1
 lfb_is_initted@LIBFEEDBACK_0_0_0 0.1.1
 lfb_set_app_id@LIBFEEDBACK_0_0_0 0.1.1
 lfb_set_feedback_profile@LIBFEEDBACK_0_0_0 0.1.1
 lfb_uninit@LIBFEEDBACK_0_0_0 0.1.1
0707010000002C000081A400000000000000000000000166F7A513000001C8000000000000000000000000000000000000003000000000feedbackd-0.5.0/debian/libfeedback-dev.doc-baseDocument: libfeedback
Title: libfeedback Reference Manual
Author: Guido Günther
Abstract: A library to trigger feedback (such as haptic feedback)
 from your application. This document covers the C API,
 but it also useful for GObject introspection bindings
 of your favourite programming language.
Section: Programming

Format: HTML
Index: /usr/share/doc/libfeedback-dev/libfeedback-0/index.html
Files: /usr/share/doc/libfeedback-dev/libfeedback-0/*.html
0707010000002D000081A400000000000000000000000166F7A5130000002D000000000000000000000000000000000000002C00000000feedbackd-0.5.0/debian/libfeedback-dev.docsusr/share/doc/libfeedback-dev/libfeedback-0/
0707010000002E000081A400000000000000000000000166F7A51300000074000000000000000000000000000000000000002F00000000feedbackd-0.5.0/debian/libfeedback-dev.install/usr/include
/usr/share/gir-1.0/
/usr/share/vala/
/usr/lib/*/libfeedback-*.so
/usr/lib/*/pkgconfig/libfeedback-*.pc
0707010000002F000081A400000000000000000000000166F7A51300000052000000000000000000000000000000000000002D00000000feedbackd-0.5.0/debian/libfeedback-dev.linksusr/share/doc/libfeedback-dev/libfeedback-0 usr/share/devhelp/books/libfeedback-0
07070100000030000081A400000000000000000000000166F7A51300000029000000000000000000000000000000000000003900000000feedbackd-0.5.0/debian/libfeedback-dev.lintian-overrideslibfeedback-dev: privacy-breach-facebook
07070100000031000081A400000000000000000000000166F7A5130000004B000000000000000000000000000000000000002500000000feedbackd-0.5.0/debian/not-installedusr/include/gmobile/
usr/lib/*/libgmobile.*
usr/lib/*/pkgconfig/gmobile.pc
07070100000032000081ED00000000000000000000000166F7A51300000348000000000000000000000000000000000000001D00000000feedbackd-0.5.0/debian/rules#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

CONFIGURE_OPTS=--wrap-mode=default -Dudev=true

ifneq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
  CONFIGURE_OPTS += -Dtests=false
endif

ifeq (,$(filter nodoc,$(DEB_BUILD_PROFILES)))
  CONFIGURE_OPTS += -Dgtk_doc=true -Dman=true
endif

COMMON_PKG=feedbackd-common

docroot := $(CURDIR)/debian/tmp/usr/share/doc/

%:
	dh $@ --builddirectory=_build

override_dh_installdocs:
	dh_installdocs -p$(COMMON_PKG) NEWS
ifeq ($(filter nodoc,$(DEB_BUILD_PROFILES)),)
	mkdir -p $(docroot)/libfeedback-dev/libfeedback-0
	mv $(docroot)/libfeedback-0 $(docroot)/libfeedback-dev/
endif
	dh_installdocs

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIGURE_OPTS)

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dbus-run-session ninja -C _build test
endif
07070100000033000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001E00000000feedbackd-0.5.0/debian/source07070100000034000081A400000000000000000000000166F7A5130000000D000000000000000000000000000000000000002500000000feedbackd-0.5.0/debian/source/format3.0 (native)
07070100000035000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001D00000000feedbackd-0.5.0/debian/tests07070100000036000081ED00000000000000000000000166F7A513000000E6000000000000000000000000000000000000002800000000feedbackd-0.5.0/debian/tests/build-test#!/usr/bin/make -f

CFLAGS=$(shell pkg-config --cflags libfeedback-0.0)
LIBS=$(shell pkg-config --libs libfeedback-0.0)

t1: debian/tests/build-test.c
	gcc -o $@ $(CFLAGS) $< $(LIBS)
	@echo "Build test of $< succeeded"
	@rm -f $@
07070100000037000081A400000000000000000000000166F7A5130000009B000000000000000000000000000000000000002A00000000feedbackd-0.5.0/debian/tests/build-test.c#define LIBFEEDBACK_USE_UNSTABLE_API
#include <libfeedback.h>

int
main (int    argc,
      char **argv)
{
  lfb_init("org.sigxcpu.autopkgtest1", NULL);
}
07070100000038000081A400000000000000000000000166F7A5130000018B000000000000000000000000000000000000002500000000feedbackd-0.5.0/debian/tests/controlTests: build-test
Depends:
 build-essential,
 libfeedback-dev,
 pkg-config,
Restrictions: allow-stderr, superficial

Test-Command: python3 -c 'import gi; from gi.repository import Lfb'
Depends:
 gir1.2-lfb-0.0,
 python3,
 python3-gi,
Restrictions: allow-stderr, superficial

Test-Command: fbd-theme-validate /usr/share/feedbackd/themes/default.json
Depends:
 feedbackd
Restrictions: superficial
07070100000039000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001400000000feedbackd-0.5.0/doc0707010000003A000081A400000000000000000000000166F7A513000014BA000000000000000000000000000000000000002F00000000feedbackd-0.5.0/doc/Event-naming-spec-0.0.0.mdTitle: Event Naming Specification
Slug: Event Naming Specification

# Overview

This specification gives direction on how to name the Event types
(triggering feedbacks such as running the haptic motor or blinking an
LED) that are available for use by applications, when creating a
feedback theme. It does so by laying out a standard naming scheme for
Event creation, as well as providing a minimal list of must have
Events, and a larger list with many more examples to help with the
creation of extended Events for third party applications, with
different event types and usage.

This is similar in spirit (and heavily based on) to the [Sound naming spec][].

# Context

The list of default contexts for the feedback theme are:

- Alerts: Events to alert the user of an action or event which may
  have a major impact on the system or their current use
- Notifications: Events to trigger feedback to notify the user that
  the system, or their current use case has changed state in some way,
  e.g. new email arriving
- Actions:	Event that notify the user on their actions.
- Input Event: This triggers feedbacks that give direct response to
  input events from the user, such as key presses on an on screen
  keyboard

# Event naming guides

Here we define some guidelines for when creating new Event names
that extend the standardized list of Event names defined here, in
order to provide Events for more specific events and usages.

Event names are in the en_US.US_ASCII locale. This means that the
characters allowed in the Event names must fall within the US-ASCII
character set. As a further restriction, all Event names may only
contain lowercase letters, numbers, underscore, dash, or period
characters. Spaces, colons, slashes, and backslashes are not
allowed. Also, sound names must be spelled as they are in the en_US
dictionary.

Events for branded applications should be named the same as the binary
executable for the application, prefixed by the string “x-”, to avoid
name space clashes with future standardized names. Example:
“x-openoffice-foobar”.

## Standard Event names

This section describes the standard Event names that should be used
by artists when creating themes, and by developers when writing
applications which will use the Feedback Theme Specification. Application
developers should only use event names from the *Applications*
section as the other sections are reserved for system components.

### Applications

These events are meant to be used by applications.

#### Notifications

- camera-focus: The event used when the camera got focus.
- camera-shutter: The event used when a photo was taken.
- message-new-instant: The event used when a new IM is received.
- message-new-sms:  The event used when a new sms is received.
- message-new-email:  The event used when a new email is received.
- message-missed-email: The event used when an email was received but not seen by the user.
- message-missed-instant: The event used when a instant message was received but not seen by the user.
- message-missed-notification: The event used when a notification was shown but not seen by the user.
- message-missed-sms: The event used when a sms message was received but not seen by the user.
- phone-incoming-call: The event used when a phone/voip call is coming in.
- phone-missed-call: The event used when a phone/voip call is was incoming but not answered.
- phone-outgoing-busy: The event used when for outgoing phone/voip call when the responder is busy/not available.
- phone-hangup: The event used when a phone/voip call is hung up.
- phone-failure: The event used when a phone/voip call is terminated because of a failure.
- alarm-clock-elapsed: A user configured alarm elapsed.
- timeout-completed: A user configured timeout completed (e.g. a stop watch).

#### Actions

- message-sent-instant: The sound used when a new IM is sent.

#### Input Events

- button-pressed:	The event used when a button is pressed.
- button-released:  The event used when a button is released.

### System Components

These events are meant to be used by applications.

### Actions

- bell-terminal: The sound to use as a terminal bell.
- screen-capture: A screenshot was made
- theme-demo: A event that should be played for demoing this theme. Usually
  this should just be an alias for a very representative sound (such as
  a incoming phone call) of a theme that would work nicely as a demo event for
  a theme in the theme selector dialog.

### Alerts

- battery-low: The Event used when the battery is low (below 20%, for example).
- power-unplug-battery-low: The power cable has been unplugged and the battery level is low.

### Notifications

- battery-caution: The event used when the battery is nearing exhaustion (below 40%, for example).
- battery-full:	The event used when the battery is fully loaded up.
- device-added: The event used when a device has become available to the desktop, i.e. due to USB plugging.
- message-new-cellbroadcast: The event used when a new cell broadcast message is received.
- power-plug: The power cable has been plugged in.
- power-unplug: The power cable has been unplugged.

#### Input Events

- window-close:     The sound used when an existing window is closed.


[Sound naming spec]: http://0pointer.de/public/sound-naming-spec.html
0707010000003B000081A400000000000000000000000166F7A513000009AF000000000000000000000000000000000000003100000000feedbackd-0.5.0/doc/Feedback-theme-spec-0.0.0.mdTitle: Feedback Theme Specification
Slug: Feedback Theme Specification

# Overview

A feedback theme defines the kind of feedback that events (as
described in the [Event naming spec][]) will trigger.

The feedback daemon is responsible to select an appropriate feedback
theme for a given device.

# Definitions

- Feedback: A feedback is something that notifies the user that
  s.th. happened (e.g. a played sound, the vibration of a haptic
  motor or led blinking).

- Feedback theme: A feedback theme is a set of feedbacks grouped by
  profiles. Each feedback is mapped to a single event.

- Feedback Profile: A feedback profile groups feedbacks by
  "noisiness". The currently defined profiles names are
  *full*, *quiet* and *silent*. With *full* being the noisiest
  profile.

- Event: What the user should be notified about. The event
  names are built according to the [Event naming spec][].

# Implementation

When an application requests feedback for an event via the feedback daemon
the daemon selects the provided feedback like this,
capping the noisiness for each limit:

1. The currently selected profile provides the (global) upper limit for noisiness

2. Per application settings impose another upper limit

3. Per event noisiness is the last noisiness constraint

4. All feedback consistent with the resulting limit are selected
   and run to provide the feedback to the user

With the above a feedback theme in YAML format could look like:

```yaml
full:
    - event-name: phone-incoming-call
      type: Sound
      effect: phone-incoming-call
    - event-name: message-new-sms
    ...
quiet:
    - event-name: phone-incoming-call
      type: Vibra
      duration: 0.5s
    - event-name: message-new-sms
    ...
silent:
    - event-name: phone-incoming-call
      type: Led
      location: Front
      Color: Green
      Interval: 0.2s
    - event-name: message-new-sms
    ...
```

At the time of writing the theme format is daemon dependent. E.g. feedbackd
uses a format [similar to the above in JSON](https://source.puri.sm/Librem5/feedbackd/-/blob/main/data/default.json)


# Recommendations

- The silent theme should not produce any audible feedback. This includes
  the buzzing of haptic motors.
- The quiet theme should not play any sounds. Haptic motors and LEDs can
  be used.
- The full feedback theme can use any available feedback mechanisms

[Event naming spec]: https://source.puri.sm/Librem5/feedbackd/-/blob/main/doc/Event-naming-spec-0.0.0.md
0707010000003C000081A400000000000000000000000166F7A513000004FB000000000000000000000000000000000000002300000000feedbackd-0.5.0/doc/build-howto.mdTitle: Compiling with libfeedback
Slug: building

# Compiling with libfeedback

If you need to build libfeedback, get the source from
[here](https://source.puri.sm/Librem5/feedbackd) and see the `README.md` file.

## Using `pkg-config`

Like other GObject based libraries, libfeedback uses `pkg-config` to provide compiler
options. The package name is `libfeedback-0.0`.

When using the Meson build system you can declare a dependency like:

```meson
dependency('libfeedback-0.0')
```

## Bundling the Library

### Using a Subproject

Libfeedback can be used as a Meson subproject.  Create a
`subprojects/libfeedback.wrap` file with the following contents:

```ini
[wrap-git]
directory=libfeedback
url=https://source.puri.sm/Librem5/feedbackd.git
revision=main
depth=1
```

Add this to your `meson.build`:

```meson
libfeedback = dependency(
  'libfeedback-0.0',
  version: '>= 0.0.1',
  fallback: ['libfeedback', 'libfeedback_dep'],
  default_options: [
    'daemon=false',
    'man=false',
    'gtk_doc=false',
    'vapi=false',
    'tests=false',
  ]
)
```

Then the `libfeedback` variable can be used as a dependency.

# Next Steps

Once libfeedback has been compiled and included into your project, it needs to be
initialized. See [Initialization](initialization.html).
0707010000003D000081A400000000000000000000000166F7A5130000044D000000000000000000000000000000000000001E00000000feedbackd-0.5.0/doc/fbcli.rst.. _fbcli(1):

=====
fbcli
=====

------------------------
Emit events to feedbackd
------------------------

SYNOPSIS
--------
|   **fbcli** [OPTIONS...]


DESCRIPTION
-----------

``fbcli`` can be used to submit events to ``feedbackd`` to trigger
audio, visual or haptic feedback.

OPTIONS
=======

``-h``, ``--help``
   print help and exit

``-E=EVENT``; ``--event=EVENT``
  Submit the given event to ``feedbackd``. Valid events are listes in
  the event naming spec at
  https://source.puri.sm/Librem5/feedbackd/-/blob/main/doc/Event-naming-spec-0.0.0.md

``-t=TIMEOUT``; ``--timeout=TIMEOUT``
  The timeout in seconds after which feedback for the given event should
  be stopped.

``-P=PROFILE``; ``--profile=PROFILE``
  The feedback profile (``full``, ``quiet``, ``silent``)
  to use for the given event. If no event is specified then the global
  feedback profile is changed.

``-w=TIMEOUT``; ``--watch=TIMEOUT``
  Maximum timeout to wait for the feedback for the given event to end and
  ``fbcli`` to exit.

See also
========

``feedbackd(8)`` ``fbd-theme-validate(1)`` ``feedback-themes(5)``
0707010000003E000081A400000000000000000000000166F7A51300000475000000000000000000000000000000000000002B00000000feedbackd-0.5.0/doc/fbd-theme-validate.rst.. _fbd-theme-validate(1):

==================
fbd-theme-validate
==================

-------------------------
Validate feedbackd themes
-------------------------

SYNOPSIS
--------
|   **fbd-theme-validate** [OPTIONS...] <FILE>


DESCRIPTION
-----------

``fbd-theme-validate`` parses and validates the given feedbackd theme
file. If the theme specifies parent themes then these are parsed and
validates as well.

OPTIONS
=======

``-h``, ``--help``
   print help and exit

``--version``
   print version information and exit

``--compatible=COMPATIBLE``
  Specify the device compatible to use. Specify this if you validate a user
  theme and want to simulate how it would look like on a device with compatible
  ```COMPATIBLE```.

EXAMPLES
========

Validate a custom theme in the users home directory the same way as it would be
loaded on a Librem 5:

::

    fbd-theme-validate --compatible=purism,librem5 ~/.config/feedbackd/themes/custom.json

Validate the device theme for a OnePlus 6T:

::

    fbd-theme-validate /usr/share/feedbackd/themes/oneplus,fajita.json

See also
========

``feedbackd(8)`` ``fbcli(1)`` ``feedback-themes``
0707010000003F000081A400000000000000000000000166F7A51300000755000000000000000000000000000000000000002800000000feedbackd-0.5.0/doc/feedback-themes.rst.. _feedback-themes(5):

===============
feedback-themes
===============

---------------------------------
Theme configuration for feedbackd
---------------------------------

DESCRIPTION
-----------

In order to reflect device specifics and user overrides the feedback
(such as sound, haptic or led) that is being triggered by an event can
be configured and overridden by so called themes. Feedback themes use a JSON
format that can be validated with ``fbd-theme-validate``.

For details on how to create or modify feedback themes see
``feedbackd's documentation`` at https://source.puri.sm/Librem5/feedbackd#feedback-theme

Feedback types
--------------

To build a theme you can use several different feedback types:

- `Sound`:  Plays a sound from the installed sound theme
- `VibraRumble`: A single rumble using the haptic motor
- `VibraPeriodic`: A periodic rumble using the haptic motor
- `Led`: A LED blinking in a periodic pattern

Sound feedback
~~~~~~~~~~~~~~

Sound feedbacks specify an event name from a XDG sound theme. Sound themes
are described in the ``Sound theme spec`` at https://freedesktop.org/wiki/Specifications/sound-theme-spec/

VibraRumble feedback
~~~~~~~~~~~~~~~~~~~~

The `VibraRumble` feedback uses a single property

- `duration`: The duration of the rumble in ms.

LED feedback
~~~~~~~~~~~~

The `Led` feedback type uses two properties to specify the way a LED blinks.

- `color`: This specifies the color a LED should blink with. It supports the fixed color names `red`,
  `green`, `blue` and `white` as well as values in the RGB HEX  format (`#RRGGBB`) where
  `RR`, `GG` and `BB` are two digit  hex value between `00` and `FF` specifying the value of
  each component. E.g. `#00FFFF` corresponds to cyan color.
- `frequency`: The LEDs blinkinig frequencey in mHz.

See also
========

``feedbackd(8)`` ``fbcli(1)`` ``fbd-theme-validate(1)``
07070100000040000081A400000000000000000000000166F7A51300000696000000000000000000000000000000000000002200000000feedbackd-0.5.0/doc/feedbackd.rst.. _feedbackd(8):

=========
feedbackd
=========

--------------------------------------
A daemon to provide feedback on events
--------------------------------------

SYNOPSIS
--------
|   **feedbackd** [OPTIONS...]


DESCRIPTION
===========

``Feedbackd`` is a daemon that runs in the users session to trigger
event feedback such as playing a sound, trigger a haptic motor or blink
a LED.

The feedback triggered by a given event is determined by the feedback theme in
use. Events are submitted via a DBus API.

Any feedback triggered by a client via an event will be stopped latest when the
client disconnects from DBus. This makes sure all feedbacks get canceled if the
app that triggered it crashes.

For details refer to the event and feedback theme specs at
`<https://source.puri.sm/Librem5/feedbackd/>`__

Options
=======

``-h``, ``--help``
   print help and exit

Configuration
=============

These gsettings are used by ``feedbackd``:

- `org.gnome.desktop.sound`

    - `sound-theme`: The sound theme used for sound events

- `org.sigxcpu.feedbackd`

    - `profile`: The current overall feedback profile
    - `allow-important`: List of apps that can override the feedback level
      (useful for e.g. allowing the alarm clock to also emit sound when
      device is in silent mode).
    - `prefer-flash`: Prefer camera flash over status LED
    - `theme`: The feedback theme to use. This can be used to override
      the feedback theme picked by feedbackd based on device information.

- `org.sigxcpu.feedbackd.application`

   - `profile`: Per application profile levels

See also
========

``fbcli(1)`` ``fbd-theme-validate(1)`` ``feedback-themes(5)`` ``gsettings(1)``
07070100000041000081A400000000000000000000000166F7A513000003E1000000000000000000000000000000000000002600000000feedbackd-0.5.0/doc/initialization.mdTitle: Initialization
Slug: initialization

# Initialization

Before using libfeedback, it must be initialized. To use the library
call [func@Lfb.init]() with the id of your application (usually
the desktop file name without the .desktop extension). For that you
include the `libfeedback.h` header. Since the API is considered
unstable at this point in time you need to acknowledge this by
definining `LIBFEEDBACK_USE_UNSTABLE_API`:

```c
  #define LIBFEEDBACK_USE_UNSTABLE_API
  #include <libfeedback.h>

  int main(void)
  {
     g_autoptr (GError) *err = NULL;
     if (lfb_init ("com.example.appid", &err)) {
       g_error ("%s", err->message);
     }
     ...
     lfb_uninit ();
     return 0;
  }
```

You can also acknowledge this with the definition option of your C
compiler, like `-DFEEDBACK_USE_UNSTABLE_API`.

After initializing the library you can trigger feedback using
[class@Lfb.Event] objects.  When your application finishes call
[func@Lfb.uninit]() to free any resources:
07070100000042000081A400000000000000000000000166F7A5130000049F000000000000000000000000000000000000002800000000feedbackd-0.5.0/doc/libfeedback.toml.in[library]
version = "@VERSION@"
description = "A library to trigger feedback (such as haptic feedback) via events sent by your application."
authors = "Purism SPC"
license = "LGPL-2.1-or-later"
browse_url = "https://source.puri.sm/Librem5/feedbackd/"
repository_url = "https://source.puri.sm/Librem5/feedbackd.git"
website_url = "https://source.puri.sm/Librem5/feedbackd/"
dependencies = [
  "Gio-2.0",
  "GLib-2.0",
]
devhelp = true
search_index = true

[dependencies."Gio-2.0"]
name = "GIO"
description = "GObject Interfaces and Objects, Networking, IPC, and I/O"
docs_url = "https://docs.gtk.org/gio/"

[dependencies."GLib-2.0"]
name = "GLib	"
description = "The base type system library"
docs_url = "https://docs.gtk.org/glib/"

[theme]
name = "basic"
show_index_summary = true
show_class_hierarchy = true

[source-location]
# The base URL for the web UI
base_url = "https://source.puri.sm/Librem5/feedbackd/-/blob/main/"
# The format for links, using "filename" and "line" for the format
file_format = "{filename}#L{line}"

[extra]
content_files = [
  "overview.md",
  "build-howto.md",
  "initialization.md",
  "Event-naming-spec-0.0.0.md",
  "Feedback-theme-spec-0.0.0.md",
]
07070100000043000081A400000000000000000000000166F7A5130000074A000000000000000000000000000000000000002000000000feedbackd-0.5.0/doc/meson.buildif get_option('gtk_doc')

expand_content_md_files = [
  'overview.md',
  'build-howto.md',
  'initialization.md',
  'Event-naming-spec-0.0.0.md',
  'Feedback-theme-spec-0.0.0.md',
]

toml_data = configuration_data()
toml_data.set('VERSION', meson.project_version())

libfeedback_toml = configure_file(
  input: 'libfeedback.toml.in',
  output: 'libfeedback.toml',
  configuration: toml_data
)

dependency('gi-docgen', version: '>= 2021.1',
           fallback: ['gi-docgen', 'dummy_dep'],
           native: true,
           required: get_option('gtk_doc'))

gidocgen = find_program('gi-docgen')

docs_dir = datadir / 'doc'

custom_target('libfeedback-doc',
  input: [ libfeedback_toml, libfeedback_gir[0] ],
  output: 'libfeedback-0',
  command: [
    gidocgen,
    'generate',
    '--quiet',
    '--add-include-path=@0@'.format(meson.current_build_dir() / '../src'),
    '--config=@INPUT0@',
    '--output-dir=@OUTPUT@',
    '--no-namespace-dir',
    '--content-dir=@0@'.format(meson.current_source_dir()),
    '@INPUT1@',
  ],
  depend_files: [ expand_content_md_files ],
  build_by_default: true,
  install: true,
  install_dir: docs_dir,
)

endif

if get_option('man')
  manpages = [
    ['fbcli', 1],
    ['fbd-theme-validate', 1],
    ['feedbackd', 8],
    ['feedback-themes', 5],
  ]

  rst2man = find_program('rst2man', 'rst2man.py', required: false)
  rst2man_flags = [
    '--syntax-highlight=none',
  ]

  foreach manpage: manpages
    man_name = manpage[0]
    man_section = manpage[1]

    custom_target('man-@0@'.format(man_name),
      input: '@0@.rst'.format(man_name),
      output: '@0@.@1@'.format(man_name, man_section),
      command: [
        rst2man,
        rst2man_flags,
        '@INPUT@',
      ],
      capture: true,
      install: true,
      install_dir: get_option('mandir') / 'man@0@'.format(man_section),
    )
  endforeach
endif
07070100000044000081A400000000000000000000000166F7A5130000038C000000000000000000000000000000000000002000000000feedbackd-0.5.0/doc/overview.mdTitle: Overview
Slug: Overview

# Libfeedback Introduction

The purpose of libfeedback is to make it simple to supply audible,
haptic and visual feedback to the user. This is done by
notifying a feedback_daemon over DBus that a certain event
happened. The daemon then selects the appropriate feedbacks (such
as a buzzing haptic motor or playing an audio file) based on the
user session's current feedback profile, feedback theme and
available hardware.

Events are identified by strings like `message-new-sms` or
`message-new-sms`. The available event names are described in the
[Event naming specification](Event-naming-spec-0.0.0.html).

Libfeedback provides synchronous and asynchronous APIs to trigger and
stop feedback for these events and is usable from other languages than
C by GObject introspection.

See [Compiling with libfeedback](build-howto.html) on how to include
libfeedback in your project.
07070100000045000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001900000000feedbackd-0.5.0/examples07070100000046000081ED00000000000000000000000166F7A51300000264000000000000000000000000000000000000002400000000feedbackd-0.5.0/examples/example.py#!/usr/bin/python3
#
# depends on GObject introspection data for libfeedback
#
# After building from source you can start this example like this:
#   _build/run examples/example.py
# Otherwise like this:
#   GI_TYPELIB_PATH=</somepath/girepository-x.y/> example.py

import gi
import time
gi.require_version('Lfb', '0.0')
from gi.repository import Lfb

Lfb.init('org.sigxcpu.lfbexample')
event = Lfb.Event.new('phone-incoming-call')
event.trigger_feedback()
# feedbackd terminates feedback from clients that disconnect from DBus to avoid
# feedback not being stopped. So wait a bit before quitting:
time.sleep(3)
07070100000047000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001C00000000feedbackd-0.5.0/libfeedback07070100000048000081A400000000000000000000000166F7A513000062FC000000000000000000000000000000000000002800000000feedbackd-0.5.0/libfeedback/lfb-event.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: LGPL-2.1+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "libfeedback.h"
#include "lfb-priv.h"

#include <gio/gio.h>

/**
 * LfbEvent:
 *
 * An event triggering feedback to the user
 *
 * #LfbEvent represents an event that should trigger
 * audio, haptic and/or visual feedback to the user by triggering
 * feedback on a feedback daemon. Valid event names are specified
 * in the
 * [Event naming specification](Event-naming-spec-0.0.0.html).
 *
 * One event can trigger multiple feedbacks at once (e.g. audio and
 * haptic feedback). This is determined by the feedback theme in
 * use (which is not under the appliction's control) and the active
 * feedback profile (see [func@Lfb.set_feedback_profile].
 *
 * After initializing the library via [func@Lfb.init] feedback can be
 * triggered like:
 *
 * ```c
 *   g_autoptr (GError) err = NULL;
 *   LfbEvent *event = lfb_event_new ("message-new-instant");
 *   lfb_event_set_timeout (event, 0);
 *   if (!lfb_event_trigger_feedback (event, &err))
 *     g_warning ("Failed to trigger feedback: %s", err->message);
 * ```
 *
 * When all feedback for this event has ended the [signal@LfbEvent::feedback-ended]
 * signal is emitted. If you want to end the feedback ahead of time use
 * [method@LfbEvent.end_feedback]:
 *
 * ```c
 *   if (!lfb_event_end_feedback (event, &err))
 *     g_warning ("Failed to end feedback: %s", err->message);
 * ```
 *
 * Since these methods involve DBus calls there are asynchronous variants
 * available, e.g. [method@LfbEvent.trigger_feedback_async]:
 *
 * ```c
 *   static void
 *   on_feedback_triggered (LfbEvent      *event,
 *                          GAsyncResult  *res,
 *                          gpointer      unused)
 *   {
 *      g_autoptr (GError) err = NULL;
 *      if (!lfb_event_trigger_feedback_finish (event, res, &err)) {
 *         g_warning ("Failed to trigger feedback for %s: %s",
 *                    lfb_event_get_event (event), err->message);
 *      }
 *   }
 *
 *   static void
 *   my_function ()
 *   {
 *     LfbEvent *event = lfb_event_new ("message-new-instant");
 *     lfb_event_trigger_feedback_async (event, NULL,
 *                                      (GAsyncReadyCallback)on_feedback_triggered,
 *                                      NULL);
 *   }
 * ```
 */

enum {
  PROP_0,
  PROP_EVENT,
  PROP_TIMEOUT,
  PROP_STATE,
  PROP_END_REASON,
  PROP_FEEDBACK_PROFILE,
  PROP_IMPORTANT,
  PROP_APP_ID,
  PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];

enum {
      SIGNAL_FEEDBACK_ENDED,
      N_SIGNALS,
};
static guint signals[N_SIGNALS];

typedef struct _LfbEvent {
  GObject        parent;

  char          *event;
  gint           timeout;
  gchar         *profile;
  gboolean       important;
  char          *app_id;

  guint          id;
  LfbEventState  state;
  gint           end_reason;
  gulong         handler_id;
} LfbEvent;

G_DEFINE_TYPE (LfbEvent, lfb_event, G_TYPE_OBJECT);

typedef struct _LfbAsyncData {
  LfbEvent *event;
  GTask    *task;
} LfbAsyncData;

static void
lfb_event_set_state (LfbEvent *self, LfbEventState state)
{
  if (self->state == state)
    return;

  self->state = state;
  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_STATE]);
}

static void
lfb_event_set_end_reason (LfbEvent *self, LfbEventEndReason reason)
{
  if (self->end_reason == reason)
    return;

  self->end_reason = reason;
  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_END_REASON]);
}

static GVariant *
build_hints (LfbEvent *self)
{
  GVariantBuilder hints_builder;

  g_variant_builder_init (&hints_builder, G_VARIANT_TYPE ("a{sv}"));
  if (self->profile)
    g_variant_builder_add (&hints_builder, "{sv}", "profile", g_variant_new_string (self->profile));
  if (self->important)
    g_variant_builder_add (&hints_builder, "{sv}", "important", g_variant_new_boolean (self->important));
  return g_variant_builder_end (&hints_builder);
}

static void
on_trigger_feedback_finished (LfbGdbusFeedback *proxy,
                              GAsyncResult     *res,
                              LfbAsyncData     *data)

{
  GTask *task = data->task;
  LfbEvent *self = data->event;
  g_autoptr (GError) err = NULL;
  gboolean success;

  g_return_if_fail (G_IS_TASK (task));
  g_return_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy));
  g_return_if_fail (LFB_IS_EVENT (self));

  success = lfb_gdbus_feedback_call_trigger_feedback_finish (proxy,
                                                             &self->id,
                                                             res,
                                                             &err);

  lfb_event_set_state (self, success ? LFB_EVENT_STATE_RUNNING : LFB_EVENT_STATE_ERRORED);
  if (!success) {
    g_task_return_error (task, g_steal_pointer (&err));
  } else {
    g_task_return_boolean (task, TRUE);
    _lfb_active_add_id (self->id);
  }

  g_free (data);
  g_object_unref (task);
  g_object_unref (self);
}

static void
on_end_feedback_finished (LfbGdbusFeedback *proxy,
                          GAsyncResult     *res,
                          LfbAsyncData     *data)

{
  GTask *task = data->task;
  LfbEvent *self = data->event;
  g_autoptr (GError) err = NULL;
  gboolean success;

  g_return_if_fail (G_IS_TASK (task));
  g_return_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy));
  g_return_if_fail (LFB_IS_EVENT (self));

  success = lfb_gdbus_feedback_call_end_feedback_finish (proxy,
                                                         res,
                                                         &err);
  if (!success) {
    g_task_return_error (task, g_steal_pointer (&err));
  } else
    g_task_return_boolean (task, TRUE);

  g_free (data);
  g_object_unref (task);
  g_object_unref (self);
}

static void
lfb_event_set_property (GObject      *object,
                        guint         property_id,
                        const GValue *value,
                        GParamSpec   *pspec)
{
  LfbEvent *self = LFB_EVENT (object);

  switch (property_id) {
  case PROP_EVENT:
    g_free (self->event);
    self->event = g_value_dup_string (value);
    g_object_notify_by_pspec (G_OBJECT (self), props[PROP_EVENT]);
    break;
  case PROP_TIMEOUT:
    lfb_event_set_timeout (self, g_value_get_int (value));
    break;
  case PROP_FEEDBACK_PROFILE:
    lfb_event_set_feedback_profile (self, g_value_get_string (value));
    break;
  case PROP_IMPORTANT:
    lfb_event_set_important (self, g_value_get_boolean (value));
    break;
  case PROP_APP_ID:
    lfb_event_set_app_id (self, g_value_get_string (value));
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}


static void
lfb_event_get_property (GObject    *object,
                        guint       property_id,
                        GValue     *value,
                        GParamSpec *pspec)
{
  LfbEvent *self = LFB_EVENT (object);

  switch (property_id) {
  case PROP_EVENT:
    g_value_set_string (value, self->event);
    break;
  case PROP_TIMEOUT:
    g_value_set_int (value, self->timeout);
    break;
  case PROP_FEEDBACK_PROFILE:
    g_value_set_string (value, lfb_event_get_feedback_profile (self));
    break;
  case PROP_IMPORTANT:
    g_value_set_boolean (value, lfb_event_get_important (self));
    break;
  case PROP_APP_ID:
    g_value_set_string (value, lfb_event_get_app_id (self));
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
lfb_event_finalize (GObject *object)
{
  LfbEvent *self = LFB_EVENT (object);

  /* Signal handler is disconnected automatically due to g_signal_connect_object */
  self->handler_id = 0;

  g_clear_pointer (&self->event, g_free);
  g_clear_pointer (&self->profile, g_free);
  g_clear_pointer (&self->app_id, g_free);

  G_OBJECT_CLASS (lfb_event_parent_class)->finalize (object);
}

static void
lfb_event_class_init (LfbEventClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->set_property = lfb_event_set_property;
  object_class->get_property = lfb_event_get_property;

  object_class->finalize = lfb_event_finalize;

  /**
   * LfbEvent:event:
   *
   * The type of event from the Event naming spec, e.g. 'message-new-instant'.
   */
  props[PROP_EVENT] =
    g_param_spec_string (
      "event",
      "Event",
      "The name of the event triggering the feedback",
      NULL,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  /**
   * LfbEvent:timeout:
   *
   * How long feedback should be provided in seconds. The special value
   * %-1 uses the natural length of each feedback while %0 plays each feedback
   * in a loop until ended explicitly via e.g. [method@LfbEvent.end_feedback].
   */
  props[PROP_TIMEOUT] =
    g_param_spec_int (
      "timeout",
      "Timeout",
      "When the event should timeout",
      -1, G_MAXINT, -1,
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  props[PROP_STATE] =
    g_param_spec_enum (
      "state",
      "State",
      "The event's state",
      LFB_TYPE_EVENT_STATE,
      LFB_EVENT_END_REASON_NATURAL,
      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_END_REASON] =
    g_param_spec_enum (
      "end-reason",
      "End reason",
      "The reason why the feedbacks ended",
      LFB_TYPE_EVENT_END_REASON,
      LFB_EVENT_END_REASON_NATURAL,
      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  /**
   * LfbEvent:feedback-profile:
   *
   * The name of the feedback profile to use for this event. See
   * [method@LfbEvent.set_feedback_profile] for details.
   */
  props[PROP_FEEDBACK_PROFILE] =
    g_param_spec_string (
      "feedback-profile",
      "Feedback profile",
      "Feedback profile to use for this event",
      NULL,
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  /**
   * LfbEvent:important:
   *
   * Whether to flag this event as important.
   * [method@LfbEvent.set_important] for details.
   */
  props[PROP_IMPORTANT] =
    g_param_spec_boolean (
      "important",
      "Important",
      "Whether to flags this event as important",
      FALSE,
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  /**
   * LfbEvent:app-id:
   *
   * The application id to use for the event.
   * [method@LfbEvent.set_feedback_profile] for details.
   */
  props[PROP_APP_ID] =
    g_param_spec_string (
      "app-id",
      "Application Id",
      "The Application id to use for this event",
      NULL,
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);

  /**
   * LfbEvent::feedback-ended:
   *
   * Emitted when all feedbacks triggered by the event have ended.
   */
  signals[SIGNAL_FEEDBACK_ENDED] = g_signal_new ("feedback-ended",
                                                 G_TYPE_FROM_CLASS (klass),
                                                 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
                                                 NULL,
                                                 G_TYPE_NONE,
                                                 0);
}

static void
lfb_event_init (LfbEvent *self)
{
  self->timeout = -1;
  self->state = LFB_EVENT_STATE_NONE;
  self->end_reason = LFB_EVENT_END_REASON_NATURAL;
}

/**
 * lfb_event_new:
 * @event: The event's name.
 *
 * Creates a new [class@Lfb.Event] based on the given event
 * name. See [property@Lfb.Event:event] for details.
 *
 * Returns: The [class@Lfb.Event].
 */
LfbEvent *
lfb_event_new (const char *event)
{
  return g_object_new (LFB_TYPE_EVENT, "event", event, NULL);
}

static void
on_feedback_ended (LfbEvent         *self,
                   guint             event_id,
                   guint             reason,
                   LfbGdbusFeedback *proxy)
{
  g_return_if_fail (LFB_IS_EVENT (self));
  g_return_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy));

  if (event_id != self->id)
    return;

  lfb_event_set_end_reason (self, reason);
  lfb_event_set_state (self, LFB_EVENT_STATE_ENDED);
  g_signal_emit (self, signals[SIGNAL_FEEDBACK_ENDED], 0);
  _lfb_active_remove_id (self->id);
  self->id = 0;
  g_signal_handler_disconnect (proxy, self->handler_id);
  self->handler_id = 0;
}

/**
 * lfb_event_trigger_feedback:
 * @self: The event to trigger feedback for.
 * @error: The returned error information.
 *
 * Tells the feedback server to provide proper feedback for the give
 * event to the user.
 *
 * Returns: %TRUE if successful. On error, this will return %FALSE and set
 *          @error.
 */
gboolean
lfb_event_trigger_feedback (LfbEvent *self, GError **error)
{
  LfbGdbusFeedback *proxy;
  gboolean success;
  const char *app_id;

  g_return_val_if_fail (LFB_IS_EVENT (self), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

   if (!lfb_is_initted ())
     g_error ("You must call lfb_init() before triggering events.");

   proxy = _lfb_get_proxy ();
   g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), FALSE);

   if (self->handler_id == 0) {
     self->handler_id = g_signal_connect_object (proxy,
                                                 "feedback-ended",
                                                 G_CALLBACK (on_feedback_ended),
                                                 self,
                                                 G_CONNECT_SWAPPED);
   }

   app_id = self->app_id ?: lfb_get_app_id ();
   success =  lfb_gdbus_feedback_call_trigger_feedback_sync (proxy,
                                                             app_id,
                                                             self->event,
                                                             build_hints (self),
                                                             self->timeout,
                                                             &self->id,
                                                             NULL,
                                                             error);
   if (success)
     _lfb_active_add_id (self->id);
   lfb_event_set_state (self, success ? LFB_EVENT_STATE_RUNNING : LFB_EVENT_STATE_ERRORED);
   return success;
}

/**
 * lfb_event_trigger_feedback_async:
 * @self: The event to trigger feedback for.
 * @cancellable: (nullable): A #GCancellable to cancel the operation or %NULL.
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
 * @user_data: User data to pass to @callback.
 *
 * Tells the feedback server to provide proper feedback for the give
 * event to the user. This is the sync version of
 * [method@LfbEvent.trigger_feedback].
 */
void
lfb_event_trigger_feedback_async (LfbEvent            *self,
                                  GCancellable        *cancellable,
                                  GAsyncReadyCallback  callback,
                                  gpointer             user_data)
{
  LfbAsyncData *data;
  LfbGdbusFeedback *proxy;
  const char *app_id;

  g_return_if_fail (LFB_IS_EVENT (self));
  if (!lfb_is_initted ())
     g_error ("You must call lfb_init() before triggering events.");

  proxy = _lfb_get_proxy ();
  g_return_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy));

  if (self->handler_id == 0) {
    self->handler_id = g_signal_connect_object (proxy,
                                                "feedback-ended",
                                                G_CALLBACK (on_feedback_ended),
                                                self,
                                                G_CONNECT_SWAPPED);
  }

  data = g_new0 (LfbAsyncData, 1);
  data->task = g_task_new (self, cancellable, callback, user_data);
  data->event = g_object_ref (self);

  app_id = self->app_id ?: lfb_get_app_id ();
  lfb_gdbus_feedback_call_trigger_feedback (proxy,
                                            app_id,
                                            self->event,
                                            build_hints (self),
                                            self->timeout,
                                            cancellable,
                                            (GAsyncReadyCallback)on_trigger_feedback_finished,
                                            data);
}

/**
 * lfb_event_trigger_feedback_finish:
 * @self: the event
 * @res: Result object passed to the callback of [method@LfbEvent.trigger_feedback_async]
 * @error: Return location for error
 *
 * Finish an async operation started by [method@LfbEvent.trigger_feedback_async]. You
 * must call this function in the callback to free memory and receive any
 * errors which occurred.
 *
 * Returns: %TRUE if triggering the feedbacks was successful
 */
gboolean
lfb_event_trigger_feedback_finish (LfbEvent      *self,
                                   GAsyncResult  *res,
                                   GError       **error)
{
  g_return_val_if_fail (g_task_is_valid (res, self), FALSE);

  return g_task_propagate_boolean (G_TASK (res), error);
}

/**
 * lfb_event_end_feedback:
 * @self: The event to end feedback for.
 * @error: The returned error information.
 *
 * Tells the feedback server to end all feedback for the given event as
 * soon as possible.
 *
 * Returns: %TRUE if successful. On error, this will return %FALSE and set
 *          @error.
 */
gboolean
lfb_event_end_feedback (LfbEvent *self, GError **error)
{
  LfbGdbusFeedback *proxy;

  g_return_val_if_fail (LFB_IS_EVENT (self), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  if (!lfb_is_initted ())
     g_error ("You must call lfb_init() before ending events.");

  proxy = _lfb_get_proxy ();
  g_return_val_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy), FALSE);
  return lfb_gdbus_feedback_call_end_feedback_sync (proxy, self->id, NULL, error);
}

/**
 * lfb_event_end_feedback_finish:
 * @self: the event
 * @res: Result object passed to the callback of [method@LfbEvent.end_feedback_async]
 * @error: Return location for error
 *
 * Finish an async operation started by lfb_event_end_feedback_async. You
 * must call this function in the callback to free memory and receive any
 * errors which occurred.
 *
 * This does not mean that the feedbacks finished right away. Connect to the
 * [@signal@LfbEvent::feedback-ended] signal for this.
 *
 * Returns: %TRUE if ending the feedbacks was successful
 */
gboolean
lfb_event_end_feedback_finish (LfbEvent      *self,
                               GAsyncResult  *res,
                               GError       **error)
{
  g_return_val_if_fail (g_task_is_valid (res, self), FALSE);

  return g_task_propagate_boolean (G_TASK (res), error);
}

/**
 * lfb_event_end_feedback_async:
 * @self: The event to end feedback for.
 * @cancellable: (nullable): A #GCancellable to cancel the operation or %NULL.
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
 * @user_data: User data to pass to @callback.
 *
 * Tells the feedback server to end all feedback for the given event as
 * soon as possible.
 */
void
lfb_event_end_feedback_async (LfbEvent            *self,
                              GCancellable        *cancellable,
                              GAsyncReadyCallback  callback,
                              gpointer             user_data)
{
  LfbAsyncData *data;
  LfbGdbusFeedback *proxy;

  g_return_if_fail (LFB_IS_EVENT (self));
  if (!lfb_is_initted ())
     g_error ("You must call lfb_init() before ending events.");

  proxy = _lfb_get_proxy ();
  g_return_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy));

  data = g_new0 (LfbAsyncData, 1);
  data->task = g_task_new (self, cancellable, callback, user_data);
  data->event = g_object_ref (self);
  lfb_gdbus_feedback_call_end_feedback (proxy,
                                        self->id,
                                        cancellable,
                                        (GAsyncReadyCallback)on_end_feedback_finished,
                                        data);
}

/**
 * lfb_event_set_timeout:
 * @self: The event
 * @timeout: The timeout
 *
 * Tells the feedback server to end feedack after #timeout seconds.
 * The value -1 indicates to not set a timeout and let feedbacks stop
 * on their own while 0 indicates to loop all feedbacks endlessly.
 * They must be stopped via [method@LfbEvent.end_feedback] in this case.
 *
 * It is an error to change the timeout after the feedback has been triggered
 * via [method@LfbEvent.trigger_feedback].
 */
void
lfb_event_set_timeout (LfbEvent *self, gint timeout)
{
  g_return_if_fail (LFB_IS_EVENT (self));

  if (self->timeout == timeout)
    return;

  self->timeout = timeout;
  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TIMEOUT]);
}

/**
 * lfb_event_get_event:
 * @self: The event
 *
 * Get the event's name according to the event naming spec.
 *
 * Returns: The event name
 */
const char *
lfb_event_get_event (LfbEvent *self)
{
  g_return_val_if_fail (LFB_IS_EVENT (self), NULL);
  return self->event;
}

/**
 * lfb_event_get_timeout:
 * @self: The event
 *
 * Get the currently set timeout.
 *
 * Returns: The event timeout in milliseconds
 */
gint
lfb_event_get_timeout (LfbEvent *self)
{
  g_return_val_if_fail (LFB_IS_EVENT (self), -1);
  return self->timeout;
}

/**
 * lfb_event_get_state:
 * @self: The event
 *
 * Get the current event state (e.g. if triggered feeedback is
 * currently running.
 *
 * Returns: The state of the feedback triggered by event.
 */
LfbEventState
lfb_event_get_state (LfbEvent *self)
{
  g_return_val_if_fail (LFB_IS_EVENT (self), LFB_EVENT_STATE_NONE);
  return self->state;
}

/**
 * lfb_event_get_end_reason:
 * @self: The event
 *
 * Get the reason why the feadback ended.
 *
 * Returns: The reason why feedback ended.
 */
LfbEventEndReason
lfb_event_get_end_reason (LfbEvent *self)
{
  g_return_val_if_fail (LFB_IS_EVENT (self), LFB_EVENT_END_REASON_NATURAL);
  return self->end_reason;
}

/**
 * lfb_event_set_feedback_profile:
 * @self: The event
 * @profile: The feedback profile to use
 *
 * Tells the feedback server to use the given feedback profile for
 * this event when it is submitted. The server might ignore this
 * request.  Valid profile names and their 'noisiness' are specified
 * in the [Feedback theme specification](Feedback-theme-spec-0.0.0.html).
 *
 * A value of %NULL (the default) lets the server pick the profile.
 */
void
lfb_event_set_feedback_profile (LfbEvent *self, const gchar *profile)
{
  g_return_if_fail (LFB_IS_EVENT (self));

  if (!g_strcmp0 (self->profile, profile))
    return;

  g_free (self->profile);
  self->profile = g_strdup (profile);
  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_FEEDBACK_PROFILE]);
}

/**
 * lfb_event_get_feedback_profile:
 * @self: The event
 *
 * Gets the set feedback profile. If no profile was set it returns
 * %NULL. The event uses the system wide profile in this case.
 *
 * Returns: The set feedback profile to use for this event or %NULL.
 */
const char *
lfb_event_get_feedback_profile (LfbEvent *self)
{
  g_return_val_if_fail (LFB_IS_EVENT (self), NULL);

  return self->profile;
}

/**
 * lfb_event_set_important:
 * @self: The event
 * @important: Whether to flag this event as important
 *
 * Tells the feedback server that the sender deems this to be an
 * important event. A feedback server might allow the sender to
 * override the current feedback level when this is set.
 */
void
lfb_event_set_important (LfbEvent *self, gboolean important)
{
  g_return_if_fail (LFB_IS_EVENT (self));

  if (self->important == important)
    return;

  self->important = important;
  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_IMPORTANT]);
}

/**
 * lfb_event_get_important:
 * @self: The event
 *
 * Gets the set feedback profile. If no profile was set it returns
 * %NULL. The event uses the system wide profile in this case.
 *
 * Returns: The set feedback profile to use for this event or %NULL.
 */
gboolean
lfb_event_get_important (LfbEvent *self)
{
  g_return_val_if_fail (LFB_IS_EVENT (self), FALSE);

  return self->important;
}

/**
 * lfb_event_set_app_id:
 * @self: The event
 * @app_id: The application id to use
 *
 * Tells the feedback server to use the given application id for
 * this event when it is submitted. The server might ignore this
 * request. This can be used by notification daemons to honor per
 * application settings automatically.
 *
 * The functions is usually not used by applications.
 *
 * A value of %NULL (the default) lets the server pick the profile.
 */
void
lfb_event_set_app_id (LfbEvent *self, const gchar *app_id)
{
  g_return_if_fail (LFB_IS_EVENT (self));

  if (!g_strcmp0 (self->app_id, app_id))
    return;

  g_free (self->app_id);
  self->app_id = g_strdup (app_id);
  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_APP_ID]);
}

/**
 * lfb_event_get_app_id:
 * @self: The event
 *
 * Returns the app-id for this event. If no app-id has been explicitly
 * set, %NULL is returned. The event uses the app-id returned by
 * [func@Lfb.get_app_id] in this case.
 *
 * Returns:(transfer none): The set app-id for this event or %NULL.
 */
const char *
lfb_event_get_app_id (LfbEvent *self)
{
  g_return_val_if_fail (LFB_IS_EVENT (self), NULL);

  return self->app_id;
}
07070100000049000081A400000000000000000000000166F7A51300000E10000000000000000000000000000000000000002800000000feedbackd-0.5.0/libfeedback/lfb-event.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: LGPL-2.1+
 */
#pragma once

#include <gio/gio.h>
#include <glib-object.h>

#if !defined (__LIBFEEDBACK_H_INSIDE__) && !defined (LIBFEEDBACK_COMPILATION)
#error "Only <libfeedback.h> can be included directly."
#endif

G_BEGIN_DECLS

/**
 * LfbEventState:
 * @LFB_EVENT_STATE_ERRORED: An error occurred triggering feedbacks
 * @LFB_EVENT_STATE_NONE: No state information yet
 * @LFB_EVENT_STATE_RUNNING: The feedbacks for this event are currently running
 * @LFB_EVENT_STATE_ENDED: All feedbacks for this event ended
 *
 * Enum values to indicate the current state of the feedbacks
 * triggered by an event.
 */

typedef enum _LfbEventState {
  LFB_EVENT_STATE_ERRORED = -1,
  LFB_EVENT_STATE_NONE    = 0,
  LFB_EVENT_STATE_RUNNING = 1,
  LFB_EVENT_STATE_ENDED   = 2,
} LfbEventState;

/**
 * LfbEventEndReason:
 * @LFB_EVENT_END_REASON_NOT_FOUND: There was no feedback in the current theme for this event
 *                                  so no feedback was provided to the user.
 * @LFB_EVENT_END_REASON_NATURAL: All feedbacks finished playing their natural length
 * @LFB_EVENT_END_REASON_EXPIRED: Feedbacks ran until the set timeout expired
 * @LFB_EVENT_END_REASON_EXPLICIT: The feedbacks were ended explicitly
 *
 * Enum values used to indicate why the feedbacks for an event ended.
 **/
typedef enum _LfbEventEndReason {

  LFB_EVENT_END_REASON_NOT_FOUND = -1,
  LFB_EVENT_END_REASON_NATURAL   = 0,
  LFB_EVENT_END_REASON_EXPIRED   = 1,
  LFB_EVENT_END_REASON_EXPLICIT  = 2,
} LfbEventEndReason;

#define LFB_TYPE_EVENT (lfb_event_get_type())

G_DECLARE_FINAL_TYPE (LfbEvent, lfb_event, LFB, EVENT, GObject)

LfbEvent*   lfb_event_new (const char *event);
gboolean    lfb_event_trigger_feedback (LfbEvent *self, GError **error);
void        lfb_event_trigger_feedback_async (LfbEvent            *self,
                                              GCancellable        *cancellable,
                                              GAsyncReadyCallback  callback,
                                              gpointer             user_data);
gboolean    lfb_event_trigger_feedback_finish (LfbEvent            *self,
                                               GAsyncResult        *res,
                                               GError             **error);
gboolean    lfb_event_end_feedback (LfbEvent *self, GError **error);
void        lfb_event_end_feedback_async (LfbEvent            *self,
                                          GCancellable        *cancellable,
                                          GAsyncReadyCallback  callback,
                                          gpointer             user_data);
gboolean    lfb_event_end_feedback_finish (LfbEvent            *self,
                                           GAsyncResult        *res,
                                           GError             **error);
void        lfb_event_set_timeout (LfbEvent *self, gint timeout);
gint        lfb_event_get_timeout (LfbEvent *self);
void        lfb_event_set_feedback_profile (LfbEvent *self, const char *profile);
const char *lfb_event_get_feedback_profile (LfbEvent *self);
void        lfb_event_set_important (LfbEvent *self, gboolean important);
gboolean    lfb_event_get_important (LfbEvent *self);
void        lfb_event_set_app_id (LfbEvent *self, const char *app_id);
const char *lfb_event_get_app_id (LfbEvent *self);
const char *lfb_event_get_event (LfbEvent *self);

LfbEventState     lfb_event_get_state (LfbEvent *self);
LfbEventEndReason lfb_event_get_end_reason (LfbEvent *self);

G_END_DECLS
0707010000004A000081A400000000000000000000000166F7A513000000E2000000000000000000000000000000000000002800000000feedbackd-0.5.0/libfeedback/lfb-names.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: LGPL-2.1+
 */

#pragma once

#define FB_DBUS_NAME "org.sigxcpu.Feedback"
#define FB_DBUS_PATH "/org/sigxcpu/Feedback"

#define FB_DBUS_TYPE G_BUS_TYPE_SESSION
0707010000004B000081A400000000000000000000000166F7A51300000137000000000000000000000000000000000000002700000000feedbackd-0.5.0/libfeedback/lfb-priv.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: LGPL-2.1+
 */

#pragma once

#include <gio/gio.h>
#include "lfb-gdbus.h"

G_BEGIN_DECLS

LfbGdbusFeedback *_lfb_get_proxy (void);
void              _lfb_active_add_id (guint id);
void              _lfb_active_remove_id (guint id);

G_END_DECLS
0707010000004C000081A400000000000000000000000166F7A5130000125C000000000000000000000000000000000000002A00000000feedbackd-0.5.0/libfeedback/libfeedback.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: LGPL-2.1+
 * Author: Guido Günther <agx@sigxcpu.org>
 */
#include "libfeedback.h"
#include "lfb-gdbus.h"
#include "lfb-priv.h"

#include "lfb-names.h"

static LfbGdbusFeedback *_proxy;
static char             *_app_id;
static gboolean          _initted;
static GHashTable       *_active_ids;

static void
lfb_cancel_feedbacks (void)
{
  gpointer key, value;
  GHashTableIter iter;

  g_hash_table_iter_init (&iter, _active_ids);

  while (g_hash_table_iter_next (&iter, &key, &value)) {
    guint id = GPOINTER_TO_UINT(key);
    g_hash_table_iter_remove (&iter);
    g_debug ("Cancellling feedback on shutdown %d", id);
    /* Need to use a sync call here since there might not be a main loop anymore */
    lfb_gdbus_feedback_call_end_feedback_sync (_proxy, id, NULL, NULL);
  }
}

void
_lfb_active_add_id (guint id)
{
  g_return_if_fail (id > 0);

  if (!_initted)
    return;

  g_hash_table_add (_active_ids, GUINT_TO_POINTER (id));
}

void
_lfb_active_remove_id (guint id)
{
  gboolean success;

  g_return_if_fail (id > 0);

  if (!_initted)
    return;

  success = g_hash_table_remove (_active_ids, GUINT_TO_POINTER(id));
  if (!success)
    g_warning ("Event id %d not known", id);
}


LfbGdbusFeedback *
_lfb_get_proxy (void)
{
  /* Caller needs to check since the proxy might be gone when
     the last event gets finalized */
  return _proxy;
}

/**
 * lfb_init:
 * @app_id: The application id
 * @error: Error information
 *
 * Initialize libfeedback. This must be called before any other of libfeedback's functions.
 *
 * Returns: %TRUE if successful, or %FALSE on error.
 */
gboolean
lfb_init (const gchar *app_id, GError **error)
{
  g_return_val_if_fail (app_id != NULL, FALSE);
  g_return_val_if_fail (*app_id != '\0', FALSE);

  if (_initted)
    return TRUE;

  lfb_set_app_id (app_id);
  _proxy = lfb_gdbus_feedback_proxy_new_for_bus_sync(
      FB_DBUS_TYPE, 0, FB_DBUS_NAME, FB_DBUS_PATH, NULL, error);
  if (!_proxy)
    return FALSE;

  _active_ids = g_hash_table_new (g_direct_hash, g_direct_equal);
  g_object_add_weak_pointer (G_OBJECT (_proxy), (gpointer *) &_proxy);

  _initted = TRUE;
  return TRUE;
}

/**
 * lfb_uninit:
 *
 * Uninitialize the library when no longer used. Usually called
 * on program shutdown.
 */
void
lfb_uninit (void)
{
  _initted = FALSE;

  /* Cancel all feedbacks that the client forgot to clean up */
  lfb_cancel_feedbacks ();
  g_clear_pointer (&_active_ids, g_hash_table_destroy);
  g_clear_pointer (&_app_id, g_free);
  g_clear_object (&_proxy);
}

/**
 * lfb_set_app_id:
 * @app_id: The application id
 *
 * Sets the application id.
 */
void
lfb_set_app_id (const char *app_id)
{
  g_free (_app_id);
  _app_id = g_strdup (app_id);
}

/**
 * lfb_get_app_id:
 *
 * Get the application id set via [func@Lfb.set_app_id].
 *
 * Returns:  the application id.
 */
const gchar *
lfb_get_app_id (void)
{
  return _app_id;
}

/**
 * lfb_is_initted:
 *
 * Gets whether or not libfeedback is initialized.
 *
 * Returns: %TRUE if libfeedback is initialized, or %FALSE otherwise.
 */
gboolean
lfb_is_initted (void)
{
  return _initted;
}

/**
 * lfb_get_feedback_profile:
 *
 * Gets the currently set feedback profile.
 *
 * Returns: The current profile or %NULL on error.
 */
const char *
lfb_get_feedback_profile (void)
{
  LfbGdbusFeedback *proxy;

  if (!lfb_is_initted ())
    g_error ("You must call lfb_init() before ending events.");

  proxy = _lfb_get_proxy ();
  g_return_val_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy), NULL);

  return lfb_gdbus_feedback_get_profile (LFB_GDBUS_FEEDBACK (proxy));
}


/**
 * lfb_set_feedback_profile:
 * @profile: The profile to set
 *
 * Sets the active feedback profile to #profile. It is up to the feedback
 * daemon to ignore this request. The new profile might not become active
 * immediately. You can listen to changes #LfbGdbusFeedback's ::profile
 * property to get notified when it takes effect.
 */
void
lfb_set_feedback_profile (const gchar *profile)
{
  LfbGdbusFeedback *proxy;

  if (!lfb_is_initted ())
    g_error ("You must call lfb_init() before ending events.");

  proxy = _lfb_get_proxy ();
  g_return_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy));

  lfb_gdbus_feedback_set_profile (LFB_GDBUS_FEEDBACK (proxy), profile);
}

/**
 * lfb_get_proxy:
 *
 * This can be used to access the lower level API e.g. to listen to
 * property changes. The object is not owned by the caller. Don't
 * unref it after use.
 *
 * Returns: (transfer none): The DBus proxy.
 */
LfbGdbusFeedback *
lfb_get_proxy (void)
{
  LfbGdbusFeedback *proxy = _lfb_get_proxy ();

  g_return_val_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy), NULL);
  return proxy;
}
0707010000004D000081A400000000000000000000000166F7A513000002F9000000000000000000000000000000000000002A00000000feedbackd-0.5.0/libfeedback/libfeedback.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: LGPL-2.1+
 */
#pragma once

#include <glib.h>

G_BEGIN_DECLS

#define __LIBFEEDBACK_H_INSIDE__

#ifndef LIBFEEDBACK_USE_UNSTABLE_API
#error    LIBFEEDBACK is unstable API. You must define LIBFEEDBACK_USE_UNSTABLE_API before including libfeedback.h
#endif

#include "lfb-enums.h"
#include "lfb-event.h"
#include "lfb-gdbus.h"

gboolean    lfb_init (const gchar *app_id, GError **error);
void        lfb_uninit (void);
void        lfb_set_app_id (const char *app_id);
const char *lfb_get_app_id (void);
gboolean    lfb_is_initted (void);
void        lfb_set_feedback_profile (const char *profile);
const char *lfb_get_feedback_profile (void);
LfbGdbusFeedback *lfb_get_proxy (void);

G_END_DECLS
0707010000004E000081A400000000000000000000000166F7A51300000036000000000000000000000000000000000000002D00000000feedbackd-0.5.0/libfeedback/libfeedback.symsLIBFEEDBACK_0_0_0 {
	global:
		lfb_*;
	local:
		*;
};
0707010000004F000081A400000000000000000000000166F7A51300000CB5000000000000000000000000000000000000002800000000feedbackd-0.5.0/libfeedback/meson.build# Shared library and language bindings

libfeedback_libdir = get_option('libdir')
libfeedback_header_dir = get_option('includedir') / libname
libfeedback_link_args = []
libfeedback_symbols_file = 'libfeedback.syms'

# Check linker flags
ld_version_script_arg = '-Wl,--version-script,@0@'.format(meson.current_source_dir() / libfeedback_symbols_file)
if cc.links('int main() { return 0; }', args : ld_version_script_arg, name : 'ld_supports_version_script')
  libfeedback_link_args += [ld_version_script_arg]
endif

lfb_enum_headers = files([
  'lfb-event.h',
])
lfb_enum_sources = gnome.mkenums_simple('lfb-enums',
  sources : lfb_enum_headers,
  install_header : true,
  install_dir: libfeedback_header_dir,
)

libfeedback_headers = [
  'libfeedback.h',
  'lfb-event.h',
]

libfeedback_sources = [
  generated_dbus_sources,
  lfb_enum_sources,
  libfeedback_headers,
  'libfeedback.c',
  'lfb-event.c',
]

libfeedback_deps = [
  gio,
  gio_unix,
  glib,
]

libfeedback_c_args = [
  '-DG_LOG_DOMAIN="libfeedback"',
  '-DLIBFEEDBACK_COMPILATION',
  '-DLIBFEEDBACK_USE_UNSTABLE_API',
]

libtype = 'shared_library'
libfeedback = build_target(
  'feedback-' + apiversion,
  libfeedback_sources,
            soversion : 0,
               c_args : libfeedback_c_args,
         dependencies : libfeedback_deps,
            link_args : libfeedback_link_args,
              install : true,
          install_dir : libfeedback_libdir,
          target_type : libtype,
)

libfeedback_inc = include_directories('.')
libfeedback_dep = declare_dependency(
  sources : [generated_dbus_sources, lfb_enum_sources[1]],
  link_with : libfeedback,
  dependencies: libfeedback_deps,
  include_directories : libfeedback_inc,
)
install_headers(libfeedback_headers, subdir : libname)

pkgconfig = import('pkgconfig')

pkgconfig.generate(
      libraries : [libfeedback],
        subdirs : libname,
        version : meson.project_version(),
           name : 'Feedback',
       filebase : 'libfeedback-@0@'.format(apiversion),
    description : 'GNOME feedback library',
       requires : 'gio-2.0',
    install_dir : join_paths(libfeedback_libdir, 'pkgconfig'),
  )

if introspection
  libfeedback_gir_extra_args = [
    '-I' + dbus_header_dir,
    '--c-include=libfeedback.h',
    '--quiet',
    '-DLIBFEEDBACK_COMPILATION',
    '-DLIBFEEDBACK_USE_UNSTABLE_API',
    '--warn-all',
  ]

  libfeedback_gir = gnome.generate_gir(libfeedback,
                sources : libfeedback_sources,
              nsversion : apiversion,
              namespace : 'Lfb',
        export_packages : 'libfeedback-@0@'.format(apiversion),
          symbol_prefix : 'lfb',
      identifier_prefix : 'Lfb',
              link_with : libfeedback,
               includes : ['Gio-2.0'],
                install : true,
        install_dir_gir : girdir,
    install_dir_typelib : typelibdir,
             extra_args : libfeedback_gir_extra_args,
         fatal_warnings : true,
   )

  if get_option('vapi')
    libfeedback_vapi = gnome.generate_vapi('libfeedback-' + apiversion,
             sources  : libfeedback_gir[0],
             packages : ['gio-2.0'],
             install  : true,
         install_dir  : vapidir,
       metadata_dirs  : [meson.current_source_dir()],
     )
  endif
endif
07070100000050000081A400000000000000000000000166F7A513000010BF000000000000000000000000000000000000001C00000000feedbackd-0.5.0/meson.buildproject('feedbackd', 'c',
          version : '0.5.0',
          license : 'LGPLv3+',
    meson_version : '>= 1.0.0',
  default_options : [
    'warning_level=1',
    'buildtype=debugoptimized',
    'c_std=gnu11',
  ],
)

gio            = dependency('gio-2.0', version: '>=2.50.0')
gio_unix       = dependency('gio-unix-2.0', version: '>=2.50.0')
glib           = dependency('glib-2.0', version: '>=2.50.0')
udev           = dependency('udev', required: false)
if get_option('daemon')
  gobject        = dependency('gobject-2.0', version: '>=2.50.0')
  gmobile        = dependency('gmobile',
    version: '>= 0.1.0',
    fallback: ['gmobile', 'gmobile_dep'],
    default_options: [
      'examples=false',
      'introspection=false',
      'gtk_doc=false',
      'tests=false',
  ])
  gsound         = dependency('gsound')
  gudev          = dependency('gudev-1.0', version: '>=232')
  json_glib      = dependency('json-glib-1.0')
  systemd_dep    = dependency('systemd', required: false)
endif

prefix = get_option('prefix')

bindir = join_paths(prefix, get_option('bindir'))
datadir = join_paths(prefix, get_option('datadir'))
libdir = join_paths(prefix, get_option('libdir'))
girdir = join_paths(prefix, join_paths(datadir, 'gir-1.0'))
ifacedir = join_paths(prefix, join_paths(datadir, 'dbus-1', 'interfaces'))
servicedir = join_paths(prefix, join_paths(datadir, 'dbus-1', 'services'))
libexecdir = join_paths(prefix, get_option('libexecdir'))
typelibdir = join_paths(prefix, join_paths(libdir, 'girepository-1.0'))
vapidir = join_paths(prefix, join_paths(datadir, 'vala', 'vapi'))
feedbackd_theme_dir = join_paths(datadir, 'feedbackd', 'themes')
if udev.found() and get_option('daemon')
  udevdir = udev.get_variable('udevdir') / 'rules.d'
else
  udevdir = prefix / 'lib' / 'udev' / 'rules.d'
endif

run_data = configuration_data()
run_data.set('ABS_BUILDDIR', meson.current_build_dir())
run_data.set('ABS_SRCDIR', meson.current_source_dir())
configure_file(
  input: 'run.in',
  output: 'run',
  configuration: run_data)

gnome = import('gnome')

cc = meson.get_compiler('c')

test_c_args = [
  '-Wcast-align',
  '-Wdate-time',
  ['-Werror=format-security', '-Werror=format=2'],
  '-Wendif-labels',
  '-Werror=incompatible-pointer-types',
  '-Werror=missing-declarations',
  '-Werror=overflow',
  '-Werror=return-type',
  '-Werror=shift-count-overflow',
  '-Werror=shift-overflow=2',
  '-Werror=implicit-fallthrough=3',
  '-Wformat-nonliteral',
  '-Wformat-security',
  '-Winit-self',
  '-Wmaybe-uninitialized',
  '-Wmissing-field-initializers',
  '-Wmissing-include-dirs',
  '-Wmissing-noreturn',
  '-Wnested-externs',
  '-Wno-missing-field-initializers',
  '-Wno-sign-compare',
  '-Wno-strict-aliasing',
  '-Wno-unused-parameter',
  '-Wold-style-definition',
  '-Wpointer-arith',
  '-Wredundant-decls',
  '-Wstrict-prototypes',
  '-Wtype-limits',
  '-Wundef',
  '-Wunused-function',
]

if get_option('buildtype') != 'plain'
  test_c_args += '-fstack-protector-strong'
endif

global_c_args = [
  '-DFEEDBACKD_THEME_DIR="@0@"'.format(feedbackd_theme_dir),
  '-DLIBFEEDBACK_COMPILATION',
  '-DFBD_VERSION="@0@"'.format(meson.project_version()),
]

add_project_arguments(
  global_c_args + cc.get_supported_arguments(test_c_args),
  language: 'c'
)

introspection_feature = get_option('introspection')
introspection = introspection_feature.enabled() or introspection_feature.auto()

apiversion = '0.0'
libname = 'libfeedback-' + apiversion

json_glib_validate = find_program('json-glib-validate', required: false)

meson.add_install_script(
  join_paths('build-aux', 'post_install.py'),
  datadir
)

subdir('data')
subdir('libfeedback')
subdir('src')
subdir('cli')
subdir('tests')
subdir('doc')

summary = [
        '',
        '---------------',
        'feedbackd @0@'.format(meson.project_version()),
        '',
	'         Daemon: @0@'.format(get_option('daemon')),
	'     Udev rules: @0@'.format(get_option('udev')),
        '  Documentation: @0@'.format(get_option('gtk_doc')),
        '   Manual pages: @0@'.format(get_option('man')),
        '  Introspection: @0@'.format(introspection),
        '           Vapi: @0@'.format(get_option('vapi')),
        '          Tests: @0@'.format(get_option('tests')),
        '---------------',
        ''
]
message('\n'.join(summary))
07070100000051000081A400000000000000000000000166F7A51300000318000000000000000000000000000000000000002200000000feedbackd-0.5.0/meson_options.txtoption('introspection', type: 'feature', value: 'auto')
option('vapi', type: 'boolean', value: true)

option('udev',
       type: 'boolean', value: true,
       description: 'Whether to install the udev rules')
option('daemon',
       type: 'boolean', value: true,
       description: 'Whether to build the daemon')
option('gtk_doc',
       type: 'boolean', value: false,
       description: 'Whether to generate the API reference for Libfeedback')
option('man',
       type: 'boolean', value : false,
       description : 'generate man pages (requires rst2man)')
option('tests',
       type: 'boolean', value: true,
       description: 'Whether to compile unit tests')
option('systemd_user_unit_dir',
       type: 'string', value: '',
       description: 'Directory for systemd user units')
07070100000052000081ED00000000000000000000000166F7A5130000019D000000000000000000000000000000000000001700000000feedbackd-0.5.0/run.in#!/bin/sh
set -e

ABS_BUILDDIR='@ABS_BUILDDIR@'
ABS_SRCDIR='@ABS_SRCDIR@'
FEEDBACK_THEME=${FEEDBACK_THEME:-"${ABS_SRCDIR}/data/default.json"}

export FEEDBACK_THEME
export GSETTINGS_SCHEMA_DIR="${ABS_BUILDDIR}/data"
export GI_TYPELIB_PATH="${ABS_BUILDDIR}/libfeedback:$GI_TYPELIB_PATH"

if [ "${FBD_GDB}" = 1 ]; then
    echo "Running feedbackd under gdb"
    WRAPPER="gdb --args"
fi

set -x
exec ${WRAPPER} "$@"
07070100000053000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001400000000feedbackd-0.5.0/src07070100000054000081A400000000000000000000000166F7A513000017DD000000000000000000000000000000000000002700000000feedbackd-0.5.0/src/fbd-alert-slider.c/*
 * Copyright (C) 2024 The Phosh Developers
 *
 * SPDX-License-Identifier: GPL-3.0+
 *
 * Heavily based on a shell script posted to the phosh matrix channel
 * by isyourbrain foss
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-alert-slider"

#define LIBFEEDBACK_USE_UNSTABLE_API
#include "libfeedback.h"

#include "fbd.h"

#include <gudev/gudev.h>

#include <glib.h>
#include <gio/gio.h>

#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/ioctl.h>

#include <linux/input.h>

#define BITS_PER_LONG (sizeof(long) * 8)
#define NBITS(x) ((((x) - 1) / BITS_PER_LONG) + 1)
#define OFF(x)  ((x) % BITS_PER_LONG)
#define BIT(x)  (1UL << OFF (x))
#define LONG(x) ((x) / BITS_PER_LONG)
#define test_bit(bit, array)    ((array[LONG (bit)] >> OFF (bit)) & 1)

typedef enum {
  FBD_ALERT_SLIDER_STATE_SILENT = 0,
  FBD_ALERT_SLIDER_STATE_QUIET = 1,
  FBD_ALERT_SLIDER_STATE_FULL = 2,
} FbdAlertSliderState;

GSettings *settings = NULL;

static void
set_level (FbdAlertSliderState state, gboolean silent)
{
  g_autoptr (LfbEvent) event = NULL;
  const char *profile;

  switch (state) {
  case FBD_ALERT_SLIDER_STATE_SILENT:
    profile = "silent";
    break;
  case FBD_ALERT_SLIDER_STATE_QUIET:
    profile = "quiet";
    break;
  case FBD_ALERT_SLIDER_STATE_FULL:
    profile = "full";
    break;
  default:
    g_return_if_reached ();
  }

  g_debug ("Setting profile to %s", profile);
  lfb_set_feedback_profile (profile);

  if (!silent) {
    event = lfb_event_new ("button-pressed");
    lfb_event_set_important (event, TRUE);
    lfb_event_set_feedback_profile (event, "quiet");
    lfb_event_trigger_feedback (event, NULL);
  }
}


static int
get_initial_value (int fd, int axis)
{
  int abs[6] = {0};

  ioctl (fd, EVIOCGABS (axis), abs);
  return abs[0];
}


static int
probe (FbdAlertSliderState *initial)
{
  GList *l;
  g_autolist (GUdevClient) devices = NULL;
  g_autoptr (GUdevClient) client = NULL;
  unsigned int code;
  int version, fd, value = 0;
  char name[256] = "Unknown";
  unsigned long bit[EV_MAX][NBITS (KEY_MAX)];
  const char *device_file = NULL;
  const char * const subsystems[] = { "input", NULL };

  client = g_udev_client_new (subsystems);
  devices = g_udev_client_query_by_subsystem (client, "input");

  for (l = devices; l != NULL; l = l->next) {
    GUdevDevice *dev = l->data;

    if (!g_strcmp0 (g_udev_device_get_property (dev, FEEDBACKD_UDEV_ATTR), "alert-slider")) {
      device_file = g_udev_device_get_device_file (dev);
      g_debug ("Found alert slider device: %s", device_file);
      break;
    }
  }

  if (!device_file) {
    g_debug ("No matching device found");
    return -ENOENT;
  }

  if ((fd = open (device_file, O_RDONLY)) < 0) {
    g_warning ("Failed to open alert slider device: %s", strerror (errno));
    return -1;
  }

  if (ioctl (fd, EVIOCGVERSION, &version)) {
    g_warning ("Can't get version %s", strerror (errno));
    return -1;
  }
  g_debug ("Input driver version: %d.%d.%d", version >> 16, (version >> 8) & 0xff, version & 0xff);

  ioctl (fd, EVIOCGNAME (sizeof(name)), name);
  g_debug ("Input device name: '%s'", name);
  if (g_strcmp0 (name, "Alert slider")) {
    g_critical ("Not an alert slider but '%s'", name);
    return -1;
  }

  memset (bit, 0, sizeof(bit));
  ioctl (fd, EVIOCGBIT (0, EV_MAX), bit[0]);

  if (test_bit (EV_ABS, bit[0])) {
    ioctl (fd, EVIOCGBIT (EV_ABS, KEY_MAX), bit[EV_ABS]);
    for (code = 0; code < KEY_MAX; code++) {
      if (test_bit (code, bit[EV_ABS])) {
        value = get_initial_value (fd, code);
        break;
      }
    }
  } else {
    g_critical ("Device doesn't support EV_ABS");
    return -1;
  }

  if (fd >= 0) {
    g_debug ("Initial value: %d", value);
    *initial = value;
  }
  return fd;
}


static gboolean
on_input_ready (GIOChannel *source, GIOCondition cond, gpointer unused)
{
  GIOError status;
  struct input_event ev[64];
  gsize rd;

  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
    status = g_io_channel_read (source, (char *)ev, sizeof(ev), &rd /*, &err */);
  G_GNUC_END_IGNORE_DEPRECATIONS
  if (status != G_IO_ERROR_NONE ) {
    g_warning ("Failed to read event: %d", status);
    return TRUE;
  }

  if (rd < sizeof(struct input_event)) {
    g_warning ("Expected %d bytes, got %zd", (int) sizeof(struct input_event), rd);
    return TRUE;
  }

  for (int i = 0; i < rd / sizeof(struct input_event); i++) {
    unsigned int type, code;

    type = ev[i].type;
    code = ev[i].code;

    if (type == EV_SYN)
      continue;

    if (type != EV_ABS || code != 34) {
      g_warning ("Unexpected event %d / %d", type, code);
      continue;
    }

    g_debug ("Event: time %ld.%06ld, value: %d",
             ev[i].input_event_sec,
             ev[i].input_event_usec,
             ev[i].value);
    set_level (ev[i].value, FALSE);
  }

  return TRUE;
}


int
main (int argc, char *argv[])
{
  g_autoptr (GError) err = NULL;
  g_autoptr (GOptionContext) opt_context = NULL;
  g_autoptr (GIOChannel) input = NULL;
  g_autoptr (GMainLoop) loop = NULL;
  FbdAlertSliderState state = 0;
  int fd;
  const GOptionEntry options [] = {
    { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
  };

  opt_context = g_option_context_new ("- helper to prepare sysfs for feedbackd");
  g_option_context_add_main_entries (opt_context, options, NULL);
  if (!g_option_context_parse (opt_context, &argc, &argv, &err)) {
    g_print ("%s", err->message);
    return 1;
  }

  fd = probe (&state);
  if (fd < 0) {
    if (fd == -ENOENT)
      return EXIT_SUCCESS;
    else
      return EXIT_FAILURE;
  }

  if (!lfb_init ("org.sigxcpu.FbdAlertSlider", &err)) {
    g_print ("Failed to init libfeedback: %s\n", err->message);
    return 1;
  }

  set_level (state, TRUE);

  input = g_io_channel_unix_new (fd);
  g_io_channel_set_encoding (input, NULL, NULL);
  g_io_add_watch (input, G_IO_IN | G_IO_ERR | G_IO_HUP, on_input_ready, NULL);

  loop = g_main_loop_new (NULL, FALSE);
  g_main_loop_run (loop);

  g_clear_object (&settings);

  return 0;
}
07070100000055000081A400000000000000000000000166F7A5130000077B000000000000000000000000000000000000002800000000feedbackd-0.5.0/src/fbd-dev-led-flash.c/*
 * Copyright (C) 2024 The Phosh Developers
 *
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 *
 * See Documentation/ABI/testing/sysfs-class-led-trigger-pattern
 */

#define G_LOG_DOMAIN "fbd-dev-led-flash"

#include "fbd-dev-led-priv.h"
#include "fbd-dev-led-flash.h"
#include "fbd-enums.h"
#include "fbd-udev.h"

#include <gio/gio.h>

/**
 * fbd-dev-led-flash:
 *
 * The LED of a camera flash
 */
typedef struct _FbdDevLedFlash {
  FbdDevLed parent;
} FbdDevLedFlash;


G_DEFINE_TYPE (FbdDevLedFlash, fbd_dev_led_flash, FBD_TYPE_DEV_LED)


static gboolean
fbd_dev_led_flash_probe (FbdDevLed *led, GError **error)
{
  GUdevDevice *dev = fbd_dev_led_get_device (led);
  const gchar *name, *path;
  guint max_brightness;

  name = g_udev_device_get_name (dev);
  if (!g_udev_device_get_sysfs_attr (dev, "flash_strobe") ||
      !g_udev_device_get_sysfs_attr (dev, "flash_brightness")) {
    g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s is no flash LED", name);
    return FALSE;
  }

  max_brightness = g_udev_device_get_sysfs_attr_as_int (dev, LED_MAX_BRIGHTNESS_ATTR);
  if (!max_brightness) {
    g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s has no max_brightness", name);
    return FALSE;
  }

  fbd_dev_led_set_max_brightness (led, max_brightness);
  fbd_dev_led_set_supported_color (led, FBD_FEEDBACK_LED_COLOR_FLASH);

  path = g_udev_device_get_sysfs_path (dev);
  g_debug ("LED at '%s' usable as flash", path);

  return TRUE;
}


static void
fbd_dev_led_flash_class_init (FbdDevLedFlashClass *klass)
{
  FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_CLASS (klass);

  fbd_dev_led_class->probe = fbd_dev_led_flash_probe;
}


static void
fbd_dev_led_flash_init (FbdDevLedFlash *self)
{
}


FbdDevLed *
fbd_dev_led_flash_new (GUdevDevice *dev, GError **err)
{
  return g_initable_new (FBD_TYPE_DEV_LED_FLASH, NULL, err, "dev", dev, NULL);
}
07070100000056000081A400000000000000000000000166F7A51300000181000000000000000000000000000000000000002800000000feedbackd-0.5.0/src/fbd-dev-led-flash.h/*
 * Copyright (C) 2024 The Phosh Developers
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-dev-led.h"

G_BEGIN_DECLS

#define FBD_TYPE_DEV_LED_FLASH fbd_dev_led_flash_get_type()

G_DECLARE_FINAL_TYPE (FbdDevLedFlash, fbd_dev_led_flash, FBD, DEV_LED_FLASH, FbdDevLed)

FbdDevLed          *fbd_dev_led_flash_new  (GUdevDevice *dev, GError **err);

G_END_DECLS
07070100000057000081A400000000000000000000000166F7A5130000171C000000000000000000000000000000000000002D00000000feedbackd-0.5.0/src/fbd-dev-led-multicolor.c/*
 * Copyright (C) 2023  Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 *
 * See Documentation/ABI/testing/sysfs-class-led-trigger-pattern
 */

#define G_LOG_DOMAIN "fbd-dev-led-multicolor"

#include "fbd-dev-led-priv.h"
#include "fbd-dev-led-multicolor.h"
#include "fbd-enums.h"
#include "fbd-udev.h"

#include <gio/gio.h>

#define LED_MULTI_INDEX_ATTR     "multi_index"
#define LED_MULTI_INDEX_RED      "red"
#define LED_MULTI_INDEX_GREEN    "green"
#define LED_MULTI_INDEX_BLUE     "blue"
#define LED_MULTI_INTENSITY_ATTR "multi_intensity"

/**
 * fbd-dev-led-multicolor:
 *
 * A multicolor led using the `multi_intensitiy` sysfs attribute
 */
typedef struct _FbdDevLedMulticolorPrivate {
  guint               red_index;
  guint               green_index;
  guint               blue_index;
} FbdDevLedMulticolorPrivate;


G_DEFINE_TYPE_WITH_PRIVATE (FbdDevLedMulticolor, fbd_dev_led_multicolor, FBD_TYPE_DEV_LED)


static gboolean
fbd_dev_led_multicolor_probe (FbdDevLed *led, GError **error)
{
  FbdDevLedMulticolor *self = FBD_DEV_LED_MULTICOLOR (led);
  FbdDevLedMulticolorPrivate *priv = fbd_dev_led_multicolor_get_instance_private (self);
  GUdevDevice *dev = fbd_dev_led_get_device (led);
  const gchar *name, *path;
  const gchar * const *index;
  guint counter = 0;
  guint max_brightness;

  name = g_udev_device_get_name (dev);

  index = g_udev_device_get_sysfs_attr_as_strv (dev, LED_MULTI_INDEX_ATTR);
  if (index == NULL) {
    g_set_error (error,
                 G_FILE_ERROR, G_FILE_ERROR_FAILED,
                 "%s is no multicolor LED", name);
    return FALSE;
  }

  max_brightness = g_udev_device_get_sysfs_attr_as_int (dev, LED_MAX_BRIGHTNESS_ATTR);
  if (!max_brightness) {
    g_set_error (error,
                 G_FILE_ERROR, G_FILE_ERROR_FAILED,
                 "%s has no max_brightness", name);
    return FALSE;
  }
  fbd_dev_led_set_max_brightness (led, max_brightness);
  fbd_dev_led_set_supported_color (led, FBD_FEEDBACK_LED_COLOR_RGB);

  for (int i = 0; index[i] != NULL; i++) {
    g_debug ("Index: %s", index[i]);
    if (g_strcmp0 (index[i], LED_MULTI_INDEX_RED) == 0) {
      priv->red_index = counter;
      counter++;
    } else if (g_strcmp0 (index[i], LED_MULTI_INDEX_GREEN) == 0) {
      priv->green_index = counter;
      counter++;
    } else if (g_strcmp0 (index[i], LED_MULTI_INDEX_BLUE) == 0) {
      priv->blue_index = counter;
      counter++;
    } else {
      g_warning ("Unsupport LED color index: %d %s", counter, index[i]);
    }
  }

  path = g_udev_device_get_sysfs_path (dev);
  g_debug ("LED at '%s' usable as multicolor", path);
  return TRUE;
}


static gboolean
fbd_dev_led_multicolor_set_color (FbdDevLed           *led,
                                  FbdFeedbackLedColor  color,
                                  FbdLedRgbColor      *rgb)
{
  FbdDevLedMulticolor *self = FBD_DEV_LED_MULTICOLOR (led);
  FbdDevLedMulticolorPrivate *priv = fbd_dev_led_multicolor_get_instance_private (self);
  GUdevDevice *dev = fbd_dev_led_get_device (led);
  g_autofree char *intensity = NULL;
  g_autoptr (GError) err = NULL;
  gboolean success = FALSE;
  guint max_brightness;
  guint colors[] = { 0, 0, 0 };

  max_brightness = fbd_dev_led_get_max_brightness (led);
  switch (color) {
  case FBD_FEEDBACK_LED_COLOR_WHITE:
    colors[priv->red_index] = max_brightness;
    colors[priv->green_index] = max_brightness;
    colors[priv->blue_index] = max_brightness;
    break;
  case FBD_FEEDBACK_LED_COLOR_RED:
    colors[priv->red_index] = max_brightness;
    colors[priv->green_index] = 0;
    colors[priv->blue_index] = 0;
    break;
  case FBD_FEEDBACK_LED_COLOR_GREEN:
    colors[priv->red_index] = 0;
    colors[priv->green_index] = max_brightness;
    colors[priv->blue_index] = 0;
    break;
  case FBD_FEEDBACK_LED_COLOR_BLUE:
    colors[priv->red_index] = 0;
    colors[priv->green_index] = 0;
    colors[priv->blue_index] = max_brightness;
    break;
  case FBD_FEEDBACK_LED_COLOR_RGB:
    colors[priv->red_index] = rgb->r;
    colors[priv->green_index] = rgb->g;
    colors[priv->blue_index] = rgb->b;
    break;
  default:
    g_warning("Unhandled color: %d\n", color);
    return FALSE;
  }

  intensity = g_strdup_printf ("%u %u %u\n", colors[0], colors[1], colors[2]);
  g_debug ("Multicolor intensity: %s", intensity);

  fbd_dev_led_set_brightness (led, max_brightness);
  success = fbd_udev_set_sysfs_path_attr_as_string (dev,
                                                    LED_MULTI_INTENSITY_ATTR,
                                                    intensity,
                                                    &err);
  if (!success) {
    g_warning ("Failed to set multi intensity: %s", err->message);
    return FALSE;
  }

  return TRUE;
}


static gboolean
fbd_dev_led_multicolor_supports_color (FbdDevLed           *led,
                                       FbdFeedbackLedColor  color)
{
  switch(color) {
    case FBD_FEEDBACK_LED_COLOR_WHITE:
      return TRUE;
    case FBD_FEEDBACK_LED_COLOR_RED:
      return TRUE;
    case FBD_FEEDBACK_LED_COLOR_GREEN:
      return TRUE;
    case FBD_FEEDBACK_LED_COLOR_BLUE:
      return TRUE;
    case FBD_FEEDBACK_LED_COLOR_RGB:
      return TRUE;
    default:
      g_warning ("Color unsupported: %d", color);
      return FALSE;
  }
}


static void
fbd_dev_led_multicolor_class_init (FbdDevLedMulticolorClass *klass)
{
  FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_CLASS (klass);

  fbd_dev_led_class->probe = fbd_dev_led_multicolor_probe;
  fbd_dev_led_class->set_color = fbd_dev_led_multicolor_set_color;
  fbd_dev_led_class->supports_color = fbd_dev_led_multicolor_supports_color;
}


static void
fbd_dev_led_multicolor_init (FbdDevLedMulticolor *self)
{
}


FbdDevLed *
fbd_dev_led_multicolor_new (GUdevDevice *dev, GError **err)
{
  return g_initable_new (FBD_TYPE_DEV_LED_MULTICOLOR, NULL, err, "dev", dev, NULL);
}
07070100000058000081A400000000000000000000000166F7A513000001DF000000000000000000000000000000000000002D00000000feedbackd-0.5.0/src/fbd-dev-led-multicolor.h/*
 * Copyright (C) 2023 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-dev-led.h"

G_BEGIN_DECLS

#define FBD_TYPE_DEV_LED_MULTICOLOR fbd_dev_led_multicolor_get_type()

G_DECLARE_DERIVABLE_TYPE (FbdDevLedMulticolor, fbd_dev_led_multicolor, FBD, DEV_LED_MULTICOLOR, FbdDevLed)

FbdDevLed          *fbd_dev_led_multicolor_new  (GUdevDevice *dev, GError **err);

struct _FbdDevLedMulticolorClass {
  FbdDevLedClass parent_class;
};

G_END_DECLS
07070100000059000081A400000000000000000000000166F7A5130000020C000000000000000000000000000000000000002700000000feedbackd-0.5.0/src/fbd-dev-led-priv.h/*
 * Copyright (C) 2023 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-dev-led.h"
#include "fbd-feedback-led.h"

#include <gudev/gudev.h>
#include <glib-object.h>

G_BEGIN_DECLS

#define LED_MAX_BRIGHTNESS_ATTR  "max_brightness"

GUdevDevice      *fbd_dev_led_get_device  (FbdDevLed *led);
void              fbd_dev_led_set_max_brightness (FbdDevLed *led, guint max_brightness);
void              fbd_dev_led_set_supported_color (FbdDevLed *led, FbdFeedbackLedColor color);

G_END_DECLS
0707010000005A000081A400000000000000000000000166F7A5130000091F000000000000000000000000000000000000003200000000feedbackd-0.5.0/src/fbd-dev-led-qcom-multicolor.c/*
 * Copyright (C) 2023 Dylan Van Assche <me@dylanvanassche.be>
 * SPDX-License-Identifier: GPL-3.0+
 */

#define G_LOG_DOMAIN "fbd-dev-led-qcom-multicolor"

#include "fbd-dev-led-priv.h"
#include "fbd-dev-led.h"
#include "fbd-dev-led-qcom.h"
#include "fbd-dev-led-qcom-priv.h"
#include "fbd-dev-led-qcom-multicolor.h"
#include "fbd-enums.h"
#include "fbd-udev.h"

#include <gio/gio.h>


typedef struct _FbdDevLedQcomMulticolor {
  FbdDevLedMulticolor parent;

  FbdDevLedQcom *qcom_led;
} FbdDevLedQcomMulticolor;


G_DEFINE_TYPE (FbdDevLedQcomMulticolor, fbd_dev_led_qcom_multicolor, FBD_TYPE_DEV_LED_MULTICOLOR)


static gboolean
fbd_dev_led_qcom_multicolor_probe (FbdDevLed *led, GError **error)
{
  FbdDevLedQcomMulticolor *self = FBD_DEV_LED_QCOM_MULTICOLOR (led);
  GUdevDevice *dev = fbd_dev_led_get_device (FBD_DEV_LED (led));

  self->qcom_led = FBD_DEV_LED_QCOM (fbd_dev_led_qcom_new (dev, error));
  if (!self->qcom_led)
    return FALSE;

  return FBD_DEV_LED_CLASS (fbd_dev_led_qcom_multicolor_parent_class)->probe(led, error);
}

static gboolean
fbd_dev_led_qcom_multicolor_start_periodic (FbdDevLed *led,
		                            guint      max_brightness_percentage,
					    guint      freq)
{
  FbdDevLedQcomMulticolor *self = FBD_DEV_LED_QCOM_MULTICOLOR (led);

  return fbd_dev_led_start_periodic (FBD_DEV_LED (self->qcom_led), max_brightness_percentage, freq);
}

static void
fbd_dev_led_qcom_multicolor_finalize (GObject *object)
{
  FbdDevLedQcomMulticolor *self = FBD_DEV_LED_QCOM_MULTICOLOR (object);

  g_clear_object (&self->qcom_led);

  G_OBJECT_CLASS (fbd_dev_led_qcom_multicolor_parent_class)->finalize (object);
}

static void
fbd_dev_led_qcom_multicolor_class_init (FbdDevLedQcomMulticolorClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_CLASS (klass);

  object_class->finalize = fbd_dev_led_qcom_multicolor_finalize;

  fbd_dev_led_class->probe = fbd_dev_led_qcom_multicolor_probe;
  fbd_dev_led_class->start_periodic = fbd_dev_led_qcom_multicolor_start_periodic;
}


static void
fbd_dev_led_qcom_multicolor_init (FbdDevLedQcomMulticolor *self)
{
}


FbdDevLed *
fbd_dev_led_qcom_multicolor_new (GUdevDevice *dev, GError **err)
{
  return g_initable_new (FBD_TYPE_DEV_LED_QCOM_MULTICOLOR, NULL, err, "dev", dev, NULL);
}
0707010000005B000081A400000000000000000000000166F7A513000001E4000000000000000000000000000000000000003200000000feedbackd-0.5.0/src/fbd-dev-led-qcom-multicolor.h/*
 * Copyright (C) 2023 Dylan Van Assche <me@dylanvanassche.be>
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-dev-led-multicolor.h"

G_BEGIN_DECLS

#define FBD_TYPE_DEV_LED_QCOM_MULTICOLOR fbd_dev_led_qcom_multicolor_get_type()

G_DECLARE_FINAL_TYPE (FbdDevLedQcomMulticolor, fbd_dev_led_qcom_multicolor, FBD, DEV_LED_QCOM_MULTICOLOR, FbdDevLedMulticolor)

FbdDevLed          *fbd_dev_led_qcom_multicolor_new  (GUdevDevice *dev, GError **err);

G_END_DECLS
0707010000005C000081A400000000000000000000000166F7A51300000112000000000000000000000000000000000000002C00000000feedbackd-0.5.0/src/fbd-dev-led-qcom-priv.h/*
 * Copyright (C) 2023 Dylan Van Assche <me@dylanvanassche.be>
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-dev-led-qcom.h"

#include <glib-object.h>

G_BEGIN_DECLS

gboolean fbd_dev_led_probe_qcom (FbdDevLed *led, GError **error);

G_END_DECLS
0707010000005D000081A400000000000000000000000166F7A51300000FDD000000000000000000000000000000000000002700000000feedbackd-0.5.0/src/fbd-dev-led-qcom.c/*
 * Copyright (C) 2023 Dylan Van Assche <me@dylanvanassche.be>
 *
 * SPDX-License-Identifier: GPL-3.0+
 */

#define G_LOG_DOMAIN "fbd-dev-led-qcom"

#include "fbd-dev-led-priv.h"
#include "fbd-dev-led-qcom.h"
#include "fbd-dev-led-qcom-priv.h"
#include "fbd-enums.h"
#include "fbd-udev.h"

#include <gio/gio.h>

#define LED_HW_PATTERN_ATTR   "hw_pattern"
#define LED_REPEAT_ATTR       "repeat"
#define LED_REPEAT_INFINITY   "-1"
#define QCOM_LPG_MAX_PAUSE_MS 511
#define LED_DRIVER_PROP       "DRIVER"
#define QCOM_LED_DRIVER       "qcom-spmi-lpg"

typedef struct _FbdDevLedQcom {
  FbdDevLed parent;
} FbdDevLedQcom;


G_DEFINE_TYPE (FbdDevLedQcom, fbd_dev_led_qcom, FBD_TYPE_DEV_LED)


static gboolean
fbd_dev_led_qcom_check_driver (FbdDevLedQcom *self, const char *name)
{
  g_autoptr (GUdevDevice) dev = NULL;
  gboolean found = FALSE;

  dev = g_object_ref (fbd_dev_led_get_device (FBD_DEV_LED (self)));
  do {
    g_autoptr (GUdevDevice) parent = NULL;
    const char *driver = g_udev_device_get_property (dev, LED_DRIVER_PROP);

    if (g_strcmp0 (driver, QCOM_LED_DRIVER) == 0) {
      found = TRUE;
      break;
    }

    parent = g_udev_device_get_parent (dev);
    g_set_object (&dev, parent);
  } while (dev);

  return found;
}


static gboolean
fbd_dev_led_qcom_probe (FbdDevLed *led, GError **error)
{
  GUdevDevice *dev = fbd_dev_led_get_device (led);
  const char *name;
  const char * const *index;

  name = g_udev_device_get_name (dev);

  index = g_udev_device_get_sysfs_attr_as_strv (dev, LED_HW_PATTERN_ATTR);
  if (index == NULL) {
    g_set_error (error,
               G_FILE_ERROR, G_FILE_ERROR_FAILED,
               "%s is no LED with HW support", name);
    return FALSE;
  }

  if (!fbd_dev_led_qcom_check_driver (FBD_DEV_LED_QCOM (led), QCOM_LED_DRIVER)) {
    g_set_error (error,
                 G_FILE_ERROR, G_FILE_ERROR_FAILED,
                 "%s is no QCOM LED with HW support", name);
    return FALSE;
  }

  return FBD_DEV_LED_CLASS (fbd_dev_led_qcom_parent_class)->probe(led, error);
}


static gboolean
fbd_dev_led_qcom_start_periodic (FbdDevLed *led,
                                 guint      max_brightness_percentage,
                                 guint      freq)
{
  GUdevDevice *dev = fbd_dev_led_get_device (led);
  gdouble max;
  gdouble t;
  g_autofree char *str = NULL;
  g_autoptr (GError) err = NULL;
  gboolean success;

  g_return_val_if_fail (max_brightness_percentage <= 100.0, FALSE);
  max = fbd_dev_led_get_max_brightness (led) * (max_brightness_percentage / 100.0);

  g_debug ("Using hw_pattern interface for QCOM LPG LED");

  /* QCOM LPG LEDs can only pause up to 511ms */
  /*  ms     mHz           T/2 */
  t = 1000.0 * 1000.0 / freq / 2.0;
  if (t > QCOM_LPG_MAX_PAUSE_MS)
    t = QCOM_LPG_MAX_PAUSE_MS;

  str = g_strdup_printf ("0 %d 0 0 %d %d %d 0\n", (gint)t, (gint)max, (gint)t, (gint)max);

  success = fbd_udev_set_sysfs_path_attr_as_string (dev, LED_REPEAT_ATTR, LED_REPEAT_INFINITY, &err);
  if (!success) {
    g_warning ("Failed to set LED repeat: %s", err->message);
    goto failure;
  }

  success = fbd_udev_set_sysfs_path_attr_as_string (dev, LED_HW_PATTERN_ATTR, str, &err);
  if (!success) {
    g_warning ("Failed to set LED hw_pattern: %s", err->message);
    goto failure;
  }

  g_debug ("Freq %d mHz, Brightness: %d%%, Blink pattern: %s, HW: yes", freq, max_brightness_percentage, str);
  return TRUE;

failure:
  g_warning("Falling back to software pattern");
  return FBD_DEV_LED_CLASS (fbd_dev_led_qcom_parent_class)->start_periodic (
    led, max_brightness_percentage, freq);
}


static void
fbd_dev_led_qcom_class_init (FbdDevLedQcomClass *klass)
{
  FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_CLASS (klass);

  fbd_dev_led_class->probe = fbd_dev_led_qcom_probe;
  fbd_dev_led_class->start_periodic = fbd_dev_led_qcom_start_periodic;
}


static void
fbd_dev_led_qcom_init (FbdDevLedQcom *self)
{
}


FbdDevLed *
fbd_dev_led_qcom_new (GUdevDevice *dev, GError **err)
{
  return g_initable_new (FBD_TYPE_DEV_LED_QCOM, NULL, err, "dev", dev, NULL);
}
0707010000005E000081A400000000000000000000000166F7A5130000018E000000000000000000000000000000000000002700000000feedbackd-0.5.0/src/fbd-dev-led-qcom.h/*
 * Copyright (C) 2023 Dylan Van Assche <me@dylanvanassche.be>
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-dev-led.h"

G_BEGIN_DECLS

#define FBD_TYPE_DEV_LED_QCOM fbd_dev_led_qcom_get_type()

G_DECLARE_FINAL_TYPE (FbdDevLedQcom, fbd_dev_led_qcom, FBD, DEV_LED_QCOM, FbdDevLed)

FbdDevLed          *fbd_dev_led_qcom_new  (GUdevDevice *dev, GError **err);

G_END_DECLS
0707010000005F000081A400000000000000000000000166F7A5130000228E000000000000000000000000000000000000002200000000feedbackd-0.5.0/src/fbd-dev-led.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 *
 * See Documentation/ABI/testing/sysfs-class-led-trigger-pattern
 */

#define G_LOG_DOMAIN "fbd-dev-led"

#include "fbd-dev-led.h"
#include "fbd-dev-led-priv.h"
#include "fbd-enums.h"
#include "fbd-udev.h"

#include <gio/gio.h>

#define LED_BRIGHTNESS_ATTR      "brightness"
#define LED_PATTERN_ATTR         "pattern"

enum {
  PROP_0,
  PROP_DEV,
  PROP_LAST_PROP
};
static GParamSpec *props[PROP_LAST_PROP];

/**
 * FbdDevLed:
 *
 * A single color LED driven by Linux sysfs
 */
typedef struct _FbdDevLedPrivate {
  GUdevDevice        *dev;
  guint               max_brightness;

  FbdFeedbackLedColor color;
} FbdDevLedPrivate;


static void initable_iface_init (GInitableIface *iface);

G_DEFINE_TYPE_WITH_CODE (FbdDevLed, fbd_dev_led, G_TYPE_OBJECT,
                         G_ADD_PRIVATE (FbdDevLed)
                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init))

static gboolean
fbd_dev_led_probe_default (FbdDevLed *led, GError **error)
{
  FbdDevLedPrivate *priv = fbd_dev_led_get_instance_private (led);
  const gchar *name, *path;
  gboolean success = FALSE;

  name = g_udev_device_get_name (priv->dev);
  for (int i = 0; i <= FBD_FEEDBACK_LED_COLOR_RGB; i++) {
    g_autofree char *color = NULL;
    g_autofree char *enum_name = NULL;
    gchar *c;

    enum_name = g_enum_to_string (FBD_TYPE_FEEDBACK_LED_COLOR, i);
    c = strrchr (enum_name, '_');
    color = g_ascii_strdown (c+1, -1);
    if (g_strstr_len (name, -1, color)) {
      guint brightness = g_udev_device_get_sysfs_attr_as_int (priv->dev, LED_MAX_BRIGHTNESS_ATTR);

      if (!brightness)
        continue;

      priv->color = i;
      fbd_dev_led_set_max_brightness (led, brightness);

      path = g_udev_device_get_sysfs_path (priv->dev);
      g_debug ("LED at '%s' usable for %s", path, color);
      success = TRUE;
      break;
    }
  }

  if (!success) {
    g_set_error (error,
                 G_FILE_ERROR, G_FILE_ERROR_FAILED,
                 "%s not usable as RGB LED", name);
  }

  return success;
}


static gboolean
fbd_dev_led_set_color_default (FbdDevLed           *led,
                               FbdFeedbackLedColor  color,
                               FbdLedRgbColor      *rgb)
{
  /* Ignore setting color as we have a single color only */
  return TRUE;
}


static gboolean
fbd_dev_led_supports_color_default (FbdDevLed           *led,
                                    FbdFeedbackLedColor  color)
{
  FbdDevLedPrivate *priv;

  g_return_val_if_fail (FBD_IS_DEV_LED (led), FALSE);
  priv = fbd_dev_led_get_instance_private (led);

  return priv->color == color;
}


static gboolean
fbd_dev_led_start_periodic_default (FbdDevLed *led,
                                    guint      max_brightness_percentage,
                                    guint      freq)
{
  FbdDevLedPrivate *priv;
  g_autoptr (GError) err = NULL;
  g_autofree gchar *str = NULL;
  gboolean success = FALSE;
  gdouble max;
  gdouble t;

  g_return_val_if_fail (FBD_IS_DEV_LED (led), FALSE);
  g_return_val_if_fail (max_brightness_percentage <= 100, FALSE);
  priv = fbd_dev_led_get_instance_private (led);

  max =  priv->max_brightness * (max_brightness_percentage / 100.0);
  /*  ms     mHz           T/2 */
  t = 1000.0 * 1000.0 / freq / 2.0;
  str = g_strdup_printf ("0 %d %d %d\n", (gint)t, (gint)max, (gint)t);
  g_debug ("Freq %d mHz, Brightness: %d%%, Blink pattern: %s", freq, max_brightness_percentage, str);

  success = fbd_udev_set_sysfs_path_attr_as_string (priv->dev, LED_PATTERN_ATTR, str, &err);
  if (!success)
    g_warning ("Failed to set led pattern: %s", err->message);

  return success;
}


static void
fbd_dev_led_set_property (GObject      *object,
                          guint         property_id,
                          const GValue *value,
                          GParamSpec   *pspec)
{
  FbdDevLed *led = FBD_DEV_LED (object);
  FbdDevLedPrivate *priv = fbd_dev_led_get_instance_private (led);

  switch (property_id) {
  case PROP_DEV:
    priv->dev = g_value_dup_object (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}


static void
fbd_dev_led_get_property (GObject    *object,
                          guint       property_id,
                          GValue     *value,
                          GParamSpec *pspec)
{
  FbdDevLed *led = FBD_DEV_LED (object);
  FbdDevLedPrivate *priv = fbd_dev_led_get_instance_private (led);

  switch (property_id) {
  case PROP_DEV:
    g_value_set_object (value, priv->dev);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}


static void
fbd_dev_led_finalize (GObject *object)
{
  FbdDevLed *self = FBD_DEV_LED (object);
  FbdDevLedPrivate *priv = fbd_dev_led_get_instance_private (self);

  g_clear_object (&priv->dev);

  G_OBJECT_CLASS (fbd_dev_led_parent_class)->finalize (object);
}


static gboolean
initable_init (GInitable    *initable,
               GCancellable *cancellable,
               GError      **error)
{
  FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_GET_CLASS (initable);

  return fbd_dev_led_class->probe (FBD_DEV_LED (initable), error);
}


static void
initable_iface_init (GInitableIface *iface)
{
  iface->init = initable_init;
}


static void
fbd_dev_led_class_init (FbdDevLedClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_CLASS (klass);

  object_class->get_property = fbd_dev_led_get_property;
  object_class->set_property = fbd_dev_led_set_property;
  object_class->finalize = fbd_dev_led_finalize;

  fbd_dev_led_class->probe = fbd_dev_led_probe_default;
  fbd_dev_led_class->start_periodic = fbd_dev_led_start_periodic_default;
  fbd_dev_led_class->set_color = fbd_dev_led_set_color_default;
  fbd_dev_led_class->supports_color = fbd_dev_led_supports_color_default;

  props[PROP_DEV] =
    g_param_spec_object ("dev", "", "",
                         G_UDEV_TYPE_DEVICE,
                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}


static void
fbd_dev_led_init (FbdDevLed *self)
{
}


FbdDevLed *
fbd_dev_led_new (GUdevDevice *dev, GError **err)
{
  return g_initable_new (FBD_TYPE_DEV_LED, NULL, err, "dev", dev, NULL);
}


gboolean
fbd_dev_led_set_brightness (FbdDevLed *led, guint brightness)
{
  FbdDevLedPrivate *priv;
  g_autoptr (GError) err = NULL;

  g_return_val_if_fail (FBD_IS_DEV_LED (led), FALSE);
  priv = fbd_dev_led_get_instance_private (led);

  if (!fbd_udev_set_sysfs_path_attr_as_int (priv->dev, LED_BRIGHTNESS_ATTR, brightness, &err)) {
    g_warning ("Failed to setup brightness: %s", err->message);
    return FALSE;
  }

  return TRUE;
}


gboolean
fbd_dev_led_start_periodic (FbdDevLed *led,
                            guint      max_brightness_percentage,
                            guint      freq)
{
  FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_GET_CLASS (led);

  g_return_val_if_fail (FBD_IS_DEV_LED (led), FALSE);

  return fbd_dev_led_class->start_periodic (led, max_brightness_percentage, freq);
}


gboolean
fbd_dev_led_set_color (FbdDevLed           *led,
                       FbdFeedbackLedColor  color,
                       FbdLedRgbColor      *rgb)
{
  FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_GET_CLASS (led);

  g_return_val_if_fail (FBD_IS_DEV_LED (led), FALSE);

  return fbd_dev_led_class->set_color (led, color, rgb);
}


gboolean
fbd_dev_led_supports_color (FbdDevLed *led, FbdFeedbackLedColor color)
{
  FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_GET_CLASS (led);

  g_return_val_if_fail (FBD_IS_DEV_LED (led), FALSE);

  return fbd_dev_led_class->supports_color (led, color);
}


guint
fbd_dev_led_get_max_brightness (FbdDevLed *led)
{
  FbdDevLedPrivate *priv;

  g_return_val_if_fail (FBD_IS_DEV_LED (led), 0);
  priv = fbd_dev_led_get_instance_private (led);

  return priv->max_brightness;
}

/* Functions for derived classes */

GUdevDevice *
fbd_dev_led_get_device (FbdDevLed *led)
{
  FbdDevLedPrivate *priv;

  g_return_val_if_fail (FBD_IS_DEV_LED (led), NULL);
  priv = fbd_dev_led_get_instance_private (led);

  return priv->dev;
}


void
fbd_dev_led_set_supported_color (FbdDevLed *led, FbdFeedbackLedColor color)
{
  FbdDevLedPrivate *priv;

  g_return_if_fail (FBD_IS_DEV_LED (led));
  priv = fbd_dev_led_get_instance_private (led);

  priv->color = color;
}


void
fbd_dev_led_set_max_brightness (FbdDevLed *led, guint max_brightness)
{
  FbdDevLedPrivate *priv;

  g_return_if_fail (FBD_IS_DEV_LED (led));
  priv = fbd_dev_led_get_instance_private (led);

  priv->max_brightness = max_brightness;
}
07070100000060000081A400000000000000000000000166F7A513000006A4000000000000000000000000000000000000002200000000feedbackd-0.5.0/src/fbd-dev-led.h/*
 * Copyright (C) 2023 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-feedback-led.h"

#include <gudev/gudev.h>

#include <glib-object.h>

G_BEGIN_DECLS

#define FBD_TYPE_DEV_LED fbd_dev_led_get_type()

G_DECLARE_DERIVABLE_TYPE (FbdDevLed, fbd_dev_led, FBD, DEV_LED, GObject)

FbdDevLed          *fbd_dev_led_new  (GUdevDevice *dev, GError **err);
gboolean            fbd_dev_led_set_brightness (FbdDevLed *led, guint brightness);
guint               fbd_dev_led_get_max_brightness (FbdDevLed *led);
gboolean            fbd_dev_led_set_color (FbdDevLed           *led,
                                           FbdFeedbackLedColor  color,
                                           FbdLedRgbColor      *rgb);
gboolean            fbd_dev_led_start_periodic (FbdDevLed      *led,
                                                guint           max_brightness_percentage,
                                                guint           freq);
gboolean            fbd_dev_led_supports_color (FbdDevLed *led, FbdFeedbackLedColor color);

struct _FbdDevLedClass {
  GObjectClass parent_class;

  gboolean (*probe)          (FbdDevLed            *led, GError **error);
  gboolean (*start_periodic) (FbdDevLed           *led,
                              guint                max_brightness_percentage,
                              guint                freq);
  gboolean (*set_color)      (FbdDevLed            *led,
                              FbdFeedbackLedColor   color,
                              FbdLedRgbColor       *rgb);
  gboolean (*supports_color) (FbdDevLed            *led,
                              FbdFeedbackLedColor   color);
};

G_END_DECLS
07070100000061000081A400000000000000000000000166F7A51300001880000000000000000000000000000000000000002300000000feedbackd-0.5.0/src/fbd-dev-leds.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 *
 * See Documentation/ABI/testing/sysfs-class-led-trigger-pattern
 */

#define G_LOG_DOMAIN "fbd-dev-leds"

#include "fbd.h"
#include "fbd-enums.h"
#include "fbd-dev-led.h"
#include "fbd-dev-led-flash.h"
#include "fbd-dev-led-multicolor.h"
#include "fbd-dev-led-qcom.h"
#include "fbd-dev-led-qcom-multicolor.h"
#include "fbd-dev-leds.h"
#include "fbd-feedback-led.h"
#include "fbd-udev.h"

#include <gio/gio.h>

#define LED_SUBSYSTEM            "leds"

/**
 * FbdDevLeds:
 *
 * LED device interface
 *
 * #FbdDevLeds is used to interface with all LEDs detected in sysfs
 * It currently only supports one pattern per led at a time.
 */
typedef struct _FbdDevLeds {
  GObject      parent;

  GUdevClient *client;
  GSList      *leds;
} FbdDevLeds;

static void initable_iface_init (GInitableIface *iface);

G_DEFINE_TYPE_WITH_CODE (FbdDevLeds, fbd_dev_leds, G_TYPE_OBJECT,
                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init));

static FbdDevLed *
find_led_by_color (FbdDevLeds *self, FbdFeedbackLedColor color)
{
  g_return_val_if_fail (self->leds, NULL);

  for (GSList *l = self->leds; l != NULL; l = l->next) {
    FbdDevLed *led = FBD_DEV_LED (l->data);
    if (fbd_dev_led_supports_color (led, color))
      return led;
  }

  /* If we did not match a color pick the first non flash LED */
  for (GSList *l = self->leds; l != NULL; l = l->next) {
    FbdDevLed *led = FBD_DEV_LED (l->data);

    if (!fbd_dev_led_supports_color (led, FBD_FEEDBACK_LED_COLOR_FLASH))
      return led;
  }

  return NULL;
}


static FbdDevLed*
probe_led (GUdevDevice *dev, GError **error) {
  FbdDevLed *led = NULL;

  led = fbd_dev_led_qcom_multicolor_new (dev, error);
  if (led != NULL) {
    g_debug ("Discovered QCOM multicolor LED");
    return led;
  }
  g_clear_error (error);

  led = fbd_dev_led_qcom_new (dev, error);
  if (led != NULL) {
    g_debug ("Discovered QCOM single color LED");
    return led;
  }
  g_clear_error (error);

  led = fbd_dev_led_multicolor_new (dev, error);
  if (led != NULL) {
    g_debug ("Discovered multicolor LED");
    return led;
  }
  g_clear_error (error);

  led = fbd_dev_led_flash_new (dev, error);
  if (led != NULL) {
    g_debug ("Discovered flash LED");
    return led;
  }
  g_clear_error (error);

  led = fbd_dev_led_new (dev, error);
  if (led != NULL) {
    g_debug ("Discovered single color LED");
    return led;
  }

  g_debug ("Unable to determine LED driver");
  return NULL;
}


static gboolean
initable_init (GInitable    *initable,
               GCancellable *cancellable,
               GError      **error)
{
  const gchar * const subsystems[] = { LED_SUBSYSTEM, NULL };
  FbdDevLeds *self = FBD_DEV_LEDS (initable);
  g_autolist (GUdevDevice) leds = NULL;
  gboolean found = FALSE;

  self->client = g_udev_client_new (subsystems);

  leds = g_udev_client_query_by_subsystem (self->client, LED_SUBSYSTEM);

  for (GList *l = leds; l != NULL; l = l->next) {
    g_autoptr (GError) err = NULL;
    GUdevDevice *dev = G_UDEV_DEVICE (l->data);
    FbdDevLed *led;

    if (g_strcmp0 (g_udev_device_get_property (dev, FEEDBACKD_UDEV_ATTR),
                   FEEDBACKD_UDEV_VAL_LED)) {
      continue;
    }

    led = probe_led (dev, &err);

    if (led) {
      self->leds = g_slist_append (self->leds, led);
      found = TRUE;
    }
  }

  /* TODO: listen for new leds via udev events */

  if (!found) {
    g_set_error (error,
                 G_FILE_ERROR, G_FILE_ERROR_FAILED,
                 "No usable LEDs found");
  }

  return found;
}

static void
initable_iface_init (GInitableIface *iface)
{
  iface->init = initable_init;
}

static void
fbd_dev_leds_dispose (GObject *object)
{
  FbdDevLeds *self = FBD_DEV_LEDS (object);

  g_clear_object (&self->client);
  g_slist_free_full (self->leds, (GDestroyNotify)g_object_unref);
  self->leds = NULL;

  G_OBJECT_CLASS (fbd_dev_leds_parent_class)->dispose (object);
}

static void
fbd_dev_leds_class_init (FbdDevLedsClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->dispose = fbd_dev_leds_dispose;
}

static void
fbd_dev_leds_init (FbdDevLeds *self)
{
}

FbdDevLeds *
fbd_dev_leds_new (GError **error)
{
  return FBD_DEV_LEDS (g_initable_new (FBD_TYPE_DEV_LEDS,
                                       NULL,
                                       error,
                                       NULL));
}

/**
 * fbd_dev_leds_start_periodic:
 * @self: The #FbdDevLeds
 * @color: The color LED to use for the LED pattern
 * @rgb: The rgb value to set (if `color` indicates an RGB led)
 * @max_brightness_percentage: The max brightness (in percent) to use for the pattern
 * @freq: The pattern's frequency in mHz
 *
 * Start periodic feedback.
 */
gboolean
fbd_dev_leds_start_periodic (FbdDevLeds          *self,
                             FbdFeedbackLedColor  color,
                             FbdLedRgbColor      *rgb,
                             guint                max_brightness_percentage,
                             guint                freq)
{
  FbdDevLed *led;

  g_return_val_if_fail (FBD_IS_DEV_LEDS (self), FALSE);
  g_return_val_if_fail (max_brightness_percentage <= 100.0, FALSE);
  led = find_led_by_color (self, color);
  if (!led) {
    g_warning_once ("No usable led found");
    return FALSE;
  }

  fbd_dev_led_set_color (led, color, rgb);

  return fbd_dev_led_start_periodic (led, max_brightness_percentage, freq);
}

gboolean
fbd_dev_leds_stop (FbdDevLeds *self, FbdFeedbackLedColor color)
{
  FbdDevLed *led;

  g_return_val_if_fail (FBD_IS_DEV_LEDS (self), FALSE);

  led = find_led_by_color (self, color);
  if (!led) {
    g_warning_once ("No usable led found");
    return FALSE;
  }

  return fbd_dev_led_set_brightness (led, 0);
}

/**
 * fbd_dev_leds_has_led:
 * @self: The FbdDevLeds
 * @color: The color type to check
 *
 * Whether there's a usable LED of the given type
 *
 * Returns: `TRUE` if there's a at least one usable LED, otherwise `FALSE`
 */
gboolean
fbd_dev_leds_has_led (FbdDevLeds *self, FbdFeedbackLedColor color)
{
  g_return_val_if_fail (FBD_IS_DEV_LEDS (self), FALSE);

  return !!find_led_by_color (self, color);
}
07070100000062000081A400000000000000000000000166F7A51300000373000000000000000000000000000000000000002300000000feedbackd-0.5.0/src/fbd-dev-leds.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-feedback-led.h"
#include "fbd-udev.h"

#include <glib-object.h>

G_BEGIN_DECLS

#define FBD_TYPE_DEV_LEDS (fbd_dev_leds_get_type ())

G_DECLARE_FINAL_TYPE (FbdDevLeds, fbd_dev_leds, FBD, DEV_LEDS, GObject);

FbdDevLeds *fbd_dev_leds_new (GError **error);
gboolean    fbd_dev_leds_start_periodic (FbdDevLeds          *self,
                                         FbdFeedbackLedColor  color,
                                         FbdLedRgbColor      *rgb,
                                         guint                max_brighness,
                                         guint                freq);
gboolean    fbd_dev_leds_stop (FbdDevLeds *self, FbdFeedbackLedColor color);
gboolean    fbd_dev_leds_has_led (FbdDevLeds *self, FbdFeedbackLedColor color);

G_END_DECLS
07070100000063000081A400000000000000000000000166F7A5130000199E000000000000000000000000000000000000002400000000feedbackd-0.5.0/src/fbd-dev-sound.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 *
 * See https://www.kernel.org/doc/html/latest/input/ff.html
 * and fftest.c from the joystick package.
 */

#define G_LOG_DOMAIN "fbd-dev-sound"

#include "fbd-dev-sound.h"
#include "fbd-feedback-sound.h"

#include <gsound.h>

#define GNOME_SOUND_SCHEMA_ID "org.gnome.desktop.sound"
#define GNOME_SOUND_KEY_THEME_NAME "theme-name"

/**
 * SECTION:fbd-dev-sound
 * @short_description: Sound interface
 * @Title: FbdDevSound
 *
 * The #FbdDevSound is used to play sounds via the systems audio
 * system.
 */

typedef struct _FbdAsyncData {
  FbdDevSoundPlayedCallback  callback;
  FbdFeedbackSound          *feedback;
  FbdDevSound               *dev;
  GCancellable              *cancel;
} FbdAsyncData;

typedef struct _FbdDevSound {
  GObject parent;

  GSoundContext *ctx;
  GSettings     *sound_settings;
  GHashTable    *playbacks;
} FbdDevSound;

static void initable_iface_init (GInitableIface *iface);

G_DEFINE_TYPE_WITH_CODE (FbdDevSound, fbd_dev_sound, G_TYPE_OBJECT,
                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init));

static void
on_sound_theme_name_changed (FbdDevSound *self,
                             const gchar *key,
                             GSettings   *settings)
{
  gboolean ok;
  g_autoptr(GError) error = NULL;
  g_autofree gchar *name = NULL;

  g_return_if_fail (FBD_IS_DEV_SOUND (self));
  g_return_if_fail (G_IS_SETTINGS (settings));
  g_return_if_fail (!g_strcmp0 (key, GNOME_SOUND_KEY_THEME_NAME));
  g_return_if_fail (self->ctx);

  name = g_settings_get_string (settings, key);
  g_debug ("Setting sound theme to %s", name);

  ok = gsound_context_set_attributes (self->ctx,
				      &error,
				      GSOUND_ATTR_CANBERRA_XDG_THEME_NAME,
				      name,
				      NULL);
  if (!ok)
    g_warning ("Failed to set sound theme name to %s: %s", key, error->message);
}

static FbdAsyncData*
fbd_async_data_new (FbdDevSound *dev, FbdFeedbackSound *feedback, FbdDevSoundPlayedCallback callback)
{
  FbdAsyncData* data;

  data = g_new0 (FbdAsyncData, 1);
  data->callback = callback;
  data->feedback = g_object_ref (feedback);
  data->dev = g_object_ref (dev);
  data->cancel = g_cancellable_new ();

  return data;
}

static void
fbd_async_data_dispose (FbdAsyncData *data)
{
  g_object_unref (data->feedback);
  g_object_unref (data->dev);
  g_object_unref (data->cancel);
  g_free (data);
}

static void
fbd_dev_sound_dispose (GObject *object)
{
  FbdDevSound *self = FBD_DEV_SOUND (object);

  g_clear_object (&self->ctx);
  g_clear_object (&self->sound_settings);
  g_clear_pointer (&self->playbacks, g_hash_table_unref);

  G_OBJECT_CLASS (fbd_dev_sound_parent_class)->dispose (object);
}

static gboolean
initable_init (GInitable    *initable,
               GCancellable *cancellable,
               GError      **error)
{
  FbdDevSound *self = FBD_DEV_SOUND (initable);
  const char *desktop;
  gboolean gnome_session = FALSE;

  self->playbacks = g_hash_table_new (g_direct_hash, g_direct_equal);
  self->ctx = gsound_context_new (NULL, error);
  if (!self->ctx)
    return FALSE;

  desktop = g_getenv ("XDG_CURRENT_DESKTOP");
  if (desktop) {
    g_auto (GStrv) components = g_strsplit (desktop, ":", -1);
    gnome_session = g_strv_contains ((const char * const *)components, "GNOME");
  }

  if (gnome_session) {
    self->sound_settings = g_settings_new (GNOME_SOUND_SCHEMA_ID);

    g_signal_connect_object (self->sound_settings, "changed::" GNOME_SOUND_KEY_THEME_NAME,
			     G_CALLBACK (on_sound_theme_name_changed), self,
			     G_CONNECT_SWAPPED);
    on_sound_theme_name_changed (self, GNOME_SOUND_KEY_THEME_NAME, self->sound_settings);
  }

  return TRUE;
}

static void
initable_iface_init (GInitableIface *iface)
{
    iface->init = initable_init;
}

static void
fbd_dev_sound_class_init (FbdDevSoundClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->dispose = fbd_dev_sound_dispose;
}

static void
fbd_dev_sound_init (FbdDevSound *self)
{
}

FbdDevSound *
fbd_dev_sound_new (GError **error)
{
  return FBD_DEV_SOUND (g_initable_new (FBD_TYPE_DEV_SOUND,
                                        NULL,
                                        error,
                                        NULL));
}


static void
on_sound_play_finished_callback (GSoundContext *ctx,
                                 GAsyncResult  *res,
                                 FbdAsyncData  *data)
{
  g_autoptr (GError) err = NULL;

  if (!gsound_context_play_full_finish (ctx, res, &err)) {
    if (err->domain == GSOUND_ERROR && err->code == GSOUND_ERROR_NOTFOUND) {
      g_debug ("Failed to find sound '%s'", fbd_feedback_sound_get_effect (data->feedback));
    } else if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
      g_debug ("Sound '%s' cancelled", fbd_feedback_sound_get_effect (data->feedback));
    } else {
      g_warning ("Failed to play sound '%s': %s",
		 fbd_feedback_sound_get_effect (data->feedback),
		 err->message);
    }
  }

  /* Order matters here. We need to remove the feedback from the hash table before
     invoking the callback. */
  g_hash_table_remove (data->dev->playbacks, data->feedback);
  (*data->callback)(data->feedback);

  fbd_async_data_dispose (data);
}


gboolean
fbd_dev_sound_play (FbdDevSound *self, FbdFeedbackSound *feedback, FbdDevSoundPlayedCallback callback)
{
  FbdAsyncData *data;

  g_return_val_if_fail (FBD_IS_DEV_SOUND (self), FALSE);
  g_return_val_if_fail (GSOUND_IS_CONTEXT (self->ctx), FALSE);

  data = fbd_async_data_new (self, feedback, callback);

  if (!g_hash_table_insert (self->playbacks, feedback, data))
    g_warning ("Feedback %p already present", feedback);

  gsound_context_play_full (self->ctx, data->cancel,
                            (GAsyncReadyCallback) on_sound_play_finished_callback,
                            data,
                            GSOUND_ATTR_EVENT_ID, fbd_feedback_sound_get_effect (feedback),
                            GSOUND_ATTR_EVENT_DESCRIPTION, "Feedbackd sound feedback",
                            GSOUND_ATTR_MEDIA_ROLE, "event",
                            NULL);
  return TRUE;
}

gboolean
fbd_dev_sound_stop (FbdDevSound *self, FbdFeedbackSound *feedback)
{
  FbdAsyncData *data;

  g_return_val_if_fail (FBD_IS_DEV_SOUND (self), FALSE);

  data = g_hash_table_lookup (self->playbacks, feedback);

  if (data == NULL)
    return FALSE;

  g_cancellable_cancel (data->cancel);

  return TRUE;
}
07070100000064000081A400000000000000000000000166F7A513000002BA000000000000000000000000000000000000002400000000feedbackd-0.5.0/src/fbd-dev-sound.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include <glib-object.h>

#include "fbd-feedback-sound.h"

G_BEGIN_DECLS

#define FBD_TYPE_DEV_SOUND (fbd_dev_sound_get_type())

G_DECLARE_FINAL_TYPE (FbdDevSound, fbd_dev_sound, FBD, DEV_SOUND, GObject);

typedef void (*FbdDevSoundPlayedCallback)(FbdFeedbackSound *feedback);

FbdDevSound *fbd_dev_sound_new (GError **error);
gboolean     fbd_dev_sound_play (FbdDevSound *self,
                                 FbdFeedbackSound *feedback,
                                 FbdDevSoundPlayedCallback callback);
gboolean     fbd_dev_sound_stop (FbdDevSound *self, FbdFeedbackSound *feedback);

G_END_DECLS
07070100000065000081A400000000000000000000000166F7A51300002543000000000000000000000000000000000000002400000000feedbackd-0.5.0/src/fbd-dev-vibra.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 *
 * See https://www.kernel.org/doc/html/latest/input/ff.html
 * and fftest.c from the joystick package.
 */

#define G_LOG_DOMAIN "fbd-dev-vibra"

#include "fbd-dev-vibra.h"

#include <gio/gio.h>

#include <errno.h>
#include <fcntl.h>
#include <linux/input.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>

/**
 * SECTION:fbd-dev-vibra
 * @short_description: Haptic motor device interface
 * @Title: FbdDevVibra
 *
 * The #FbdDevVibra is used to interface with haptic motor via the force
 * feedback interface. It currently only supports one id at a time.
 */

enum {
  PROP_0,
  PROP_DEVICE,
  PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];

typedef enum {
  FBD_DEV_VIBRA_FEATURE_RUMBLE,
  FBD_DEV_VIBRA_FEATURE_PERIODIC,
  FBD_DEV_VIBRA_FEATURE_GAIN,
} FbdDevVibraFeatureFlags;

typedef struct _FbdDevVibra {
  GObject parent;

  GUdevDevice *device;
  gint fd;
  gint id; /* currently used id */

  FbdDevVibraFeatureFlags features;
} FbdDevVibra;

static void initable_iface_init (GInitableIface *iface);

G_DEFINE_TYPE_WITH_CODE (FbdDevVibra, fbd_dev_vibra, G_TYPE_OBJECT,
                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init));

static void
fbd_dev_vibra_set_property (GObject      *object,
                            guint         property_id,
                            const GValue *value,
                            GParamSpec   *pspec)
{
  FbdDevVibra *self = FBD_DEV_VIBRA (object);

  switch (property_id) {
  case PROP_DEVICE:
    g_clear_object (&self->device);
    self->device = g_value_dup_object (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}


static void
fbd_dev_vibra_get_property (GObject    *object,
                            guint       property_id,
                            GValue     *value,
                            GParamSpec *pspec)
{
  switch (property_id) {
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

#define BITS_PER_LONG (8 * sizeof (long))

#define HAS_FEATURE(fbit, a) \
  (a[(fbit/BITS_PER_LONG)] >> ((fbit % BITS_PER_LONG)) & 1)

static gboolean
initable_init (GInitable     *initable,
               GCancellable  *cancellable,
               GError       **error)
{
  FbdDevVibra *self = FBD_DEV_VIBRA (initable);
  const char *filename = g_udev_device_get_device_file (self->device);
  gulong features[1 + FF_MAX/BITS_PER_LONG];
  struct input_event gain = { 0 };

  self->fd = open (filename, O_RDWR | O_NONBLOCK, O_RDWR);
  if (self->fd < 0) {
    g_set_error (error,
                 G_FILE_ERROR, G_FILE_ERROR_FAILED,
                 "Unable to open '%s': %s",
                 filename, g_strerror (errno));
    return FALSE;
  }

  if (ioctl (self->fd, EVIOCGBIT(EV_FF, sizeof (features)), features) == -1) {
    g_set_error (error,
                 G_FILE_ERROR, G_FILE_ERROR_FAILED,
                 "Unable to probe features of '%s': %s",
                 filename, g_strerror (errno));
    return FALSE;
  }

  if (HAS_FEATURE(FF_RUMBLE, features))
    self->features |= FBD_DEV_VIBRA_FEATURE_RUMBLE;
  else {
    g_set_error (error,
                 G_FILE_ERROR, G_FILE_ERROR_FAILED,
                 "No rumble capable vibra device “%s”: %s",
                 filename, g_strerror (errno));
    return FALSE;
  }

  if (HAS_FEATURE(FF_PERIODIC, features))
    self->features |= FBD_DEV_VIBRA_FEATURE_PERIODIC;
  else {
    g_set_error (error,
                 G_FILE_ERROR, G_FILE_ERROR_FAILED,
                 "No rumble capable vibra device “%s”: %s",
                 filename, g_strerror (errno));
    return FALSE;
  }

  /* Set gain to 75% if supported */
  if (HAS_FEATURE(FF_GAIN, features)) {
    self->features |= FBD_DEV_VIBRA_FEATURE_GAIN;
    memset(&gain, 0, sizeof(gain));
    gain.type = EV_FF;
    gain.code = FF_GAIN;
    gain.value = 0xC000; /* [0, 0xFFFF]) */

    g_debug("Setting master gain to 75%%");
    if (write(self->fd, &gain, sizeof(gain)) != sizeof(gain)) {
      g_set_error (error,
                 G_FILE_ERROR, G_FILE_ERROR_FAILED,
                 "Unable to set gain of '%s': %s",
                 filename, g_strerror (errno));
    }
  } else {
    g_debug ("Gain unsupported");
  }

  g_debug ("Vibra device at '%s' usable", filename);
  return TRUE;
}

static void
initable_iface_init (GInitableIface *iface)
{
    iface->init = initable_init;
}

static void
fbd_dev_vibra_dispose (GObject *object)
{
  FbdDevVibra *self = FBD_DEV_VIBRA (object);

  g_clear_object (&self->device);

  G_OBJECT_CLASS (fbd_dev_vibra_parent_class)->dispose (object);
}

static void
fbd_dev_vibra_finalize (GObject *object)
{
  FbdDevVibra *self = FBD_DEV_VIBRA (object);

  if (self->fd >= 0) {
    close (self->fd);
    self->fd = -1;
  }

  G_OBJECT_CLASS (fbd_dev_vibra_parent_class)->finalize (object);
}

static void
fbd_dev_vibra_class_init (FbdDevVibraClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->set_property = fbd_dev_vibra_set_property;
  object_class->get_property = fbd_dev_vibra_get_property;

  object_class->dispose = fbd_dev_vibra_dispose;
  object_class->finalize = fbd_dev_vibra_finalize;

  props[PROP_DEVICE] =
    g_param_spec_object (
      "device",
      "Device",
      "The udev device",
      G_UDEV_TYPE_DEVICE,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}

static void
fbd_dev_vibra_init (FbdDevVibra *self)
{
}

FbdDevVibra *
fbd_dev_vibra_new (GUdevDevice *device, GError **error)
{
  return FBD_DEV_VIBRA (g_initable_new (FBD_TYPE_DEV_VIBRA,
                                        NULL,
                                        error,
                                        "device", device,
                                        NULL));
}

gboolean
fbd_dev_vibra_rumble (FbdDevVibra *self, guint duration, gboolean upload)
{
  struct input_event event = { 0 };
  struct ff_effect effect = { 0 };

  g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE);

  memset(&effect, 0, sizeof(effect));
  effect.type = FF_RUMBLE;
  effect.id = -1;
  effect.u.rumble.strong_magnitude = 0x8000;
  effect.u.rumble.weak_magnitude = 0;
  effect.replay.length = duration;
  effect.replay.delay = 0;

  if (upload) {
    g_debug("Uploading rumbling vibra effect (%d)", self->fd);
    if (ioctl(self->fd, EVIOCSFF, &effect) == -1) {
      g_warning ("Failed to upload rumbling vibra effect: %s", g_strerror (errno));
      return FALSE;
    }
    self->id = effect.id;
  }

  g_debug("Playing rumbling vibra effect id %d", effect.id);
  event.type = EV_FF;
  event.value = 1;
  event.code = self->id;

  if (write (self->fd, (const void*) &event, sizeof (event)) < 0) {
    g_warning ("Failed to play rumbling vibra effect.");
    return FALSE;
  }

  return TRUE;
}

/* TODO: fall back to multiple rumbles when sine not supported */
gboolean
fbd_dev_vibra_periodic (FbdDevVibra *self, guint duration, guint magnitude,
			guint fade_in_level, guint fade_in_time)
{
  struct input_event event;
  struct ff_effect effect = { 0 };

  g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE);

  if (!magnitude)
    magnitude = 0x7FFF;

  if (!fade_in_level)
    fade_in_level = magnitude;

  if (!fade_in_time)
    fade_in_time = duration;

  effect.type = FF_PERIODIC;
  effect.id = -1;
  effect.u.periodic.waveform = FF_SINE;
  effect.u.periodic.period = 10;
  effect.u.periodic.magnitude = magnitude;
  effect.u.periodic.offset = 0;
  effect.u.periodic.phase = 0;
  effect.direction = 0x4000;
  effect.u.periodic.envelope.attack_length = fade_in_time;
  effect.u.periodic.envelope.attack_level = fade_in_level;;
  effect.u.periodic.envelope.fade_length = 0;
  effect.u.periodic.envelope.fade_level = 0;
  effect.trigger.button = 0;
  effect.trigger.interval = 0;
  effect.replay.length = duration;
  effect.replay.delay = 200;

  g_debug("Uploading periodic effect (%d)", self->fd);
  if (ioctl(self->fd, EVIOCSFF, &effect) == -1) {
    g_warning ("Failed to upload periodic vibra effect: %s", g_strerror (errno));
    return FALSE;
  }

  g_debug("Playing periodic vibra effect id %d", effect.id);
  event.type = EV_FF;
  self->id = event.code = effect.id;
  event.value = 1;

  if (write (self->fd, (const void*) &event, sizeof (event)) < 0) {
    g_warning ("Failed to play rumbling effect.");
    return FALSE;
  }

  return TRUE;
}


gboolean
fbd_dev_vibra_remove_effect (FbdDevVibra *self)
{
  g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE);

  g_debug("Erasing vibra effect (%d)", self->fd);
  if (ioctl(self->fd, EVIOCRMFF, self->id) == -1) {
    g_warning  ("Failed to erase vibra effect with id %d: %s", self->id, strerror(errno));
    return FALSE;
  }
  return TRUE;
}


gboolean
fbd_dev_vibra_stop(FbdDevVibra *self)
{
  struct input_event stop = { 0 };

  g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE);

  stop.type = EV_FF;
  stop.code = self->id;
  stop.value = 0;

  if (write(self->fd, (const void*) &stop, sizeof(stop)) < 0) {
    g_warning  ("Failed to stop vibra effect with id %d: %s", self->id, strerror(errno));
    return FALSE;
  }

  return fbd_dev_vibra_remove_effect (self);
}

GUdevDevice *
fbd_dev_vibra_get_device(FbdDevVibra *self)
{
  g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE);

  return self->device;
}
07070100000066000081A400000000000000000000000166F7A5130000030B000000000000000000000000000000000000002400000000feedbackd-0.5.0/src/fbd-dev-vibra.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include <glib-object.h>
#include <gudev/gudev.h>

G_BEGIN_DECLS

#define FBD_TYPE_DEV_VIBRA (fbd_dev_vibra_get_type())

G_DECLARE_FINAL_TYPE (FbdDevVibra, fbd_dev_vibra, FBD, DEV_VIBRA, GObject);

FbdDevVibra *fbd_dev_vibra_new (GUdevDevice *device, GError **error);
gboolean     fbd_dev_vibra_rumble (FbdDevVibra *device, guint duration, gboolean upload);
gboolean     fbd_dev_vibra_periodic (FbdDevVibra *self, guint duration, guint magnitude,
				     guint fade_in_level, guint fade_in_time);
gboolean     fbd_dev_vibra_stop (FbdDevVibra *self);
gboolean     fbd_dev_vibra_remove_effect (FbdDevVibra *self);
GUdevDevice *fbd_dev_vibra_get_device(FbdDevVibra *self);


G_END_DECLS
07070100000067000081A400000000000000000000000166F7A51300000122000000000000000000000000000000000000002000000000feedbackd-0.5.0/src/fbd-error.c/*
 * Copyright (C) 2022 Guido Günther
 *
 * SPDX-License-Identifier: GPL-3.0+
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "fbd.h"

GQuark
fbd_error_quark (void)
{
  static GQuark quark = 0;

  if (!quark)
    quark = g_quark_from_static_string("fbd");

  return quark;
}
07070100000068000081A400000000000000000000000166F7A51300003388000000000000000000000000000000000000002000000000feedbackd-0.5.0/src/fbd-event.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-event"

#include "lfb-names.h"
#include "fbd.h"
#include "fbd-enums.h"
#include "fbd-event.h"

enum {
  SIGNAL_FEEDBACKS_ENDED,
  N_SIGNALS
};
static guint signals[N_SIGNALS];

enum {
  PROP_0,
  PROP_ID,
  PROP_APP_ID,
  PROP_EVENT,
  PROP_END_REASON,
  PROP_FEEDBACKS_ENDED,
  PROP_TIMEOUT,
  PROP_SENDER,
  PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];

typedef struct _FbdEvent {
  GObject parent;

  guint id;
  char *app_id;
  char *event;
  char *sender;

  int  timeout;
  gboolean expired;
  guint timeout_id;

  gboolean ended;
  FbdEventEndReason end_reason;

  GSList *feedbacks;
} FbdEvent;

G_DEFINE_TYPE (FbdEvent, fbd_event, G_TYPE_OBJECT);

static gboolean
on_timeout_expired (FbdEvent *self)
{
  g_return_val_if_fail (FBD_IS_EVENT (self), G_SOURCE_REMOVE);

  self->expired = TRUE;
  self->timeout_id = 0;
  return G_SOURCE_REMOVE;
}

static gboolean
check_ended (FbdEvent *self)
{
  if (!fbd_event_get_feedbacks_ended (self))
    return FALSE;

  self->ended = TRUE;
  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_FEEDBACKS_ENDED]);
  g_signal_emit (self, signals[SIGNAL_FEEDBACKS_ENDED], 0);
  return TRUE;
}

static void
on_fb_ended (FbdEvent *self, FbdFeedbackBase *fb)
{
  switch (self->timeout) {
  case FBD_EVENT_TIMEOUT_ONESHOT:
    check_ended (self);
    break;
  case FBD_EVENT_TIMEOUT_LOOP:
    if (self->end_reason != FBD_EVENT_END_REASON_NATURAL)
      check_ended (self);
    else
      fbd_feedback_run (fb);
    break;
  default:
    if (!self->expired && self->end_reason == FBD_EVENT_END_REASON_NATURAL)
      fbd_feedback_run (fb);
    else
      check_ended (self);
    break;
  }
}

static void
fbd_event_set_property (GObject      *object,
                        guint         property_id,
                        const GValue *value,
                        GParamSpec   *pspec)
{
  FbdEvent *self = FBD_EVENT (object);

  switch (property_id) {
  case PROP_ID:
    self->id = g_value_get_int (value);
    break;
  case PROP_APP_ID:
    g_free (self->app_id);
    self->app_id = g_value_dup_string (value);
    break;
  case PROP_EVENT:
    g_free (self->event);
    self->event = g_value_dup_string (value);
    break;
  case PROP_TIMEOUT:
    self->timeout = g_value_get_int (value);
    break;
  case PROP_END_REASON:
    fbd_event_set_end_reason (self, g_value_get_enum (value));
    break;
  case PROP_SENDER:
    g_free (self->sender);
    self->sender = g_value_dup_string (value);
    break;
  case PROP_FEEDBACKS_ENDED:
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
fbd_event_get_property (GObject    *object,
                        guint       property_id,
                        GValue     *value,
                        GParamSpec *pspec)
{
  FbdEvent *self = FBD_EVENT (object);

  switch (property_id) {
  case PROP_ID:
    g_value_set_int (value, self->id);
    break;
  case PROP_APP_ID:
    g_value_set_string (value, self->app_id);
    break;
  case PROP_EVENT:
    g_value_set_string (value, self->event);
    break;
  case PROP_TIMEOUT:
    g_value_set_int (value, self->timeout);
    break;
  case PROP_END_REASON:
    g_value_set_enum (value, fbd_event_get_end_reason (self));
    break;
  case PROP_FEEDBACKS_ENDED:
    g_value_set_boolean (value, self->ended);
    break;
  case PROP_SENDER:
    g_value_set_string (value, self->sender);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
fbd_event_dispose (GObject *object)
{
  FbdEvent *self = FBD_EVENT (object);

  g_clear_handle_id (&self->timeout_id, g_source_remove);

  if (self->feedbacks) {
    /* Feedbacks end themselves when unrefed */
    g_slist_free_full (self->feedbacks, g_object_unref);
    self->feedbacks = NULL;
  }

  G_OBJECT_CLASS (fbd_event_parent_class)->dispose (object);
}

static void
fbd_event_finalize (GObject *object)
{
  FbdEvent *self = FBD_EVENT (object);

  g_clear_pointer (&self->app_id, g_free);
  g_clear_pointer (&self->event, g_free);
  g_clear_pointer (&self->sender, g_free);

  G_OBJECT_CLASS (fbd_event_parent_class)->finalize (object);
}

static void
fbd_event_class_init (FbdEventClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->set_property = fbd_event_set_property;
  object_class->get_property = fbd_event_get_property;

  object_class->dispose = fbd_event_dispose;
  object_class->finalize = fbd_event_finalize;

  props[PROP_ID] =
    g_param_spec_int (
      "id",
      "Id",
      "The event id",
      0, G_MAXINT, 0,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  props[PROP_APP_ID] =
    g_param_spec_string (
      "app-id",
      "App id",
      "The application id",
      NULL,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  props[PROP_EVENT] =
    g_param_spec_string (
      "event",
      "Event",
      "The event name",
      NULL,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  props[PROP_TIMEOUT] =
    g_param_spec_int (
      "timeout",
      "Timeout",
      "Timeout after which feedback for event should end",
      -1, G_MAXINT, -1,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  props[PROP_FEEDBACKS_ENDED] =
    g_param_spec_boolean (
      "feedbacks-ended",
      "Feedbacks ended",
      "Whether all feedbacks have ended playing",
      FALSE,
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  props[PROP_END_REASON] =
    g_param_spec_enum (
      "end-reason",
      "End reason",
      "The reason why the feedbacks ends/ended",
      FBD_TYPE_EVENT_END_REASON,
      FBD_EVENT_END_REASON_NATURAL,
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  /**
   * FbdEvent:Sender:
   *
   * The DBus name of the sender
   */
  props[PROP_SENDER] =
    g_param_spec_string (
      "sender",
      "",
      "",
      NULL,
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);

  /**
   * FbdEvent::feedbacks-ended:
   *
   * Emitted when all feedbacks associated with this event ended.
   */
  signals[SIGNAL_FEEDBACKS_ENDED] = g_signal_new ("feedbacks-ended",
                                                  G_TYPE_FROM_CLASS (klass),
                                                  G_SIGNAL_RUN_LAST, 0, NULL, NULL,
                                                  NULL,
                                                  G_TYPE_NONE,
                                                  0);
}

static void
fbd_event_init (FbdEvent *self)
{
  self->timeout = -1;
}

FbdEvent *
fbd_event_new (int id, const char *app_id, const char *event, int timeout, const char *sender)
{
  return FBD_EVENT (g_object_new (FBD_TYPE_EVENT,
                                  "id", id,
                                  "app_id", app_id,
                                  "event", event,
                                  "timeout", timeout,
                                  "sender", sender,
                                  NULL));
}

const char *
fbd_event_get_event (FbdEvent *self)
{
  g_return_val_if_fail (FBD_IS_EVENT (self), NULL);

  return self->event;
}

const char *
fbd_event_get_app_id (FbdEvent *self)
{
  g_return_val_if_fail (FBD_IS_EVENT (self), NULL);

  return self->app_id;
}

guint
fbd_event_get_id (FbdEvent *self)
{
  g_return_val_if_fail (FBD_IS_EVENT (self), 0);

  return self->id;
}

int
fbd_event_get_timeout (FbdEvent *self)
{
  g_return_val_if_fail (FBD_IS_EVENT (self), -1);

  return self->timeout;
}

/**
 * fbd_event_add_feedback:
 * @self: The event that gets a feedback added
 * @feedback: (transfer-none): The feedback to add
 *
 * Add a feedback to the list of feedbacks triggered by event
 */
void
fbd_event_add_feedback (FbdEvent *self, FbdFeedbackBase *feedback)
{
  self->feedbacks = g_slist_prepend (self->feedbacks, g_object_ref (feedback));
  g_object_set_data (G_OBJECT (feedback), "event-id", GUINT_TO_POINTER (self->id));
  g_signal_connect_object (feedback,
                           "ended",
                           (GCallback) on_fb_ended,
                           self,
                           G_CONNECT_SWAPPED);
}

GSList *
fbd_event_get_feedbacks (FbdEvent *self)
{
  return self->feedbacks;
}

int
fbd_event_remove_feedback (FbdEvent *self, FbdFeedbackBase *feedback)
{
  guint len;

  g_return_val_if_fail (FBD_IS_EVENT (self), 0);

  if (!self->feedbacks)
    return 0;

  if (g_slist_index (self->feedbacks, feedback) >= 0) {
    g_signal_handlers_disconnect_by_data (feedback, self);
    /* Drop our reference, feedbacks end themselves when unref'ed */
    g_object_unref (feedback);
  }

  self->feedbacks = g_slist_remove (self->feedbacks, feedback);

  len = g_slist_length (self->feedbacks);
  if (!len)
    check_ended (self);

  return len;
}

/**
 * fbd_event_run_feedbacks:
 * @self: The Event
 *
 * Run all feedbacks associated for an event.
 */
void
fbd_event_run_feedbacks (FbdEvent *self)
{
  g_return_if_fail (FBD_IS_EVENT (self));

  g_debug ("Running %d feedbacks for event %d", g_slist_length (self->feedbacks), self->id);

  if (!self->feedbacks)
    return;

  if (self->timeout > 0) {
    self->timeout_id = g_timeout_add_seconds (self->timeout,
                                              (GSourceFunc)on_timeout_expired,
                                              self);
    g_source_set_name_by_id (self->timeout_id, "event timeout source");
  }

  g_object_ref (self);
  for (GSList *l = self->feedbacks; l; l = l->next) {
    FbdFeedbackBase *fb = FBD_FEEDBACK_BASE (l->data);
    fbd_feedback_run (fb);
  }
  g_object_unref (self);
}

/**
 * fbd_event_end_feedbacks:
 * @self: The Event
 *
 * End all running feedbacks as early as possible.
 */
void
fbd_event_end_feedbacks (FbdEvent *self)
{
  g_return_if_fail (FBD_IS_EVENT (self));

  fbd_event_set_end_reason (self, FBD_EVENT_END_REASON_EXPLICIT);
  g_debug ("Ending %d feedbacks for event %d", g_slist_length (self->feedbacks), self->id);
  g_slist_foreach (self->feedbacks, (GFunc)fbd_feedback_end, NULL);
}

/**
 * fbd_event_end_feedbacks_by_level:
 * @self: The Event
 * @level: The profile level
 *
 * End all feedback strictly above the given profile level.
 */
void
fbd_event_end_feedbacks_by_level (FbdEvent *self, guint level)
{
  g_autoptr (GSList) feedbacks = NULL;
  guint num = 0;

  g_return_if_fail (FBD_IS_EVENT (self));
  /* Copy the list as we will remove feedbacks from self->feedbacks */
  feedbacks = g_slist_copy (fbd_event_get_feedbacks (self));

  for (GSList *l = feedbacks; l; l = l->next) {
    FbdFeedbackBase *fb = FBD_FEEDBACK_BASE (l->data);
    guint event_level;

    event_level = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (fb), "fbd-level"));
    if (event_level > level)
      num++;
  }

  if (num == 0)
    return;

  g_debug ("Will end %d feedbacks of event %s", num, fbd_event_get_event (self));
  /* Set 'explicit' if we end all remaining feedbacks */
  if (num == g_slist_length (self->feedbacks))
      fbd_event_set_end_reason (self, FBD_EVENT_END_REASON_EXPLICIT);

  for (GSList *l = feedbacks; l; l = l->next) {
    FbdFeedbackBase *fb = FBD_FEEDBACK_BASE (l->data);
    guint event_level;

    event_level = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (fb), "fbd-level"));
    if (event_level > level) {
      fbd_event_remove_feedback (self, fb);
      fbd_feedback_end (fb);
    }
  }
}

/**
 * fbd_event_get_feedbacks_ended:
 * @self: The Event
 *
 * Whether all feedbacks have finished running.
 *
 * Returns: %TRUE if all feedbacks have finished, otherwise %FALSE.
 */
gboolean
fbd_event_get_feedbacks_ended (FbdEvent *self)
{
  GSList *l;

  g_return_val_if_fail (FBD_IS_EVENT (self), FALSE);

  if (!self->feedbacks)
    return TRUE;

  for (l = self->feedbacks; l ; l = l->next) {
    if (!fbd_feedback_get_ended (FBD_FEEDBACK_BASE (l->data)))
      return FALSE;
  }

  return TRUE;
}

/**
 * fbd_event_set_end_reason:
 * @self: The Event
 * @reason: The reason why feedback for the event ended
 *
 * Sets the reason why feedback for the event ends/has ended.
 */
void
fbd_event_set_end_reason (FbdEvent *self, FbdEventEndReason reason)
{
  g_return_if_fail (FBD_IS_EVENT (self));

  if (self->end_reason == reason)
    return;
  self->end_reason = reason;
  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_END_REASON]);
}

/**
 * fbd_event_get_end_reason:
 * @self: The Event
 *
 * Returns: The reason why feedback for the event ended.
 */
FbdEventEndReason
fbd_event_get_end_reason (FbdEvent *self)
{
  g_return_val_if_fail (FBD_IS_EVENT (self), FBD_EVENT_END_REASON_NATURAL);

  return self->end_reason;
}

/**
 * fbd_event_get_sender:
 * @self: The Event
 *
 * Returns: The DBus sender that triggered the event.
 */
const char *
fbd_event_get_sender (FbdEvent *self)
{
  g_return_val_if_fail (FBD_IS_EVENT (self), NULL);

  return self->sender;
}
07070100000069000081A400000000000000000000000166F7A5130000079A000000000000000000000000000000000000002000000000feedbackd-0.5.0/src/fbd-event.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-feedback-base.h"
#include "fbd-feedback-manager.h"

#include <glib-object.h>

G_BEGIN_DECLS

typedef enum _FbdEventEndReason {
  /* No usable feedback in current theme for this event */
  FBD_EVENT_END_REASON_NOT_FOUND = -1,
  /* all feedbacks finished playing their natural length */
  FBD_EVENT_END_REASON_NATURAL   = 0,
  /* The timer expired */
  FBD_EVENT_END_REASON_EXPIRED   = 1,
  /* Application wanted to end feedbacks explicitly */
  FBD_EVENT_END_REASON_EXPLICIT  = 2,
} FbdEventEndReason;

typedef enum _FbdEventTimeout {
  /* Run each feedback once */
  FBD_EVENT_TIMEOUT_ONESHOT  = -1,
  FBD_EVENT_TIMEOUT_LOOP     =  0,
} FbdEventTimeout;

#define FBD_TYPE_EVENT (fbd_event_get_type())

G_DECLARE_FINAL_TYPE (FbdEvent, fbd_event, FBD, EVENT, GObject);

FbdEvent    *fbd_event_new (gint id, const char *app_id, const char *event, int timeout, const char *sender);
const char  *fbd_event_get_event (FbdEvent *event);
const char  *fbd_event_get_app_id (FbdEvent *event);
guint        fbd_event_get_id (FbdEvent *event);
int          fbd_event_get_timeout (FbdEvent *self);
void         fbd_event_set_end_reason (FbdEvent *self, FbdEventEndReason reason);
FbdEventEndReason fbd_event_get_end_reason (FbdEvent *self);
GSList *     fbd_event_get_feedbacks (FbdEvent *self);
void         fbd_event_add_feedback (FbdEvent *self,
                                     FbdFeedbackBase *feedback);
int          fbd_event_remove_feedback (FbdEvent *self,
                                        FbdFeedbackBase *feedback);
void         fbd_event_run_feedbacks (FbdEvent *self);
void         fbd_event_end_feedbacks (FbdEvent *self);
void         fbd_event_end_feedbacks_by_level (FbdEvent *self, guint level);
gboolean     fbd_event_get_feedbacks_ended (FbdEvent *self);
const char  *fbd_event_get_sender (FbdEvent *self);

G_END_DECLS
0707010000006A000081A400000000000000000000000166F7A51300001788000000000000000000000000000000000000002800000000feedbackd-0.5.0/src/fbd-feedback-base.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-feedback-base"

#include "fbd-feedback-base.h"

/**
 * SECTION:fbd-feedback-base
 * @short_description: Base class for different feedback types
 * @Title: FbdFeedbackManager
 *
 * You usually don't want to create objects of this type. It just
 * serves as a base class for other feedback types.
 */

enum {
  PROP_0,
  PROP_EVENT_NAME,
  PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];

enum {
  SIGNAL_ENDED,
  N_SIGNALS
};
static guint signals[N_SIGNALS];

typedef struct _FbdFeedbackBasePrivate {
  gchar *event_name;
  gboolean ended;
} FbdFeedbackBasePrivate;

G_DEFINE_TYPE_WITH_PRIVATE (FbdFeedbackBase, fbd_feedback_base, G_TYPE_OBJECT);

static void
fbd_feedback_base_set_property (GObject        *object,
				guint         property_id,
				const GValue *value,
				GParamSpec   *pspec)
{
  FbdFeedbackBase *self = FBD_FEEDBACK_BASE (object);
  FbdFeedbackBasePrivate *priv = fbd_feedback_base_get_instance_private (self);

  switch (property_id) {
  case PROP_EVENT_NAME:
    g_free (priv->event_name);
    priv->event_name = g_value_dup_string (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}


static void
fbd_feedback_base_get_property (GObject  *object,
				guint       property_id,
				GValue     *value,
				GParamSpec *pspec)
{
  FbdFeedbackBase *self = FBD_FEEDBACK_BASE (object);
  FbdFeedbackBasePrivate *priv = fbd_feedback_base_get_instance_private (self);

  switch (property_id) {
  case PROP_EVENT_NAME:
    g_value_set_string (value, priv->event_name);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
fbd_feedback_base_dispose (GObject *object)
{
  FbdFeedbackBase *self = FBD_FEEDBACK_BASE (object);

  /* end feedback if running */
  if (!fbd_feedback_get_ended (self))
    fbd_feedback_end (self);

  G_OBJECT_CLASS (fbd_feedback_base_parent_class)->dispose (object);
}

static void
fbd_feedback_base_finalize (GObject *object)
{
  FbdFeedbackBase *self = FBD_FEEDBACK_BASE (object);
  FbdFeedbackBasePrivate *priv = fbd_feedback_base_get_instance_private (self);

  g_clear_pointer (&priv->event_name, g_free);

  G_OBJECT_CLASS (fbd_feedback_base_parent_class)->finalize (object);
}

static void
fbd_feedback_base_class_init (FbdFeedbackBaseClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->set_property = fbd_feedback_base_set_property;
  object_class->get_property = fbd_feedback_base_get_property;

  object_class->dispose = fbd_feedback_base_dispose;
  object_class->finalize = fbd_feedback_base_finalize;

  props[PROP_EVENT_NAME] =
    g_param_spec_string (
      "event-name",
      "Event Name",
      "The event this feedback is associated with",
      NULL,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);

  /**
   * FbdFeedbackBase::ended:
   *
   * Emitted when the feedback has ended
   */
  signals[SIGNAL_ENDED] = g_signal_new ("ended",
                                        G_TYPE_FROM_CLASS (klass),
                                        G_SIGNAL_RUN_LAST, 0, NULL, NULL,
                                        NULL,
                                        G_TYPE_NONE,
                                        0);
}

static void
fbd_feedback_base_init (FbdFeedbackBase *self)
{
}

/**
 * fbd_feedback_get_event_name:
 * @self: The feedback
 *
 * Returns: the name from the event naming spec this feedback is associated with.
 */
const gchar *
fbd_feedback_get_event_name (FbdFeedbackBase *self)
{
  FbdFeedbackBasePrivate *priv;

  g_return_val_if_fail (FBD_IS_FEEDBACK_BASE (self), NULL);
  priv = fbd_feedback_base_get_instance_private (self);

  return priv->event_name;
}

/**
 * fbd_feedback_run:
 * @self: The feedback to run
 *
 * Emit the feedback.
 */
void
fbd_feedback_run (FbdFeedbackBase *self)
{
  FbdFeedbackBaseClass *klass;
  FbdFeedbackBasePrivate *priv;

  g_return_if_fail (FBD_IS_FEEDBACK_BASE (self));
  priv = fbd_feedback_base_get_instance_private (self);

  priv->ended = FALSE;
  klass = FBD_FEEDBACK_BASE_GET_CLASS (self);
  g_return_if_fail (klass->run);
  klass->run (self);
}

/**
 * fbd_feedback_end:
 * @self: The feedback to end
 *
 * End the feedback immediately.
 */
void
fbd_feedback_end (FbdFeedbackBase *self)
{
  FbdFeedbackBaseClass *klass;

  g_return_if_fail (FBD_IS_FEEDBACK_BASE (self));

  klass = FBD_FEEDBACK_BASE_GET_CLASS (self);
  g_return_if_fail (klass->end);
  klass->end (self);
}


/**
 * fbd_feedback_get_ended:
 * @self: The feedback
 *
 * Whether the feedback is ended.
 *
 * Returns: %TRUE if feedback has ended, otherwise %FALSE.
 */
gboolean
fbd_feedback_get_ended (FbdFeedbackBase *self)
{
  FbdFeedbackBasePrivate *priv = fbd_feedback_base_get_instance_private (self);

  return priv->ended;
}

/**
 * fbd_feedback_base_done:
 * @self: The feedback
 *
 * Invoked by a derived classes to notify that it's done emitting feedback,
 * e.g. when the vibra motor stopped or a sound finished playing.
 */
void
fbd_feedback_base_done (FbdFeedbackBase *self)
{
  FbdFeedbackBasePrivate *priv = fbd_feedback_base_get_instance_private (self);

  priv->ended = TRUE;
  g_signal_emit (self, signals[SIGNAL_ENDED], 0);
}

/**
 * fbd_feedback_available:
 * @self: The feedback
 *
 * Whether this feedback type is available at all. This can be %FALSE e.g.
 * due to missing hardware.
 *
 * Returns: %FALSE if the feedback type is not available at all %TRUE if unsure
 * or available.
 */
gboolean
fbd_feedback_is_available (FbdFeedbackBase *self)
{
  FbdFeedbackBaseClass *klass;

  g_return_val_if_fail (FBD_IS_FEEDBACK_BASE (self), FALSE);

  klass = FBD_FEEDBACK_BASE_GET_CLASS (self);
  if (klass->is_available)
    return klass->is_available (self);
  else
    return TRUE;
}

0707010000006B000081A400000000000000000000000166F7A51300000366000000000000000000000000000000000000002800000000feedbackd-0.5.0/src/fbd-feedback-base.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include <glib-object.h>

G_BEGIN_DECLS

#define FBD_TYPE_FEEDBACK_BASE (fbd_feedback_base_get_type())

G_DECLARE_DERIVABLE_TYPE (FbdFeedbackBase, fbd_feedback_base, FBD, FEEDBACK_BASE, GObject);

struct _FbdFeedbackBaseClass
{
  GObjectClass parent_class;

  void     (*run) (FbdFeedbackBase *self);
  void     (*end) (FbdFeedbackBase *self);
  gboolean (*is_available) (FbdFeedbackBase *self);
};


const gchar *fbd_feedback_get_event_name (FbdFeedbackBase *self);
void         fbd_feedback_run (FbdFeedbackBase *self);
void         fbd_feedback_end (FbdFeedbackBase *self);
gboolean     fbd_feedback_get_ended (FbdFeedbackBase *self);
void         fbd_feedback_base_done (FbdFeedbackBase *self);
gboolean     fbd_feedback_is_available (FbdFeedbackBase *self);

G_END_DECLS
0707010000006C000081A400000000000000000000000166F7A51300000CB4000000000000000000000000000000000000002900000000feedbackd-0.5.0/src/fbd-feedback-dummy.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-feedback-dummy"

#include "fbd-enums.h"
#include "fbd-feedback-dummy.h"
#include "fbd-feedback-manager.h"

/**
 * SECTION:fbd-feedback-dummy
 * @short_description: Describes a dummy feedback event that does nothing
 * @Title: FbdFeedbackDummy
 */

enum {
  PROP_0,
  PROP_DURATION,
  PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];

typedef struct _FbdFeedbackDummy {
  FbdFeedbackBase parent;

  guint duration;
  guint timer_id;
} FbdFeedbackDummy;

G_DEFINE_TYPE (FbdFeedbackDummy, fbd_feedback_dummy, FBD_TYPE_FEEDBACK_BASE);

static void
fbd_feedback_dummy_set_property (GObject      *object,
                                   guint         property_id,
                                   const GValue *value,
                                   GParamSpec   *pspec)
{
  FbdFeedbackDummy *self = FBD_FEEDBACK_DUMMY (object);

  switch (property_id) {
  case PROP_DURATION:
    self->duration = g_value_get_uint (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
fbd_feedback_dummy_get_property (GObject    *object,
				 guint       property_id,
				 GValue     *value,
				 GParamSpec *pspec)
{
  FbdFeedbackDummy *self = FBD_FEEDBACK_DUMMY (object);

  switch (property_id) {
  case PROP_DURATION:
    g_value_set_uint (value, self->duration);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static gboolean
on_timeout_expired (FbdFeedbackDummy *self)
{
  fbd_feedback_base_done (FBD_FEEDBACK_BASE(self));
  return G_SOURCE_REMOVE;
}

static void
fbd_feedback_dummy_run (FbdFeedbackBase *base)
{
  FbdFeedbackDummy *self = FBD_FEEDBACK_DUMMY (base);

  if (self->duration) {
    self->timer_id = g_timeout_add (self->duration,
				  (GSourceFunc)on_timeout_expired,
				  self);
    g_source_set_name_by_id (self->timer_id, "feedback-dummy-timer");
  } else {
    fbd_feedback_base_done (base);
  }
}

static void
fbd_feedback_dummy_end (FbdFeedbackBase *base)
{
  FbdFeedbackDummy *self = FBD_FEEDBACK_DUMMY (base);

  g_clear_handle_id(&self->timer_id, g_source_remove);
  fbd_feedback_base_done (base);
}

static void
fbd_feedback_dummy_class_init (FbdFeedbackDummyClass *klass)
{
  FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass);
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->set_property = fbd_feedback_dummy_set_property;
  object_class->get_property = fbd_feedback_dummy_get_property;

  base_class->run = fbd_feedback_dummy_run;
  base_class->end = fbd_feedback_dummy_end;

  props[PROP_DURATION] =
    g_param_spec_uint (
      "duration",
      "Duration",
      "Dummy event duration in msecs",
      0, G_MAXUINT, 0,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}

static void
fbd_feedback_dummy_init (FbdFeedbackDummy *self)
{
}

guint
fbd_feedback_dummy_get_duration (FbdFeedbackDummy *self)
{
  g_return_val_if_fail (FBD_IS_FEEDBACK_DUMMY (self), 0);

  return self->duration;
}
0707010000006D000081A400000000000000000000000166F7A5130000017F000000000000000000000000000000000000002900000000feedbackd-0.5.0/src/fbd-feedback-dummy.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-feedback-base.h"

G_BEGIN_DECLS

#define FBD_TYPE_FEEDBACK_DUMMY (fbd_feedback_dummy_get_type())

G_DECLARE_FINAL_TYPE (FbdFeedbackDummy, fbd_feedback_dummy, FBD, FEEDBACK_DUMMY, FbdFeedbackBase);

guint fbd_feedback_dummy_get_duration (FbdFeedbackDummy *self);

G_END_DECLS
0707010000006E000081A400000000000000000000000166F7A513000025AE000000000000000000000000000000000000002700000000feedbackd-0.5.0/src/fbd-feedback-led.c/*
 * Copyright (C) 2020 Purism SPC
 *               2024 The Phosh Developers
 * SPDX-License-Identifier: GPL-3.0+
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-feedback-led"

#include "fbd.h"
#include "fbd-enums.h"
#include "fbd-dev-leds.h"
#include "fbd-feedback-led.h"
#include "fbd-feedback-manager.h"

#include <gmobile.h>

/**
 * FbdFeedbackLed:
 *
 * The `FbdFeedbackLed` describes a feedback via an LED. It currently
 * only supports periodic patterns.
 */

enum {
  PROP_0,
  PROP_FREQUENCY,
  PROP_COLOR,
  PROP_MAX_BRIGHTNESS,
  PROP_PRIORITY,
  PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];

typedef struct _FbdFeedbackLed {
  FbdFeedbackBase  parent;

  guint            frequency;
  guint            priority;
  guint            max_brightness;
  char            *color;
  gboolean         prefer_flash;

  GSettings       *settings;
} FbdFeedbackLed;

G_DEFINE_TYPE (FbdFeedbackLed, fbd_feedback_led, FBD_TYPE_FEEDBACK_BASE)

/**
 * ascii_to_int:
 * @c: a character
 *
 * Interprets a character as digit. E.g. '1' will be converted to 1,
 * 'C' or 'c' will be converted to 12.
 *
 * Returns: The integer value or -1 if the character isn't a hex digit.
 */
static int
hex_ascii_to_int (char c)
{
  switch (c) {
  case '0'...'9':
    return c - '0';
    break;
  case 'a'...'f':
    return 10 + c - 'a';
    break;
  case 'A'...'F':
    return 10 + c - 'A';
    break;
  default:
    return -1;
  }
}


static gboolean
parse_hex_color (const char *color, FbdLedRgbColor *rgb)
{
  FbdLedRgbColor parsed = { 0 };

  if (color[0] != '#')
    return FALSE;

  if (strlen (color) != strlen ("#11AA00"))
    return FALSE;

  if (!rgb)
    return TRUE;

  for (int i = 1; color[i]; i++) {
    int c = hex_ascii_to_int (color[i]);

    if (c < 0)
      return FALSE;

    switch (i) {
    case 1:
      parsed.r |= hex_ascii_to_int (color[i]) << 4;
      break;
    case 2:
      parsed.r |= hex_ascii_to_int (color[i]);
      break;
    case 3:
      parsed.g |= hex_ascii_to_int (color[i]) << 4;
      break;
    case 4:
      parsed.g |= hex_ascii_to_int (color[i]);
      break;
    case 5:
      parsed.b |= hex_ascii_to_int (color[i]) << 4;
      break;
    case 6:
      parsed.b |= hex_ascii_to_int (color[i]);
      break;
    }
  }

  memcpy (rgb, &parsed, sizeof (FbdLedRgbColor));

  return TRUE;
}


static FbdFeedbackLedColor
color_string_to_color (const char *color, gboolean prefer_flash, FbdLedRgbColor *rgb)
{
  FbdFeedbackLedColor type;

  g_return_val_if_fail (!gm_str_is_null_or_empty (color), FBD_FEEDBACK_LED_COLOR_WHITE);

  if (g_strcmp0 (color, "red") == 0) {
    if (rgb)
      rgb->r = 255;
    type = FBD_FEEDBACK_LED_COLOR_RED;
  } else if (g_strcmp0 (color, "green") == 0) {
    if (rgb)
      rgb->g = 255;
    type = FBD_FEEDBACK_LED_COLOR_GREEN;
  } else if (g_strcmp0 (color, "blue") == 0) {
    if (rgb)
      rgb->b = 255;
    type = FBD_FEEDBACK_LED_COLOR_BLUE;
  } else if (g_strcmp0 (color, "white") == 0) {
    if (rgb)
      rgb->r = rgb->g = rgb->b = 255;
    type = FBD_FEEDBACK_LED_COLOR_WHITE;
  } else if (parse_hex_color (color, rgb)) {
    type = FBD_FEEDBACK_LED_COLOR_RGB;
  } else {
    g_warning_once ("Can't parse color '%s' using white", color);
    if (rgb)
      rgb->r = rgb->g = rgb->b = 255;
    type = FBD_FEEDBACK_LED_COLOR_WHITE;
  }

  /* Override the LED color type at the very end as we want rgb filled
   * in so it can be used in case we need to fall back to non flash
   * LED */
  if (prefer_flash)
    type = FBD_FEEDBACK_LED_COLOR_FLASH;

  return type;
}


static void
on_prefer_flash_changed (FbdFeedbackLed *self)
{
  self->prefer_flash = g_settings_get_boolean (self->settings, "prefer-flash");
  g_debug ("Prefer flash: %d", self->prefer_flash);
}


static void
fbd_feedback_led_set_property (GObject      *object,
                               guint         property_id,
                               const GValue *value,
                               GParamSpec   *pspec)
{
  FbdFeedbackLed *self = FBD_FEEDBACK_LED (object);

  switch (property_id) {
  case PROP_FREQUENCY:
    self->frequency = g_value_get_uint (value);
    break;
  case PROP_PRIORITY:
    self->priority = g_value_get_uint (value);
    break;
  case PROP_MAX_BRIGHTNESS:
    self->max_brightness = g_value_get_uint (value);
    break;
  case PROP_COLOR:
    self->color = g_value_dup_string (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}


static void
fbd_feedback_led_get_property (GObject    *object,
                               guint       property_id,
                               GValue     *value,
                               GParamSpec *pspec)
{
  FbdFeedbackLed *self = FBD_FEEDBACK_LED (object);

  switch (property_id) {
  case PROP_FREQUENCY:
    g_value_set_uint (value, self->frequency);
    break;
  case PROP_PRIORITY:
    g_value_set_uint (value, self->priority);
    break;
  case PROP_MAX_BRIGHTNESS:
    g_value_set_uint (value, self->max_brightness);
    break;
  case PROP_COLOR:
    g_value_set_string (value, self->color);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}


static void
fbd_feedback_led_run (FbdFeedbackBase *base)
{
  FbdFeedbackLed *self = FBD_FEEDBACK_LED (base);
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevLeds *dev = fbd_feedback_manager_get_dev_leds (manager);
  FbdFeedbackLedColor color;
  FbdLedRgbColor rgb;

  g_return_if_fail (FBD_IS_DEV_LEDS (dev));
  g_debug ("Periodic led feedback: max brightness: %d, freq: %d", self->max_brightness, self->frequency);

  color = color_string_to_color (self->color, self->prefer_flash, &rgb);
  /* FIXME: handle priority */
  fbd_dev_leds_start_periodic (dev,
                               color,
                               &rgb,
                               self->max_brightness,
                               self->frequency);
}


static void
fbd_feedback_led_end (FbdFeedbackBase *base)
{
  FbdFeedbackLed *self = FBD_FEEDBACK_LED (base);
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevLeds *dev = fbd_feedback_manager_get_dev_leds (manager);
  FbdFeedbackLedColor color;

  color = color_string_to_color (self->color, self->prefer_flash, NULL);
  if (dev)
    fbd_dev_leds_stop (dev, color);
  fbd_feedback_base_done (FBD_FEEDBACK_BASE (self));
}


static gboolean
fbd_feedback_led_is_available (FbdFeedbackBase *base)
{
  FbdFeedbackLed *self = FBD_FEEDBACK_LED (base);
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevLeds *dev = fbd_feedback_manager_get_dev_leds (manager);

  if (!FBD_IS_DEV_LEDS (dev))
    return FALSE;

  if (self->prefer_flash &&
      fbd_dev_leds_has_led (dev, FBD_FEEDBACK_LED_COLOR_FLASH)) {
    return TRUE;
  }

  return fbd_dev_leds_has_led (dev, FBD_FEEDBACK_LED_COLOR_WHITE);
}


static void
fbd_feedback_led_finalize (GObject *object)
{
  FbdFeedbackLed *self = FBD_FEEDBACK_LED (object);

  g_clear_object (&self->settings);
  g_clear_pointer (&self->color, g_free);

  G_OBJECT_CLASS (fbd_feedback_led_parent_class)->finalize (object);
}


static void
fbd_feedback_led_class_init (FbdFeedbackLedClass *klass)
{
  FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass);
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->set_property = fbd_feedback_led_set_property;
  object_class->get_property = fbd_feedback_led_get_property;
  object_class->finalize = fbd_feedback_led_finalize;

  base_class->run = fbd_feedback_led_run;
  base_class->end = fbd_feedback_led_end;
  base_class->is_available = fbd_feedback_led_is_available;

  /**
   * FbdFeedbackLed:frequency:
   *
   * The frequency the LED should blink with in mHz.
   */
  props[PROP_FREQUENCY] =
    g_param_spec_uint ("frequency", "", "",
                       0, G_MAXUINT, 0,
                       G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
  /**
   * FbdFeedbackLed:color:
   *
   * The color the LED should blink with. The color is given as color
   * name or `rgb()` color value.
   */
  props[PROP_COLOR] =
    g_param_spec_string ("color", "", "",
                         NULL,
                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
  /**
   * FbdFeedbackLed:priority:
   *
   * Priority of the LED pattern. LED devices can only display a limited
   * amount of patterns at a time. In this case the pattern with the highest
   * priority wins.
   */
  props[PROP_PRIORITY] =
    g_param_spec_uint ("priority", "", "",
                       0, 255, 0,
                       G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
  /**
   * FbdFeedbackLed:max-brightness:
   *
   * The maximum brightness in the LED pattern in percent of the LEDs
   * maximum brightness.
   */
  props[PROP_MAX_BRIGHTNESS] =
    g_param_spec_uint ("max-brightness", "", "",
                       1, 100, 100,
                       G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}


static void
fbd_feedback_led_init (FbdFeedbackLed *self)
{
  self->max_brightness = 100;
  self->settings = g_settings_new (FEEDBACKD_SCHEMA_ID);

  g_signal_connect_object (self->settings,
                           "changed::prefer-flash",
                           G_CALLBACK (on_prefer_flash_changed),
                           self,
                           G_CONNECT_SWAPPED);
  on_prefer_flash_changed (self);
}
0707010000006F000081A400000000000000000000000166F7A5130000041D000000000000000000000000000000000000002700000000feedbackd-0.5.0/src/fbd-feedback-led.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-feedback-base.h"

G_BEGIN_DECLS

/**
 * FbdDevLedColor:
 * @FBD_FEEDBACK_LED_COLOR_WHITE: A white LED
 * @FBD_FEEDBACK_LED_COLOR_RED: A red LED
 * @FBD_FEEDBACK_LED_COLOR_GREEN: A green LED
 * @FBD_FEEDBACK_LED_COLOR_BLUE: A blue LED
 * @FBD_FEEDBACK_LED_COLOR_RGB: A multicolor LED that can display arbitrary RGB values
 * @FBD_FEEDBACK_LED_COLOR_FLASH: A flash (usually white)
 *
 * The color of a hardware LED.
 */
typedef enum _FbdFeedbackLedColor {
  FBD_FEEDBACK_LED_COLOR_WHITE = 0,
  FBD_FEEDBACK_LED_COLOR_RED = 1,
  FBD_FEEDBACK_LED_COLOR_GREEN = 2,
  FBD_FEEDBACK_LED_COLOR_BLUE = 3,
  FBD_FEEDBACK_LED_COLOR_RGB = 4,
  /* Keep this last in the list */
  FBD_FEEDBACK_LED_COLOR_FLASH = 5,
} FbdFeedbackLedColor;

typedef struct {
  guint r, g, b;
} FbdLedRgbColor;

#define FBD_TYPE_FEEDBACK_LED (fbd_feedback_led_get_type ())

G_DECLARE_FINAL_TYPE (FbdFeedbackLed, fbd_feedback_led, FBD, FEEDBACK_LED, FbdFeedbackBase);

G_END_DECLS
07070100000070000081A400000000000000000000000166F7A51300004F45000000000000000000000000000000000000002B00000000feedbackd-0.5.0/src/fbd-feedback-manager.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-feedback-manager"

#include "lfb-names.h"
#include "fbd.h"
#include "fbd-dev-vibra.h"
#include "fbd-dev-leds.h"
#include "fbd-event.h"
#include "fbd-feedback-vibra.h"
#include "fbd-feedback-manager.h"
#include "fbd-feedback-theme.h"
#include "fbd-theme-expander.h"

#include <gmobile.h>

#include <gio/gio.h>
#include <glib-unix.h>
#include <gudev/gudev.h>

#define FEEDBACKD_KEY_PROFILE "profile"
#define FEEDBACKD_KEY_THEME "theme"
#define FEEDBACKD_KEY_ALLOW_IMPORTANT "allow-important"

#define APP_SCHEMA FEEDBACKD_SCHEMA_ID ".application"
#define APP_PREFIX "/org/sigxcpu/feedbackd/application/"

#define FEEDBACKD_THEME_VAR "FEEDBACK_THEME"

/**
 * SECTION:fbd-feedback-manager
 * @short_description: The manager processing incoming events
 * @Title: FbdFeedbackManager
 *
 * The #FbdFeedbackManager listens for DBus messages and triggers feedbacks
 * based on the incoming events.
 */

typedef struct _FbdFeedbackManager {
  LfbGdbusFeedbackSkeleton parent;

  GSettings               *settings;
  FbdFeedbackProfileLevel  level;
  FbdFeedbackTheme        *theme;
  guint                    next_id;
  GStrv                    allow_important;

  /* Key: event id, value: event */
  GHashTable              *events;
  /* Key: DBus name, value: watch_id */
  GHashTable              *clients;

  /* Hardware interaction */
  GUdevClient             *client;
  FbdDevVibra             *vibra;
  FbdDevSound             *sound;
  FbdDevLeds              *leds;
} FbdFeedbackManager;

static void fbd_feedback_manager_feedback_iface_init (LfbGdbusFeedbackIface *iface);

G_DEFINE_TYPE_WITH_CODE (FbdFeedbackManager,
                         fbd_feedback_manager,
                         LFB_GDBUS_TYPE_FEEDBACK_SKELETON,
                         G_IMPLEMENT_INTERFACE (
                           LFB_GDBUS_TYPE_FEEDBACK,
                           fbd_feedback_manager_feedback_iface_init));

static void
device_changes (FbdFeedbackManager *self, gchar *action, GUdevDevice *device,
                GUdevClient        *client)
{
  g_debug ("Device changes: action = %s, device = %s",
           action, g_udev_device_get_sysfs_path (device));

  if (g_strcmp0 (action, "remove") == 0 && self->vibra) {
    GUdevDevice *dev = fbd_dev_vibra_get_device (self->vibra);

    if (g_strcmp0 (g_udev_device_get_sysfs_path (dev),
                   g_udev_device_get_sysfs_path (device)) == 0) {
      g_debug ("Vibra device %s got removed", g_udev_device_get_sysfs_path (dev));
      g_clear_object (&self->vibra);
    }
  } else if (g_strcmp0 (action, "add") == 0) {
    if (!g_strcmp0 (g_udev_device_get_property (device, FEEDBACKD_UDEV_ATTR), "vibra")) {
      g_autoptr (GError) err = NULL;

      g_debug ("Found hotplugged vibra device at %s", g_udev_device_get_sysfs_path (device));
      g_clear_object (&self->vibra);
      self->vibra = fbd_dev_vibra_new (device, &err);
      if (!self->vibra)
        g_warning ("Failed to init vibra device: %s", err->message);
    }
  }
}

static gchar *
munge_app_id (const gchar *app_id)
{
  gchar *id = g_strdup (app_id);
  gint i;

  g_strcanon (id,
              "0123456789"
              "abcdefghijklmnopqrstuvwxyz"
              "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
              "-",
              '-');
  for (i = 0; id[i] != '\0'; i++)
    id[i] = g_ascii_tolower (id[i]);

  return id;
}

static FbdFeedbackProfileLevel
app_get_feedback_level (const gchar *app_id)
{
  g_autofree gchar *profile = NULL;
  g_autofree gchar *munged_app_id = munge_app_id (app_id);
  g_autofree gchar *path = g_strconcat (APP_PREFIX, munged_app_id, "/", NULL);
  g_autoptr (GSettings) setting =  g_settings_new_with_path (APP_SCHEMA, path);

  profile = g_settings_get_string (setting, FEEDBACKD_KEY_PROFILE);
  g_debug ("%s uses app profile %s", app_id, profile);
  return fbd_feedback_profile_level (profile);
}

static void
init_devices (FbdFeedbackManager *self)
{
  GList *l;
  g_autolist (GUdevClient) devices = NULL;
  g_autoptr(GError) err = NULL;

  devices = g_udev_client_query_by_subsystem (self->client, "input");

  for (l = devices; l != NULL; l = l->next) {
    GUdevDevice *dev = l->data;

    if (!g_strcmp0 (g_udev_device_get_property (dev, FEEDBACKD_UDEV_ATTR), "vibra")) {
      g_debug ("Found vibra device");
      self->vibra = fbd_dev_vibra_new (dev, &err);
      if (!self->vibra) {
        g_warning ("Failed to init vibra device: %s", err->message);
        g_clear_error (&err);
      }
    }
  }
  if (!self->vibra)
    g_debug ("No vibra capable device found");

  self->leds = fbd_dev_leds_new (&err);
  if (!self->leds) {
    g_debug ("Failed to init leds device: %s", err->message);
    g_clear_error (&err);
  }

  self->sound = fbd_dev_sound_new (&err);
  if (!self->sound) {
    g_warning ("Failed to init sound device: %s", err->message);
    g_clear_error (&err);
  }
}

static void
on_event_feedbacks_ended (FbdFeedbackManager *self, FbdEvent *event)
{
  guint event_id;

  g_return_if_fail (FBD_IS_FEEDBACK_MANAGER (self));
  g_return_if_fail (FBD_IS_EVENT (event));

  event_id = fbd_event_get_id (event);
  event = g_hash_table_lookup (self->events, GUINT_TO_POINTER (event_id));
  if (!event) {
    g_warning ("Feedback ended for unknown event %d", event_id);
    return;
  }

  g_return_if_fail (fbd_event_get_feedbacks_ended (event));

  lfb_gdbus_feedback_emit_feedback_ended (LFB_GDBUS_FEEDBACK (self), event_id,
                                          fbd_event_get_end_reason (event));

  g_debug ("All feedbacks for event %d finished", event_id);
  g_hash_table_remove (self->events, GUINT_TO_POINTER (event_id));
}

static void
on_profile_changed (FbdFeedbackManager *self, GParamSpec *psepc, gpointer unused)
{
  const gchar *pname;

  g_return_if_fail (FBD_IS_FEEDBACK_MANAGER (self));

  pname = lfb_gdbus_feedback_get_profile (LFB_GDBUS_FEEDBACK (self));

  if (!fbd_feedback_manager_set_profile (self, pname))
    g_warning ("Invalid profile '%s'", pname);
}

static void
on_feedbackd_setting_changed (FbdFeedbackManager *self,
                              const gchar        *key,
                              GSettings          *settings)
{
  g_autofree gchar *profile = NULL;

  g_return_if_fail (FBD_IS_FEEDBACK_MANAGER (self));
  g_return_if_fail (G_IS_SETTINGS (settings));

  if (g_str_equal (key, FEEDBACKD_KEY_PROFILE)) {
    profile = g_settings_get_string (settings, key);
    fbd_feedback_manager_set_profile (self, profile);
  } else if (g_str_equal (key, FEEDBACKD_KEY_THEME)) {
    fbd_feedback_manager_load_theme (self);
  } else {
    g_critical ("Unknown settings key '%s'", key);
  }
}


static gboolean
app_is_important (FbdFeedbackManager *self, const char *app_id)
{
  if (!self->allow_important)
    return FALSE;

  if (g_strv_contains ((const char *const *)self->allow_important, app_id))
    return TRUE;

  return FALSE;
}


static void
on_feedbackd_allow_important_changed (FbdFeedbackManager *self,
                                      const gchar        *key,
                                      GSettings          *settings)
{
  g_return_if_fail (FBD_IS_FEEDBACK_MANAGER (self));
  g_return_if_fail (G_IS_SETTINGS (settings));

  g_strfreev (self->allow_important);
  self->allow_important = g_settings_get_strv(self->settings, FEEDBACKD_KEY_ALLOW_IMPORTANT);
}


static void
on_client_vanished (GDBusConnection *connection,
		    const gchar     *name,
		    gpointer         user_data)
{
  FbdFeedbackManager *self = FBD_FEEDBACK_MANAGER (user_data);
  GHashTableIter iter;
  gpointer key, value;
  FbdEvent *event;
  GSList *l;
  g_autoptr (GSList) events = NULL;

  g_return_if_fail (name);

  g_debug ("Client %s vanished", name);

  /*
   * Prepare a list of events to end feedback for so we don't modify
   * the hash table in place when 'feedbacks-ended' fires.
   */
  g_hash_table_iter_init (&iter, self->events);
  while (g_hash_table_iter_next (&iter, &key, &value)) {
    event = FBD_EVENT (value);
    if (!g_strcmp0 (fbd_event_get_sender (event), name))
      events = g_slist_append (events, event);
  }

  for (l = events; l; l = l->next) {
    event = l->data;
    g_debug ("Ending event %s (%d) since %s vanished",
             fbd_event_get_event (event),
             fbd_event_get_id (event),
             name);
    fbd_event_end_feedbacks (event);
  }

  g_hash_table_remove (self->clients, name);
}

static void
watch_client (FbdFeedbackManager *self, GDBusMethodInvocation *invocation)
{
  guint watch_id;
  GDBusConnection *conn = g_dbus_method_invocation_get_connection (invocation);
  const char *sender = g_dbus_method_invocation_get_sender (invocation);

  watch_id = g_bus_watch_name_on_connection (conn,
					     sender,
					     G_BUS_NAME_WATCHER_FLAGS_NONE,
					     NULL,
					     on_client_vanished,
					     self,
					     NULL);
  g_hash_table_insert (self->clients, g_strdup (sender), GUINT_TO_POINTER (watch_id));
}

static void
free_client_watch (gpointer data)
{
  guint watch_id = GPOINTER_TO_UINT (data);

  if (watch_id == 0)
    return;
  g_bus_unwatch_name (watch_id);
}

static FbdFeedbackProfileLevel
get_max_level (FbdFeedbackProfileLevel global_level,
               FbdFeedbackProfileLevel app_level,
               FbdFeedbackProfileLevel event_level)
{
  FbdFeedbackProfileLevel level;

  /* Per app configuration can only select a *lower* feedback level */
  level = MIN (global_level, app_level);
  /* A hint in an event can only select a *lower* feedback level */
  level = MIN (level, event_level);

  return level;
}

static gboolean
parse_hints (GVariant *hints, FbdFeedbackProfileLevel *level, gboolean *hint_important)
{
  const gchar *profile;
  gboolean found, important;
  g_auto (GVariantDict) dict = G_VARIANT_DICT_INIT (NULL);

  g_variant_dict_init (&dict, hints);

  found = g_variant_dict_lookup (&dict, "profile", "&s", &profile);
  if (level && found)
    *level = fbd_feedback_profile_level (profile);

  found = g_variant_dict_lookup (&dict, "important", "b", &important);
  if (hint_important && found)
    *hint_important = important;

  return TRUE;
}

static gboolean
fbd_feedback_manager_handle_trigger_feedback (LfbGdbusFeedback      *object,
                                              GDBusMethodInvocation *invocation,
                                              const gchar           *arg_app_id,
                                              const gchar           *arg_event,
                                              GVariant              *arg_hints,
                                              gint                   arg_timeout)
{
  FbdFeedbackManager *self;
  FbdEvent *event;
  GSList *feedbacks, *l;
  guint event_id;
  const gchar *sender;
  FbdFeedbackProfileLevel app_level, level, hint_level = FBD_FEEDBACK_PROFILE_LEVEL_FULL;
  gboolean found_fb = FALSE;
  gboolean hint_important = FALSE, can_important;

  sender = g_dbus_method_invocation_get_sender (invocation);
  g_debug ("Event '%s' for '%s' from %s", arg_event, arg_app_id, sender);

  g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (object), FALSE);
  g_return_val_if_fail (arg_app_id, FALSE);
  g_return_val_if_fail (arg_event, FALSE);

  self = FBD_FEEDBACK_MANAGER (object);
  if (!strlen (arg_app_id)) {
    g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
                                           G_DBUS_ERROR_INVALID_ARGS,
                                           "Invalid app id %s", arg_app_id);
    return TRUE;
  }

  if (!strlen (arg_event)) {
    g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
                                           G_DBUS_ERROR_INVALID_ARGS,
                                           "Invalid event %s", arg_event);
    return TRUE;
  }

  if (!parse_hints (arg_hints, &hint_level, &hint_important)) {
    g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR,
                                           G_DBUS_ERROR_INVALID_ARGS,
                                           "Invalid hints");
    return TRUE;
  }

  if (arg_timeout < -1)
    arg_timeout = -1;

  event_id = self->next_id++;

  event = fbd_event_new (event_id, arg_app_id, arg_event, arg_timeout, sender);
  g_hash_table_insert (self->events, GUINT_TO_POINTER (event_id), event);

  app_level = app_get_feedback_level (arg_app_id);
  can_important = app_is_important (self, arg_app_id);

  if (hint_important && can_important)
    level = hint_level;
  else
    level = get_max_level (self->level, app_level, hint_level);

  feedbacks = fbd_feedback_theme_lookup_feedback (self->theme, level, event);
  if (feedbacks) {
    for (l = feedbacks; l; l = l->next) {
      FbdFeedbackBase *fb = FBD_FEEDBACK_BASE (l->data);

      if (fbd_feedback_is_available (FBD_FEEDBACK_BASE (fb))) {
        fbd_event_add_feedback (event, fb);
        found_fb = TRUE;
      }
    }
    g_slist_free_full (feedbacks, g_object_unref);
  } else {
    /* No feedbacks found at all */
    found_fb = FALSE;
  }

  lfb_gdbus_feedback_complete_trigger_feedback (object, invocation, event_id);

  if (found_fb) {
    g_signal_connect_object (event, "feedbacks-ended",
                             (GCallback) on_event_feedbacks_ended,
                             self,
                             G_CONNECT_SWAPPED);
    fbd_event_run_feedbacks (event);
    watch_client (self, invocation);
  } else {
    g_hash_table_remove (self->events, GUINT_TO_POINTER (event_id));
    lfb_gdbus_feedback_emit_feedback_ended (LFB_GDBUS_FEEDBACK (self), event_id,
                                            FBD_EVENT_END_REASON_NOT_FOUND);
  }

  return TRUE;
}

static gboolean
fbd_feedback_manager_handle_end_feedback (LfbGdbusFeedback      *object,
                                          GDBusMethodInvocation *invocation,
                                          guint                  event_id)
{
  FbdFeedbackManager *self;
  FbdEvent *event;

  g_debug ("Ending feedback for event '%d'", event_id);

  g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (object), FALSE);
  g_return_val_if_fail (event_id, FALSE);

  self = FBD_FEEDBACK_MANAGER (object);

  event = g_hash_table_lookup (self->events, GUINT_TO_POINTER (event_id));
  if (event) {
    /* The last feedback ending will trigger event disposal via
       `on_fb_ended` */
    fbd_event_end_feedbacks (event);
  } else {
    g_warning ("Tried to end non-existing event %d", event_id);
  }

  lfb_gdbus_feedback_complete_end_feedback (object, invocation);
  return TRUE;
}


static void
fbd_feedback_manager_constructed (GObject *object)
{
  FbdFeedbackManager *self = FBD_FEEDBACK_MANAGER (object);

  G_OBJECT_CLASS (fbd_feedback_manager_parent_class)->constructed (object);

  g_signal_connect (self, "notify::profile", (GCallback)on_profile_changed, NULL);

  self->settings = g_settings_new (FEEDBACKD_SCHEMA_ID);
  g_signal_connect_swapped (self->settings, "changed::" FEEDBACKD_KEY_THEME,
                            G_CALLBACK (on_feedbackd_setting_changed), self);
  g_signal_connect_swapped (self->settings, "changed::" FEEDBACKD_KEY_PROFILE,
                            G_CALLBACK (on_feedbackd_setting_changed), self);
  on_feedbackd_setting_changed (self, FEEDBACKD_KEY_PROFILE, self->settings);

  g_signal_connect_swapped (self->settings, "changed::" FEEDBACKD_KEY_ALLOW_IMPORTANT,
                            G_CALLBACK (on_feedbackd_allow_important_changed), self);
  on_feedbackd_allow_important_changed (self, FEEDBACKD_KEY_ALLOW_IMPORTANT, self->settings);
}


static void
fbd_feedback_manager_dispose (GObject *object)
{
  FbdFeedbackManager *self = FBD_FEEDBACK_MANAGER (object);

  g_clear_object (&self->settings);
  g_clear_object (&self->theme);
  g_clear_object (&self->sound);
  g_clear_object (&self->vibra);
  g_clear_object (&self->leds);
  g_clear_object (&self->client);

  g_clear_pointer (&self->allow_important, g_strfreev);
  g_clear_pointer (&self->events, g_hash_table_destroy);
  g_clear_pointer (&self->clients, g_hash_table_destroy);

  G_OBJECT_CLASS (fbd_feedback_manager_parent_class)->dispose (object);
}

static void
fbd_feedback_manager_feedback_iface_init (LfbGdbusFeedbackIface *iface)
{
  iface->handle_trigger_feedback = fbd_feedback_manager_handle_trigger_feedback;
  iface->handle_end_feedback = fbd_feedback_manager_handle_end_feedback;
}

static void
fbd_feedback_manager_class_init (FbdFeedbackManagerClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->constructed = fbd_feedback_manager_constructed;
  object_class->dispose = fbd_feedback_manager_dispose;
}

static void
fbd_feedback_manager_init (FbdFeedbackManager *self)
{
  const gchar * const subsystems[] = { "input", NULL };

  self->next_id = 1;
  self->level = FBD_FEEDBACK_PROFILE_LEVEL_UNKNOWN;

  self->client = g_udev_client_new (subsystems);
  g_signal_connect_swapped (G_OBJECT (self->client), "uevent",
                            G_CALLBACK (device_changes), self);
  init_devices (self);

  self->events = g_hash_table_new_full (g_direct_hash,
                                        g_direct_equal,
                                        NULL,
                                        (GDestroyNotify)g_object_unref);
  self->clients = g_hash_table_new_full (g_str_hash,
                                         g_str_equal,
                                         g_free,
                                         free_client_watch);
}

FbdFeedbackManager *
fbd_feedback_manager_get_default (void)
{
  static FbdFeedbackManager *instance;

  if (instance == NULL) {
    instance = g_object_new (FBD_TYPE_FEEDBACK_MANAGER, NULL);
    g_object_add_weak_pointer (G_OBJECT (instance), (gpointer *)&instance);
  }
  return instance;
}

FbdDevVibra *
fbd_feedback_manager_get_dev_vibra (FbdFeedbackManager *self)
{
  g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (self), NULL);

  return self->vibra;
}

FbdDevSound *
fbd_feedback_manager_get_dev_sound (FbdFeedbackManager *self)
{
  g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (self), NULL);

  return self->sound;
}

FbdDevLeds *
fbd_feedback_manager_get_dev_leds (FbdFeedbackManager *self)
{
  g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (self), NULL);

  return self->leds;
}

void
fbd_feedback_manager_load_theme (FbdFeedbackManager *self)
{
  g_autoptr (FbdThemeExpander) expander = NULL;
  g_autoptr (FbdFeedbackTheme) theme = NULL;
  g_autoptr (GError) err = NULL;
  g_auto (GStrv) compatibles = NULL;
  g_autofree char *theme_name = NULL;
  const char *theme_file = g_getenv (FEEDBACKD_THEME_VAR);

  compatibles = gm_device_tree_get_compatibles (NULL, &err);
  if (compatibles == NULL && err) {
    g_debug ("Failed to get compatibles: %s", err->message);
    g_clear_error (&err);
  }

  if (theme_file == NULL)
    theme_name = g_settings_get_string (self->settings, FEEDBACKD_KEY_THEME);

  expander = fbd_theme_expander_new ((const char *const *)compatibles,
                                     theme_name, theme_file);
  theme = fbd_theme_expander_load_theme_files (expander, &err);
  if (theme) {
    g_set_object(&self->theme, theme);
  } else {
    if (self->theme)
      g_warning ("Failed to reload theme: %s", err->message);
    else
      g_error ("Failed to load any theme: %s", err->message); // No point to carry on
  }
}


static void
cancel_running (FbdFeedbackManager *self)
{
  g_autoptr (GList) running = g_hash_table_get_values (self->events);

  for (GList *l = running; l ; l = l->next) {
    FbdEvent *event = FBD_EVENT (l->data);

    fbd_event_end_feedbacks_by_level (event, self->level);
  }
}


gboolean
fbd_feedback_manager_set_profile (FbdFeedbackManager *self, const gchar *profile)
{
  FbdFeedbackProfileLevel level;

  g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (self), FALSE);

  level = fbd_feedback_profile_level (profile);

  if (level == FBD_FEEDBACK_PROFILE_LEVEL_UNKNOWN)
    return FALSE;

  if (level == self->level)
    return TRUE;

  g_debug ("Switching profile to '%s'", profile);
  self->level = level;
  lfb_gdbus_feedback_set_profile (LFB_GDBUS_FEEDBACK (self), profile);
  g_settings_set_string (self->settings, FEEDBACKD_KEY_PROFILE, profile);

  cancel_running (self);

  return TRUE;
}
07070100000071000081A400000000000000000000000166F7A51300000381000000000000000000000000000000000000002B00000000feedbackd-0.5.0/src/fbd-feedback-manager.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-dev-vibra.h"
#include "fbd-dev-leds.h"
#include "fbd-dev-sound.h"

#include "lfb-gdbus.h"
#include <glib-object.h>

G_BEGIN_DECLS

#define FBD_TYPE_FEEDBACK_MANAGER (fbd_feedback_manager_get_type())

G_DECLARE_FINAL_TYPE (FbdFeedbackManager, fbd_feedback_manager, FBD, FEEDBACK_MANAGER, LfbGdbusFeedbackSkeleton);

FbdFeedbackManager *fbd_feedback_manager_get_default (void);
FbdDevVibra *fbd_feedback_manager_get_dev_vibra (FbdFeedbackManager *self);
FbdDevSound *fbd_feedback_manager_get_dev_sound (FbdFeedbackManager *self);
FbdDevLeds  *fbd_feedback_manager_get_dev_leds  (FbdFeedbackManager *self);
void         fbd_feedback_manager_load_theme    (FbdFeedbackManager *self);
gboolean     fbd_feedback_manager_set_profile (FbdFeedbackManager *self, const gchar *profile);

G_END_DECLS
07070100000072000081A400000000000000000000000166F7A51300002E31000000000000000000000000000000000000002B00000000feedbackd-0.5.0/src/fbd-feedback-profile.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-feedback-profile"

#include "fbd-feedback-dummy.h"
#include "fbd-feedback-profile.h"
#include "fbd-feedback-sound.h"
#include "fbd-feedback-led.h"
#include "fbd-feedback-vibra-periodic.h"
#include "fbd-feedback-vibra-rumble.h"

#include <json-glib/json-glib.h>

#define FBD_FEEDBACK_CLS_PREFIX "FbdFeedback"

enum {
  PROP_0,
  PROP_NAME,
  PROP_FEEDBACKS,
  PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];

/**
 * SECTION:fbd-feedback-profile
 * @short_description: A profile in a #FbdFeedbackTheme
 * @Title: FbdFeedbackProfile
 */

typedef struct _FbdFeedbackProfile {
  GObject parent;

  gchar *name;
  GHashTable *feedbacks; /* key: event name, value: feedback */
} FbdFeedbackProfile;

static void json_serializable_iface_init (JsonSerializableIface *iface);

G_DEFINE_TYPE_WITH_CODE (FbdFeedbackProfile, fbd_feedback_profile, G_TYPE_OBJECT,
                         G_IMPLEMENT_INTERFACE (JSON_TYPE_SERIALIZABLE,
                                                json_serializable_iface_init));


static JsonNode *
fbd_feedback_profile_serializable_serialize_property (JsonSerializable *serializable,
                                                      const gchar *property_name,
                                                      const GValue *value,
                                                      GParamSpec *pspec)
{
  FbdFeedbackProfile *self = FBD_FEEDBACK_PROFILE (serializable);
  JsonNode *node = NULL;

  if (g_strcmp0 (property_name, "feedbacks") == 0) {
    GHashTableIter iter;
    gpointer key;
    FbdFeedbackProfile *profile;
    g_autoptr (JsonArray) array = json_array_sized_new (FBD_FEEDBACK_PROFILE_N_PROFILES);

    g_hash_table_iter_init (&iter, self->feedbacks);
    while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *) &profile)) {
      json_array_add_element (array, json_gobject_serialize (G_OBJECT(profile)));
    }
    node = json_node_init_array (json_node_alloc (), array);
  } else {
    node = json_serializable_default_serialize_property (serializable,
                                                         property_name,
                                                         value,
                                                         pspec);
  }
  return node;
}

static GType
feedback_get_type (JsonNode *feedback_node)
{
  g_autofree gchar *type_name = NULL;
  JsonObject *obj = json_node_get_object (feedback_node);
  JsonNode *type_node = json_object_get_member (obj, "type");
  GType gtype = 0;

  /* Ensure all feedback types so the json parsing can use them */
  g_type_ensure (FBD_TYPE_FEEDBACK_DUMMY);
  g_type_ensure (FBD_TYPE_FEEDBACK_LED);
  g_type_ensure (FBD_TYPE_FEEDBACK_VIBRA_PERIODIC);
  g_type_ensure (FBD_TYPE_FEEDBACK_VIBRA_RUMBLE);
  g_type_ensure (FBD_TYPE_FEEDBACK_SOUND);

  g_return_val_if_fail (type_node, FBD_TYPE_FEEDBACK_DUMMY);

  type_name = g_strdup_printf ("FbdFeedback%s",
                               json_node_get_string (type_node));
  type_name[strlen(FBD_FEEDBACK_CLS_PREFIX)] =
    g_ascii_toupper (type_name[strlen(FBD_FEEDBACK_CLS_PREFIX)]);
  gtype = g_type_from_name (type_name);

  g_debug ("Feedback %s, type %" G_GSIZE_FORMAT, type_name, gtype);
  g_return_val_if_fail (gtype, FBD_TYPE_FEEDBACK_DUMMY);
  return gtype;
}

static gboolean
fbd_feedback_profile_serializable_deserialize_property (JsonSerializable *serializable,
                                                        const gchar *property_name,
                                                        GValue *value,
                                                        GParamSpec *pspec,
                                                        JsonNode *property_node)
{
  if (g_strcmp0 (property_name, "feedbacks") == 0) {
    if (JSON_NODE_TYPE (property_node) == JSON_NODE_NULL) {
      g_value_set_pointer (value, NULL);
      return TRUE;
    } else if (JSON_NODE_TYPE (property_node) == JSON_NODE_ARRAY) {
      JsonArray *array = json_node_get_array (property_node);
      guint i, array_len = json_array_get_length (array);
      GHashTable *feedbacks = g_hash_table_new_full (g_str_hash,
                                                     g_str_equal,
                                                     g_free,
                                                     (GDestroyNotify)g_object_unref);
      for (i = 0; i < array_len; i++) {
        JsonNode *element_node = json_array_get_element (array, i);

        if (JSON_NODE_HOLDS_OBJECT (element_node)) {
          gchar *event_name;
          FbdFeedbackBase *feedback;
          GType gtype = feedback_get_type (element_node);

          feedback = FBD_FEEDBACK_BASE (json_gobject_deserialize (gtype, element_node));
          event_name = g_strdup (fbd_feedback_get_event_name (FBD_FEEDBACK_BASE(feedback)));
          g_hash_table_insert (feedbacks, event_name, feedback);
        } else {
          return FALSE;
        }
      }
      g_value_set_boxed (value, feedbacks);
      return TRUE;
    }
    return FALSE;
  } else {
    return json_serializable_default_deserialize_property (serializable,
                                                           property_name,
                                                           value,
                                                           pspec,
                                                           property_node);
  }
  return FALSE;
}

static void
fbd_feedback_profile_set_property (GObject        *object,
                                   guint         property_id,
                                   const GValue *value,
                                   GParamSpec   *pspec)
{
  FbdFeedbackProfile *self = FBD_FEEDBACK_PROFILE (object);

  switch (property_id) {
  case PROP_NAME:
    g_free (self->name);
    self->name = g_value_dup_string (value);
    break;
  case PROP_FEEDBACKS:
    if (self->feedbacks)
      g_hash_table_unref (self->feedbacks);
    self->feedbacks = g_value_get_boxed (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}


static void
fbd_feedback_profile_get_property (GObject  *object,
                                   guint       property_id,
                                   GValue     *value,
                                   GParamSpec *pspec)
{
  FbdFeedbackProfile *self = FBD_FEEDBACK_PROFILE (object);

  switch (property_id) {
  case PROP_NAME:
    g_value_set_string (value, self->name);
    break;
  case PROP_FEEDBACKS:
    g_value_set_boxed (value, self->feedbacks);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
fbd_feedback_profile_dispose (GObject *object)
{
  FbdFeedbackProfile *self = FBD_FEEDBACK_PROFILE (object);

  g_clear_pointer (&self->feedbacks, g_hash_table_unref);

  G_OBJECT_CLASS (fbd_feedback_profile_parent_class)->dispose (object);
}

static void
fbd_feedback_profile_finalize (GObject *object)
{
  FbdFeedbackProfile *self = FBD_FEEDBACK_PROFILE (object);

  g_clear_pointer (&self->name, g_free);

  G_OBJECT_CLASS (fbd_feedback_profile_parent_class)->finalize (object);
}

static void
json_serializable_iface_init (JsonSerializableIface *iface)
{
  iface->serialize_property = fbd_feedback_profile_serializable_serialize_property;
  iface->deserialize_property = fbd_feedback_profile_serializable_deserialize_property;
}

static void
fbd_feedback_profile_constructed (GObject *object)
{
  FbdFeedbackProfile *self = FBD_FEEDBACK_PROFILE (object);

  G_OBJECT_CLASS (fbd_feedback_profile_parent_class)->constructed (object);

  if (!self->feedbacks) {
    self->feedbacks = g_hash_table_new_full (g_str_hash,
                                             g_str_equal,
                                             g_free,
                                             (GDestroyNotify)g_object_unref);
  }
}


static void
fbd_feedback_profile_class_init (FbdFeedbackProfileClass *klass)
{

  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->set_property = fbd_feedback_profile_set_property;
  object_class->get_property = fbd_feedback_profile_get_property;

  object_class->constructed = fbd_feedback_profile_constructed;
  object_class->dispose = fbd_feedback_profile_dispose;
  object_class->finalize = fbd_feedback_profile_finalize;

  props[PROP_NAME] =
    g_param_spec_string (
      "name",
      "Name",
      "The feedback name",
      NULL,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  props[PROP_FEEDBACKS] =
    g_param_spec_boxed (
      "feedbacks",
      "Feedbacks",
      "The feedbacks for this profile",
      G_TYPE_HASH_TABLE,
      /* Can't be CONSTRUCT_ONLY since json-glib can't handle it */
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}

static void
fbd_feedback_profile_init (FbdFeedbackProfile *self)
{
}

FbdFeedbackProfile *
fbd_feedback_profile_new (const gchar *name)
{
  return g_object_new(FBD_TYPE_FEEDBACK_PROFILE,
                      "name", name,
                      NULL);
}

const char *
fbd_feedback_profile_get_name (FbdFeedbackProfile *self)
{
  g_return_val_if_fail (FBD_IS_FEEDBACK_PROFILE (self), "");

  return self->name;
}

void
fbd_feedback_profile_add_feedback (FbdFeedbackProfile *self, FbdFeedbackBase *feedback)
{
  g_return_if_fail (FBD_IS_FEEDBACK_PROFILE (self));
  gchar *name = g_strdup (fbd_feedback_get_event_name (feedback));

  /* TODO: allow for more than one feedback per event and profile */
  g_hash_table_insert (self->feedbacks, name, g_object_ref (feedback));
}

FbdFeedbackBase *
fbd_feedback_profile_get_feedback (FbdFeedbackProfile *self, const char *event_name)
{
  g_return_val_if_fail (FBD_IS_FEEDBACK_PROFILE (self), NULL);

  return g_hash_table_lookup (self->feedbacks, event_name);
}

FbdFeedbackProfileLevel
fbd_feedback_profile_level (const char *name)
{
  FbdFeedbackProfileLevel profile = FBD_FEEDBACK_PROFILE_LEVEL_UNKNOWN;

  if (!g_strcmp0("silent", name)) {
    profile = FBD_FEEDBACK_PROFILE_LEVEL_SILENT;
  } else if (!g_strcmp0("quiet", name)) {
    profile = FBD_FEEDBACK_PROFILE_LEVEL_QUIET;
  } else if (!g_strcmp0("full", name)) {
    profile = FBD_FEEDBACK_PROFILE_LEVEL_FULL;
  }

  return profile;
}

const char*
fbd_feedback_profile_level_to_string (FbdFeedbackProfileLevel level)
{
  switch (level) {
  case FBD_FEEDBACK_PROFILE_LEVEL_SILENT:
    return "silent";
  case FBD_FEEDBACK_PROFILE_LEVEL_QUIET:
    return "quiet";
  case FBD_FEEDBACK_PROFILE_LEVEL_FULL:
    return "full";
  case FBD_FEEDBACK_PROFILE_LEVEL_UNKNOWN:
  default:
    return "full";
  }
}

/**
 * fbd_profile_update:
 * @self: The profile that should be updated
 * @new: The profile theme we want to take new feedbacks from
 *
 * Updates a profile. Feedbacks are read from the `new` profile. If
 * feedback already exists in `self` it is overwritten with the feedback
 * from `new`.
 *
 * It is not allowed to update a profile with a profile of a different name.
 */
void
fbd_feedback_profile_update (FbdFeedbackProfile *self, FbdFeedbackProfile *new)
{
  GHashTableIter iter;
  const char *event_name;
  FbdFeedbackBase *fb;

  g_return_if_fail (FBD_IS_FEEDBACK_PROFILE (self));
  g_return_if_fail (FBD_IS_FEEDBACK_PROFILE (new));

  g_return_if_fail (g_str_equal (fbd_feedback_profile_get_name (self),
                                 fbd_feedback_profile_get_name (new)));

  g_hash_table_iter_init (&iter, new->feedbacks);
  while (g_hash_table_iter_next (&iter, (gpointer)&event_name, (gpointer)&fb)) {
    g_hash_table_insert (self->feedbacks, g_strdup (event_name), g_object_ref (fb));
  }
}
07070100000073000081A400000000000000000000000166F7A51300000568000000000000000000000000000000000000002B00000000feedbackd-0.5.0/src/fbd-feedback-profile.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include <fbd-feedback-base.h>

#include <glib-object.h>

G_BEGIN_DECLS

typedef enum _FbdFeedbackProfileLevel {
  FBD_FEEDBACK_PROFILE_LEVEL_UNKNOWN = -1,
  FBD_FEEDBACK_PROFILE_LEVEL_SILENT  =  0,
  FBD_FEEDBACK_PROFILE_LEVEL_QUIET,
  FBD_FEEDBACK_PROFILE_LEVEL_FULL,
  FBD_FEEDBACK_PROFILE_N_PROFILES,
} FbdFeedbackProfileLevel;

#define FBD_TYPE_FEEDBACK_PROFILE (fbd_feedback_profile_get_type())

G_DECLARE_FINAL_TYPE (FbdFeedbackProfile, fbd_feedback_profile, FBD, FEEDBACK_PROFILE, GObject);

FbdFeedbackProfile      *fbd_feedback_profile_new (const gchar *name);
void                     fbd_feedback_profile_update (FbdFeedbackProfile *self,
                                                      FbdFeedbackProfile *new);
const gchar             *fbd_feedback_profile_get_name (FbdFeedbackProfile *self);
void                     fbd_feedback_profile_add_feedback (FbdFeedbackProfile *self,
                                                            FbdFeedbackBase *feedback);
FbdFeedbackBase         *fbd_feedback_profile_get_feedback (FbdFeedbackProfile *self,
							    const char *event_name);
FbdFeedbackProfileLevel  fbd_feedback_profile_level (const char *name);
const char*              fbd_feedback_profile_level_to_string (FbdFeedbackProfileLevel level);

G_END_DECLS
07070100000074000081A400000000000000000000000166F7A51300001004000000000000000000000000000000000000002900000000feedbackd-0.5.0/src/fbd-feedback-sound.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-feedback-sound"

#include "fbd-enums.h"
#include "fbd-feedback-sound.h"
#include "fbd-feedback-manager.h"

/**
 * SECTION:fbd-feedback-sound
 * @short_description: Describes a feedback via a haptic motor
 * @Title: FbdFeedbackSound
 *
 * The #FbdSoundSound describes the properties of a sound feedback
 * event. It knows nothing about how to play sound itself but calls
 * #FbdDevSound for that.
 */

enum {
  PROP_0,
  PROP_EFFECT,
  PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];

typedef struct _FbdFeedbackSound {
  FbdFeedbackBase parent;

  gchar *effect;
} FbdFeedbackSound;

G_DEFINE_TYPE (FbdFeedbackSound, fbd_feedback_sound, FBD_TYPE_FEEDBACK_BASE);

static void
on_effect_finished (FbdFeedbackSound *self)

{
  fbd_feedback_base_done (FBD_FEEDBACK_BASE(self));
}

static void
fbd_feedback_sound_run (FbdFeedbackBase *base)
{
  FbdFeedbackSound *self = FBD_FEEDBACK_SOUND (base);
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevSound *sound = fbd_feedback_manager_get_dev_sound (manager);

  g_return_if_fail (FBD_IS_DEV_SOUND (sound));
  g_debug ("Sound event %s", self->effect);
  fbd_dev_sound_play (sound, self, on_effect_finished);
}


static void
fbd_feedback_sound_end (FbdFeedbackBase *base)
{
  FbdFeedbackSound *self = FBD_FEEDBACK_SOUND (base);
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevSound *sound = fbd_feedback_manager_get_dev_sound (manager);

  fbd_dev_sound_stop (sound, self);
}

static gboolean
fbd_feedback_sound_is_available (FbdFeedbackBase *base)
{
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevSound *sound = fbd_feedback_manager_get_dev_sound (manager);

  return FBD_IS_DEV_SOUND (sound);
}

static void
fbd_feedback_sound_set_property (GObject      *object,
                                 guint         property_id,
                                 const GValue *value,
                                 GParamSpec   *pspec)
{
  FbdFeedbackSound *self = FBD_FEEDBACK_SOUND (object);

  switch (property_id) {
  case PROP_EFFECT:
    self->effect = g_value_dup_string (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
fbd_feedback_sound_get_property (GObject    *object,
                                 guint       property_id,
                                 GValue     *value,
                                 GParamSpec *pspec)
{
  FbdFeedbackSound *self = FBD_FEEDBACK_SOUND (object);

  switch (property_id) {
  case PROP_EFFECT:
    g_value_set_string (value, fbd_feedback_sound_get_effect (self));
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
fbd_feedback_sound_finalize (GObject *object)
{
  FbdFeedbackSound *self = FBD_FEEDBACK_SOUND (object);

  g_clear_pointer (&self->effect, g_free);

  G_OBJECT_CLASS (fbd_feedback_sound_parent_class)->finalize (object);
}

static void
fbd_feedback_sound_class_init (FbdFeedbackSoundClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass);

  object_class->finalize = fbd_feedback_sound_finalize;
  object_class->set_property = fbd_feedback_sound_set_property;
  object_class->get_property = fbd_feedback_sound_get_property;

  base_class->run = fbd_feedback_sound_run;
  base_class->end = fbd_feedback_sound_end;
  base_class->is_available = fbd_feedback_sound_is_available;

  props[PROP_EFFECT] =
    g_param_spec_string (
      "effect",
      "Effect",
      "The sound effects name",
      "",
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}

static void
fbd_feedback_sound_init (FbdFeedbackSound *self)
{
}

const char *fbd_feedback_sound_get_effect (FbdFeedbackSound *self)
{
  return self->effect;
}
07070100000075000081A400000000000000000000000166F7A51300000183000000000000000000000000000000000000002900000000feedbackd-0.5.0/src/fbd-feedback-sound.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-feedback-base.h"

G_BEGIN_DECLS

#define FBD_TYPE_FEEDBACK_SOUND (fbd_feedback_sound_get_type())

G_DECLARE_FINAL_TYPE (FbdFeedbackSound, fbd_feedback_sound, FBD, FEEDBACK_SOUND, FbdFeedbackBase);

const char *fbd_feedback_sound_get_effect (FbdFeedbackSound *self);

G_END_DECLS
07070100000076000081A400000000000000000000000166F7A51300002CD2000000000000000000000000000000000000002900000000feedbackd-0.5.0/src/fbd-feedback-theme.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-feedback-theme"

#include "fbd-feedback-base.h"
#include "fbd-feedback-dummy.h"
#include "fbd-feedback-sound.h"
#include "fbd-feedback-theme.h"
#include "fbd-feedback-vibra.h"
#include "fbd-feedback-profile.h"

#include <json-glib/json-glib.h>

enum {
  PROP_0,
  PROP_NAME,
  PROP_PARENT_NAME,
  PROP_PROFILES,
  PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];

typedef struct _FbdFeedbackTheme {
  GObject parent;

  char *name;
  char *parent_name;

  GHashTable *profiles;
} FbdFeedbackTheme;

static void json_serializable_iface_init (JsonSerializableIface *iface);

G_DEFINE_TYPE_WITH_CODE (FbdFeedbackTheme, fbd_feedback_theme, G_TYPE_OBJECT,
			 G_IMPLEMENT_INTERFACE (JSON_TYPE_SERIALIZABLE,
                                                json_serializable_iface_init));


static JsonNode *
fbd_theme_serializable_serialize_property (JsonSerializable *serializable,
					   const gchar      *property_name,
					   const GValue     *value,
					   GParamSpec       *pspec)
{
  FbdFeedbackTheme *self = FBD_FEEDBACK_THEME (serializable);
  JsonNode *node = NULL;

  if (g_strcmp0 (property_name, "profiles") == 0) {
    GHashTableIter iter;
    gpointer key;
    FbdFeedbackProfile *profile;
    g_autoptr (JsonArray) array = json_array_sized_new (FBD_FEEDBACK_PROFILE_N_PROFILES);

    g_hash_table_iter_init (&iter, self->profiles);
    while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *) &profile)) {
      json_array_add_element (array, json_gobject_serialize (G_OBJECT(profile)));
    }
    node = json_node_init_array (json_node_alloc (), array);
  } else {
    node = json_serializable_default_serialize_property (serializable,
							 property_name,
							 value,
							 pspec);
  }
  return node;
}

static gboolean
fbd_theme_serializable_deserialize_property (JsonSerializable *serializable,
					     const gchar      *property_name,
					     GValue           *value,
					     GParamSpec       *pspec,
					     JsonNode         *property_node)
{
  if (g_strcmp0 (property_name, "profiles") == 0) {
    if (JSON_NODE_TYPE (property_node) == JSON_NODE_NULL) {
      g_value_set_pointer (value, NULL);
      return TRUE;
    } else if (JSON_NODE_TYPE (property_node) == JSON_NODE_ARRAY) {
      JsonArray *array = json_node_get_array (property_node);
      guint i, array_len = json_array_get_length (array);
      GHashTable *profiles = g_hash_table_new_full (g_str_hash,
						    g_str_equal,
						    g_free,
						    (GDestroyNotify)g_object_unref);

      for (i = 0; i < array_len; i++) {
	JsonNode *element_node = json_array_get_element (array, i);
	FbdFeedbackProfile *profile;
	gchar *name;

	if (JSON_NODE_HOLDS_OBJECT (element_node)) {
	  profile = FBD_FEEDBACK_PROFILE (json_gobject_deserialize (FBD_TYPE_FEEDBACK_PROFILE,
								    element_node));
	  name = g_strdup (fbd_feedback_profile_get_name (profile));
	  g_hash_table_insert (profiles, name, profile);
	} else {
	  return FALSE;
	}
      }
      g_value_set_boxed (value, profiles);
      return TRUE;
    }
    return FALSE;
  } else {
    return json_serializable_default_deserialize_property (serializable,
							   property_name,
							   value,
							   pspec,
							   property_node);
  }
  return FALSE;
}

static void
fbd_feedback_theme_set_property (GObject      *object,
                                 guint         property_id,
                                 const GValue *value,
                                 GParamSpec   *pspec)
{
  FbdFeedbackTheme *self = FBD_FEEDBACK_THEME (object);

  switch (property_id) {
  case PROP_NAME:
    fbd_feedback_theme_set_name (self, g_value_get_string (value));
    break;
  case PROP_PARENT_NAME:
    fbd_feedback_theme_set_parent_name (self, g_value_get_string (value));
    break;
  case PROP_PROFILES:
    if (self->profiles)
      g_hash_table_unref (self->profiles);
    self->profiles = g_value_get_boxed (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}


static void
fbd_feedback_theme_get_property (GObject  *object,
                                 guint       property_id,
                                 GValue     *value,
                                 GParamSpec *pspec)
{
  FbdFeedbackTheme *self = FBD_FEEDBACK_THEME (object);

  switch (property_id) {
  case PROP_NAME:
    g_value_set_string (value, fbd_feedback_theme_get_name (self));
    break;
  case PROP_PARENT_NAME:
    g_value_set_string (value, fbd_feedback_theme_get_parent_name (self));
    break;
  case PROP_PROFILES:
    g_value_set_boxed (value, self->profiles);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
fbd_feedback_theme_dispose (GObject *object)
{
  FbdFeedbackTheme *self = FBD_FEEDBACK_THEME (object);

  g_clear_pointer (&self->profiles, g_hash_table_unref);

  G_OBJECT_CLASS (fbd_feedback_theme_parent_class)->dispose (object);
}

static void
fbd_feedback_theme_finalize (GObject *object)
{
  FbdFeedbackTheme *self = FBD_FEEDBACK_THEME (object);

  g_clear_pointer (&self->parent_name, g_free);
  g_clear_pointer (&self->name, g_free);

  G_OBJECT_CLASS (fbd_feedback_theme_parent_class)->finalize (object);
}

static void
json_serializable_iface_init (JsonSerializableIface *iface)
{
  iface->serialize_property = fbd_theme_serializable_serialize_property;
  iface->deserialize_property = fbd_theme_serializable_deserialize_property;
}

static void
fbd_feedback_theme_class_init (FbdFeedbackThemeClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->set_property = fbd_feedback_theme_set_property;
  object_class->get_property = fbd_feedback_theme_get_property;

  object_class->dispose = fbd_feedback_theme_dispose;
  object_class->finalize = fbd_feedback_theme_finalize;

  props[PROP_NAME] =
    g_param_spec_string (
      "name",
      "Name",
      "The theme name",
      NULL,
      G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  props[PROP_PARENT_NAME] =
    g_param_spec_string (
      "parent-name",
      "Parent theme Name",
      "The parent theme name",
      NULL,
      G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  props[PROP_PROFILES] =
    g_param_spec_boxed (
      "profiles",
      "Profiles",
      "The feedback profiles",
      G_TYPE_HASH_TABLE,
      /* Can't be CONSTRUCT_ONLY since json-glib can't handle it */
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}

static void
fbd_feedback_theme_init (FbdFeedbackTheme *self)
{
  self->profiles = g_hash_table_new_full (g_str_hash,
                                          g_str_equal,
                                          g_free,
                                          (GDestroyNotify)g_object_unref);
}

FbdFeedbackTheme *
fbd_feedback_theme_new (const gchar *name)
{
  return FBD_FEEDBACK_THEME (g_object_new (FBD_TYPE_FEEDBACK_THEME,
                                           "name", name,
                                           NULL));
}


FbdFeedbackTheme *
fbd_feedback_theme_new_from_data (const gchar *data, GError **error)
{
  g_autoptr (JsonNode) node = json_from_string(data, error);
  if (!node)
    return NULL;

  return FBD_FEEDBACK_THEME (json_gobject_deserialize (FBD_TYPE_FEEDBACK_THEME, node));
}


FbdFeedbackTheme *
fbd_feedback_theme_new_from_file (const gchar *filename, GError **error)
{
  g_autofree char *data = NULL;

  if (!g_file_get_contents (filename, &data, NULL, error))
    return NULL;

  return fbd_feedback_theme_new_from_data (data, error);
}

void
fbd_feedback_theme_set_name (FbdFeedbackTheme *self, const char *name)
{
  g_return_if_fail (FBD_IS_FEEDBACK_THEME (self));

  if (g_strcmp0 (self->name, name) == 0)
    return;

  g_free (self->name);
  self->name = g_strdup (name);

  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_NAME]);
}

const char *
fbd_feedback_theme_get_name (FbdFeedbackTheme *self)
{
  g_return_val_if_fail (FBD_IS_FEEDBACK_THEME (self), "");

  return self->name;
}


void
fbd_feedback_theme_set_parent_name (FbdFeedbackTheme *self, const char *parent_name)
{
  g_return_if_fail (FBD_IS_FEEDBACK_THEME (self));

  if (g_strcmp0 (self->parent_name, parent_name) == 0)
    return;

  g_free (self->parent_name);
  self->parent_name = g_strdup (parent_name);

  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_PARENT_NAME]);
}


const char *
fbd_feedback_theme_get_parent_name (FbdFeedbackTheme *self)
{
  g_return_val_if_fail (FBD_IS_FEEDBACK_THEME (self), "");

  return self->parent_name;
}


void
fbd_feedback_theme_add_profile (FbdFeedbackTheme *self, FbdFeedbackProfile *profile)
{
  gchar *name;

  g_return_if_fail (FBD_IS_FEEDBACK_THEME (self));
  g_return_if_fail (FBD_IS_FEEDBACK_PROFILE (profile));
  name = g_strdup (fbd_feedback_profile_get_name (profile));

  g_hash_table_insert (self->profiles, name, g_object_ref (profile));
}

FbdFeedbackProfile *
fbd_feedback_theme_get_profile (FbdFeedbackTheme *self, const char *name)
{
  g_return_val_if_fail (FBD_IS_FEEDBACK_THEME (self), NULL);

  return g_hash_table_lookup (self->profiles, name);
}

GSList *
fbd_feedback_theme_lookup_feedback (FbdFeedbackTheme *self,
                                    FbdFeedbackProfileLevel level,
                                    FbdEvent *event)
{
  GSList *feedbacks = NULL;

  for (int i = level; i >= FBD_FEEDBACK_PROFILE_LEVEL_SILENT; i--) {
    const char *profile_name = fbd_feedback_profile_level_to_string (i);
    FbdFeedbackProfile *profile = fbd_feedback_theme_get_profile (self, profile_name);
    FbdFeedbackBase *feedback = fbd_feedback_profile_get_feedback (profile,
								   fbd_event_get_event (event));
    if (feedback) {
      g_object_set_data (G_OBJECT (feedback), "fbd-level", GUINT_TO_POINTER (i));
      feedbacks = g_slist_prepend (feedbacks, g_object_ref (feedback));
    }
  }

  if (!g_slist_length (feedbacks))
    g_debug ("No feedback for event %s", fbd_event_get_event (event));
  return feedbacks;
}


/**
 * fbd_feedback_theme_update:
 * @self: The feedback theme that should be updated
 * @new: The feedback theme we want to take profiles and feedbacks new
 *
 * Merges two feedback themes. Feedbacks and profiles are read new
 * the `new` theme.  If feedback already exists in the same profile
 * of `self` it is overwritten with the feedback in `new`.
 */
void
fbd_feedback_theme_update (FbdFeedbackTheme *self, FbdFeedbackTheme *new)
{
  GHashTableIter iter;
  const char *profile_name;
  FbdFeedbackProfile *profile;

  g_return_if_fail (FBD_IS_FEEDBACK_THEME (self));
  g_return_if_fail (FBD_IS_FEEDBACK_THEME (new));

  fbd_feedback_theme_set_name (self, fbd_feedback_theme_get_name (new));

  g_hash_table_iter_init (&iter, new->profiles);
  while (g_hash_table_iter_next (&iter, (gpointer)&profile_name, (gpointer)&profile)) {
    FbdFeedbackProfile *current;

    current = g_hash_table_lookup (self->profiles, profile_name);
    if (current == NULL) {
      current = fbd_feedback_profile_new (profile_name);
      g_hash_table_insert (self->profiles,
                           g_strdup (profile_name),
                           current);
    }

    fbd_feedback_profile_update (current, profile);
  }
}
07070100000077000081A400000000000000000000000166F7A51300000664000000000000000000000000000000000000002900000000feedbackd-0.5.0/src/fbd-feedback-theme.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-event.h"
#include "fbd-feedback-base.h"
#include "fbd-feedback-manager.h"
#include "fbd-feedback-profile.h"

#include <glib-object.h>

G_BEGIN_DECLS

#define FBD_TYPE_FEEDBACK_THEME (fbd_feedback_theme_get_type())

G_DECLARE_FINAL_TYPE (FbdFeedbackTheme, fbd_feedback_theme, FBD, FEEDBACK_THEME, GObject);

FbdFeedbackTheme   *fbd_feedback_theme_new (const char *name);
FbdFeedbackTheme   *fbd_feedback_theme_new_from_data (const gchar *data, GError **error);
FbdFeedbackTheme   *fbd_feedback_theme_new_from_file (const gchar *filename, GError **error);
void                fbd_feedback_theme_update (FbdFeedbackTheme *self, FbdFeedbackTheme *from);

const char         *fbd_feedback_theme_get_name (FbdFeedbackTheme *self);
void                fbd_feedback_theme_set_name (FbdFeedbackTheme *self, const char *name);
void                fbd_feedback_theme_set_parent_name (FbdFeedbackTheme *self,
                                                        const char *parent_name);
const char         *fbd_feedback_theme_get_parent_name (FbdFeedbackTheme *self);
void                fbd_feedback_theme_add_profile (FbdFeedbackTheme *self,
						    FbdFeedbackProfile *profile);
FbdFeedbackProfile *fbd_feedback_theme_get_profile (FbdFeedbackTheme *self, const char *name);

GSList             *fbd_feedback_theme_lookup_feedback (FbdFeedbackTheme *self,
                                                        FbdFeedbackProfileLevel profile,
                                                        FbdEvent *event);

G_END_DECLS
07070100000078000081A400000000000000000000000166F7A513000012A3000000000000000000000000000000000000003200000000feedbackd-0.5.0/src/fbd-feedback-vibra-periodic.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-feedback-vibra-periodic"

#include "fbd-enums.h"
#include "fbd-feedback-vibra-periodic.h"
#include "fbd-feedback-manager.h"

/**
 * SECTION:fbd-feedback-vibra-periodic
 * @short_description: Describes a periodic feedback via a haptic motor
 * @Title: FbdFeedbackVibraPeriodic
 *
 * The #FbdVibraVibraPeriodic describes the properties of a haptic feedback
 * event. It knows nothing about the hardware itself but calls
 * #FbdDevVibra for that.
 */

enum {
  PROP_0,
  PROP_MAGNITUDE,
  PROP_FADE_IN_LEVEL,
  PROP_FADE_IN_TIME,
  PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];

typedef struct _FbdFeedbackVibraPeriodic {
  FbdFeedbackVibra parent;

  guint magnitude;
  guint fade_in_level;
  guint fade_in_time;
} FbdFeedbackVibraPeriodic;

G_DEFINE_TYPE (FbdFeedbackVibraPeriodic, fbd_feedback_vibra_periodic, FBD_TYPE_FEEDBACK_VIBRA);

static void
fbd_feedback_vibra_periodic_set_property (GObject      *object,
					  guint         property_id,
					  const GValue *value,
					  GParamSpec   *pspec)
{
  FbdFeedbackVibraPeriodic *self = FBD_FEEDBACK_VIBRA_PERIODIC (object);

  switch (property_id) {
  case PROP_MAGNITUDE:
    self->magnitude = g_value_get_uint (value);
    break;
  case PROP_FADE_IN_LEVEL:
    self->fade_in_level = g_value_get_uint (value);
    break;
  case PROP_FADE_IN_TIME:
    self->fade_in_time = g_value_get_uint (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
fbd_feedback_vibra_periodic_get_property (GObject  *object,
					  guint       property_id,
					  GValue     *value,
					  GParamSpec *pspec)
{
  FbdFeedbackVibraPeriodic *self = FBD_FEEDBACK_VIBRA_PERIODIC (object);

  switch (property_id) {
  case PROP_MAGNITUDE:
    g_value_set_uint (value, self->magnitude);
    break;
  case PROP_FADE_IN_LEVEL:
    g_value_set_uint (value, self->fade_in_level);
    break;
  case PROP_FADE_IN_TIME:
    g_value_set_uint (value, self->fade_in_time);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
fbd_feedback_vibra_periodic_end_vibra (FbdFeedbackVibra *vibra)
{
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);

  fbd_dev_vibra_stop (dev);
}

static void
fbd_feedback_vibra_periodic_start_vibra (FbdFeedbackVibra *vibra)
{
  FbdFeedbackVibraPeriodic *self = FBD_FEEDBACK_VIBRA_PERIODIC (vibra);
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);
  guint duration = fbd_feedback_vibra_get_duration (vibra);

  g_return_if_fail (FBD_IS_DEV_VIBRA (dev));
  g_debug ("Periodic Vibra: %d %d %d %d",
	   duration, self->magnitude, self->fade_in_level, self->fade_in_time);

  fbd_dev_vibra_periodic (dev, duration, self->magnitude, self->fade_in_level,
			  self->fade_in_time);
}

static gboolean
fbd_feedback_vibra_periodic_is_available (FbdFeedbackBase *base)
{
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);

  return FBD_IS_DEV_VIBRA (dev);
}

static void
fbd_feedback_vibra_periodic_class_init (FbdFeedbackVibraPeriodicClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass);
  FbdFeedbackVibraClass *vibra_class = FBD_FEEDBACK_VIBRA_CLASS (klass);

  object_class->set_property = fbd_feedback_vibra_periodic_set_property;
  object_class->get_property = fbd_feedback_vibra_periodic_get_property;

  base_class->is_available = fbd_feedback_vibra_periodic_is_available;

  vibra_class->start_vibra = fbd_feedback_vibra_periodic_start_vibra;
  vibra_class->end_vibra = fbd_feedback_vibra_periodic_end_vibra;

  props[PROP_MAGNITUDE] =
    g_param_spec_uint (
      "magnitude",
      "Magnitude",
      "total magnitude",
      0, 0xFFFF, 0x7FFF,
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  props[PROP_FADE_IN_TIME] =
    g_param_spec_uint (
      "fade-in-time",
      "Fade in time",
      "Fade in time until full strength",
      0, G_MAXINT, 0,
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  props[PROP_FADE_IN_LEVEL] =
    g_param_spec_uint (
      "fade-in-level",
      "Fade in level",
      "Fade in start level",
      0, 0xFFFF, 0x7FFF,
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}

static void
fbd_feedback_vibra_periodic_init (FbdFeedbackVibraPeriodic *self)
{
}
07070100000079000081A400000000000000000000000166F7A5130000017C000000000000000000000000000000000000003200000000feedbackd-0.5.0/src/fbd-feedback-vibra-periodic.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-feedback-vibra.h"

G_BEGIN_DECLS

#define FBD_TYPE_FEEDBACK_VIBRA_PERIODIC (fbd_feedback_vibra_periodic_get_type())

G_DECLARE_FINAL_TYPE (FbdFeedbackVibraPeriodic, fbd_feedback_vibra_periodic, FBD,
		      FEEDBACK_VIBRA_PERIODIC,
		      FbdFeedbackVibra);

G_END_DECLS
0707010000007A000081A400000000000000000000000166F7A513000014A0000000000000000000000000000000000000003000000000feedbackd-0.5.0/src/fbd-feedback-vibra-rumble.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-feedback-vibra-rumble"

#include "fbd-enums.h"
#include "fbd-feedback-vibra-rumble.h"
#include "fbd-feedback-manager.h"

/**
 * SECTION:fbd-feedback-vibra
 * @short_description: Describes a rumble feedback via a haptic motor
 * @Title: FbdFeedbackVibraRumble
 *
 * The #FbdVibraVibraRumble describes the properties of a haptic feedback
 * event. It knows nothing about the hardware itself but calls
 * #FbdDevVibra for that.
 */

enum {
  PROP_0,
  PROP_COUNT,
  PROP_PAUSE,
  PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];

typedef struct _FbdFeedbackVibraRumble {
  FbdFeedbackVibra parent;

  guint count;   /* number of rumbles */
  guint pause;   /* pause in msecs */

  guint rumble;  /* rumble in msecs */
  guint periods; /* number of periods to play */
  guint timer_id;
} FbdFeedbackVibraRumble;

G_DEFINE_TYPE (FbdFeedbackVibraRumble, fbd_feedback_vibra_rumble, FBD_TYPE_FEEDBACK_VIBRA);

static void
fbd_feedback_vibra_rumble_set_property (GObject      *object,
					guint         property_id,
					const GValue *value,
					GParamSpec   *pspec)
{
  FbdFeedbackVibraRumble *self = FBD_FEEDBACK_VIBRA_RUMBLE (object);

  switch (property_id) {
  case PROP_COUNT:
    self->count = g_value_get_uint (value);
    break;
  case PROP_PAUSE:
    self->pause = g_value_get_uint (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
fbd_feedback_vibra_rumble_get_property (GObject  *object,
					  guint       property_id,
					  GValue     *value,
					  GParamSpec *pspec)
{
  FbdFeedbackVibraRumble *self = FBD_FEEDBACK_VIBRA_RUMBLE (object);

  switch (property_id) {
  case PROP_COUNT:
    g_value_set_uint (value, self->count);
    break;
  case PROP_PAUSE:
    g_value_set_uint (value, self->pause);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static gboolean
on_period_ended (FbdFeedbackVibraRumble *self)
{
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);

  g_return_val_if_fail (FBD_IS_FEEDBACK_VIBRA_RUMBLE (self), G_SOURCE_REMOVE);

  if (self->periods) {
    fbd_dev_vibra_rumble (dev, self->rumble, FALSE);
    self->periods--;
    return G_SOURCE_CONTINUE;
  }
  return G_SOURCE_REMOVE;
}

static void
fbd_feedback_vibra_rumble_end_vibra (FbdFeedbackVibra *vibra)
{
  FbdFeedbackVibraRumble *self = FBD_FEEDBACK_VIBRA_RUMBLE (vibra);
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);

  fbd_dev_vibra_stop (dev);
  g_clear_handle_id(&self->timer_id, g_source_remove);
}

static void
fbd_feedback_vibra_rumble_start_vibra (FbdFeedbackVibra *vibra)
{
  FbdFeedbackVibraRumble *self = FBD_FEEDBACK_VIBRA_RUMBLE (vibra);
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);
  guint duration = fbd_feedback_vibra_get_duration (vibra);
  guint period;

  self->rumble = (duration / self->count) - self->pause;
  if (self->rumble <= 0) {
    self->rumble = FBD_FEEDBACK_VIBRA_DEFAULT_DURATION;
    self->pause = 0;
    self->count = 1;
  }
  period = self->rumble + self->pause;
  self->periods = self->count;

  g_debug ("Rumble Vibra event: duration %d, rumble: %d, pause: %d, period: %d",
	   duration, self->rumble, self->pause, period);
  fbd_dev_vibra_rumble (dev, self->rumble, TRUE);
  self->periods--;
  if (self->periods) {
    self->timer_id = g_timeout_add (period, (GSourceFunc) on_period_ended, self);
  }
}

static gboolean
fbd_feedback_vibra_rumble_is_available (FbdFeedbackBase *base)
{
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);

  return FBD_IS_DEV_VIBRA (dev);
}

static void
fbd_feedback_vibra_rumble_class_init (FbdFeedbackVibraRumbleClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass);
  FbdFeedbackVibraClass *vibra_class = FBD_FEEDBACK_VIBRA_CLASS (klass);

  object_class->set_property = fbd_feedback_vibra_rumble_set_property;
  object_class->get_property = fbd_feedback_vibra_rumble_get_property;

  base_class->is_available = fbd_feedback_vibra_rumble_is_available;

  vibra_class->start_vibra = fbd_feedback_vibra_rumble_start_vibra;
  vibra_class->end_vibra = fbd_feedback_vibra_rumble_end_vibra;

  props[PROP_COUNT] =
    g_param_spec_uint (
      "count",
      "Count",
      "The number of rumbles",
      0, G_MAXINT, 1,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  props[PROP_PAUSE] =
    g_param_spec_uint (
      "pause",
      "Pause",
      "The pause in msecs between rumbles",
      0, G_MAXINT, 0,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}

static void
fbd_feedback_vibra_rumble_init (FbdFeedbackVibraRumble *self)
{
  self->count = 1;
}
0707010000007B000081A400000000000000000000000166F7A51300000172000000000000000000000000000000000000003000000000feedbackd-0.5.0/src/fbd-feedback-vibra-rumble.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-feedback-vibra.h"

G_BEGIN_DECLS

#define FBD_TYPE_FEEDBACK_VIBRA_RUMBLE (fbd_feedback_vibra_rumble_get_type())

G_DECLARE_FINAL_TYPE (FbdFeedbackVibraRumble, fbd_feedback_vibra_rumble, FBD,
		      FEEDBACK_VIBRA_RUMBLE,
		      FbdFeedbackVibra);

G_END_DECLS
0707010000007C000081A400000000000000000000000166F7A513000010BB000000000000000000000000000000000000002900000000feedbackd-0.5.0/src/fbd-feedback-vibra.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-feedback-vibra"

#include "fbd-enums.h"
#include "fbd-feedback-vibra.h"
#include "fbd-feedback-manager.h"

/**
 * SECTION:fbd-feedback-vibra
 * @short_description: Describes a feedback via a haptic motor
 * @Title: FbdFeedbackVibra
 *
 * The #FbdVibraVibra describes the properties of a haptic feedback
 * event. It knows nothing about the hardware itself but calls
 * #FbdDevVibra for that.
 */

enum {
  PROP_0,
  PROP_DURATION,
  PROP_LAST_PROP,
};
static GParamSpec *props[PROP_LAST_PROP];

typedef struct _FbdFeedbackVibraPrivate {
  guint duration;
  guint timer_id;
} FbdFeedbackVibraPrivate;

G_DEFINE_TYPE_WITH_PRIVATE (FbdFeedbackVibra, fbd_feedback_vibra, FBD_TYPE_FEEDBACK_BASE);


static gboolean
on_timeout_expired (FbdFeedbackVibra *self)
{
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();
  FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager);

  fbd_dev_vibra_remove_effect (dev);
  fbd_feedback_base_done (FBD_FEEDBACK_BASE(self));
  return G_SOURCE_REMOVE;
}

static void
fbd_feedback_vibra_run (FbdFeedbackBase *base)
{
  FbdFeedbackVibra *self = FBD_FEEDBACK_VIBRA (base);
  FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self);
  FbdFeedbackVibraClass *klass;

  klass = FBD_FEEDBACK_VIBRA_GET_CLASS (self);
  g_return_if_fail (klass->start_vibra);
  klass->start_vibra (self);

  priv->timer_id = g_timeout_add (priv->duration,
				  (GSourceFunc)on_timeout_expired,
				  self);
  g_source_set_name_by_id (priv->timer_id, "feedback-vibra-timer");
}


static void
fbd_feedback_vibra_end (FbdFeedbackBase *base)
{
  FbdFeedbackVibra *self = FBD_FEEDBACK_VIBRA (base);
  FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self);
  FbdFeedbackVibraClass *klass = FBD_FEEDBACK_VIBRA_GET_CLASS (self);

  if (!priv->timer_id)
    return;

  g_return_if_fail (klass->end_vibra);
  klass->end_vibra(self);
  g_clear_handle_id(&priv->timer_id, g_source_remove);
  fbd_feedback_base_done (FBD_FEEDBACK_BASE(self));
}


static void
fbd_feedback_vibra_set_property (GObject      *object,
                                guint         property_id,
                                const GValue *value,
                                GParamSpec   *pspec)
{
  FbdFeedbackVibra *self = FBD_FEEDBACK_VIBRA (object);
  FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self);

  switch (property_id) {
  case PROP_DURATION:
    priv->duration = g_value_get_uint (value);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
fbd_feedback_vibra_get_property (GObject    *object,
				 guint       property_id,
				 GValue     *value,
				 GParamSpec *pspec)
{
  FbdFeedbackVibra *self = FBD_FEEDBACK_VIBRA (object);
  FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self);

  switch (property_id) {
  case PROP_DURATION:
    g_value_set_uint (value, priv->duration);
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}

static void
fbd_feedback_vibra_class_init (FbdFeedbackVibraClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass);

  object_class->set_property = fbd_feedback_vibra_set_property;
  object_class->get_property = fbd_feedback_vibra_get_property;

  base_class->run = fbd_feedback_vibra_run;
  base_class->end = fbd_feedback_vibra_end;

  props[PROP_DURATION] =
    g_param_spec_uint (
      "duration",
      "Duration",
      "Vibra event duration in msecs",
      0, G_MAXUINT, FBD_FEEDBACK_VIBRA_DEFAULT_DURATION,
      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}

static void
fbd_feedback_vibra_init (FbdFeedbackVibra *self)
{
}

guint
fbd_feedback_vibra_get_duration (FbdFeedbackVibra *self)
{
  FbdFeedbackVibraPrivate *priv;

  g_return_val_if_fail (FBD_IS_FEEDBACK_VIBRA (self), 0);
  priv = fbd_feedback_vibra_get_instance_private (self);
  return priv->duration;
}
0707010000007D000081A400000000000000000000000166F7A5130000025D000000000000000000000000000000000000002900000000feedbackd-0.5.0/src/fbd-feedback-vibra.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include "fbd-feedback-base.h"

G_BEGIN_DECLS

#define FBD_TYPE_FEEDBACK_VIBRA (fbd_feedback_vibra_get_type())

#define FBD_FEEDBACK_VIBRA_DEFAULT_DURATION 1000

G_DECLARE_DERIVABLE_TYPE (FbdFeedbackVibra, fbd_feedback_vibra, FBD, FEEDBACK_VIBRA, FbdFeedbackBase);

struct _FbdFeedbackVibraClass
{
  FbdFeedbackBaseClass parent_class;

  void (*start_vibra) (FbdFeedbackVibra *self);
  void (*end_vibra) (FbdFeedbackVibra *self);
};

guint fbd_feedback_vibra_get_duration (FbdFeedbackVibra *self);

G_END_DECLS
0707010000007E000081A400000000000000000000000166F7A5130000148A000000000000000000000000000000000000002200000000feedbackd-0.5.0/src/fbd-ledctrl.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-ledctrl"

#include <glib.h>

#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#define LED_BRIGHTNESS_ATTR      "brightness"
#define LED_MULTI_INTENSITY_ATTR "multi_intensity"
#define LED_PATTERN_ATTR         "pattern"
#define LED_REPEAT_ATTR          "repeat"
#define LED_TRIGGER_ATTR         "trigger"
#define LED_TRIGGER_PATTERN      "pattern"
#define LED_TRIGGER_HW_PATTERN   "hw_pattern"

enum {
  FBD_LEDCTRL_ERR_CMDLINE = 1,
  FBD_LEDCTRL_ERR_TRIGGER = 2,
  FBD_LEDCTRL_ERR_PERMS   = 3,
};

static gboolean
write_sysfs_attr (const char *sysfs_path, const char *attr, const char *val)
{
  gint fd;
  int len;
  g_autofree gchar *path = g_strjoin ("/", sysfs_path, attr, NULL);

  fd = open (path, O_WRONLY|O_TRUNC, 0666);
  if (fd < 0) {
    fprintf (stderr, "Failed to open %s: %s\n", path, strerror (errno));
    return FALSE;
  }

  len = strlen (val);
  if (write (fd, val, len) < 0) {
    fprintf (stderr, "Failed to write %s to %s: %s\n", val, path, strerror (errno));
    close (fd);
    return FALSE;
  }

  if (close (fd) < 0) {
    fprintf (stderr, "Failed to close %s: %s\n", path, strerror (errno));
    return FALSE;
  }

  return TRUE;
}

static gchar *
read_sysfs_attr (const char *sysfs_path, const char *attr)
{
  gchar *content = NULL;
  g_autoptr (GError) err = NULL;
  g_autofree gchar *path = g_strjoin ("/", sysfs_path, attr, NULL);


  if (!g_file_get_contents (path, &content, NULL, &err)) {
    fprintf (stderr, "Failed to read %s: %s\n", path, err->message);
    return NULL;
  }
  
  return content;
}

static gboolean
set_sysfs_attr_perm (const char *sysfs_path, const char *attr, gid_t gid)
{
  g_autofree gchar *path = g_strjoin ("/", sysfs_path, attr, NULL);
  
  if (chown(path, -1, gid) < 0) {
    fprintf (stderr, "Failed to set perms of %s to %d: %s\n", path, gid, strerror (errno));
    return FALSE;
  }

  if (chmod(path, 0664) < 0) {
    fprintf (stderr, "Failed to set mode of %s: %s\n", path, strerror (errno));
    return FALSE;
  }
  
  return TRUE;
}

static gboolean
set_trigger (const char *sysfs_path, const char *trigger)
{
  g_autofree gchar *val = NULL;
  g_auto(GStrv) triggers = NULL;

  /*
   * Check the current trigger, don't do anything if it's already
   * set. This prevents a change event storm when setting the
   * same trigger over and over again in a udev rule.
   */
  val = read_sysfs_attr (sysfs_path, LED_TRIGGER_ATTR);
  g_strstrip(val);
  triggers = g_strsplit (val, " ", 0);

  /* 
   * The active trigger is marked with [...] so if we don't find the
   * trigger verbatim it's already the active one:
   */
  if (!g_strv_contains ((const gchar * const *)triggers, trigger))
    return TRUE;

  return write_sysfs_attr (sysfs_path, LED_TRIGGER_ATTR, trigger);
}

static gboolean
set_perms (const char *sysfs_path, const char *trigger, const char *gname)
{
  struct group *group;
  gboolean success = TRUE;

  group = getgrnam (gname);

  if (!set_sysfs_attr_perm (sysfs_path, LED_BRIGHTNESS_ATTR, group->gr_gid))
      return FALSE;

  /* Attribute is optional */
  set_sysfs_attr_perm (sysfs_path, LED_MULTI_INTENSITY_ATTR, group->gr_gid);

  if (!g_strcmp0 (trigger, LED_TRIGGER_PATTERN)) {
    if (!set_sysfs_attr_perm (sysfs_path, LED_PATTERN_ATTR, group->gr_gid))
      success = FALSE;
    if (!set_sysfs_attr_perm (sysfs_path, LED_REPEAT_ATTR, group->gr_gid))
      success = FALSE;

    /* Attribute is optional */
    set_sysfs_attr_perm (sysfs_path, LED_TRIGGER_HW_PATTERN, group->gr_gid);
  }

  /* specific setup for other triggers goes here */
  return success;
}

int main(int argc, char *argv[])
{
  g_autoptr(GError) err = NULL;
  g_autoptr(GOptionContext) opt_context = NULL;
  g_autofree gchar *sysfs_path = NULL;
  g_autofree gchar *group = NULL;
  g_autofree gchar *trigger = NULL;

  const GOptionEntry options [] = {
    {"path", 'p', 0, G_OPTION_ARG_STRING, &sysfs_path,
     "Path to LEDs sysfs dir", NULL},
    {"group", 'G', 0, G_OPTION_ARG_STRING, &group,
     "Group to set permissions to", NULL},
    {"trigger", 't', 0, G_OPTION_ARG_STRING, &trigger,
     "LED trigger to configure", NULL},
    { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
  };

  opt_context = g_option_context_new ("- helper to prepare sysfs for feedbackd");
  g_option_context_add_main_entries (opt_context, options, NULL);
  if (!g_option_context_parse (opt_context, &argc, &argv, &err)) {
    fprintf (stderr, "%s", err->message);
    g_clear_error (&err);
    return 1;
  }

  if (!sysfs_path) {
    fprintf (stderr, "No sysfs path given\n");
    return FBD_LEDCTRL_ERR_CMDLINE;
  }

  if (!trigger) {
    fprintf (stderr, "No trigger specified\n");
    return FBD_LEDCTRL_ERR_CMDLINE;;
  }
  g_debug ("Configuring LED at %s for trigger %s", sysfs_path, trigger);

  if (!set_trigger (sysfs_path, trigger))
    return FBD_LEDCTRL_ERR_TRIGGER;

  if (group) {
    g_debug ("Setting permission of %s to %s", sysfs_path, group);
    if (!set_perms (sysfs_path, trigger, group))
      return FBD_LEDCTRL_ERR_PERMS;
  }
    
  return 0;
}
0707010000007F000081A400000000000000000000000166F7A5130000321C000000000000000000000000000000000000002900000000feedbackd-0.5.0/src/fbd-theme-expander.c/*
 * Copyright (C) 2022 Guido Günther
 *
 * SPDX-License-Identifier: GPL-3.0+
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd-theme-expander"

#include "fbd.h"
#include "fbd-feedback-theme.h"
#include "fbd-theme-expander.h"

#define DEFAULT_THEME_NAME  "default"
#define DEVICE_THEME_NAME   "$device"

#define MAX_THEME_DEPTH 10

/**
 * SECTION:theme-expander
 * @short_description: Feedback theme expander
 * @Title: FbdThemeExpander
 *
 * The theme expander reads themes from disks and expands references
 * to other themes
 */

enum {
  PROP_0,
  PROP_THEME_NAME,
  PROP_THEME_FILE,
  PROP_COMPATIBLES,
  PROP_LAST_PROP
};
static GParamSpec *props[PROP_LAST_PROP];

struct _FbdThemeExpander {
  GObject    parent;

  char      *theme_name;
  char      *theme_file;
  gboolean   device_theme_loaded;
  GStrv      compatibles;
};
G_DEFINE_TYPE (FbdThemeExpander, fbd_theme_expander, G_TYPE_OBJECT)


static void
fbd_theme_expander_set_compatibles (FbdThemeExpander *self, const char * const * compatibles)
{
  g_return_if_fail (FBD_IS_THEME_EXPANDER (self));

  g_strfreev (self->compatibles);
  self->compatibles = g_strdupv ((GStrv)compatibles);

  /* Make sure we reload the device theme */
  self->device_theme_loaded = FALSE;
}

static void
fbd_theme_expander_set_theme_name (FbdThemeExpander *self, const char *theme_name)
{
  g_return_if_fail (FBD_IS_THEME_EXPANDER (self));

  g_free (self->theme_name);
  if (theme_name)
    self->theme_name = g_strdup (theme_name);
  else
    self->theme_name = g_strdup (DEFAULT_THEME_NAME);

  /* Make sure we reload the device theme */
  self->device_theme_loaded = FALSE;
}

static void
fbd_theme_expander_set_theme_file (FbdThemeExpander *self, const char *theme_file)
{
  g_return_if_fail (FBD_IS_THEME_EXPANDER (self));

  g_free (self->theme_file);
  self->theme_file = g_strdup (theme_file);

  /* Make sure we reload the device theme */
  self->device_theme_loaded = FALSE;
}


static char *
fbd_theme_expander_find_theme_in_xdg_data (const char *theme_name)
{
  const char * const *xdg_data_dirs = g_get_system_data_dirs ();
  g_autofree char *theme_file_name = g_strconcat (theme_name, ".json", NULL);

  for (int i = 0; xdg_data_dirs[i] != NULL; i++) {
    g_autofree char *theme_path = NULL;

    theme_path = g_build_filename (xdg_data_dirs[i], "feedbackd", "themes",
                                   theme_file_name, NULL);
    g_debug ("Looking for theme file at %s", theme_path);

    /* Check if file exist */
    if (g_file_test (theme_path, (G_FILE_TEST_EXISTS))) {
      g_info ("Loading theme file at '%s'", theme_path);
      return g_steal_pointer (&theme_path);
    }
  }
  return NULL;
}


static char *
fbd_theme_expander_find_device_theme_path (FbdThemeExpander *self, const char *theme_name)
{
  /* Device specific lookup only for default theme */
  if (g_str_equal (theme_name, DEVICE_THEME_NAME) == FALSE &&
      g_str_equal (theme_name, DEFAULT_THEME_NAME) == FALSE) {
    return NULL;
  }

  if (self->device_theme_loaded)
    return NULL;

  self->device_theme_loaded = TRUE;

  /* no compatibles found */
  if (self->compatibles == NULL)
    return NULL;

  for (int i = 0; i < g_strv_length (self->compatibles); i++) {
    const char *compatible = self->compatibles[i];
    g_autofree char *theme_path = NULL;

    theme_path = fbd_theme_expander_find_theme_in_xdg_data (compatible);
    if (theme_path) {
      g_debug ("Loading themefile for compatible '%s' at: %s", compatible, theme_path);
      return g_steal_pointer (&theme_path);
    }
  }

  g_debug ("No device theme found");
  return NULL;
}


static char *
fbd_theme_expander_find_user_theme_path (const char *theme_name)
{
  g_autofree char *filename = g_strdup_printf ("%s.json", theme_name);
  g_autofree char *user_config_path = NULL;

  user_config_path = g_build_filename (g_get_user_config_dir (), "feedbackd",
                                       "themes", filename, NULL);
  if (g_file_test (user_config_path, (G_FILE_TEST_EXISTS))) {
    g_info ("Found theme file at: %s", user_config_path);
    return g_steal_pointer (&user_config_path);
  }

  g_debug ("No user theme found for '%s'", theme_name);
  return NULL;
}


static char *
fbd_theme_expander_find_theme_path (FbdThemeExpander *self, const char *theme_name)
{
  g_autofree char *file_name = NULL;
  char *theme_path;

  g_assert (theme_name);

  theme_path = fbd_theme_expander_find_user_theme_path (theme_name);
  if (theme_path)
    return theme_path;

  theme_path = fbd_theme_expander_find_device_theme_path (self, theme_name);
  if (theme_path)
    return theme_path;

  if (g_str_equal (theme_name, DEFAULT_THEME_NAME) == FALSE)
    g_critical ("Theme '%s' not found, falling back to default theme", theme_name);

  theme_path = fbd_theme_expander_find_theme_in_xdg_data (DEFAULT_THEME_NAME);
  if (theme_path)
    return theme_path;

  /* Last resort is shipped default config */
  file_name = g_strdup_printf ("%s.json", theme_name);
  g_info ("Using theme_file: %s", file_name);
  return g_build_filename (FEEDBACKD_THEME_DIR, file_name, NULL);
}


static void
fbd_theme_expander_set_property (GObject      *object,
                                 guint         property_id,
                                 const GValue *value,
                                 GParamSpec   *pspec)
{
  FbdThemeExpander *self = FBD_THEME_EXPANDER (object);

  switch (property_id) {
  case PROP_THEME_NAME:
    fbd_theme_expander_set_theme_name (self, g_value_get_string (value));
    break;
  case PROP_THEME_FILE:
    fbd_theme_expander_set_theme_file (self, g_value_get_string (value));
    break;
  case PROP_COMPATIBLES:
    fbd_theme_expander_set_compatibles (self, g_value_get_boxed (value));
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}


static void
fbd_theme_expander_get_property (GObject    *object,
                                 guint       property_id,
                                 GValue     *value,
                                 GParamSpec *pspec)
{
  FbdThemeExpander *self = FBD_THEME_EXPANDER (object);

  switch (property_id) {
  case PROP_THEME_NAME:
    g_value_set_string (value, fbd_theme_expander_get_theme_name (self));
    break;
  case PROP_THEME_FILE:
    g_value_set_string (value, fbd_theme_expander_get_theme_file (self));
    break;
  case PROP_COMPATIBLES:
    g_value_set_boxed (value, fbd_theme_expander_get_compatibles (self));
    break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    break;
  }
}


static void
fbd_theme_expander_finalize (GObject *object)
{
  FbdThemeExpander *self = FBD_THEME_EXPANDER(object);

  g_clear_pointer (&self->theme_name, g_free);
  g_clear_pointer (&self->theme_file, g_free);
  g_clear_pointer (&self->compatibles, g_strfreev);

  G_OBJECT_CLASS (fbd_theme_expander_parent_class)->finalize (object);
}


static void
fbd_theme_expander_class_init (FbdThemeExpanderClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->get_property = fbd_theme_expander_get_property;
  object_class->set_property = fbd_theme_expander_set_property;
  object_class->finalize = fbd_theme_expander_finalize;

  /**
   * FbdThemeExpander:theme-name:
   *
   * Specifies the theme to expand. Assumes `default` if unset.
   *
   * The `compatibles` defines which device specific theme bits are loaded.
   */
  props[PROP_THEME_NAME] =
    g_param_spec_string ("theme-name", "", "",
                         DEFAULT_THEME_NAME,
                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY |
                         G_PARAM_STATIC_STRINGS);
  /**
   * FbdThemeExpander:theme-file:
   *
   * Specifies the theme-file to load an expand. Takes preference over `theme`.
   */
  props[PROP_THEME_FILE] =
    g_param_spec_string ("theme-file", "", "",
                         NULL,
                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY |
                         G_PARAM_STATIC_STRINGS);
  /**
   * FbdThemeExpander:compatibles:
   *
   * Specifies the device types this device is compatible with.  The
   * device compatbiles to look for. When unset the value is retrieved
   * from /sysfs.
   *
   * The `compatibles` defines which device specific theme bits are loaded.
   */
  props[PROP_COMPATIBLES] =
    g_param_spec_boxed ("compatibles", "", "",
                        G_TYPE_STRV,
                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}


static void
fbd_theme_expander_init (FbdThemeExpander *self)
{
}


FbdThemeExpander *
fbd_theme_expander_new (const char * const *compatibles,
                        const char *theme_name,
                        const char *theme_file)
{
  return FBD_THEME_EXPANDER (g_object_new (FBD_TYPE_THEME_EXPANDER,
                                           "theme-name", theme_name,
                                           "theme-file", theme_file,
                                           "compatibles", compatibles,
                                           NULL));
}


static void
update_theme (gpointer data, gpointer user_data)
{
  FbdFeedbackTheme *theme = FBD_FEEDBACK_THEME (data);
  FbdFeedbackTheme *merged = FBD_FEEDBACK_THEME (user_data);

  g_assert (FBD_IS_FEEDBACK_THEME (theme));
  g_assert (FBD_IS_FEEDBACK_THEME (merged));

  fbd_feedback_theme_update (merged, theme);
}


/**
 * fbd_theme_expander_load_theme_files:
 * @self: The theme expander
 * @err: return location for error or %NULL
 *
 * Parses a theme recursively taking the theme's `parent-name` relations into
 * account as well as the expander's list of `compatibles`.
 *
 * Returns: (transfer full)(allow-none): The parsed theme or %NULL on error
 */
FbdFeedbackTheme *
fbd_theme_expander_load_theme_files (FbdThemeExpander *self, GError **err)
{
  g_autoqueue (FbdFeedbackTheme) queue = g_queue_new ();
  g_autoptr (FbdFeedbackTheme) merged = fbd_feedback_theme_new ("merged-theme");
  g_autoptr (FbdFeedbackTheme) theme = NULL;
  g_autofree char *theme_file = NULL;
  guint len = 0;

  g_return_val_if_fail (FBD_IS_THEME_EXPANDER (self), NULL);
  g_return_val_if_fail (err == NULL || *err == NULL, NULL);

  if (self->theme_file) {
    theme_file = g_strdup (self->theme_file);
  } else {
    theme_file = fbd_theme_expander_find_theme_path (self, self->theme_name);
    if (g_strcmp0 (self->theme_file, theme_file)) {
      self->theme_file = g_steal_pointer (&theme_file);
      g_object_notify_by_pspec (G_OBJECT (self), props[PROP_THEME_FILE]);
    }
  }

  g_info ("Loading theme file at '%s'", self->theme_file);
  theme = fbd_feedback_theme_new_from_file (self->theme_file, err);
  if (theme == NULL)
      return NULL;

  /* Build a list of themes */
  while (TRUE) {
    g_autofree char *parent_path = NULL;
    const char *parent_name, *theme_name;

    if (len > MAX_THEME_DEPTH) {
      g_set_error (err, fbd_error_quark(), FBD_ERROR_THEME_EXPAND, "Theme depth exceeded");
      return NULL;
    }

    theme_name = fbd_feedback_theme_get_name (theme);
    if (theme_name == NULL || theme_name[0] == '\0') {
      g_set_error (err, fbd_error_quark(), FBD_ERROR_THEME_EXPAND,
                   "Theme name of %s can't be empty", self->theme_file);
      return NULL;
    }

    parent_name = fbd_feedback_theme_get_parent_name (theme);

    if (parent_name &&
        g_str_equal (fbd_feedback_theme_get_name (theme), DEFAULT_THEME_NAME)) {
      g_set_error (err, fbd_error_quark(), FBD_ERROR_THEME_EXPAND,
                   "Default theme can't specify a parent");
      return NULL;
    }

    parent_name = fbd_feedback_theme_get_parent_name (theme);

    g_queue_push_head (queue, g_steal_pointer (&theme));

    if (parent_name == NULL)
      break;

    parent_path = fbd_theme_expander_find_theme_path (self, parent_name);
    theme = fbd_feedback_theme_new_from_file (parent_path, err);
    if (theme == NULL)
      return NULL;

    len++;
  }

  /* Merge themes bottom to top */
  g_queue_foreach (queue, update_theme, merged);

  fbd_feedback_theme_set_name (merged, self->theme_name);
  return g_steal_pointer (&merged);
}

const char *
fbd_theme_expander_get_theme_name (FbdThemeExpander *self)
{
  g_return_val_if_fail (FBD_IS_THEME_EXPANDER (self), NULL);

  return self->theme_name;

}

const char *
fbd_theme_expander_get_theme_file (FbdThemeExpander *self)
{
  g_return_val_if_fail (FBD_IS_THEME_EXPANDER (self), NULL);

  return self->theme_file;
}

const char * const *
fbd_theme_expander_get_compatibles (FbdThemeExpander *self)
{
  g_return_val_if_fail (FBD_IS_THEME_EXPANDER (self), NULL);

  return (const char * const*)self->compatibles;
}
07070100000080000081A400000000000000000000000166F7A513000003FA000000000000000000000000000000000000002900000000feedbackd-0.5.0/src/fbd-theme-expander.h/*
 * Copyright (C) 2022 Guido Günther
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#pragma once

#include "fbd-feedback-theme.h"

#include <glib-object.h>

G_BEGIN_DECLS

#define FBD_TYPE_THEME_EXPANDER (fbd_theme_expander_get_type ())

G_DECLARE_FINAL_TYPE (FbdThemeExpander, fbd_theme_expander, FBD, THEME_EXPANDER, GObject)


FbdThemeExpander   *fbd_theme_expander_new (const char * const *compatibles,
                                            const char *theme_name,
                                            const char *theme_file);
FbdFeedbackTheme   *fbd_theme_expander_load_theme_files (FbdThemeExpander  *self,
                                                         GError           **err);
const char         *fbd_theme_expander_get_theme_name (FbdThemeExpander *self);
const char         *fbd_theme_expander_get_theme_file (FbdThemeExpander *self);
const char * const *fbd_theme_expander_get_compatibles (FbdThemeExpander *self);

G_END_DECLS
07070100000081000081A400000000000000000000000166F7A51300000929000000000000000000000000000000000000002900000000feedbackd-0.5.0/src/fbd-theme-validate.c/*
 * Copyright (C) 2022 Guido Günther
 *
 * SPDX-License-Identifier: GPL-3.0+
 */

#define G_LOG_DOMAIN "fbd"

#include "fbd-theme-expander.h"

#include <gio/gio.h>

#define BLURP "- A validator for feedback themes"

G_NORETURN
static void
print_version (void)
{
  g_print ("%s %s " BLURP "\n", g_get_prgname(), FBD_VERSION);
  exit (0);
}

static void
log_handler (const gchar   *log_domain,
             GLogLevelFlags log_level,
             const gchar   *message,
             gpointer       user_data)
{
  g_print ("%s\n", message);
}


int main(int argc, char *argv[])
{
  g_autoptr (GError) err = NULL;
  g_autoptr (GOptionContext) opt_context = NULL;
  g_autoptr (FbdThemeExpander) expander = NULL;
  g_autoptr (FbdFeedbackTheme) theme = NULL;
  g_autofree char *theme_file = NULL;
  const char *compatible = NULL;
  gboolean version = FALSE;
  GStrv args = NULL;
  const char *compatibles[] = { NULL, NULL };
  int ret = EXIT_FAILURE;

  const GOptionEntry options [] = {
    {"version", 0, 0, G_OPTION_ARG_NONE, &version,
     "Show version information", NULL},
    {"compatible", 0, 0, G_OPTION_ARG_STRING, &compatible,
     "The device compatible", NULL},
    { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL, NULL },
    G_OPTION_ENTRY_NULL,
  };

  opt_context = g_option_context_new ("THEME-FILE " BLURP);
  g_option_context_add_main_entries (opt_context, options, NULL);
  if (!g_option_context_parse (opt_context, &argc, &argv, &err)) {
    g_warning ("%s", err->message);
    g_clear_error (&err);
    return 1;
  }

  if (version) {
    print_version ();
  }

  g_log_set_handler ("fbd-theme-expander", G_LOG_LEVEL_INFO | G_LOG_FLAG_RECURSION,
                     log_handler, NULL);

  if (!args) {
    g_printerr ("%s: No theme file given\n", g_get_prgname ());
    g_printerr ("Try \"%s --help\" for more information.", g_get_prgname ());
    g_printerr ("\n");
    return 1;
  }

  compatibles[0] = compatible;
  theme_file = *args;
  expander = fbd_theme_expander_new (compatibles, NULL, theme_file);
  theme = fbd_theme_expander_load_theme_files (expander, &err);
  if (theme == NULL) {
    g_printerr ("Validation of '%s' failed \n\n", theme_file);
    g_printerr ("error: %s\n\n", err->message);
  } else {
    g_print ("Validation successful.\n");
    ret = EXIT_SUCCESS;
  }

  return ret;
}
07070100000082000081A400000000000000000000000166F7A5130000087F000000000000000000000000000000000000001F00000000feedbackd-0.5.0/src/fbd-udev.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 *
 */

#define G_LOG_DOMAIN "fbd-udev"

#include "fbd-udev.h"

#include <gio/gio.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>

gboolean
fbd_udev_set_sysfs_path_attr_as_string (GUdevDevice *dev, const gchar *attr,
                                        const gchar *s, GError **err)
{
  gint fd;
  int len;
  g_autofree gchar *path = g_strjoin ("/", g_udev_device_get_sysfs_path (dev),
                                      attr, NULL);

  fd = open (path, O_WRONLY|O_TRUNC, 0666);
  if (fd < 0) {
    g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to open %s: %s",
                 path, strerror (errno));
    return FALSE;
  }

  len = strlen (s);
  if (write (fd, s, len) < 0) {
    g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to write %s to %s: %s",
                 s, path, strerror (errno));
    close (fd);
    return FALSE;
  }

  if (close (fd) < 0) {
    g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to close %s: %s",
                 path, strerror (errno));
    return FALSE;
  }

  return TRUE;
}

gboolean
fbd_udev_set_sysfs_path_attr_as_int (GUdevDevice *dev, const gchar *attr,
                                     gint val, GError **err)
{
  gint fd;
  int len;
  g_autofree gchar *s = NULL;

  g_autofree gchar *path = g_strjoin ("/", g_udev_device_get_sysfs_path (dev),
                                      attr, NULL);

  fd = open (path, O_WRONLY|O_TRUNC, 0666);
  if (fd < 0) {
    g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to open %s: %s",
                 path, strerror (errno));
    return FALSE;
  }

  s = g_strdup_printf ("%d", val);
  len = strlen (s);
  if (write (fd, s, len) < len) {
    g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to write %s: %s",
                 path, strerror (errno));
    close (fd);
    return FALSE;
  }

  if (close (fd) < 0) {
    g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to close %s: %s",
                 path, strerror (errno));
    return FALSE;
  }

  return TRUE;
}
07070100000083000081A400000000000000000000000166F7A5130000019A000000000000000000000000000000000000001F00000000feedbackd-0.5.0/src/fbd-udev.h/*
 * Copyright (C) 2020 Purism SPC
 *
 * SPDX-License-Identifier: GPL-3.0+
 */
#pragma once

#include <glib.h>
#include <gudev/gudev.h>


G_BEGIN_DECLS

gboolean fbd_udev_set_sysfs_path_attr_as_string (GUdevDevice *dev, const gchar *attr,
						 const gchar *s, GError **err);
gboolean fbd_udev_set_sysfs_path_attr_as_int (GUdevDevice *dev, const gchar *attr,
					      gint val, GError **err);

G_END_DECLS
07070100000084000081A400000000000000000000000166F7A51300000BCF000000000000000000000000000000000000001A00000000feedbackd-0.5.0/src/fbd.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define G_LOG_DOMAIN "fbd"

#include "fbd.h"
#include "fbd-feedback-manager.h"
#include "lfb-names.h"
#include "lfb-gdbus.h"

#include <gio/gio.h>
#include <glib-unix.h>


static GMainLoop *loop;

static gboolean
quit_cb (gpointer user_data)
{
  g_info ("Caught signal, shutting down...");

  if (loop)
    g_idle_add ((GSourceFunc) g_main_loop_quit, loop);
  else
    exit (0);

  return FALSE;
}

static gboolean
reload_cb (gpointer user_data)
{
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default();

  g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (manager), FALSE);

  g_debug ("Caught signal, reloading feedback theme...");
  fbd_feedback_manager_load_theme (manager);

  return TRUE;
}

static void
bus_acquired_cb (GDBusConnection *connection,
                 const gchar *name,
                 gpointer user_data)
{
  FbdFeedbackManager *manager = fbd_feedback_manager_get_default ();

  g_debug ("Bus acquired, creating manager...");

  g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (manager),
                                    connection,
                                    FB_DBUS_PATH,
                                    NULL);
}


static void
name_acquired_cb (GDBusConnection *connection,
                  const gchar *name,
                  gpointer user_data)
{
  g_debug ("Service name '%s' was acquired", name);
}

static void
name_lost_cb (GDBusConnection *connection,
              const gchar *name,
              gpointer user_data)
{
  /* Note that we're not allowing replacement, so once the name acquired, the
   * process won't lose it. */
  if (!name) {
    g_warning ("Could not get the session bus. Make sure "
               "the message bus daemon is running!");
  } else {
    if (connection)
      g_warning ("Could not acquire the '%s' service name", name);
    else
      g_debug ("DBus connection close");
  }

  g_main_loop_quit (loop);
}


int main(int argc, char *argv[])
{
  g_autoptr(GError) err = NULL;
  g_autoptr(GOptionContext) opt_context = NULL;
  g_autoptr (FbdFeedbackManager) manager = NULL;

  opt_context = g_option_context_new ("- A daemon to trigger event feedback");
  if (!g_option_context_parse (opt_context, &argc, &argv, &err)) {
    g_warning ("%s", err->message);
    g_clear_error (&err);
    return 1;
  }

  manager = fbd_feedback_manager_get_default ();
  fbd_feedback_manager_load_theme (manager);

  g_unix_signal_add (SIGTERM, quit_cb, NULL);
  g_unix_signal_add (SIGINT, quit_cb, NULL);
  g_unix_signal_add (SIGHUP, reload_cb, NULL);

  loop = g_main_loop_new (NULL, FALSE);

  g_bus_own_name (FB_DBUS_TYPE,
                  FB_DBUS_NAME,
                  G_BUS_NAME_OWNER_FLAGS_NONE,
                  bus_acquired_cb,
                  name_acquired_cb,
                  name_lost_cb,
                  NULL,
                  NULL);

  g_main_loop_run (loop);
  g_main_loop_unref (loop);
}
07070100000085000081A400000000000000000000000166F7A513000001A1000000000000000000000000000000000000001A00000000feedbackd-0.5.0/src/fbd.h#pragma once

#include <glib-object.h>

G_BEGIN_DECLS

/*
 * The udev attribute and values devices must have to be handled by
 *  fbd feedbackd
 */
#define FEEDBACKD_UDEV_ATTR    "FEEDBACKD_TYPE"
#define FEEDBACKD_UDEV_VAL_LED "led"

#define FEEDBACKD_SCHEMA_ID "org.sigxcpu.feedbackd"

typedef enum {
    FBD_ERROR_FAILED = 0,
    FBD_ERROR_THEME_EXPAND = 1,
} FbdError;

GQuark fbd_error_quark (void);

G_END_DECLS
07070100000086000081A400000000000000000000000166F7A5130000082B000000000000000000000000000000000000002000000000feedbackd-0.5.0/src/meson.build# Feedback daemon
if get_option('daemon')

fbd_enum_headers = files([
  'fbd-event.h',
  'fbd-feedback-led.h',
  'fbd-feedback-vibra.h',
])
fbd_enum_sources = gnome.mkenums_simple('fbd-enums',
  sources : fbd_enum_headers)

sources = [
  generated_dbus_sources,
  fbd_enum_sources,
  'fbd-error.c',
  'fbd-dev-vibra.c',
  'fbd-dev-sound.c',
  'fbd-dev-led.c',
  'fbd-dev-led-flash.c',
  'fbd-dev-led-multicolor.c',
  'fbd-dev-led-qcom.c',
  'fbd-dev-led-qcom-multicolor.c',
  'fbd-dev-leds.c',
  'fbd-event.c',
  'fbd-feedback-base.c',
  'fbd-feedback-dummy.c',
  'fbd-feedback-led.c',
  'fbd-feedback-manager.c',
  'fbd-feedback-profile.c',
  'fbd-feedback-sound.c',
  'fbd-feedback-theme.c',
  'fbd-feedback-vibra.c',
  'fbd-feedback-vibra-periodic.c',
  'fbd-feedback-vibra-rumble.c',
  'fbd-theme-expander.c',
  'fbd-udev.c',
]

fbd_deps = [
  gio,
  gio_unix,
  glib,
  gmobile,
  gobject,
  gsound,
  gudev,
  json_glib,
]

fbd_inc = [
  include_directories('.'),
  libfeedback_inc,
  dbus_inc,
]

fbd_lib = static_library(
  'fbd',
  sources,
  include_directories : fbd_inc,
  dependencies : fbd_deps,
  c_args: '-DGMOBILE_USE_UNSTABLE_API',
  install : false,
)

fbd_dep = declare_dependency(
  sources: [generated_dbus_sources, fbd_enum_sources],
  include_directories : fbd_inc,
  link_with : fbd_lib,
  dependencies : fbd_deps,
)

executable(
  'feedbackd',
  sources : ['fbd.c', generated_dbus_sources[1]],
  include_directories : fbd_inc,
  dependencies : fbd_dep,
  install : true,
  install_dir: libexecdir,
)

executable(
  'fbd-ledctrl',
  sources : ['fbd-ledctrl.c'],
  include_directories : fbd_inc,
  dependencies : [glib],
  install : true,
  install_dir: libexecdir,
)

executable(
  'fbd-alert-slider',
  sources : ['fbd-alert-slider.c'],
  include_directories : fbd_inc,
  dependencies : [glib, gio, gio_unix, gudev, libfeedback_dep],
  install : true,
  install_dir: libexecdir,
)

executable(
  'fbd-theme-validate',
  sources : ['fbd-theme-validate.c'],
  include_directories : fbd_inc,
  dependencies : fbd_dep,
  install : true,
  install_dir: bindir,
)

endif
07070100000087000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001C00000000feedbackd-0.5.0/subprojects07070100000088000081A400000000000000000000000166F7A5130000006A000000000000000000000000000000000000002900000000feedbackd-0.5.0/subprojects/gmobile.wrap[wrap-git]
directory=gmobile
url=https://gitlab.gnome.org/World/Phosh/gmobile.git
revision=v0.1.0
depth=1
07070100000089000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001600000000feedbackd-0.5.0/tests0707010000008A000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001B00000000feedbackd-0.5.0/tests/data0707010000008B000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000002200000000feedbackd-0.5.0/tests/data/parent0707010000008C000081A400000000000000000000000166F7A51300000222000000000000000000000000000000000000002C00000000feedbackd-0.5.0/tests/data/parent/base.json{
  "name" : "base",
  "profiles" : [
    {
      "name" : "full",
      "feedbacks" : [
        {
          "type"       : "Dummy",
          "event-name" : "test-dummy-00",
          "duration"   : 1
        },
        {
          "type"       : "Dummy",
          "event-name" : "test-dummy-01",
          "duration"   : 2
        }
      ]
    },
    {
      "name" : "quiet",
      "feedbacks" : [
        {
          "type"       : "Dummy",
          "event-name" : "test-dummy-00",
          "duration"   : 3
        }
      ]
    }
  ]
}
0707010000008D000081A400000000000000000000000166F7A513000002E5000000000000000000000000000000000000002C00000000feedbackd-0.5.0/tests/data/parent/test.json{
  "name" : "test",
  "profiles" : [
    {
      "name" : "full",
      "feedbacks" : [
        {
          "type"       : "Dummy",
          "event-name" : "test-dummy-00",
          "duration"   : 16
        },
        {
          "type"       : "Dummy",
          "event-name" : "test-dummy-10",
          "duration"   : 32
        }
      ]
    },
    {
      "name" : "quiet",
      "feedbacks" : [
        {
          "type"       : "Dummy",
          "event-name" : "test-dummy-10",
          "duration"   : 48
        }
      ]
    },
    {
      "name" : "silent",
      "feedbacks" : [
        {
          "type"       : "Dummy",
          "event-name" : "test-dummy-10",
          "duration"   : 64
        }
      ]
    }
  ]
}
0707010000008E000081A400000000000000000000000166F7A51300000294000000000000000000000000000000000000002500000000feedbackd-0.5.0/tests/data/test.json{
  "name" : "default",
  "profiles" : [
    {
      "name" : "full",
      "feedbacks" : [
        {
          "type"       : "Dummy",
          "event-name" : "test-dummy-0"
        },
        {
          "type"       : "Dummy",
          "event-name" : "test-dummy-10",
          "duration"   : 10000
        }
      ]
    },
    {
      "name" : "quiet",
      "feedbacks" : [
        {
          "type"       : "Dummy",
          "event-name" : "test-dummy-0"
        },
        {
          "type"       : "Dummy",
          "event-name" : "test-dummy-10",
          "duration"   : 10000
        }
      ]
    },
    {
      "name" : "silent"
    }
  ]
}
0707010000008F000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000002400000000feedbackd-0.5.0/tests/data/umockdev07070100000090000081A400000000000000000000000166F7A5130000188B000000000000000000000000000000000000003700000000feedbackd-0.5.0/tests/data/umockdev/led-flash.umockdevP: /devices/platform/soc@0/c440000.spmi/spmi-0/0-03/c440000.spmi:pmic@3:led-controller@d300/leds/white:flash
E: FEEDBACKD_TYPE=led
E: CURRENT_TAGS=:seat:
E: ID_FOR_SEAT=leds-platform-c440000_spmi-platform-c440000_spmi_pmic_3_led-controller_d300
E: ID_PATH=platform-c440000.spmi-platform-c440000.spmi:pmic@3:led-controller@d300
E: ID_PATH_TAG=platform-c440000_spmi-platform-c440000_spmi_pmic_3_led-controller_d300
E: OF_COMPATIBLE_N=0
E: OF_FULLNAME=/soc@0/spmi@c440000/pmic@3/led-controller@d300/led-0
E: OF_NAME=led-0
E: SUBSYSTEM=leds
E: TAGS=:seat:
A: brightness=0\n
L: device=../../../c440000.spmi:pmic@3:led-controller@d300
A: flash_brightness=12500\n
A: flash_fault=flash-timeout-exceeded \n
A: flash_strobe=1\n
A: flash_timeout=10000\n
A: max_brightness=255\n
A: max_flash_brightness=1500000\n
A: max_flash_timeout=1280000\n
A: pattern=
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n
A: repeat=-1\n
A: trigger=none usb-gadget usb-host kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock usbport timer oneshot heartbeat backlight cpu cpu0 cpu1 cpu2 cpu3 cpu4 cpu5 cpu6 cpu7 activity default-on transient flash torch panic netdev [pattern] audio-mute audio-micmute rfkill-any rfkill-none bq27411-0-charging-or-full bq27411-0-charging bq27411-0-full bq27411-0-charging-blink-full-solid pmi8998-charger-online bluetooth-power hci0-power rfkill0 phy0rx phy0tx phy0assoc phy0radio rfkill1\n

P: /devices/platform/soc@0/c440000.spmi/spmi-0/0-03/c440000.spmi:pmic@3:led-controller@d300
E: DRIVER=leds-qcom-flash
E: ID_PATH=platform-c440000.spmi-platform-c440000.spmi:pmic@3:led-controller@d300
E: ID_PATH_TAG=platform-c440000_spmi-platform-c440000_spmi_pmic_3_led-controller_d300
E: MODALIAS=of:Nled-controllerT(null)Cqcom,pmi8998-flash-ledCqcom,spmi-flash-led
E: OF_COMPATIBLE_0=qcom,pmi8998-flash-led
E: OF_COMPATIBLE_1=qcom,spmi-flash-led
E: OF_COMPATIBLE_N=2
E: OF_FULLNAME=/soc@0/spmi@c440000/pmic@3/led-controller@d300
E: OF_NAME=led-controller
E: SUBSYSTEM=platform
L: driver=../../../../../../../bus/platform/drivers/leds-qcom-flash
A: driver_override=(null)\n
A: modalias=of:Nled-controllerT(null)Cqcom,pmi8998-flash-ledCqcom,spmi-flash-led\n
L: of_node=../../../../../../../firmware/devicetree/base/soc@0/spmi@c440000/pmic@3/led-controller@d300
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/soc@0/c440000.spmi/spmi-0/0-03
E: DRIVER=pmic-spmi
E: MODALIAS=of:NpmicT(null)Cqcom,pmi8998Cqcom,spmi-pmic
E: OF_COMPATIBLE_0=qcom,pmi8998
E: OF_COMPATIBLE_1=qcom,spmi-pmic
E: OF_COMPATIBLE_N=2
E: OF_FULLNAME=/soc@0/spmi@c440000/pmic@3
E: OF_NAME=pmic
E: SUBSYSTEM=spmi
L: driver=../../../../../../bus/spmi/drivers/pmic-spmi
L: of_node=../../../../../../firmware/devicetree/base/soc@0/spmi@c440000/pmic@3
A: power/control=auto\n
A: power/runtime_active_time=132131678\n
A: power/runtime_status=active\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/soc@0/c440000.spmi/spmi-0
E: MODALIAS=of:NspmiT(null)Cqcom,spmi-pmic-arb
E: OF_COMPATIBLE_0=qcom,spmi-pmic-arb
E: OF_COMPATIBLE_N=1
E: OF_FULLNAME=/soc@0/spmi@c440000
E: OF_NAME=spmi
E: SUBSYSTEM=spmi
L: of_node=../../../../../firmware/devicetree/base/soc@0/spmi@c440000
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/soc@0/c440000.spmi
E: DRIVER=spmi_pmic_arb
E: ID_PATH=platform-c440000.spmi
E: ID_PATH_TAG=platform-c440000_spmi
E: MODALIAS=of:NspmiT(null)Cqcom,spmi-pmic-arb
E: OF_COMPATIBLE_0=qcom,spmi-pmic-arb
E: OF_COMPATIBLE_N=1
E: OF_FULLNAME=/soc@0/spmi@c440000
E: OF_NAME=spmi
E: SUBSYSTEM=platform
L: consumer:platform:c440000.spmi:pmic@0:adc@3100=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:adc@3100
L: consumer:platform:c440000.spmi:pmic@0:pon@800:pwrkey=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:pon@800:pwrkey
L: consumer:platform:c440000.spmi:pmic@0:rtc@6000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:rtc@6000
L: consumer:platform:c440000.spmi:pmic@0:temp-alarm@2400=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:temp-alarm@2400
L: consumer:platform:c440000.spmi:pmic@2:charger@1000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@2:charger@1000
L: consumer:platform:c440000.spmi:pmic@3:haptics@c000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@3:haptics@c000
L: driver=../../../../bus/platform/drivers/spmi_pmic_arb
A: driver_override=(null)\n
A: modalias=of:NspmiT(null)Cqcom,spmi-pmic-arb\n
L: of_node=../../../../firmware/devicetree/base/soc@0/spmi@c440000
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/soc@0
E: DRIVER=simple-pm-bus
E: ID_PATH=platform-soc@0
E: ID_PATH_TAG=platform-soc_0
E: MODALIAS=of:NsocT(null)Csimple-bus
E: OF_COMPATIBLE_0=simple-bus
E: OF_COMPATIBLE_N=1
E: OF_FULLNAME=/soc@0
E: OF_NAME=soc
E: SUBSYSTEM=platform
L: consumer:platform:17c90000.timer=../../virtual/devlink/platform:soc@0--platform:17c90000.timer
L: consumer:platform:890000.i2c=../../virtual/devlink/platform:soc@0--platform:890000.i2c
L: consumer:platform:898000.serial=../../virtual/devlink/platform:soc@0--platform:898000.serial
L: consumer:platform:a600000.usb=../../virtual/devlink/platform:soc@0--platform:a600000.usb
L: consumer:platform:a84000.serial=../../virtual/devlink/platform:soc@0--platform:a84000.serial
L: consumer:platform:a88000.i2c=../../virtual/devlink/platform:soc@0--platform:a88000.i2c
L: consumer:platform:a90000.i2c=../../virtual/devlink/platform:soc@0--platform:a90000.i2c
L: driver=../../../bus/platform/drivers/simple-pm-bus
A: driver_override=(null)\n
A: modalias=of:NsocT(null)Csimple-bus\n
L: of_node=../../../firmware/devicetree/base/soc@0
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

07070100000091000081A400000000000000000000000166F7A513000008BD000000000000000000000000000000000000003C00000000feedbackd-0.5.0/tests/data/umockdev/led-multicolor.umockdevP: /devices/platform/led-controller/leds/rgb:status
E: CURRENT_TAGS=:seat:
E: FEEDBACKD_TYPE=led
E: ID_FOR_SEAT=leds-platform-led-controller
E: ID_PATH=platform-led-controller
E: ID_PATH_TAG=platform-led-controller
E: OF_COMPATIBLE_N=0
E: OF_FULLNAME=/led-controller/multi-led
E: OF_NAME=multi-led
E: SUBSYSTEM=leds
E: TAGS=:seat:
A: brightness=0\n
L: device=../../../led-controller
A: max_brightness=248\n
A: multi_index=blue green red\n
A: multi_intensity=248 0 0\n
A: pattern=
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n
A: repeat=-1\n
A: trigger=none kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock disk-activity disk-read disk-write mtd nand-disk heartbeat backlight cpu cpu0 cpu1 cpu2 cpu3 panic mmc1 mmc0 usb-gadget usb-host tps6598x-source-psy-0-003f-online bq25890-charger-0-online max170xx_battery-charging-or-full max170xx_battery-charging max170xx_battery-full max170xx_battery-charging-blink-full-solid timer rfkill-any rfkill-none rfkill0 rfkill1 rfkill2 rfkill3 bluetooth-power [pattern] phy2rx phy2tx phy2assoc phy2radio rfkill6\n

P: /devices/platform/led-controller
E: DRIVER=leds_pwm_multicolor
E: ID_PATH=platform-led-controller
E: ID_PATH_TAG=platform-led-controller
E: MODALIAS=of:Nled-controllerT(null)Cpwm-leds-multicolor
E: OF_COMPATIBLE_0=pwm-leds-multicolor
E: OF_COMPATIBLE_N=1
E: OF_FULLNAME=/led-controller
E: OF_NAME=led-controller
E: SUBSYSTEM=platform
L: driver=../../../bus/platform/drivers/leds_pwm_multicolor
A: driver_override=(null)\n
A: modalias=of:Nled-controllerT(null)Cpwm-leds-multicolor\n
L: of_node=../../../firmware/devicetree/base/led-controller
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n
L: supplier:platform:30670000.pwm=../../virtual/devlink/platform:30670000.pwm--platform:led-controller
L: supplier:platform:30680000.pwm=../../virtual/devlink/platform:30680000.pwm--platform:led-controller
L: supplier:platform:30690000.pwm=../../virtual/devlink/platform:30690000.pwm--platform:led-controller

07070100000092000081A400000000000000000000000166F7A51300001637000000000000000000000000000000000000004100000000feedbackd-0.5.0/tests/data/umockdev/led-qcom-multicolor.umockdevP: /devices/platform/soc@0/c440000.spmi/spmi-0/0-03/c440000.spmi:pmic@3:pwm/leds/rgb:status
E: FEEDBACKD_TYPE=led
E: ID_FOR_SEAT=leds-platform-c440000_spmi-platform-c440000_spmi_pmic_3_pwm
E: ID_PATH=platform-c440000.spmi-platform-c440000.spmi:pmic@3:pwm
E: ID_PATH_TAG=platform-c440000_spmi-platform-c440000_spmi_pmic_3_pwm
E: OF_COMPATIBLE_N=0
E: OF_FULLNAME=/soc@0/spmi@c440000/pmic@3/pwm/multi-led
E: OF_NAME=multi-led
E: SUBSYSTEM=leds
E: TAGS=:seat:
A: brightness=0\n
L: device=../../../c440000.spmi:pmic@3:pwm
A: hw_pattern=
A: max_brightness=511\n
A: multi_index=blue green red\n
A: multi_intensity=0 0 0\n
A: pattern=
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n
A: repeat=-1\n
A: trigger=none kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock timer oneshot heartbeat backlight cpu cpu0 cpu1 cpu2 cpu3 cpu4 cpu5 cpu6 cpu7 activity default-on panic [pattern] mmc0 rfkill-any rfkill-none bluetooth-power hci0-power rfkill0 pmi8998-charger-online qcom-battery-charging-or-full qcom-battery-charging qcom-battery-full qcom-battery-charging-blink-full-solid\n

P: /devices/platform/soc@0/c440000.spmi/spmi-0/0-03/c440000.spmi:pmic@3:pwm
E: DRIVER=qcom-spmi-lpg
E: MODALIAS=of:NpwmT(null)Cqcom,pmi8998-lpg
E: OF_COMPATIBLE_0=qcom,pmi8998-lpg
E: OF_COMPATIBLE_N=1
E: OF_FULLNAME=/soc@0/spmi@c440000/pmic@3/pwm
E: OF_NAME=pwm
E: SUBSYSTEM=platform
L: driver=../../../../../../../bus/platform/drivers/qcom-spmi-lpg
A: driver_override=(null)\n
A: modalias=of:NpwmT(null)Cqcom,pmi8998-lpg\n
L: of_node=../../../../../../../firmware/devicetree/base/soc@0/spmi@c440000/pmic@3/pwm
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/soc@0/c440000.spmi/spmi-0/0-03
E: DRIVER=pmic-spmi
E: MODALIAS=of:NpmicT(null)Cqcom,pmi8998Cqcom,spmi-pmic
E: OF_COMPATIBLE_0=qcom,pmi8998
E: OF_COMPATIBLE_1=qcom,spmi-pmic
E: OF_COMPATIBLE_N=2
E: OF_FULLNAME=/soc@0/spmi@c440000/pmic@3
E: OF_NAME=pmic
E: SUBSYSTEM=spmi
L: driver=../../../../../../bus/spmi/drivers/pmic-spmi
L: of_node=../../../../../../firmware/devicetree/base/soc@0/spmi@c440000/pmic@3
A: power/control=auto\n
A: power/runtime_active_time=7149472\n
A: power/runtime_status=active\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/soc@0/c440000.spmi/spmi-0
E: MODALIAS=of:NspmiT(null)Cqcom,spmi-pmic-arb
E: OF_COMPATIBLE_0=qcom,spmi-pmic-arb
E: OF_COMPATIBLE_N=1
E: OF_FULLNAME=/soc@0/spmi@c440000
E: OF_NAME=spmi
E: SUBSYSTEM=spmi
L: of_node=../../../../../firmware/devicetree/base/soc@0/spmi@c440000
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/soc@0/c440000.spmi
E: DRIVER=spmi_pmic_arb
E: MODALIAS=of:NspmiT(null)Cqcom,spmi-pmic-arb
E: OF_COMPATIBLE_0=qcom,spmi-pmic-arb
E: OF_COMPATIBLE_N=1
E: OF_FULLNAME=/soc@0/spmi@c440000
E: OF_NAME=spmi
E: SUBSYSTEM=platform
L: consumer:platform:c440000.spmi:pmic@0:adc@3100=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:adc@3100
L: consumer:platform:c440000.spmi:pmic@0:pon@800:pwrkey=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:pon@800:pwrkey
L: consumer:platform:c440000.spmi:pmic@0:pon@800:resin=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:pon@800:resin
L: consumer:platform:c440000.spmi:pmic@0:rtc@6000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:rtc@6000
L: consumer:platform:c440000.spmi:pmic@0:temp-alarm@2400=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:temp-alarm@2400
L: consumer:platform:c440000.spmi:pmic@2:charger@1000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@2:charger@1000
L: consumer:platform:c440000.spmi:pmic@2:fuel-gauge@4000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@2:fuel-gauge@4000
L: consumer:platform:c440000.spmi:pmic@3:haptics@c000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@3:haptics@c000
L: driver=../../../../bus/platform/drivers/spmi_pmic_arb
A: driver_override=(null)\n
A: modalias=of:NspmiT(null)Cqcom,spmi-pmic-arb\n
L: of_node=../../../../firmware/devicetree/base/soc@0/spmi@c440000
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/soc@0
E: DRIVER=simple-pm-bus
E: MODALIAS=of:NsocT(null)Csimple-bus
E: OF_COMPATIBLE_0=simple-bus
E: OF_COMPATIBLE_N=1
E: OF_FULLNAME=/soc@0
E: OF_NAME=soc
E: SUBSYSTEM=platform
L: consumer:platform:17c90000.timer=../../virtual/devlink/platform:soc@0--platform:17c90000.timer
L: consumer:platform:894000.i2c=../../virtual/devlink/platform:soc@0--platform:894000.i2c
L: consumer:platform:898000.serial=../../virtual/devlink/platform:soc@0--platform:898000.serial
L: consumer:platform:a600000.usb=../../virtual/devlink/platform:soc@0--platform:a600000.usb
L: consumer:platform:a84000.serial=../../virtual/devlink/platform:soc@0--platform:a84000.serial
L: consumer:platform:a8c000.i2c=../../virtual/devlink/platform:soc@0--platform:a8c000.i2c
L: driver=../../../bus/platform/drivers/simple-pm-bus
A: driver_override=(null)\n
A: modalias=of:NsocT(null)Csimple-bus\n
L: of_node=../../../firmware/devicetree/base/soc@0
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

07070100000093000081A400000000000000000000000166F7A513000016AB000000000000000000000000000000000000003D00000000feedbackd-0.5.0/tests/data/umockdev/led-qcom-simple.umockdevP: /devices/platform/soc@0/c440000.spmi/spmi-0/0-03/c440000.spmi:pmic@3:pwm/leds/white:status
E: FEEDBACKD_TYPE=led
E: ID_FOR_SEAT=leds-platform-c440000_spmi-platform-c440000_spmi_pmic_3_pwm
E: ID_PATH=platform-c440000.spmi-platform-c440000.spmi:pmic@3:pwm
E: ID_PATH_TAG=platform-c440000_spmi-platform-c440000_spmi_pmic_3_pwm
E: OF_COMPATIBLE_N=0
E: OF_FULLNAME=/soc@0/spmi@c440000/pmic@3/pwm/led@5
E: OF_NAME=led
E: SUBSYSTEM=leds
E: TAGS=:seat:
A: brightness=0\n
L: device=../../../c440000.spmi:pmic@3:pwm
A: hw_pattern=
A: max_brightness=511\n
A: pattern=
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n
A: repeat=-1\n
A: trigger=none kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock timer oneshot heartbeat backlight cpu cpu0 cpu1 cpu2 cpu3 cpu4 cpu5 cpu6 cpu7 activity default-on panic [pattern] mmc0 rfkill-any rfkill-none bluetooth-power hci0-power rfkill0 pmi8998-charger-online qcom-battery-charging-or-full qcom-battery-charging qcom-battery-full qcom-battery-charging-blink-full-solid phy0rx phy0tx phy0assoc phy0radio rfkill1\n

P: /devices/platform/soc@0/c440000.spmi/spmi-0/0-03/c440000.spmi:pmic@3:pwm
E: DRIVER=qcom-spmi-lpg
E: MODALIAS=of:NpwmT(null)Cqcom,pmi8998-lpg
E: OF_COMPATIBLE_0=qcom,pmi8998-lpg
E: OF_COMPATIBLE_N=1
E: OF_FULLNAME=/soc@0/spmi@c440000/pmic@3/pwm
E: OF_NAME=pwm
E: SUBSYSTEM=platform
L: driver=../../../../../../../bus/platform/drivers/qcom-spmi-lpg
A: driver_override=(null)\n
A: modalias=of:NpwmT(null)Cqcom,pmi8998-lpg\n
L: of_node=../../../../../../../firmware/devicetree/base/soc@0/spmi@c440000/pmic@3/pwm
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/soc@0/c440000.spmi/spmi-0/0-03
E: DRIVER=pmic-spmi
E: MODALIAS=of:NpmicT(null)Cqcom,pmi8998Cqcom,spmi-pmic
E: OF_COMPATIBLE_0=qcom,pmi8998
E: OF_COMPATIBLE_1=qcom,spmi-pmic
E: OF_COMPATIBLE_N=2
E: OF_FULLNAME=/soc@0/spmi@c440000/pmic@3
E: OF_NAME=pmic
E: SUBSYSTEM=spmi
L: driver=../../../../../../bus/spmi/drivers/pmic-spmi
L: of_node=../../../../../../firmware/devicetree/base/soc@0/spmi@c440000/pmic@3
A: power/control=auto\n
A: power/runtime_active_time=124723680\n
A: power/runtime_status=active\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/soc@0/c440000.spmi/spmi-0
E: MODALIAS=of:NspmiT(null)Cqcom,spmi-pmic-arb
E: OF_COMPATIBLE_0=qcom,spmi-pmic-arb
E: OF_COMPATIBLE_N=1
E: OF_FULLNAME=/soc@0/spmi@c440000
E: OF_NAME=spmi
E: SUBSYSTEM=spmi
L: of_node=../../../../../firmware/devicetree/base/soc@0/spmi@c440000
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/soc@0/c440000.spmi
E: DRIVER=spmi_pmic_arb
E: MODALIAS=of:NspmiT(null)Cqcom,spmi-pmic-arb
E: OF_COMPATIBLE_0=qcom,spmi-pmic-arb
E: OF_COMPATIBLE_N=1
E: OF_FULLNAME=/soc@0/spmi@c440000
E: OF_NAME=spmi
E: SUBSYSTEM=platform
L: consumer:platform:c440000.spmi:pmic@0:adc@3100=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:adc@3100
L: consumer:platform:c440000.spmi:pmic@0:pon@800:pwrkey=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:pon@800:pwrkey
L: consumer:platform:c440000.spmi:pmic@0:pon@800:resin=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:pon@800:resin
L: consumer:platform:c440000.spmi:pmic@0:rtc@6000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:rtc@6000
L: consumer:platform:c440000.spmi:pmic@0:temp-alarm@2400=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@0:temp-alarm@2400
L: consumer:platform:c440000.spmi:pmic@2:charger@1000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@2:charger@1000
L: consumer:platform:c440000.spmi:pmic@2:fuel-gauge@4000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@2:fuel-gauge@4000
L: consumer:platform:c440000.spmi:pmic@3:haptics@c000=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@3:haptics@c000
L: consumer:platform:c440000.spmi:pmic@3:leds@d800=../../../virtual/devlink/platform:c440000.spmi--platform:c440000.spmi:pmic@3:leds@d800
L: driver=../../../../bus/platform/drivers/spmi_pmic_arb
A: driver_override=(null)\n
A: modalias=of:NspmiT(null)Cqcom,spmi-pmic-arb\n
L: of_node=../../../../firmware/devicetree/base/soc@0/spmi@c440000
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n

P: /devices/platform/soc@0
E: DRIVER=simple-pm-bus
E: MODALIAS=of:NsocT(null)Csimple-bus
E: OF_COMPATIBLE_0=simple-bus
E: OF_COMPATIBLE_N=1
E: OF_FULLNAME=/soc@0
E: OF_NAME=soc
E: SUBSYSTEM=platform
L: consumer:platform:17c90000.timer=../../virtual/devlink/platform:soc@0--platform:17c90000.timer
L: consumer:platform:894000.i2c=../../virtual/devlink/platform:soc@0--platform:894000.i2c
L: consumer:platform:898000.serial=../../virtual/devlink/platform:soc@0--platform:898000.serial
L: consumer:platform:a600000.usb=../../virtual/devlink/platform:soc@0--platform:a600000.usb
L: consumer:platform:a84000.serial=../../virtual/devlink/platform:soc@0--platform:a84000.serial
L: consumer:platform:a98000.i2c=../../virtual/devlink/platform:soc@0--platform:a98000.i2c
L: driver=../../../bus/platform/drivers/simple-pm-bus
A: driver_override=(null)\n
A: modalias=of:NsocT(null)Csimple-bus\n
L: of_node=../../../firmware/devicetree/base/soc@0
A: power/control=auto\n
A: power/runtime_active_time=0\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n


07070100000094000081A400000000000000000000000166F7A51300000A8C000000000000000000000000000000000000003800000000feedbackd-0.5.0/tests/data/umockdev/led-simple.umockdevP: /devices/LNXSYSTM:00/LNXSYBUS:00/PURI4543:00/leds/blue:status
E: CURRENT_TAGS=:seat:
E: FEEDBACKD_TYPE=led
E: ID_FOR_SEAT=leds-acpi-PURI4543_00
E: ID_PATH=acpi-PURI4543:00
E: ID_PATH_TAG=acpi-PURI4543_00
E: SUBSYSTEM=leds
E: TAGS=:seat:
A: brightness=0\n
L: device=../../../PURI4543:00
A: max_brightness=255\n
A: pattern=
A: power/async=disabled\n
A: power/control=auto\n
A: power/runtime_active_kids=0\n
A: power/runtime_active_time=0\n
A: power/runtime_enabled=disabled\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n
A: power/runtime_usage=0\n
A: repeat=-1\n
A: trigger=none kbd-scrolllock kbd-numlock kbd-capslock kbd-kanalock kbd-shiftlock kbd-altgrlock kbd-ctrllock kbd-altlock kbd-shiftllock kbd-shiftrlock kbd-ctrlllock kbd-ctrlrlock disk-activity disk-read disk-write mtd nand-disk cpu cpu0 cpu1 cpu2 cpu3 cpu4 cpu5 cpu6 cpu7 panic usb-gadget usb-host BAT0-charging-or-full BAT0-charging BAT0-full BAT0-charging-blink-full-solid rc-feedback [pattern] AC-online audio-mute audio-micmute rfkill-any rfkill-none bluetooth-power phy2rx phy2tx phy2assoc phy2radio rfkill28 hci0-power rfkill52 r8169-0-200:00:link r8169-0-200:00:1Gbps r8169-0-200:00:100Mbps r8169-0-200:00:10Mbps\n

P: /devices/LNXSYSTM:00/LNXSYBUS:00/PURI4543:00
E: DRIVER=Librem EC ACPI Driver
E: ID_VENDOR_FROM_DATABASE=Purism SPC
E: MODALIAS=acpi:PURI4543:
E: SUBSYSTEM=acpi
L: driver=../../../../bus/acpi/drivers/Librem EC ACPI Driver
A: hid=PURI4543\n
A: modalias=acpi:PURI4543:\n
A: path=\\_SB_.LIEC\n
L: physical_node=../../../platform/PURI4543:00
A: power/async=disabled\n
A: power/control=auto\n
A: power/runtime_active_kids=0\n
A: power/runtime_active_time=0\n
A: power/runtime_enabled=disabled\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n
A: power/runtime_usage=0\n
A: uid=0\n

P: /devices/LNXSYSTM:00/LNXSYBUS:00
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation
E: MODALIAS=acpi:LNXSYBUS:
E: SUBSYSTEM=acpi
A: hid=LNXSYBUS\n
A: modalias=acpi:LNXSYBUS:\n
A: path=\\_SB_\n
A: power/async=disabled\n
A: power/control=auto\n
A: power/runtime_active_kids=0\n
A: power/runtime_active_time=0\n
A: power/runtime_enabled=disabled\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n
A: power/runtime_usage=0\n

P: /devices/LNXSYSTM:00
E: ID_VENDOR_FROM_DATABASE=The Linux Foundation
E: MODALIAS=acpi:LNXSYSTM:
E: SUBSYSTEM=acpi
A: hid=LNXSYSTM\n
A: modalias=acpi:LNXSYSTM:\n
A: path=\\\n
A: power/async=disabled\n
A: power/control=auto\n
A: power/runtime_active_kids=0\n
A: power/runtime_active_time=0\n
A: power/runtime_enabled=disabled\n
A: power/runtime_status=unsupported\n
A: power/runtime_suspended_time=0\n
A: power/runtime_usage=0\n

07070100000095000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000002700000000feedbackd-0.5.0/tests/data/user-config07070100000096000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000003100000000feedbackd-0.5.0/tests/data/user-config/feedbackd07070100000097000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000003800000000feedbackd-0.5.0/tests/data/user-config/feedbackd/themes07070100000098000081A400000000000000000000000166F7A51300000182000000000000000000000000000000000000004400000000feedbackd-0.5.0/tests/data/user-config/feedbackd/themes/custom.json{
  "name" : "custom",
  "parent-name": "default",
  "profiles" : [
    {
      "name" : "full",
      "feedbacks" : [
        {
          "event-name" : "test-dummy-0",
          "type"       : "Dummy",
          "duration"   : 16
        },
        {
          "event-name" : "test-dummy-2",
          "type"       : "Dummy",
          "duration"   : 48
        }
      ]
    }
  ]
}
07070100000099000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000002400000000feedbackd-0.5.0/tests/data/xdg-data0707010000009A000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000002E00000000feedbackd-0.5.0/tests/data/xdg-data/feedbackd0707010000009B000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000003500000000feedbackd-0.5.0/tests/data/xdg-data/feedbackd/themes0707010000009C000081A400000000000000000000000166F7A51300000035000000000000000000000000000000000000004200000000feedbackd-0.5.0/tests/data/xdg-data/feedbackd/themes/chainup.json{
  "name" : "$device",
  "parent-name": "default"
}
0707010000009D000081A400000000000000000000000166F7A5130000022D000000000000000000000000000000000000004200000000feedbackd-0.5.0/tests/data/xdg-data/feedbackd/themes/default.json{
  "name" : "default",
  "profiles" : [
    {
      "name" : "full",
      "feedbacks" : [
        {
          "event-name" : "test-dummy-0",
          "type"       : "Dummy"
        },
        {
          "event-name" : "test-dummy-1",
          "type"       : "Dummy"
        }
      ]
    },
    {
      "name" : "quiet",
      "feedbacks" : [
        {
          "event-name" : "test-dummy-0",
          "type"       : "Dummy"
        },
        {
          "event-name" : "test-dummy-1",
          "type"       : "Dummy"
        }
      ]
    }
  ]
}
0707010000009E000081A400000000000000000000000166F7A51300000183000000000000000000000000000000000000004200000000feedbackd-0.5.0/tests/data/xdg-data/feedbackd/themes/replace.json{
  "name" : "$device",
  "parent-name": "default",
  "profiles" : [
    {
      "name" : "full",
      "feedbacks" : [
        {
          "event-name" : "test-dummy-0",
          "type"       : "Dummy",
          "duration"   : 16
        },
        {
          "event-name" : "test-dummy-2",
          "type"       : "Dummy",
          "duration"   : 32
        }
      ]
    }
  ]
}
0707010000009F000081A400000000000000000000000166F7A513000009C6000000000000000000000000000000000000002200000000feedbackd-0.5.0/tests/meson.buildif get_option('tests')

umockdev_dep = dependency('umockdev-1.0')

add_test_setup ('umockdev',
  exe_wrapper: 'umockdev-wrapper',
  is_default: true
)

test_env = environment()
test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
test_env.set('G_DEBUG', 'gc-friendly,fatal-warnings')
test_env.set('GSETTINGS_BACKEND', 'memory')
test_env.set('GSETTINGS_SCHEMA_DIR', '@0@/data'.format(meson.project_build_root()))
test_env.set('PYTHONDONTWRITEBYTECODE', 'yes')
test_env.set('MALLOC_CHECK_', '2')
test_env.set('XDG_CONFIG_HOME', meson.current_source_dir() / 'data' / 'user-config')
test_env.set('XDG_CONFIG_DIRS', meson.current_source_dir())

# Shared library Unit tests

test_lfb_cflags = [
  '-DTEST_APP_ID="org.sigxcpu.feedbackd_test"',
  '-DLIBFEEDBACK_USE_UNSTABLE_API',
  '-DTEST_DATA_DIR="@0@"'.format(join_paths(meson.current_source_dir(), 'data')),
]

test_lfb_link_args = [
  '-fPIC',
]

test_lfb_deps = [
  libfeedback_dep,
  glib,
  gio_unix,
]

lfb_tests = [
  'lfb-event',
]

if get_option ('daemon')
  # The integration test needs the daemon
  lfb_tests += 'lfb-integration'
  subdir('services')
endif

foreach test : lfb_tests
  t = executable('test-@0@'.format(test),
                 ['test-@0@.c'.format(test)],
                 c_args : test_lfb_cflags,
                 pie : true,
                 link_args : test_lfb_link_args,
                 dependencies : test_lfb_deps)
  test(test, t, env: test_env)
endforeach

# Daemon Unit tests
if get_option('daemon')

test_env_fbd = test_env
test_env_fbd.set('XDG_DATA_DIRS', meson.current_source_dir() / 'data' / 'xdg-data')

test_fbd_cflags = [
    '-DTEST_APP_ID="org.sigxcpu.feedbackd_test"',
    '-DTEST_DATA_DIR="@0@"'.format(join_paths(meson.current_source_dir(), 'data')),
  ]

test_fbd_link_args = [
  '-fPIC',
]

test_fbd_deps = [
  fbd_dep,
  umockdev_dep,
]

# HW independent tests
fbd_tests = [
  'fbd-feedback-led',
  'fbd-feedback-profile',
  'fbd-feedback-theme',
  'fbd-event',
  'fbd-theme-expander',
  'fbd-dev-led',
]

foreach test : fbd_tests
  t = executable('test-@0@'.format(test),
                 ['test-@0@.c'.format(test),
		  'testlib.c',
		  generated_dbus_sources[1]],
                 c_args : test_fbd_cflags,
                 pie : true,
                 link_args : test_fbd_link_args,
		 include_directories : fbd_inc,
                 dependencies : test_fbd_deps)
  test(test, t, env : test_env_fbd)
endforeach

endif # daemon

endif
070701000000A0000041ED00000000000000000000000266F7A51300000000000000000000000000000000000000000000001F00000000feedbackd-0.5.0/tests/services070701000000A1000081A400000000000000000000000166F7A513000000FA000000000000000000000000000000000000002B00000000feedbackd-0.5.0/tests/services/meson.buildservice_file = 'org.sigxcpu.Feedback.service'
service_data = configuration_data()
service_data.set('ABS_BUILDDIR', meson.project_build_root())

configure_file(
  input : service_file + '.in',
  output : service_file,
  configuration : service_data
)
070701000000A2000081A400000000000000000000000166F7A51300000060000000000000000000000000000000000000003F00000000feedbackd-0.5.0/tests/services/org.sigxcpu.Feedback.service.in[D-BUS Service]
Name=org.sigxcpu.Feedback
Exec=@ABS_BUILDDIR@/run @ABS_BUILDDIR@/src/feedbackd

070701000000A3000081A400000000000000000000000166F7A5130000164E000000000000000000000000000000000000002900000000feedbackd-0.5.0/tests/test-fbd-dev-led.c/*
 * Copyright (C) 2024 The Phosh Developers
 * SPDX-License-Identifier: GPL-3.0+
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "fbd-feedback-led.h"
#include "fbd-dev-led.h"
#include "fbd-dev-led-flash.h"
#include "fbd-dev-led-multicolor.h"
#include "fbd-dev-led-qcom.h"
#include "fbd-dev-led-qcom-multicolor.h"

#include "testlib.h"


static void
test_fbd_dev_led_simple (FbdUmockdevFixture *fixture, gconstpointer unused)
{
  GUdevClient *client;
  g_autolist (GUdevDevice) leds = NULL;
  FbdDevLed *led;
  g_autoptr (GError) err = NULL;
  GUdevDevice *dev;

  client = g_udev_client_new ((const char *const []){ "leds", NULL});
  leds = g_udev_client_query_by_subsystem (client, "leds");

  /* There should be a single device only */
  g_assert_cmpint (g_list_length (leds), ==, 1);
  dev = G_UDEV_DEVICE (leds->data);

  g_assert_cmpstr (g_udev_device_get_property (dev, "FEEDBACKD_TYPE"), ==, "led");

  led = fbd_dev_led_new (dev, &err);
  g_assert_no_error (err);
  g_assert_cmpint (fbd_dev_led_get_max_brightness (led), ==, 255);
  g_assert_true (fbd_dev_led_supports_color (led, FBD_FEEDBACK_LED_COLOR_BLUE));
  g_assert_true (fbd_dev_led_start_periodic (led, 50, 50));
  g_assert_finalize_object (led);
}


static void
test_fbd_dev_led_multicolor (FbdUmockdevFixture *fixture, gconstpointer unused)
{
  GUdevClient *client;
  g_autolist (GUdevDevice) leds = NULL;
  FbdDevLed *led;
  g_autoptr (GError) err = NULL;
  GUdevDevice *dev;

  client = g_udev_client_new ((const char *const []){ "leds", NULL});
  leds = g_udev_client_query_by_subsystem (client, "leds");

  /* There should be a single device only */
  g_assert_cmpint (g_list_length (leds), ==, 1);
  dev = G_UDEV_DEVICE (leds->data);

  g_assert_cmpstr (g_udev_device_get_property (dev, "FEEDBACKD_TYPE"), ==, "led");

  led = fbd_dev_led_multicolor_new (dev, &err);
  g_assert_no_error (err);
  g_assert_cmpint (fbd_dev_led_get_max_brightness (led), ==, 248);
  g_assert_true (fbd_dev_led_supports_color (led, FBD_FEEDBACK_LED_COLOR_BLUE));
  g_assert_true (fbd_dev_led_start_periodic (led, 50, 50));

  g_assert_finalize_object (led);
}


static void
test_fbd_dev_led_flash (FbdUmockdevFixture *fixture, gconstpointer unused)
{
  GUdevClient *client;
  g_autolist (GUdevDevice) leds = NULL;
  FbdDevLed *led;
  g_autoptr (GError) err = NULL;
  GUdevDevice *dev;

  client = g_udev_client_new ((const char *const []){ "leds", NULL});
  leds = g_udev_client_query_by_subsystem (client, "leds");

  /* There should be a single device only */
  g_assert_cmpint (g_list_length (leds), ==, 1);
  dev = G_UDEV_DEVICE (leds->data);

  g_assert_cmpstr (g_udev_device_get_property (dev, "FEEDBACKD_TYPE"), ==, "led");

  led = fbd_dev_led_flash_new (dev, &err);
  g_assert_no_error (err);
  g_assert_cmpint (fbd_dev_led_get_max_brightness (led), ==, 255);
  g_assert_true (fbd_dev_led_supports_color (led, FBD_FEEDBACK_LED_COLOR_FLASH));
  g_assert_true (fbd_dev_led_start_periodic (led, 50, 50));

  g_assert_finalize_object (led);
}


static void
test_fbd_dev_led_qcom_simple (FbdUmockdevFixture *fixture, gconstpointer unused)
{
  GUdevClient *client;
  g_autolist (GUdevDevice) leds = NULL;
  FbdDevLed *led;
  g_autoptr (GError) err = NULL;
  GUdevDevice *dev;

  client = g_udev_client_new ((const char *const []){ "leds", NULL});
  leds = g_udev_client_query_by_subsystem (client, "leds");

  /* There should be a single device only */
  g_assert_cmpint (g_list_length (leds), ==, 1);
  dev = G_UDEV_DEVICE (leds->data);

  g_assert_cmpstr (g_udev_device_get_property (dev, "FEEDBACKD_TYPE"), ==, "led");

  led = fbd_dev_led_qcom_new (dev, &err);
  g_assert_no_error (err);
  g_assert_cmpint (fbd_dev_led_get_max_brightness (led), ==, 511);
  g_assert_true (fbd_dev_led_supports_color (led, FBD_FEEDBACK_LED_COLOR_WHITE));
  g_assert_true (fbd_dev_led_start_periodic (led, 50, 50));
  g_assert_finalize_object (led);
}


static void
test_fbd_dev_led_qcom_multicolor (FbdUmockdevFixture *fixture, gconstpointer unused)
{
  GUdevClient *client;
  g_autolist (GUdevDevice) leds = NULL;
  FbdDevLed *led;
  g_autoptr (GError) err = NULL;
  GUdevDevice *dev;

  client = g_udev_client_new ((const char *const []){ "leds", NULL});
  leds = g_udev_client_query_by_subsystem (client, "leds");

  /* There should be a single device only */
  g_assert_cmpint (g_list_length (leds), ==, 1);
  dev = G_UDEV_DEVICE (leds->data);

  g_assert_cmpstr (g_udev_device_get_property (dev, "FEEDBACKD_TYPE"), ==, "led");

  led = fbd_dev_led_qcom_multicolor_new (dev, &err);
  g_assert_no_error (err);
  g_assert_cmpint (fbd_dev_led_get_max_brightness (led), ==, 511);
  g_assert_true (fbd_dev_led_supports_color (led, FBD_FEEDBACK_LED_COLOR_BLUE));
  g_assert_true (fbd_dev_led_start_periodic (led, 50, 50));

  g_assert_finalize_object (led);
}


gint
main (gint argc, gchar *argv[])
{
  g_test_init (&argc, &argv, NULL);

  FBD_UMOCKDEV_TEST_ADD ("/feedbackd/fbd/dev/led/simple",
                         test_fbd_dev_led_simple,
                         "led-simple");
  FBD_UMOCKDEV_TEST_ADD ("/feedbackd/fbd/dev/led/multicolor",
                         test_fbd_dev_led_multicolor,
                         "led-multicolor");
  FBD_UMOCKDEV_TEST_ADD ("/feedbackd/fbd/dev/led/flash",
                         test_fbd_dev_led_flash,
                         "led-flash");
  FBD_UMOCKDEV_TEST_ADD ("/feedbackd/fbd/dev/led/qcom/simple",
                         test_fbd_dev_led_qcom_simple,
                         "led-qcom-simple");
  FBD_UMOCKDEV_TEST_ADD ("/feedbackd/fbd/dev/led/qcom/multicolor",
                         test_fbd_dev_led_qcom_multicolor,
                         "led-qcom-multicolor");

  return g_test_run();
}
070701000000A4000081A400000000000000000000000166F7A51300001E91000000000000000000000000000000000000002700000000feedbackd-0.5.0/tests/test-fbd-event.c/*
 * Copyright (C) 2020 Purism SPC
 *               2023-2024 The Phosh Developers
 *
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "fbd-event.h"
#include "fbd-feedback-dummy.h"

#define TEST_EVENT "window-close"

static void
test_fbd_event (void)
{
  g_autoptr (FbdEvent) event = NULL;
  g_autofree gchar *appid = NULL;
  g_autofree gchar *name = NULL;
  g_autofree gchar *sender = NULL;
  FbdEventEndReason reason;
  gint timeout;

  event = fbd_event_new (1, TEST_APP_ID, TEST_EVENT, 2, "sender-id");

  g_assert_true (FBD_IS_EVENT (event));
  g_object_get (event,
                "end-reason", &reason,
                "event", &name,
                "app-id", &appid,
                "timeout", &timeout,
                "sender", &sender,
                NULL);

  g_assert_cmpstr (fbd_event_get_event (event), ==, TEST_EVENT);
  g_assert_cmpstr (name, ==, TEST_EVENT);

  g_assert_cmpstr (fbd_event_get_app_id (event), ==, TEST_APP_ID);
  g_assert_cmpstr (appid, ==, TEST_APP_ID);

  g_assert_cmpint (fbd_event_get_timeout (event), ==, timeout);
  g_assert_cmpint (timeout, ==, 2);

  g_assert_cmpstr (fbd_event_get_sender (event), ==, sender);
  g_assert_cmpstr (sender, ==, "sender-id");

  g_assert_cmpint (fbd_event_get_end_reason (event), ==, FBD_EVENT_END_REASON_NATURAL);
  g_assert_cmpint (reason, ==, FBD_EVENT_END_REASON_NATURAL);
}

static void
test_fbd_event_feedback (void)
{
  GSList *feedbacks;
  FbdEvent *event = NULL;
  FbdFeedbackDummy *feedback1 = NULL;
  FbdFeedbackDummy *feedback2 = NULL;

  event = fbd_event_new (1, TEST_APP_ID, TEST_EVENT, -1, NULL);
  feedback1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL);
  feedback2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL);

  feedbacks = fbd_event_get_feedbacks (event);
  g_assert_cmpint (g_slist_length (feedbacks), ==, 0);

  fbd_event_add_feedback (event, FBD_FEEDBACK_BASE (feedback1));
  feedbacks = fbd_event_get_feedbacks (event);
  g_assert_cmpint (g_slist_length (feedbacks), ==, 1);

  /* Remove non existing feedback */
  fbd_event_remove_feedback (event, FBD_FEEDBACK_BASE (feedback2));
  feedbacks = fbd_event_get_feedbacks (event);
  g_assert_cmpint (g_slist_length (feedbacks), ==, 1);

  fbd_event_remove_feedback (event, FBD_FEEDBACK_BASE (feedback1));
  feedbacks = fbd_event_get_feedbacks (event);
  g_assert_cmpint (g_slist_length (feedbacks), ==, 0);

  fbd_event_add_feedback (event, FBD_FEEDBACK_BASE (feedback1));
  fbd_event_add_feedback (event, FBD_FEEDBACK_BASE (feedback2));
  feedbacks = fbd_event_get_feedbacks (event);
  g_assert_cmpint (g_slist_length (feedbacks), ==, 2);

  g_assert_false (fbd_event_get_feedbacks_ended (event));
  fbd_event_end_feedbacks (event);
  /* Dummy feedback ends immediately */
  g_assert_true (fbd_event_get_feedbacks_ended (event));

  /* event holds a ref on the feedbacks so finalize it first */
  g_assert_finalize_object (event);
  g_assert_finalize_object (feedback2);
  g_assert_finalize_object (feedback1);
}

static void
on_feedbacks_ended (FbdEvent *event, gboolean *ended)
{
  FBD_IS_EVENT (event);

  *ended = TRUE;
}

static void
test_fbd_event_feedback_ended (void)
{
  g_autoptr (FbdEvent) event = NULL;
  g_autoptr (FbdFeedbackDummy) feedback1 = NULL;
  g_autoptr (FbdFeedbackDummy) feedback2 = NULL;
  gboolean ended = FALSE;

  event = fbd_event_new (1, TEST_APP_ID, TEST_EVENT, FBD_EVENT_TIMEOUT_ONESHOT, NULL);
  feedback1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL);
  fbd_event_add_feedback (event, FBD_FEEDBACK_BASE (feedback1));

  feedback2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL);
  fbd_event_add_feedback (event, FBD_FEEDBACK_BASE (feedback2));

  g_signal_connect (event, "feedbacks-ended",
                    (GCallback)on_feedbacks_ended, &ended);

  fbd_event_end_feedbacks (event);
  g_assert_true (ended);
}


static void
test_fbd_event_feedback_end_by_level (void)
{
  FbdEvent *event;
  FbdFeedbackDummy *feedback1, *feedback2;
  gboolean ended;

  feedback1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL);
  g_object_set_data (G_OBJECT (feedback1), "fbd-level", GUINT_TO_POINTER (10));

  feedback2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL);
  g_object_set_data (G_OBJECT (feedback2), "fbd-level", GUINT_TO_POINTER (5));

  event = fbd_event_new (1, TEST_APP_ID, TEST_EVENT, FBD_EVENT_TIMEOUT_ONESHOT, NULL);
  g_signal_connect (event, "feedbacks-ended",
                    (GCallback)on_feedbacks_ended, &ended);

  /* End all feedback at once */
  fbd_event_add_feedback (event, FBD_FEEDBACK_BASE (feedback1));
  fbd_event_add_feedback (event, FBD_FEEDBACK_BASE (feedback2));
  fbd_event_end_feedbacks_by_level (event, 3);
  g_assert_cmpint (g_slist_length (fbd_event_get_feedbacks (event)), ==, 0);
  g_assert_cmpint (fbd_event_get_end_reason (event), ==, FBD_EVENT_END_REASON_EXPLICIT);
  g_assert_true (ended);

  /* End feedback one by one */
  ended = FALSE;
  fbd_event_set_end_reason (event, FBD_EVENT_END_REASON_NATURAL);
  fbd_event_add_feedback (event, FBD_FEEDBACK_BASE (feedback1));
  fbd_event_add_feedback (event, FBD_FEEDBACK_BASE (feedback2));
  fbd_event_end_feedbacks_by_level (event, 7);
  g_assert_cmpint (g_slist_length (fbd_event_get_feedbacks (event)), ==, 1);
  g_assert_cmpint (fbd_event_get_end_reason (event), ==, FBD_EVENT_END_REASON_NATURAL);
  g_assert_false (ended);
  fbd_event_end_feedbacks_by_level (event, 4);
  g_assert_cmpint (g_slist_length (fbd_event_get_feedbacks (event)), ==, 0);
  g_assert_cmpint (fbd_event_get_end_reason (event), ==, FBD_EVENT_END_REASON_EXPLICIT);
  g_assert_true (ended);

  g_assert_finalize_object (event);
  g_assert_finalize_object (feedback2);
  g_assert_finalize_object (feedback1);
}


static void
test_fbd_event_feedback_loop (void)
{
  g_autoptr (FbdEvent) event = NULL;
  g_autoptr (FbdFeedbackDummy) feedback1 = NULL;
  g_autoptr (FbdFeedbackDummy) feedback2 = NULL;
  gboolean ended = FALSE;

  event = fbd_event_new (1, TEST_APP_ID, TEST_EVENT, FBD_EVENT_TIMEOUT_LOOP, NULL);
  feedback1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL);
  fbd_event_add_feedback (event, FBD_FEEDBACK_BASE (feedback1));
  feedback2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL);
  fbd_event_add_feedback (event, FBD_FEEDBACK_BASE (feedback2));

  g_signal_connect (event, "feedbacks-ended",
                    (GCallback)on_feedbacks_ended, &ended);
  g_assert_false (ended);

  fbd_event_end_feedbacks (event);
  g_assert_true (ended);
}

static void
test_fbd_event_feedback_timeout (void)
{
  g_autoptr (FbdEvent) event = NULL;
  g_autoptr (FbdFeedbackDummy) feedback1 = NULL;
  g_autoptr (FbdFeedbackDummy) feedback2 = NULL;
  gboolean ended = FALSE;

  event = fbd_event_new (1, TEST_APP_ID, TEST_EVENT, 1, NULL);
  feedback1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL);
  fbd_event_add_feedback (event, FBD_FEEDBACK_BASE (feedback1));
  feedback2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL);
  fbd_event_add_feedback (event, FBD_FEEDBACK_BASE (feedback2));

  g_signal_connect (event, "feedbacks-ended",
                    (GCallback)on_feedbacks_ended, &ended);
  g_assert_false (ended);

  fbd_event_end_feedbacks (event);
  g_assert_true (ended);
}

gint
main (gint argc, gchar *argv[])
{
  g_test_init (&argc, &argv, NULL);

  g_test_add_func ("/feedbackd/fbd/event/new", test_fbd_event);
  g_test_add_func ("/feedbackd/fbd/event/feedbacks/props", test_fbd_event_feedback);
  g_test_add_func ("/feedbackd/fbd/event/feedbacks/ended", test_fbd_event_feedback_ended);
  g_test_add_func ("/feedbackd/fbd/event/feedbacks/end_by_level",
                   test_fbd_event_feedback_end_by_level);
  g_test_add_func ("/feedbackd/fbd/event/feedbacks/loop", test_fbd_event_feedback_loop);
  g_test_add_func ("/feedbackd/fbd/event/feedbacks/timeout", test_fbd_event_feedback_timeout);

  return g_test_run ();
}
070701000000A5000081A400000000000000000000000166F7A513000007FB000000000000000000000000000000000000002E00000000feedbackd-0.5.0/tests/test-fbd-feedback-led.c/*
 * Copyright (C) 2024 The Phosh Developers
 *
 * SPDX-License-Identifier: GPL-3.0+
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#define GMOBILE_USE_UNSTABLE_API
#include "fbd-feedback-led.c"


static void
test_fbd_feedback_led_parse_color (void)
{
  FbdLedRgbColor rgb = { 0 };

  g_assert_true (parse_hex_color ("#11aaBB", &rgb));
  g_assert_cmpint (rgb.r, ==, 0x11);
  g_assert_cmpint (rgb.g, ==, 0xaa);
  g_assert_cmpint (rgb.b, ==, 0xbb);

  g_assert_true (parse_hex_color ("#000000", &rgb));
  g_assert_cmpint (rgb.r, ==, 0x00);
  g_assert_cmpint (rgb.g, ==, 0x00);
  g_assert_cmpint (rgb.b, ==, 0x00);

  g_assert_false (parse_hex_color ("#1bc", &rgb));
  g_assert_false (parse_hex_color ("11aaBB", &rgb));
  g_assert_false (parse_hex_color ("", &rgb));
  g_assert_false (parse_hex_color ("#", &rgb));
  g_assert_false (parse_hex_color ("#QWERTY", &rgb));
}


static void
test_fbd_feedback_led_color_string_to_color (void)
{
  FbdLedRgbColor rgb = { 0 };

  g_assert_cmpint (color_string_to_color ("red", FALSE, NULL), ==, FBD_FEEDBACK_LED_COLOR_RED);

  g_assert_cmpint (color_string_to_color ("#11aaBB", FALSE, &rgb), ==, FBD_FEEDBACK_LED_COLOR_RGB);
  g_assert_cmpint (rgb.r, ==, 0x11);
  g_assert_cmpint (rgb.g, ==, 0xaa);
  g_assert_cmpint (rgb.b, ==, 0xbb);

  g_assert_cmpint (color_string_to_color ("#00FF00", FALSE, &rgb), ==, FBD_FEEDBACK_LED_COLOR_RGB);
  g_assert_cmpint (rgb.r, ==, 0x00);
  g_assert_cmpint (rgb.g, ==, 0xFF);
  g_assert_cmpint (rgb.b, ==, 0x00);

  g_assert_cmpint (color_string_to_color ("#00FF00", TRUE, &rgb), ==, FBD_FEEDBACK_LED_COLOR_FLASH);
  g_assert_cmpint (rgb.r, ==, 0x00);
  g_assert_cmpint (rgb.g, ==, 0xFF);
  g_assert_cmpint (rgb.b, ==, 0x00);
}


gint
main (gint argc, gchar *argv[])
{
  g_test_init (&argc, &argv, NULL);

  g_test_add_func("/feedbackd/fbd/feedback-led/parse-color", test_fbd_feedback_led_parse_color);
  g_test_add_func("/feedbackd/fbd/feedback-led/color-string-to-color",
                  test_fbd_feedback_led_color_string_to_color);

  return g_test_run();
}
070701000000A6000081A400000000000000000000000166F7A51300001422000000000000000000000000000000000000003200000000feedbackd-0.5.0/tests/test-fbd-feedback-profile.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "fbd-feedback-profile.h"
#include "fbd-feedback-dummy.h"
#include "fbd-feedback-vibra.h"

#include <json-glib/json-glib.h>

#define PROFILE_NAME "test"

static void
test_fbd_feedback_profile_name (void)
{
  g_autoptr(FbdFeedbackProfile) profile = fbd_feedback_profile_new (PROFILE_NAME);

  g_assert_true (FBD_IS_FEEDBACK_PROFILE (profile));

  g_assert_cmpstr (fbd_feedback_profile_get_name (profile), ==, PROFILE_NAME);
}

static void
test_fbd_feedback_profile_feedbacks (void)
{
  GHashTable *feedbacks;
  FbdFeedbackBase *fb;
  g_autoptr (FbdFeedbackDummy) fb1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY,
						   "event-name", "event1",
						   NULL);
  g_autoptr (FbdFeedbackDummy) fb2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY,
						   "event-name", "event2",
						   NULL);
  g_autoptr(FbdFeedbackProfile) profile = fbd_feedback_profile_new (PROFILE_NAME);

  g_assert_true (FBD_IS_FEEDBACK_PROFILE (profile));
  g_object_get (profile, "feedbacks", &feedbacks, NULL);
  g_assert_nonnull (feedbacks);
  g_hash_table_unref (feedbacks);
  fbd_feedback_profile_add_feedback (profile, FBD_FEEDBACK_BASE(fb1));
  fbd_feedback_profile_add_feedback (profile, FBD_FEEDBACK_BASE(fb2));

  fb = fbd_feedback_profile_get_feedback (profile, "event1");
  g_assert_cmpstr (fbd_feedback_get_event_name (fb), ==, "event1");

  fb = fbd_feedback_profile_get_feedback (profile, "does-not-exist");
  g_assert_null (fb);
}

static void
test_fbd_feedback_profile_parse (void)
{
  const char *json ="                             "
        "    {                                    "
        "      \"name\" : \"full\",               "
        "      \"feedbacks\" : [                  "
        "        {                                "
        "          \"type\" : \"vibra\",          "
        "          \"event-name\" : \"event1\"    "
        "        },                               "
        "        {                                "
        "          \"type\" : \"dummy\",          "
        "          \"event-name\" : \"event2\"    "
        "        }                                "
        "      ]                                  "
        "    }                                    ";
  g_autoptr (GError) err = NULL;
  g_autoptr (FbdFeedbackProfile) profile = NULL;
  g_autoptr (JsonNode) node = NULL;
  FbdFeedbackBase *fb;

  node = json_from_string(json, &err);
  g_assert_no_error (err);
  profile = FBD_FEEDBACK_PROFILE (json_gobject_deserialize (FBD_TYPE_FEEDBACK_PROFILE, node));
  g_assert_nonnull (profile);
  fb = fbd_feedback_profile_get_feedback (profile, "event2");
  g_assert_true (FBD_IS_FEEDBACK_DUMMY(fb));
  fb = fbd_feedback_profile_get_feedback (profile, "event1");
  g_assert_true (FBD_IS_FEEDBACK_VIBRA(fb));
}


static void
test_fbd_feedback_profile_update (void)
{
  FbdFeedbackBase *fb;
  FbdFeedbackProfile *a = fbd_feedback_profile_new (PROFILE_NAME);
  FbdFeedbackProfile *b = fbd_feedback_profile_new (PROFILE_NAME);

  g_autoptr (FbdFeedbackDummy) fb_a_1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY,
                                                      "event-name", "a-1",
                                                      NULL);
  g_autoptr (FbdFeedbackDummy) fb_a_2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY,
                                                      "event-name", "a-2",
                                                      NULL);
  /* New event */
  g_autoptr (FbdFeedbackDummy) fb_b_1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY,
                                                      "event-name", "b-1",
                                                      NULL);
  /* overwrite existing event */
  g_autoptr (FbdFeedbackDummy) fb_b_2 = g_object_new (FBD_TYPE_FEEDBACK_VIBRA,
                                                      "event-name", "a-2",
                                                      NULL);

  fbd_feedback_profile_add_feedback (a, FBD_FEEDBACK_BASE(fb_a_1));
  fbd_feedback_profile_add_feedback (a, FBD_FEEDBACK_BASE(fb_a_2));

  fbd_feedback_profile_add_feedback (b, FBD_FEEDBACK_BASE(fb_b_1));
  fbd_feedback_profile_add_feedback (b, FBD_FEEDBACK_BASE(fb_b_2));

  fbd_feedback_profile_update (a,b);

  fb = fbd_feedback_profile_get_feedback (a, "a-1");
  g_assert_true (FBD_IS_FEEDBACK_DUMMY(fb));
  fb = fbd_feedback_profile_get_feedback (a, "a-2");
  g_assert_true (FBD_IS_FEEDBACK_VIBRA(fb));
  fb = fbd_feedback_profile_get_feedback (a, "b-1");
  g_assert_true (FBD_IS_FEEDBACK_DUMMY(fb));

  g_assert_finalize_object (b);
  g_assert_finalize_object (a);
}


gint
main (gint argc, gchar *argv[])
{
  g_test_init (&argc, &argv, NULL);

  g_test_add_func("/feedbackd/fbd/feedback-profile/name", test_fbd_feedback_profile_name);
  g_test_add_func("/feedbackd/fbd/feedback-profile/feedbacks", test_fbd_feedback_profile_feedbacks);
  g_test_add_func("/feedbackd/fbd/feedback-profile/parse", test_fbd_feedback_profile_parse);
  g_test_add_func("/feedbackd/fbd/feedback-profile/update", test_fbd_feedback_profile_update);

  return g_test_run();
}
070701000000A7000081A400000000000000000000000166F7A51300001DE4000000000000000000000000000000000000003000000000feedbackd-0.5.0/tests/test-fbd-feedback-theme.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "fbd-feedback-dummy.h"
#include "fbd-feedback-theme.h"

#include <json-glib/json-glib.h>

#define THEME_NAME "test"

static void
test_fbd_feedback_theme_name (void)
{
  g_autoptr(FbdFeedbackTheme) theme = fbd_feedback_theme_new (THEME_NAME);

  g_assert_true (FBD_IS_FEEDBACK_THEME (theme));

  g_assert_cmpstr (fbd_feedback_theme_get_name (theme), ==, THEME_NAME);
}

static void
test_fbd_feedback_theme_profiles (void)
{
  g_autoptr (FbdFeedbackDummy) quiet_fb1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY,
							 "event-name", "event1",
							 NULL);
  g_autoptr (FbdFeedbackDummy) quiet_fb2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY,
							 "event-name", "event2",
							 NULL);
  g_autoptr (FbdFeedbackDummy) full_fb1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY,
							"event-name", "event1",
							NULL);
  g_autoptr (FbdFeedbackDummy) full_fb2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY,
							"event-name", "event2",
							NULL);
  FbdFeedbackTheme *theme = fbd_feedback_theme_new (THEME_NAME);
  FbdFeedbackProfile *profile_full = fbd_feedback_profile_new ("full");
  FbdFeedbackProfile *profile_quiet = fbd_feedback_profile_new ("quiet");
  FbdFeedbackProfile *profile;
  g_autofree char *json = NULL;

  fbd_feedback_profile_add_feedback (profile_quiet, FBD_FEEDBACK_BASE(quiet_fb1));
  fbd_feedback_profile_add_feedback (profile_quiet, FBD_FEEDBACK_BASE(quiet_fb2));

  fbd_feedback_profile_add_feedback (profile_full, FBD_FEEDBACK_BASE(full_fb1));
  fbd_feedback_profile_add_feedback (profile_full, FBD_FEEDBACK_BASE(full_fb2));

  g_assert_true (FBD_IS_FEEDBACK_THEME (theme));
  fbd_feedback_theme_add_profile (theme, profile_quiet);
  fbd_feedback_theme_add_profile (theme, profile_full);

  profile = fbd_feedback_theme_get_profile (theme, "full");
  g_assert_true (FBD_IS_FEEDBACK_PROFILE (profile));

  json = json_gobject_to_data (G_OBJECT(theme), NULL);
  g_print ("%s\n", json);

  g_assert_finalize_object (theme);
  g_assert_finalize_object (profile_full);
  g_assert_finalize_object (profile_quiet);
}


static void
test_fbd_feedback_theme_parse (void)
{
  const char *json ="                             "
        "{                                        "
        "  \"name\" : \"test\",                   "
        "  \"parent-name\" : \"parent-test\",     "
        "  \"profiles\" : [                       "
        "    {                                    "
        "      \"name\" : \"full\",               "
        "      \"feedbacks\" : [                  "
        "        {                                "
        "          \"type\" : \"dummy\",          "
        "          \"event-name\" : \"event1\"    "
        "        },                               "
        "        {                                "
        "          \"type\" : \"dummy\",          "
        "          \"event-name\" : \"event2\"    "
        "        }                                "
        "      ]                                  "
        "    },                                   "
        "    {                                    "
        "      \"name\" : \"quiet\",              "
        "      \"feedbacks\" : [                  "
        "        {                                "
        "          \"type\" : \"dummy\",          "
        "          \"event-name\" : \"event1\"    "
        "        },                               "
        "        {                                "
        "          \"type\" : \"dummy\",          "
        "          \"event-name\" : \"event2\"    "
        "        }                                "
        "      ]                                  "
        "    }                                    "
        "  ]                                      "
        "}                                        ";
  g_autoptr (GError) err = NULL;
  g_autoptr (FbdFeedbackTheme) theme = NULL;
  FbdFeedbackProfile *profile;
  const char *name;

  theme = fbd_feedback_theme_new_from_data (json, &err);
  g_assert_no_error (err);
  g_assert_nonnull (theme);

  name = fbd_feedback_theme_get_name (theme);
  g_assert_cmpstr ("test", ==, name);

  name = fbd_feedback_theme_get_parent_name (theme);
  g_assert_cmpstr ("parent-test", ==, name);

  profile = fbd_feedback_theme_get_profile (theme, "full");
  g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
  g_assert_cmpstr ("full", ==,
		   fbd_feedback_profile_get_name (profile));
  profile = fbd_feedback_theme_get_profile (theme, "quiet");
  g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
  g_assert_cmpstr ("quiet", ==,
		   fbd_feedback_profile_get_name (profile));
}


static void
test_fbd_feedback_theme_update (void)
{
  g_autoptr (GError) err = NULL;
  FbdFeedbackTheme *theme, *from;
  FbdFeedbackProfile *profile;
  FbdFeedbackBase *fb;
  const char *name;

  /* test-dummy-1x feedbacks */
  from = fbd_feedback_theme_new_from_file (TEST_DATA_DIR "/parent/test.json", &err);
  g_assert_no_error (err);
  g_assert_true (FBD_IS_FEEDBACK_THEME (from));

  /* test-dummy-0{0,1} feedbacks */
  theme = fbd_feedback_theme_new_from_file (TEST_DATA_DIR "/parent/base.json", &err);
  g_assert_no_error (err);
  g_assert_true (FBD_IS_FEEDBACK_THEME (theme));

  name = fbd_feedback_theme_get_name (from);
  g_assert_cmpstr ("test", ==, name);

  name = fbd_feedback_theme_get_name (theme);
  g_assert_cmpstr ("base", ==, name);

  /* `theme` is lacking "silent" while `from` has it */
  profile = fbd_feedback_theme_get_profile (theme, "silent");
  g_assert_null (profile);
  profile = fbd_feedback_theme_get_profile (from, "silent");
  g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));

  fbd_feedback_theme_update (theme, from);

  /* After merging `theme` has a silent profile too */
  profile = fbd_feedback_theme_get_profile (theme, "silent");
  g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
  g_assert_cmpstr ("silent", ==, fbd_feedback_profile_get_name (profile));

  /* Name updated */
  name = fbd_feedback_theme_get_name (theme);
  g_assert_cmpstr ("test", ==, name);

  /* test-dummy-10 added */
  profile = fbd_feedback_theme_get_profile (theme, "full");
  fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-10");
  g_assert_cmpstr ("test-dummy-10", ==, fbd_feedback_get_event_name (fb));
  profile = fbd_feedback_theme_get_profile (theme, "quiet");
  fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-10");
  g_assert_cmpstr ("test-dummy-10", ==, fbd_feedback_get_event_name (fb));
  profile = fbd_feedback_theme_get_profile (theme, "silent");
  fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-10");
  g_assert_cmpstr ("test-dummy-10", ==, fbd_feedback_get_event_name (fb));

  /* test-dummy-00 updated */
  profile = fbd_feedback_theme_get_profile (theme, "full");
  fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-00");
  g_assert_cmpstr ("test-dummy-00", ==, fbd_feedback_get_event_name (fb));
  g_assert_cmpint (fbd_feedback_dummy_get_duration (FBD_FEEDBACK_DUMMY (fb)), ==, 0x10);

  g_assert_finalize_object (from);
  g_assert_finalize_object (theme);
}


gint
main (gint argc, gchar *argv[])
{
  g_test_init (&argc, &argv, NULL);

  g_test_add_func("/feedbackd/fbd/feedback-theme/name", test_fbd_feedback_theme_name);
  g_test_add_func("/feedbackd/fbd/feedback-theme/profiles", test_fbd_feedback_theme_profiles);
  g_test_add_func("/feedbackd/fbd/feedback-theme/parse", test_fbd_feedback_theme_parse);
  g_test_add_func("/feedbackd/fbd/feedback-theme/update", test_fbd_feedback_theme_update);

  return g_test_run();
}
070701000000A8000081A400000000000000000000000166F7A51300001409000000000000000000000000000000000000003000000000feedbackd-0.5.0/tests/test-fbd-theme-expander.c/*
 * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org>
 *
 * SPDX-License-Identifier: GPL-3.0+
 */

#include "fbd-feedback-dummy.h"
#include "fbd-theme-expander.h"

#include <json-glib/json-glib.h>


static void
test_fbd_theme_expander_object (void)
{
  g_autoptr (FbdThemeExpander) expander = g_object_new (FBD_TYPE_THEME_EXPANDER, NULL);

  g_assert_cmpstr ("default", ==, fbd_theme_expander_get_theme_name (expander));
  g_assert_null (fbd_theme_expander_get_theme_file (expander));
  g_assert_null (fbd_theme_expander_get_compatibles (expander));
}

static void
test_fbd_theme_expander_device (void)
{
  g_autoptr (GError) err = NULL;
  const char *compatibles[] = { NULL, NULL };
  FbdFeedbackProfile *profile;
  FbdThemeExpander *expander;
  FbdFeedbackTheme *theme;
  FbdFeedbackBase *fb;
  const char *const *compatibles2;

  /* just the default profile */
  compatibles[0] = "doesnotexist";
  expander = fbd_theme_expander_new (compatibles, NULL, NULL);
  g_assert_cmpstr ("default", ==, fbd_theme_expander_get_theme_name (expander));

  theme = fbd_theme_expander_load_theme_files (expander, &err);
  compatibles2 = fbd_theme_expander_get_compatibles (expander);
#if GLIB_CHECK_VERSION(2, 68, 0)
  g_assert_cmpstrv (compatibles2, compatibles);
#endif
  g_assert_no_error (err);
  profile = fbd_feedback_theme_get_profile (theme, "silent");
  g_assert_null (profile);
  profile = fbd_feedback_theme_get_profile (theme, "quiet");
  g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
  profile = fbd_feedback_theme_get_profile (theme, "full");
  g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
  g_assert_finalize_object (theme);
  g_assert_finalize_object (expander);

  /* Empty device theme that just chains up */
  compatibles[0] = "chainup";
  expander = fbd_theme_expander_new (compatibles, NULL, NULL);
  compatibles2 = fbd_theme_expander_get_compatibles (expander);
#if GLIB_CHECK_VERSION(2, 68, 0)
  g_assert_cmpstrv (compatibles2, compatibles);
#endif
  theme = fbd_theme_expander_load_theme_files (expander, &err);
  g_assert_no_error (err);
  profile = fbd_feedback_theme_get_profile (theme, "silent");
  g_assert_null (profile);
  profile = fbd_feedback_theme_get_profile (theme, "quiet");
  g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
  profile = fbd_feedback_theme_get_profile (theme, "full");
  g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
  g_assert_finalize_object (theme);
  g_assert_finalize_object (expander);

  /* Replace an existing event */
  compatibles[0] = "replace";
  expander = fbd_theme_expander_new (compatibles, NULL, NULL);
  compatibles2 = fbd_theme_expander_get_compatibles (expander);
#if GLIB_CHECK_VERSION(2, 68, 0)
  g_assert_cmpstrv (compatibles2, compatibles);
#endif
  theme = fbd_theme_expander_load_theme_files (expander, &err);
  g_assert_no_error (err);
  profile = fbd_feedback_theme_get_profile (theme, "full");
  g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
  fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-0");
  g_assert_cmpstr ("test-dummy-0", ==, fbd_feedback_get_event_name (fb));
  g_assert_cmpint (fbd_feedback_dummy_get_duration (FBD_FEEDBACK_DUMMY (fb)), ==, 0x10);
  g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
  fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-2");
  g_assert_cmpstr ("test-dummy-2", ==, fbd_feedback_get_event_name (fb));
  g_assert_cmpint (fbd_feedback_dummy_get_duration (FBD_FEEDBACK_DUMMY (fb)), ==, 0x20);
  g_assert_finalize_object (theme);
  g_assert_finalize_object (expander);
}

static void
test_fbd_theme_expander_custom (void)
{
  g_autoptr (GError) err = NULL;
  const char *compatibles[] = { NULL, NULL };
  FbdFeedbackProfile *profile;
  FbdThemeExpander *expander;
  FbdFeedbackTheme *theme;
  FbdFeedbackBase *fb;

  /* Load a custom theme that overrides a single event on top of the `replace` from above */
  compatibles[0] = "replace";
  expander = fbd_theme_expander_new (compatibles, "custom", NULL);
  theme = fbd_theme_expander_load_theme_files (expander, &err);
  g_assert_no_error (err);
  profile = fbd_feedback_theme_get_profile (theme, "full");
  g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
  fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-0");
  g_assert_cmpstr ("test-dummy-0", ==, fbd_feedback_get_event_name (fb));
  g_assert_cmpint (fbd_feedback_dummy_get_duration (FBD_FEEDBACK_DUMMY (fb)), ==, 0x10);
  g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile));
  fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-2");
  g_assert_cmpstr ("test-dummy-2", ==, fbd_feedback_get_event_name (fb));
  g_assert_cmpint (fbd_feedback_dummy_get_duration (FBD_FEEDBACK_DUMMY (fb)), ==, 0x30);
  g_assert_finalize_object (theme);
  g_assert_finalize_object (expander);
}

gint
main (int argc, char *argv[])
{
  g_test_init (&argc, &argv, NULL);

  g_test_add_func("/feedbackd/fbd/theme-expander/object", test_fbd_theme_expander_object);
  g_test_add_func("/feedbackd/fbd/theme-expander/device", test_fbd_theme_expander_device);
  g_test_add_func("/feedbackd/fbd/theme-expander/custom", test_fbd_theme_expander_custom);

  return g_test_run();
}
070701000000A9000081A400000000000000000000000166F7A51300000998000000000000000000000000000000000000002700000000feedbackd-0.5.0/tests/test-lfb-event.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "libfeedback.h"
#include <gio/gio.h>

/* Property set/get */
static void
test_lfb_event_props (void)
{
  g_autoptr(LfbEvent) event = NULL;
  g_autofree gchar *evname = NULL;
  g_autofree gchar *profile = NULL;
  g_autofree gchar *app_id = NULL;
  gboolean important;
  gint timeout;

  g_assert_true (lfb_init (TEST_APP_ID, NULL));

  event = lfb_event_new ("window-close");
  g_assert_true (LFB_IS_EVENT (event));

  g_object_get (event,
                "event", &evname,
                "timeout", &timeout,
                "feedback-profile", &profile,
                "app-id", &app_id,
                "important", &important,
                NULL);
  g_assert_cmpstr (evname, ==, "window-close");
  g_assert_cmpint (timeout, ==, -1);
  g_assert_null (profile);
  g_assert_false (important);
  g_assert_null (app_id);

  g_assert_cmpint (lfb_event_get_end_reason (event), ==, LFB_EVENT_END_REASON_NATURAL);
  g_assert_cmpint (lfb_event_get_state (event), ==, LFB_EVENT_STATE_NONE);

  g_object_set (event, "feedback-profile", "full", NULL);
  g_object_get (event, "feedback-profile", &profile, NULL);
  g_assert_cmpstr (profile, ==, "full");
  g_assert_cmpstr (lfb_event_get_feedback_profile (event), ==, "full");

  g_object_set (event, "app-id", "com.example.foo", NULL);
  g_object_get (event, "app-id", &app_id, NULL);
  g_assert_cmpstr (app_id, ==, "com.example.foo");
  g_assert_cmpstr (lfb_event_get_app_id (event), ==, "com.example.foo");

  lfb_uninit ();
}

/* Test failure paths when no feedback daemon is running */
static void
test_lfb_event_trigger (void)
{
  g_autoptr(LfbEvent) event = NULL;
  g_autoptr (GError) err = NULL;

  g_assert_true (lfb_init (TEST_APP_ID, NULL));

  event = lfb_event_new ("window-close");
  g_assert_false (lfb_event_trigger_feedback (event, &err));
  g_assert_nonnull (err);
  g_clear_error (&err);

  g_assert_false (lfb_event_end_feedback (event, &err));
  g_assert_nonnull (err);
  g_clear_error (&err);

  lfb_uninit ();
}

gint
main (gint argc, gchar *argv[])
{
  g_test_init (&argc, &argv, NULL);

  g_autoptr(GTestDBus) bus = g_test_dbus_new (0);
  g_test_dbus_up (bus);

  g_test_add_func("/feedbackd/libfeedback/lfb-event/props", test_lfb_event_props);
  g_test_add_func("/feedbackd/libfeedback/lfb-event/trigger", test_lfb_event_trigger);

  return g_test_run();
}
070701000000AA000081A400000000000000000000000166F7A51300002C4A000000000000000000000000000000000000002D00000000feedbackd-0.5.0/tests/test-lfb-integration.c/*
 * Copyright (C) 2020 Purism SPC
 * SPDX-License-Identifier: GPL-3.0+
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "libfeedback.h"
#include <gio/gio.h>

typedef struct {
  GTestDBus *dbus;

} TestFixture;

GMainLoop *mainloop;

static void
fixture_setup (TestFixture *fixture, gconstpointer unused)
{
  g_autoptr (GError) err = NULL;
  gchar *relative, *servicesdir;
  gint success;

  fixture->dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
  relative = g_test_build_filename (G_TEST_BUILT, "services", NULL);
  servicesdir = g_canonicalize_filename (relative, NULL);
  g_free (relative);

  g_test_dbus_add_service_dir (fixture->dbus, servicesdir);
  g_free (servicesdir);
  g_setenv ("FEEDBACK_THEME", TEST_DATA_DIR "/test.json", TRUE);
  g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
  g_test_dbus_up (fixture->dbus);

  g_assert_null (mainloop);
  mainloop = g_main_loop_new (NULL, FALSE);

  success = lfb_init (TEST_APP_ID, &err);
  g_assert_no_error (err);
  g_assert_true (success);
}

static void
fixture_teardown (TestFixture *fixture, gconstpointer unused)
{
  g_clear_pointer (&mainloop, g_main_loop_unref);
  lfb_uninit ();

  g_test_dbus_down (fixture->dbus);
  g_object_unref (fixture->dbus);
}

static void
on_feedback_ended (LfbEvent *event, LfbEvent **cmp)
{
  g_assert_true (LFB_IS_EVENT (event));
  g_assert_null (*cmp);

  g_debug ("Feedback ended for %s: %d",
	   lfb_event_get_event (event),
	   lfb_event_get_end_reason (event));

  g_assert_cmpint (lfb_event_get_state (event), ==, LFB_EVENT_STATE_ENDED);

  /* "Return" event */
  *cmp = event;
}

static void
test_lfb_integration_event_sync (void)
{
  g_autoptr(LfbEvent) event0 = NULL;
  g_autoptr(LfbEvent) event10 = NULL;
  g_autoptr (GError) err = NULL;
  LfbEvent *cmp = NULL;
  gboolean success;

  event0 = lfb_event_new ("test-dummy-0");
  success = lfb_event_trigger_feedback (event0, &err);
  g_assert_no_error (err);
  g_assert_true (success);

  event10 = lfb_event_new ("test-dummy-10");
  g_signal_connect (event10, "feedback-ended", (GCallback)on_feedback_ended, &cmp);
  g_signal_connect_swapped (event10, "feedback-ended", (GCallback)g_main_loop_quit, mainloop);
  success = lfb_event_trigger_feedback (event10, &err);
  g_assert_no_error (err);
  g_assert_true (success);

  success = lfb_event_end_feedback (event10, &err);
  g_assert_no_error (err);
  g_assert_true (success);

  g_main_loop_run (mainloop);

  /* If the signal fired cmp will match event */
  g_assert_true (event10 == cmp);
  g_assert_cmpint (lfb_event_get_state (event10), ==, LFB_EVENT_STATE_ENDED);
  g_assert_cmpint (lfb_event_get_end_reason (event10), ==, LFB_EVENT_END_REASON_EXPLICIT);
}

static void
test_lfb_integration_event_not_found (void)
{
  g_autoptr(LfbEvent) event0 = NULL;
  g_autoptr (GError) err = NULL;
  LfbEvent *cmp = NULL;
  gboolean success;

  event0 = lfb_event_new ("test-does-not-exist");
  g_signal_connect (event0, "feedback-ended", (GCallback)on_feedback_ended, &cmp);
  g_signal_connect_swapped (event0, "feedback-ended", (GCallback)g_main_loop_quit, mainloop);
  success = lfb_event_trigger_feedback (event0, &err);
  g_assert_no_error (err);
  g_assert_true (success);

  g_main_loop_run (mainloop);

  /* If the signal fired cmp will match event */
  g_assert_true (event0 == cmp);
  g_assert_cmpint (lfb_event_get_state (event0), ==, LFB_EVENT_STATE_ENDED);
  g_assert_cmpint (lfb_event_get_end_reason (event0), ==, LFB_EVENT_END_REASON_NOT_FOUND);
}

static void
on_event_triggered (LfbEvent      *event,
                    GAsyncResult  *res,
                    LfbEvent     **cmp)
{
  g_autoptr (GError) err = NULL;
  gboolean success;

  g_assert_true (LFB_IS_EVENT (event));
  g_assert_null (*cmp);

  g_debug ("%s: %p, %s", __func__, event, lfb_event_get_event (event));
  success = lfb_event_trigger_feedback_finish (event, res, &err);
  g_assert_no_error (err);
  g_assert_true (success);

  g_assert_cmpint (lfb_event_get_state (event), ==, LFB_EVENT_STATE_RUNNING);

  /* "Return" event */
  *cmp = event;
}

static void
on_event_triggered_quit (LfbEvent      *event,
                         GAsyncResult  *res,
                         LfbEvent     **cmp)
{
  g_autoptr (GError) err = NULL;
  gboolean success;

  g_assert_true (LFB_IS_EVENT (event));
  g_assert_null (*cmp);

  g_debug ("%s: %p, %s", __func__, event, lfb_event_get_event (event));
  success = lfb_event_trigger_feedback_finish (event, res, &err);
  g_assert_no_error (err);
  g_assert_true (success);

  g_assert_cmpint (lfb_event_get_state (event), ==, LFB_EVENT_STATE_RUNNING);

  /* "Return" event */
  *cmp = event;
  g_main_loop_quit (mainloop);
}

static void
on_event_end_finished (LfbEvent      *event,
                       GAsyncResult  *res,
                       LfbEvent     **cmp)
{
  g_autoptr (GError) err = NULL;
  gboolean success;

  g_debug ("%s: %p, %s", __func__, event, lfb_event_get_event (event));
  g_assert_true (LFB_IS_EVENT (event));
  g_assert_null (*cmp);

  success = lfb_event_end_feedback_finish (event, res, &err);
  g_assert_no_error (err);
  g_assert_true (success);

  /* This is not guaranteed for all types of feedback, see `feedback-ended` */
  g_assert_cmpint (lfb_event_get_state (event), ==, LFB_EVENT_STATE_ENDED);

  /* "Return" event */
  *cmp = event;
  g_main_loop_quit (mainloop);
}

static void
test_lfb_integration_event_not_found_async (void)
{
  g_autoptr(LfbEvent) event0 = NULL;
  LfbEvent *cmp = NULL;
  LfbEvent *cmp2 = NULL;

  event0 = lfb_event_new ("test-does-not-exist");
  g_signal_connect (event0, "feedback-ended", (GCallback)on_feedback_ended, &cmp2);

  /* The main loop will only quit if the "feedback-ended" signal actually gets emitted */
  g_signal_connect_swapped (event0, "feedback-ended", (GCallback)g_main_loop_quit, mainloop);

  lfb_event_trigger_feedback_async (event0,
                                    NULL,
                                    (GAsyncReadyCallback)on_event_triggered,
                                    &cmp);
  g_main_loop_run (mainloop);

  /* If the signal fired cmp will match event */
  g_assert_true (event0 == cmp);
  g_assert_true (event0 == cmp2);
  g_assert_cmpint (lfb_event_get_state (event0), ==, LFB_EVENT_STATE_ENDED);
  g_assert_cmpint (lfb_event_get_end_reason (event0), ==, LFB_EVENT_END_REASON_NOT_FOUND);
}

static void
test_lfb_integration_event_async (void)
{
  g_autoptr(LfbEvent) event0 = NULL;
  g_autoptr(LfbEvent) event10 = NULL;
  LfbEvent *cmp1 = NULL, *cmp2 = NULL, *cmp3 = NULL;

  event0 = lfb_event_new ("test-dummy-0");
  lfb_event_trigger_feedback_async (event0,
                                    NULL,
                                    (GAsyncReadyCallback)on_event_triggered_quit,
                                    &cmp1);
  g_main_loop_run (mainloop);
  /* The async finish callback saw the right event */
  g_assert_true (event0 == cmp1);
  cmp1 = NULL;

  event10 = lfb_event_new ("test-dummy-10");
  lfb_event_set_timeout (event10, 1);
  g_assert_cmpint (lfb_event_get_timeout (event10), ==, 1);
  lfb_event_set_feedback_profile (event10, "quiet");
  lfb_event_set_important (event10, FALSE);
  g_signal_connect (event10, "feedback-ended", (GCallback)on_feedback_ended, &cmp1);

  /* The async callback ends the main loop */
  lfb_event_trigger_feedback_async (event10,
                                    NULL,
                                    (GAsyncReadyCallback)on_event_triggered_quit,
                                    &cmp2);
  g_main_loop_run (mainloop);

  /* The async callback ends the main loop */
  lfb_event_end_feedback_async (event10,
                                NULL,
                                (GAsyncReadyCallback)on_event_end_finished,
                                &cmp3);
  g_main_loop_run (mainloop);

  /* Check if callbacks saw the right event */
  g_assert_true (event10 == cmp1);
  g_assert_true (event10 == cmp2);
  g_assert_true (event10 == cmp3);
  g_assert_cmpint (lfb_event_get_state (event10), ==, LFB_EVENT_STATE_ENDED);
  g_assert_cmpint (lfb_event_get_end_reason (event10), ==, LFB_EVENT_END_REASON_EXPLICIT);
}


static void
on_event_with_error_triggered (LfbEvent      *event,
			       GAsyncResult  *res,
			       LfbEvent     **cmp)
{
  g_autoptr (GError) err = NULL;
  gboolean success;

  g_debug ("%s: %p, %s", __func__, event, lfb_event_get_event (event));
  g_assert_true (LFB_IS_EVENT (event));
  g_assert_null (*cmp);

  success = lfb_event_end_feedback_finish (event, res, &err);
  g_assert_false (success);
  g_assert_error (err, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS);

  /* "Return" event */
  *cmp = event;
  g_main_loop_quit (mainloop);
}


static void
test_lfb_integration_event_async_error (void)
{
  g_autoptr(LfbEvent) event0 = NULL;
  LfbEvent *cmp1 = NULL;

  /* Empty event names are invalid */
  event0 = lfb_event_new ("");
  lfb_event_trigger_feedback_async (event0,
                                    NULL,
                                    (GAsyncReadyCallback)on_event_with_error_triggered,
                                    &cmp1);
  g_main_loop_run (mainloop);
  /* The async finish callback saw the right event */
  g_assert_true (event0 == cmp1);
}


static void
on_profile_changed (LfbGdbusFeedback *proxy, GParamSpec *psepc, const gchar **profile)
{
  g_assert_null (*profile);
  *profile = lfb_get_feedback_profile();
  g_debug("Set feedback profile to: '%s'", *profile);

  g_main_loop_quit (mainloop);
}

static void
test_lfb_integration_profile (void)
{
  LfbGdbusFeedback *proxy;
  gchar *cmp = NULL;

  g_assert_cmpstr (lfb_get_feedback_profile (), ==, "full");
  proxy = lfb_get_proxy ();
  g_assert_nonnull (proxy);

  lfb_set_feedback_profile ("quiet");
  g_signal_connect (proxy, "notify::profile", (GCallback)on_profile_changed, &cmp);
  g_main_loop_run (mainloop);
  g_assert_cmpstr (lfb_get_feedback_profile (), ==, "quiet");
  g_assert_cmpstr (cmp, ==, "quiet");
}

gint
main (gint argc, gchar *argv[])
{
  g_test_init (&argc, &argv, NULL);

  g_test_add("/feedbackd/lfb-integration/event_sync", TestFixture, NULL,
             (gpointer)fixture_setup,
             (gpointer)test_lfb_integration_event_sync,
             (gpointer)fixture_teardown);

  g_test_add("/feedbackd/lfb-integration/event_async/success", TestFixture, NULL,
             (gpointer)fixture_setup,
             (gpointer)test_lfb_integration_event_async,
             (gpointer)fixture_teardown);

  g_test_add("/feedbackd/lfb-integration/event_async/error", TestFixture, NULL,
             (gpointer)fixture_setup,
             (gpointer)test_lfb_integration_event_async_error,
             (gpointer)fixture_teardown);

  g_test_add("/feedbackd/lfb-integration/event_not_found", TestFixture, NULL,
             (gpointer)fixture_setup,
             (gpointer)test_lfb_integration_event_not_found,
             (gpointer)fixture_teardown);

  g_test_add("/feedbackd/lfb-integration/event_not_found_async", TestFixture, NULL,
             (gpointer)fixture_setup,
             (gpointer)test_lfb_integration_event_not_found_async,
             (gpointer)fixture_teardown);

  g_test_add("/feedbackd/lfb-integration/profile", TestFixture, NULL,
             (gpointer)fixture_setup,
             (gpointer)test_lfb_integration_profile,
             (gpointer)fixture_teardown);

  return g_test_run();
}
070701000000AB000081A400000000000000000000000166F7A51300000343000000000000000000000000000000000000002000000000feedbackd-0.5.0/tests/testlib.c/*
 * Copyright (C) 2024 The Phosh Developers
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "testlib.h"

void
fbd_test_umockdev_setup (FbdUmockdevFixture *fixture, gconstpointer mockname)
{
  g_autofree char *path = NULL;
  g_autoptr (GError) err = NULL;
  gboolean success;

  fixture->testbed = umockdev_testbed_new ();
  path = g_strdup_printf("%s/umockdev/%s.umockdev", TEST_DATA_DIR, (const char *)mockname);

  success = umockdev_testbed_add_from_file (fixture->testbed, path, &err);
  g_assert_no_error (err);
  g_assert_true (success);

  umockdev_testbed_enable (fixture->testbed);
}


void
fbd_test_umockdev_teardown (FbdUmockdevFixture *fixture, gconstpointer unused)
{
  umockdev_testbed_clear (fixture->testbed);
  umockdev_testbed_disable (fixture->testbed);
}
070701000000AC000081A400000000000000000000000166F7A5130000032D000000000000000000000000000000000000002000000000feedbackd-0.5.0/tests/testlib.h/*
 * Copyright (C) 2024 The Phosh Developers
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include <glib.h>
#include <umockdev.h>

#pragma once

G_BEGIN_DECLS

typedef struct _FbdUdevMockFixture {
  UMockdevTestbed *testbed;
} FbdUmockdevFixture;


void fbd_test_umockdev_setup (FbdUmockdevFixture *fixture, gconstpointer mockname);
void fbd_test_umockdev_teardown (FbdUmockdevFixture *fixture, gconstpointer unused);

#define FBD_UMOCKDEV_TEST_ADD(name, func, f) g_test_add ((name), FbdUmockdevFixture, (f),  \
                                                         (gpointer)fbd_test_umockdev_setup, \
                                                         (gpointer)(func),                  \
                                                         (gpointer)fbd_test_umockdev_teardown)
G_END_DECLS
07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!1024 blocks
openSUSE Build Service is sponsored by