/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Telephony.
 *
 * The Initial Developer of the Original Code is
 * the Mozilla Foundation.
 * Portions created by the Initial Developer are Copyright (C) 2011
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Philipp von Weitershausen <philipp@weitershausen.de>
 *   Ben Turner <bent.mozilla@gmail.com>
 *   Sinker Li <thinker@codemud.net>
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

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

interface nsIDOMMozMobileConnectionInfo;
interface nsIDOMDOMRequest;
interface nsIDOMWindow;

[scriptable, uuid(03eafd60-d138-4f09-81b4-90cd4996b3c7)]
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.
   */
  void callStateChanged(in unsigned long callIndex,
                        in unsigned short callState,
                        in AString number);

  /**
   * Called when nsIRadioInterfaceLayer is asked to enumerate the current
   * telephony call state (nsIRadioInterfaceLayer::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);
};

[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);
};

/**
 * Helper that runs in the content process and exposes information
 * to the DOM.
 */
[scriptable, uuid(cc9832fd-d3ce-4cab-9abe-48c6046bcebe)]
interface nsIRILContentHelper : nsIMobileConnectionProvider
{
};

[scriptable, uuid(d2025763-fc32-436e-b207-0228ea1ccd12)]
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;

  readonly attribute jsval radioState;

  void registerCallback(in nsIRILTelephonyCallback callback);
  void unregisterCallback(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;

  /**
   * 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);
};
