<commit_before>/*
 * Copyright (C) 2011 <NAME> <<EMAIL>>
 *
 * 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
 *
 */

using GLib;

DBusConnection conn = null;
string active_token;
bool registered;

static const string FSOAUDIO_BUSNAME = "org.freesmartphone.oaudiod";
static const string FSOAUDIO_PATH = "/org/freesmartphone/Audio";
static const string FSOAUDIO_MANAGER_IFNAME = "org.freesmartphone.Audio.Manager";

static const int timeout = 10;

public int fsoaudio_request_session()
{
    registered = false;
    active_token = "";

    try
    {
        conn = Bus.get_sync( BusType.SYSTEM );

        // FIXME currently we default to media stream type. We should choose the right
        // stream according to the device the user wants to open
        var params = new Variant[] {
            new Variant.string( "media" )
        };

        Variant result = conn.call_sync( FSOAUDIO_BUSNAME, FSOAUDIO_PATH, FSOAUDIO_MANAGER_IFNAME,
                                     "RegisterSession", params, VariantType.STRING,
                                     DBusCallFlags.NO_AUTO_START, timeout );

        if ( result.is_of_type( VariantType.STRING ) )
        {
            active_token = result.get_string();
            registered = true;
        }
    }
    catch ( Error err )
    {
    }

    return registered ? 0 : -1;
}

public int fsoaudio_release_session()
{
    if ( registered && conn != null && active_token.length > 0 )
    {
        try
        {
            var params = new Variant[] {
                new Variant.string( active_token )
            };

            Variant result = conn.call_sync( FSOAUDIO_BUSNAME, FSOAUDIO_PATH, FSOAUDIO_MANAGER_IFNAME,
                                             "ReleaseSession", params, VariantType.ANY,
                                             DBusCallFlags.NO_AUTO_START, timeout );

            registered = false;
        }
        catch ( Error err )
        {
        }
    }

    return 0;
}

// vim:ts=4:sw=4:expandtab<commit_msg>fsoaudiod: alsa-hooks: use vala dbus abstraction and get a typified proxy<commit_after>/*
 * Copyright (C) 2011 <NAME> <<EMAIL>>
 *
 * 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
 *
 */

using GLib;

[DBus (name = "org.freesmartphone.Audio.Manager")]
interface AudioManager : Object {
    public abstract string register_session( string name ) throws IOError;
    public abstract void release_session( string token ) throws IOError;
}

AudioManager manager = null;
string active_token;
bool registered;

static const string FSOAUDIO_BUSNAME = "org.freesmartphone.oaudiod";
static const string FSOAUDIO_PATH = "/org/freesmartphone/Audio";
static const string FSOAUDIO_MANAGER_IFNAME = "org.freesmartphone.Audio.Manager";

static const int timeout = 10;

public int fsoaudio_request_session()
{
    registered = false;
    active_token = "";

    try
    {
        manager = Bus.get_proxy_sync( BusType.SYSTEM, FSOAUDIO_BUSNAME, FSOAUDIO_PATH );

        // FIXME currently we default to media stream type. We should choose the right
        // stream according to the device the user wants to open
        active_token = manager.register_session( "media" );
        registered = true;
    }
    catch ( Error err )
    {
    }

    return registered ? 0 : -1;
}

public int fsoaudio_release_session()
{
    if ( registered && manager != null && active_token.length > 0 )
    {
        try
        {
            manager.release_session( active_token );
            registered = false;
        }
        catch ( Error err )
        {
        }
    }

    return 0;
}

// vim:ts=4:sw=4:expandtab
{'fraction_non_alphanumeric': 0.07727913060978064, 'fraction_numerical': 0.01006238679814852, 'mean_word_length': 2.585858585858586, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7303057', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1356, 'n_words': 501}