LCOV - code coverage report
Current view: directory - dom/sms/src - SmsCursor.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 43 2 4.7 %
Date: 2012-06-02 Functions: 14 2 14.3 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is Mozilla Foundation
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2011
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *   Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #include "SmsCursor.h"
      39                 : #include "nsIDOMClassInfo.h"
      40                 : #include "nsDOMError.h"
      41                 : #include "nsIDOMSmsMessage.h"
      42                 : #include "nsIDOMSmsRequest.h"
      43                 : #include "SmsRequest.h"
      44                 : #include "SmsRequestManager.h"
      45                 : #include "nsISmsDatabaseService.h"
      46                 : 
      47                 : DOMCI_DATA(MozSmsCursor, mozilla::dom::sms::SmsCursor)
      48                 : 
      49                 : namespace mozilla {
      50                 : namespace dom {
      51                 : namespace sms {
      52                 : 
      53               0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SmsCursor)
      54               0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMMozSmsCursor)
      55               0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
      56               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozSmsCursor)
      57               0 : NS_INTERFACE_MAP_END
      58                 : 
      59            1464 : NS_IMPL_CYCLE_COLLECTION_2(SmsCursor, mRequest, mMessage)
      60                 : 
      61               0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(SmsCursor)
      62               0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(SmsCursor)
      63                 : 
      64               0 : SmsCursor::SmsCursor()
      65               0 :   : mListId(-1)
      66                 : {
      67               0 : }
      68                 : 
      69               0 : SmsCursor::SmsCursor(PRInt32 aListId, nsIDOMMozSmsRequest* aRequest)
      70                 :   : mListId(aListId)
      71               0 :   , mRequest(aRequest)
      72                 : {
      73               0 : }
      74                 : 
      75               0 : SmsCursor::~SmsCursor()
      76                 : {
      77               0 :   NS_ASSERTION(!mMessage, "mMessage shouldn't be set!");
      78                 : 
      79               0 :   if (mListId != -1) {
      80                 :     nsCOMPtr<nsISmsDatabaseService> smsDBService =
      81               0 :       do_GetService(SMS_DATABASE_SERVICE_CONTRACTID);
      82                 : 
      83               0 :     if (!smsDBService) {
      84               0 :       NS_ERROR("Can't find SmsDBService!");
      85                 :     }
      86                 : 
      87               0 :     smsDBService->ClearMessageList(mListId);
      88                 :   }
      89               0 : }
      90                 : 
      91                 : void
      92               0 : SmsCursor::Disconnect()
      93                 : {
      94               0 :   NS_ASSERTION(!mMessage, "mMessage shouldn't be set!");
      95                 : 
      96               0 :   mRequest = nsnull;
      97               0 :   mListId = -1;
      98               0 : }
      99                 : 
     100                 : NS_IMETHODIMP
     101               0 : SmsCursor::GetMessage(nsIDOMMozSmsMessage** aMessage)
     102                 : {
     103               0 :   NS_IF_ADDREF(*aMessage = mMessage);
     104               0 :   return NS_OK;
     105                 : }
     106                 : 
     107                 : NS_IMETHODIMP
     108               0 : SmsCursor::Continue()
     109                 : {
     110                 :   // No message means we are waiting for a message or we got the last one.
     111               0 :   if (!mMessage) {
     112               0 :     return NS_ERROR_DOM_INVALID_STATE_ERR;
     113                 :   }
     114                 : 
     115               0 :   mMessage = nsnull;
     116               0 :   static_cast<SmsRequest*>(mRequest.get())->Reset();
     117                 : 
     118               0 :   nsCOMPtr<nsISmsRequestManager> requestManager = do_GetService(SMS_REQUEST_MANAGER_CONTRACTID);
     119                 : 
     120                 :   PRInt32 requestId;
     121               0 :   nsresult rv = requestManager->AddRequest(mRequest, &requestId);
     122               0 :   NS_ENSURE_SUCCESS(rv, rv);
     123                 : 
     124                 :   nsCOMPtr<nsISmsDatabaseService> smsDBService =
     125               0 :     do_GetService(SMS_DATABASE_SERVICE_CONTRACTID);
     126               0 :   NS_ENSURE_TRUE(smsDBService, NS_ERROR_FAILURE);
     127                 : 
     128               0 :   smsDBService->GetNextMessageInList(mListId, requestId, 0);
     129                 : 
     130               0 :   return NS_OK;
     131                 : }
     132                 : 
     133                 : } // namespace sms
     134                 : } // namespace dom
     135            4392 : } // namespace mozilla
     136                 : 

Generated by: LCOV version 1.7