mmserv/tms/tmsimpl/src/tmsringtonebodyimpl.cpp
changeset 12 5a06f39ad45b
child 20 b67dd1fc57c5
equal deleted inserted replaced
0:71ca22bcf22a 12:5a06f39ad45b
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: Telephony Multimedia Service
       
    15  *
       
    16  */
       
    17 
       
    18 #include <tms.h>
       
    19 #include <tmsringtoneobsrvr.h>
       
    20 #include "tmsutility.h"
       
    21 #include "tmsproxy.h"
       
    22 #include "tmsringtonebodyimpl.h"
       
    23 
       
    24 using namespace TMS;
       
    25 
       
    26 TMSRingToneBodyImpl::TMSRingToneBodyImpl() :
       
    27     iObserver(NULL),
       
    28     iProxy(NULL),
       
    29     iParent(NULL)
       
    30     {
       
    31     }
       
    32 
       
    33 TMSRingToneBodyImpl::~TMSRingToneBodyImpl()
       
    34     {
       
    35     if (iProxy)
       
    36         {
       
    37         iProxy->Close();
       
    38         delete iProxy;
       
    39         iProxy = NULL;
       
    40         }
       
    41     iObserver = NULL;
       
    42     iParent = NULL;
       
    43     iUserData = NULL;
       
    44     }
       
    45 
       
    46 gint TMSRingToneBodyImpl::Create(TMSRingToneBody*& bodyimpl)
       
    47     {
       
    48     gint ret(TMS_RESULT_INSUFFICIENT_MEMORY);
       
    49     TMSRingToneBodyImpl* self = new TMSRingToneBodyImpl;
       
    50     if (self)
       
    51         {
       
    52         ret = self->PostConstruct();
       
    53         if (ret != TMS_RESULT_SUCCESS)
       
    54             {
       
    55             delete self;
       
    56             self = NULL;
       
    57             }
       
    58         }
       
    59     bodyimpl = self;
       
    60     return ret;
       
    61     }
       
    62 
       
    63 gint TMSRingToneBodyImpl::Create(TMSRingToneBody*& bodyimpl,
       
    64         RWindow& /*window*/, gint /*scrid*/)
       
    65     {
       
    66     gint ret(TMS_RESULT_INSUFFICIENT_MEMORY);
       
    67     TMSRingToneBodyImpl* self = new TMSRingToneBodyImpl;
       
    68     if (self)
       
    69         {
       
    70         ret = self->PostConstruct();
       
    71         if (ret != TMS_RESULT_SUCCESS)
       
    72             {
       
    73             delete self;
       
    74             self = NULL;
       
    75             }
       
    76         }
       
    77     bodyimpl = self;
       
    78     return ret;
       
    79     }
       
    80 
       
    81 gint TMSRingToneBodyImpl::PostConstruct()
       
    82     {
       
    83     gint ret(TMS_RESULT_SUCCESS);
       
    84     iClientId = 1;
       
    85     iProxy = new TMSProxy;
       
    86 
       
    87     if (!iProxy)
       
    88         {
       
    89         ret = TMS_RESULT_INSUFFICIENT_MEMORY;
       
    90         }
       
    91     RET_REASON_IF_ERR(ret);
       
    92 
       
    93     if (iProxy->Connect() != TMS_RESULT_SUCCESS)
       
    94         {
       
    95         delete iProxy;
       
    96         iProxy = NULL;
       
    97         ret = TMS_RESULT_FATAL_ERROR;
       
    98         }
       
    99     RET_REASON_IF_ERR(ret);
       
   100     return ret;
       
   101     }
       
   102 
       
   103 gint TMSRingToneBodyImpl::AddObserver(TMSRingToneObserver& obsrvr,
       
   104         gpointer user_data)
       
   105     {
       
   106     gint ret(TMS_RESULT_SUCCESS);
       
   107     if (!iObserver)
       
   108         {
       
   109         iObserver = &obsrvr;
       
   110         iUserData = user_data;
       
   111         if (iProxy)
       
   112             {
       
   113             ret = iProxy->SetMsgQueueNotifier(EMsgQueueRingtoneType, iObserver,
       
   114                     iParent, iClientId);
       
   115             }
       
   116         else
       
   117             {
       
   118             ret = TMS_RESULT_DOES_NOT_EXIST;
       
   119             }
       
   120         }
       
   121     else
       
   122         {
       
   123         ret = TMS_RESULT_ALREADY_EXIST;
       
   124         }
       
   125     return ret;
       
   126     }
       
   127 
       
   128 gint TMSRingToneBodyImpl::RemoveObserver(TMSRingToneObserver& obsrvr)
       
   129     {
       
   130     gint ret(TMS_RESULT_SUCCESS);
       
   131     if (iProxy && (&obsrvr == iObserver))
       
   132         {
       
   133         ret = iProxy->RemoveMsgQueueNotifier(EMsgQueueRingtoneType, iObserver);
       
   134         iObserver = NULL;
       
   135         }
       
   136     else
       
   137         {
       
   138         ret = TMS_RESULT_DOES_NOT_EXIST;
       
   139         }
       
   140     return ret;
       
   141     }
       
   142 
       
   143 gint TMSRingToneBodyImpl::Init(const TMSRingToneType type, GString* str,
       
   144         GString* tts)
       
   145     {
       
   146     gint ret(TMS_RESULT_SUCCESS);
       
   147     if (iProxy)
       
   148         {
       
   149         ret = iProxy->InitRT(type, str, tts);
       
   150         }
       
   151     else
       
   152         {
       
   153         ret = TMS_RESULT_DOES_NOT_EXIST;
       
   154         }
       
   155     return ret;
       
   156     }
       
   157 
       
   158 gint TMSRingToneBodyImpl::Deinit()
       
   159     {
       
   160     gint ret(TMS_RESULT_SUCCESS);
       
   161     if (iProxy)
       
   162         {
       
   163         ret = iProxy->DeinitRT();
       
   164         }
       
   165     else
       
   166         {
       
   167         ret = TMS_RESULT_DOES_NOT_EXIST;
       
   168         }
       
   169     return ret;
       
   170     }
       
   171 
       
   172 gint TMSRingToneBodyImpl::Play()
       
   173     {
       
   174     gint ret(TMS_RESULT_SUCCESS);
       
   175     if (iProxy)
       
   176         {
       
   177         ret = iProxy->PlayRT();
       
   178         }
       
   179     else
       
   180         {
       
   181         ret = TMS_RESULT_DOES_NOT_EXIST;
       
   182         }
       
   183     return ret;
       
   184     }
       
   185 
       
   186 gint TMSRingToneBodyImpl::Stop()
       
   187     {
       
   188     gint ret(TMS_RESULT_SUCCESS);
       
   189     if (iProxy)
       
   190         {
       
   191         ret = iProxy->StopRT();
       
   192         }
       
   193     else
       
   194         {
       
   195         ret = TMS_RESULT_DOES_NOT_EXIST;
       
   196         }
       
   197     return ret;
       
   198     }
       
   199 
       
   200 gint TMSRingToneBodyImpl::Pause()
       
   201     {
       
   202     gint ret(TMS_RESULT_SUCCESS);
       
   203     if (iProxy)
       
   204         {
       
   205         ret = iProxy->PauseRT();
       
   206         }
       
   207     else
       
   208         {
       
   209         ret = TMS_RESULT_DOES_NOT_EXIST;
       
   210         }
       
   211     return ret;
       
   212     }
       
   213 
       
   214 gint TMSRingToneBodyImpl::Mute()
       
   215     {
       
   216     gint ret(TMS_RESULT_SUCCESS);
       
   217     if (iProxy)
       
   218         {
       
   219         ret = iProxy->MuteRT();
       
   220         }
       
   221     else
       
   222         {
       
   223         ret = TMS_RESULT_DOES_NOT_EXIST;
       
   224         }
       
   225     return ret;
       
   226     }
       
   227 
       
   228 
       
   229 void TMSRingToneBodyImpl::SetParent(TMSRingTone*& parent)
       
   230     {
       
   231     iParent = parent;
       
   232     }
       
   233