Commit a8e173a5 authored by Arnaud Ferraris's avatar Arnaud Ferraris
Browse files

libcallaudio: add simple wrapper library

parent bcba7508
/*
* Copyright (C) 2020 Purism SPC
* Copyright (C) 2020 Arnaud Ferraris <arnaud.ferraris@gmail.com>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "libcallaudio.h"
#include "callaudiod.h"
#include "callaudio-dbus.h"
/**
* SECTION:libcallaudio
* @Short_description: Call audio control library
* @Title: libcallaudio
*
* To use the library call #call_audio_init().
* After initializing the library you can send audio routing requests using the
* library functions.
* When your application finishes call #call_audio_deinit() to free resources:
*
* |[<!-- language="C" -->
* #include <libcallaudio.h>
*
* int main(void)
* {
* g_autoptr(GError) *err = NULL;
* if (call_audio_init(&err)) {
* g_error("%s", err->message);
* }
* ...
* call_audio_deinit();
* return 0;
* }
* ]|
*/
static CallAudioDbusCallAudio *_proxy;
static gboolean _initted;
/**
* call_audio_init:
* @error: Error information
*
* Initialize libcallaudio. This must be called before any other functions.
*
* Returns: %TRUE if successful, or %FALSE on error.
*/
gboolean call_audio_init(GError **error)
{
if (_initted)
return TRUE;
_proxy = call_audio_dbus_call_audio_proxy_new_for_bus_sync(
CALLAUDIO_DBUS_TYPE, 0, CALLAUDIO_DBUS_NAME, CALLAUDIO_DBUS_PATH, NULL, error);
if (!_proxy)
return FALSE;
g_object_add_weak_pointer(G_OBJECT(_proxy), (gpointer *)&_proxy);
_initted = TRUE;
return TRUE;
}
/**
* call_audio_deinit:
*
* Uninitialize the library when no longer used. Usually called
* on program shutdown.
*/
void call_audio_deinit(void)
{
_initted = FALSE;
g_clear_object(&_proxy);
}
/**
* call_audio_select_mode:
* @mode: Audio mode to select
*
* Select the audio mode to use.
*
* Returns: %TRUE if successful, or %FALSE on error.
*/
gboolean call_audio_select_mode(CallAudioMode mode)
{
guint result;
gboolean ret;
GError *error = NULL;
ret = call_audio_dbus_call_audio_call_select_mode_sync(_proxy, mode,
&result, NULL, &error);
if (error) {
g_critical("Couldn't set mode: %s", error->message);
}
g_debug("SelectMode %s: return %u", ret ? "succeeded" : "failed", result);
return ret;
}
/**
* call_audio_enable_speaker:
* @enable: Desired speaker state
*
* Enable or disable speaker output.
*
* Returns: %TRUE if successful, or %FALSE on error.
*/
gboolean call_audio_enable_speaker(gboolean enable)
{
guint result;
gboolean ret;
GError *error = NULL;
ret = call_audio_dbus_call_audio_call_enable_speaker_sync(_proxy, enable,
&result, NULL, &error);
if (error) {
g_critical("Couldn't enable speaker: %s", error->message);
}
g_debug("EnableSpeaker %s: return %u", ret ? "succeeded" : "failed", result);
return ret;
}
/**
* call_audio_mute_mic:
* @mute: %TRUE to mute the microphone, or %FALSE to unmute it
*
* Mute or unmute microphone.
*
* Returns: %TRUE if successful, or %FALSE on error.
*/
gboolean call_audio_mute_mic(gboolean mute)
{
guint result;
gboolean ret;
GError *error = NULL;
ret = call_audio_dbus_call_audio_call_mute_mic_sync(_proxy, mute,
&result, NULL, &error);
if (error) {
g_critical("Couldn't mute mic: %s", error->message);
}
g_debug("MuteMic %s: return %u", ret ? "succeeded" : "failed", result);
return ret;
}
/*
* Copyright (C) 2020 Purism SPC
* Copyright (C) 2020 Arnaud Ferraris <arnaud.ferraris@gmail.com>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#pragma once
#include <glib.h>
G_BEGIN_DECLS
/**
* CallAudioMode:
* @CALL_AUDIO_MODE_DEFAULT: Default mode (used for music, alarms, ringtones...)
* @CALL_AUDIO_MODE_CALL: Voice call mode
*
* Enum values to indicate the mode to be selected.
*/
typedef enum _CallAudioMode {
CALL_AUDIO_MODE_DEFAULT = 0,
CALL_AUDIO_MODE_CALL,
} CallAudioMode;
gboolean call_audio_init(GError **error);
void call_audio_deinit(void);
gboolean call_audio_select_mode(CallAudioMode mode);
gboolean call_audio_enable_speaker(gboolean enable);
gboolean call_audio_mute_mic(gboolean mute);
G_END_DECLS
LIBCALLAUDIO_0_0_0 {
global:
call_audio_*;
local:
*;
};
# Shared library and language bindings
libcallaudio_libdir = get_option('libdir')
libcallaudio_header_dir = get_option('includedir') / libname
libcallaudio_link_args = []
libcallaudio_symbols_file = 'libcallaudio.syms'
# Check linker flags
ld_version_script_arg = '-Wl,--version-script,@0@'.format(meson.current_source_dir() / libcallaudio_symbols_file)
if cc.links('int main() { return 0; }', args : ld_version_script_arg, name : 'ld_supports_version_script')
libcallaudio_link_args += [ld_version_script_arg]
endif
libcallaudio_headers = [
'libcallaudio.h',
]
libcallaudio_sources = [
generated_dbus_sources,
libcallaudio_headers,
'libcallaudio.c',
]
libcallaudio_deps = [
dependency('gobject-2.0'),
dependency('gio-unix-2.0'),
]
libcallaudio_c_args = [
'-DG_LOG_DOMAIN="libcallaudio"',
'-I../src',
]
libtype = 'shared_library'
libcallaudio = build_target(
'callaudio-' + apiversion,
libcallaudio_sources,
soversion : 0,
c_args : libcallaudio_c_args,
dependencies : libcallaudio_deps,
link_args : libcallaudio_link_args,
install : true,
install_dir : libcallaudio_libdir,
target_type : libtype,
)
libcallaudio_inc = include_directories('.')
libcallaudio_dep = declare_dependency(
sources : [generated_dbus_sources],
link_with : libcallaudio,
dependencies: libcallaudio_deps,
include_directories : libcallaudio_inc,
)
install_headers(libcallaudio_headers, subdir : libname)
pkgconfig = import('pkgconfig')
pkgconfig.generate(
libraries : [libcallaudio],
subdirs : libname,
version : meson.project_version(),
name : 'CallAudio',
filebase : 'libcallaudio-@0@'.format(apiversion),
description : 'call audio library',
requires : 'gio-2.0',
install_dir : join_paths(libcallaudio_libdir, 'pkgconfig'),
)
......@@ -9,7 +9,7 @@ project (
'callaudiod',
'c',
version : '0.0.1',
license : 'GPLv3+',
license : 'LGPLv3+',
meson_version : '>= 0.50.0',
default_options :
[
......@@ -19,12 +19,14 @@ project (
],
)
cc = meson.get_compiler('c')
app_name = meson.project_name()
prefix = get_option('prefix')
datadir = get_option('datadir')
sysconfdir = get_option('sysconfdir')
libdir = join_paths(prefix, get_option('libdir'))
ifacedir = join_paths(prefix, join_paths(datadir, 'dbus-1', 'interfaces'))
if datadir.startswith('/')
......@@ -39,6 +41,8 @@ else
full_sysconfdir = join_paths(prefix, sysconfdir)
endif
apiversion = '0'
libname = 'libcallaudio-' + apiversion
config_data = configuration_data()
config_data.set_quoted('APP_DATA_NAME', app_name)
......@@ -46,4 +50,5 @@ config_data.set_quoted('DATADIR', full_datadir)
config_data.set_quoted('SYSCONFDIR', full_sysconfdir)
subdir('data')
subdir('libcallaudio')
subdir('src')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment