/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"
#include "nsIMobileConnectionProvider.idl"

interface nsIDOMMozMobileConnectionInfo;
interface nsIDOMDOMRequest;
interface nsIDOMWindow;

[scriptable, uuid(c14c71b8-afba-403b-8320-94593de9380f)]
interface nsIRILTelephonyCallback : nsISupports
{
  /**
   * Notified when a telephony call changes state.
   *
   * @param callIndex
   *        Call identifier assigned by the RIL.
   * @param callState
   *        One of the nsIRadioInterfaceLayer::CALL_STATE_* values.
   * @param number
   *        Number of the other party.
   * @param isActive
   *        Indicates whether this call is the currently active one.
   */
  void callStateChanged(in unsigned long callIndex,
                        in unsigned short callState,
                        in AString number,
                        in boolean isActive);

  /**
   * Called when nsIRILContentHelper is asked to enumerate the current
   * telephony call state (nsIRILContentHelper::enumerateCalls). This is
   * called once per call that is currently managed by the RIL.
   *
   * @param callIndex
   *        Call identifier assigned by the RIL.
   * @param callState
   *        One of the nsIRadioInterfaceLayer::CALL_STATE_* values.
   * @param number
   *        Number of the other party.
   * @param isActive
   *        Indicates whether this call is the active one.
   *
   * @return true to continue enumeration or false to cancel.
   */
  boolean enumerateCallState(in unsigned long callIndex,
                             in unsigned short callState,
                             in AString number,
                             in boolean isActive);

  /**
   * Called when RIL error occurs.
   *
   * @param callIndex
   *        Call identifier assigned by the RIL. -1 if no connection
   * @param error
   *        Error from RIL.
   */
  void notifyError(in long callIndex,
                   in AString error);
};

[scriptable, uuid(66a55943-e63b-4731-aece-9c04bfc14019)]
interface nsIRILDataCallInfo : nsISupports
{
  readonly attribute unsigned long callState;
  readonly attribute AString cid;
  readonly attribute AString apn;
};

[scriptable, uuid(cea91bcb-3cfb-42bb-8638-dae89e8870fc)]
interface nsIRILDataCallback : nsISupports
{
  /**
   * Notified when a data call changes state.
   *
   * @param cid
   *        The CID of the data call.
   * @param interfaceName
   *        Name of the associated network interface.
   * @param dataState
   *        One of the nsIRadioInterfaceLayer::DATACALL_STATE_* values.
   */
  void dataCallStateChanged(in AString cid,
                            in AString interfaceName,
                            in unsigned short callState);

  /**
   * Called when nsIRadioInterfaceLayer is asked to enumerate the current
   * data call state.
   *
   * @param datacalls
   *        Array of nsIRILDataCallInfo objects.
   * @param length
   *        Lenght of the aforementioned array.
   */
  void receiveDataCallList([array,size_is(length)] in nsIRILDataCallInfo dataCalls,
                           in unsigned long length);
};

[scriptable, function, uuid(2bc2f51a-78be-4c0e-95dd-55a3ce2ded40)]
interface nsIRILContactCallback : nsISupports
{
  /**
   * Called when nsIRadioInterfaceLayer is asked to provide ICC contacts.
   *
   * @param type
   *        Type of the dialling number, i.e. ADN, FDN.
   * @param contacts
   *        Array of the ICC contacts of the specified type.
   */
  void receiveContactsList(in DOMString type, in jsval contacts);
};

/**
 * Helper that runs in the content process and exposes information
 * to the DOM.
 */
[scriptable, uuid(2f8b0929-2ecf-498c-bfa7-42690509696e)]
interface nsIRILContentHelper : nsIMobileConnectionProvider
{
  void registerTelephonyCallback(in nsIRILTelephonyCallback callback);
  void unregisterTelephonyCallback(in nsIRILTelephonyCallback callback);

  /**
   * Will continue calling callback.enumerateCallState until the callback
   * returns false.
   */
  void enumerateCalls(in nsIRILTelephonyCallback callback);

  /**
   * Functionality for making and managing phone calls.
   */
  void dial(in DOMString number);
  void hangUp(in unsigned long callIndex);

  void startTone(in DOMString dtmfChar);
  void stopTone();

  void answerCall(in unsigned long callIndex);
  void rejectCall(in unsigned long callIndex);
  void holdCall(in unsigned long callIndex);
  void resumeCall(in unsigned long callIndex);

  attribute bool microphoneMuted;
  attribute bool speakerEnabled;
};

[scriptable, uuid(fa923335-4cbd-40d7-8d4a-5689a6db2b6d)]
interface nsIRadioInterfaceLayer : nsISupports
{
  const unsigned short CALL_STATE_UNKNOWN = 0;
  const unsigned short CALL_STATE_DIALING = 1;
  const unsigned short CALL_STATE_ALERTING = 2;
  const unsigned short CALL_STATE_BUSY = 3;
  const unsigned short CALL_STATE_CONNECTING = 4;
  const unsigned short CALL_STATE_CONNECTED = 5;
  const unsigned short CALL_STATE_HOLDING = 6;
  const unsigned short CALL_STATE_HELD = 7;
  const unsigned short CALL_STATE_RESUMING = 8;
  const unsigned short CALL_STATE_DISCONNECTING = 9;
  const unsigned short CALL_STATE_DISCONNECTED = 10;
  const unsigned short CALL_STATE_INCOMING = 11;

  // Keep consistent with GECKO_DATACALL_STATE_* values in ril_consts.js
  const unsigned short DATACALL_STATE_UNKNOWN = 0;
  const unsigned short DATACALL_STATE_CONNECTING = 1;
  const unsigned short DATACALL_STATE_CONNECTED = 2;
  const unsigned short DATACALL_STATE_DISCONNECTING = 3;
  const unsigned short DATACALL_STATE_DISCONNECTED = 4;

  /**
   * Activates or deactivates radio power.
   */
  void setRadioEnabled(in bool value);

  readonly attribute jsval radioState;

  /**
   * PDP APIs
   */
  void setupDataCall(in long radioTech,
                     in DOMString apn,
                     in DOMString user,
                     in DOMString passwd,
                     in long chappap,
                     in DOMString pdptype);
  void deactivateDataCall(in DOMString cid,
                          in DOMString reason);
  void getDataCallList();

  void registerDataCallCallback(in nsIRILDataCallback callback);
  void unregisterDataCallCallback(in nsIRILDataCallback callback);

  /**
   * SMS-related functionality.
   */
  unsigned short getNumberOfMessagesForText(in DOMString text);
  void sendSMS(in DOMString number,
               in DOMString message,
               in long requestId,
               in unsigned long long processId);

  /**
   * ICC-related functionality.
   */
  void getICCContacts(in DOMString type, in nsIRILContactCallback callback);
};
