#ifndef IOS_RINGER_H_
#define IOS_RINGER_H_
/*---------------------------------------------------------------------------*/
/* ios_ringer.h                                                              */
/* copyright (c) innovaphone 2012                                            */
/*                                                                           */
/*---------------------------------------------------------------------------*/

NAMESPACE_BEGIN

/*---------------------------------------------------------------------------*/
/* ios_ringer                                                                */
/*---------------------------------------------------------------------------*/

class ios_ringer_query_devices {};
class ios_ringer_query_ringtones {};
class ios_ringer_query_tones {};
class ios_ringer_close {};

class ios_ringer :  public UIoContext, public IRinger,
    public UIoExecSubclass<ios_ringer_query_devices>,
    public UIoExecSubclass<ios_ringer_query_ringtones>,
    public UIoExecSubclass<ios_ringer_query_tones>,
    public UIoExecSubclass<ios_ringer_close>
{
    void SetExec(IIoMux * iomux, UIoExecSubclass<ios_ringer_query_devices> * ioContext, ios_ringer_query_devices * execContext) { iomux->SetExec(ioContext, execContext); };
    void IoExec(ios_ringer_query_devices * context);
    void SetExec(IIoMux * iomux, UIoExecSubclass<ios_ringer_query_ringtones> * ioContext, ios_ringer_query_ringtones * execContext) { iomux->SetExec(ioContext, execContext); };
    void IoExec(ios_ringer_query_ringtones * context);
    void SetExec(IIoMux * iomux, UIoExecSubclass<ios_ringer_query_tones> * ioContext, ios_ringer_query_tones * execContext) { iomux->SetExec(ioContext, execContext); };
    void IoExec(ios_ringer_query_tones * context);
    void SetExec(IIoMux * iomux, UIoExecSubclass<ios_ringer_close> * ioContext, ios_ringer_close * execContext) { iomux->SetExec(ioContext, execContext); };
    void IoExec(ios_ringer_close * context);

    class IIoMux * iomux;
    class URinger * user;
    class IInstanceLog * log;
    char tag[16]; // AC_DSP:

    const char *tone_title_from_ident(const char *ident, const char *tones, char *title_buffer);

    bool ringtone;

    unsigned int ringtone_count;
    unsigned int ringtone_number;
    const char *ringtone_ptr;
    char ringtone_title[256];
    char ringtone_ident[1024];

    void ringtone_seek(unsigned num);

    unsigned int tone_count;
    unsigned int tone_number;
    const char *tone_ptr;
    char tone_title[256];
    char tone_ident[1024];

    void tone_seek(unsigned num);

    int execCnt;
    bool shutDown;

    void init();
    void finit();

public:
    bool ringing;

    struct SAudioDevices *AudioDevices;
    unsigned AudioDeviceCount;
    void UpdateDeviceList();
    void StartListenDeviceList();
    void StopListenDeviceList();
    int device_change_pipefd[2];
    bool device_change_pipe_created;
    void IoContextNotify(bool indRX, bool indTX);

    ios_ringer(class IIoMux * const iomux, class IInstanceLog * log);
    ~ios_ringer();

    void Initialize(class URinger * const user);
    void QueryDevices(void * context);
    unsigned DeviceCount();
    const char * DeviceId(unsigned deviceNumber);
    enum RingerDeviceType DeviceType(unsigned deviceNumber);
    unsigned DeviceCapabilities(unsigned deviceNumber);
    const char * DeviceName(unsigned deviceNumber);

    void QueryRingtones(void * context);
    unsigned RingtoneCount() { return ringtone_count; }
    const char * RingtoneTitle(unsigned ringtoneNumber);
    const char * RingtoneIdent(unsigned ringtoneNumber);
    void RingtoneStart(const char *deviceId, enum RingerDeviceMode deviceMode, const char *ident);
    void RingtoneStop(const char *deviceId);

    void QueryNotificationTones(void * context);
    unsigned NotificationToneCount() { return tone_count; }
    const char * NotificationToneTitle(unsigned toneNumber);
    const char * NotificationToneIdent(unsigned toneNumber);
    void NotificationTonePlay(const char *deviceId, enum RingerDeviceMode deviceMode, const char *ident);

    void Close();
};


NAMESPACE_END

/*---------------------------------------------------------------------------*/
#endif /* IOS_RINGER_H_ */
