24
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <cdbcols.h>
|
|
20 |
#include <e32base.h>
|
|
21 |
#include <e32def.h>
|
|
22 |
|
|
23 |
// User Includes
|
|
24 |
#include "t_rmobilephonedata.h"
|
|
25 |
|
|
26 |
|
|
27 |
_LIT(KTelServerKey, "RTelServer");
|
|
28 |
_LIT(KPhone, "Phone");
|
|
29 |
|
|
30 |
/*@{*/
|
|
31 |
//LIT's for commands
|
|
32 |
_LIT(KCmdOpen, "Open");
|
|
33 |
_LIT(KCmdClose, "Close");
|
|
34 |
_LIT(KCmdInitialise, "Initialise");
|
|
35 |
/*}@*/
|
|
36 |
|
|
37 |
/**
|
|
38 |
* Two phase constructor
|
|
39 |
*
|
|
40 |
* @leave system wide error
|
|
41 |
*/
|
|
42 |
CT_RMobilePhoneData* CT_RMobilePhoneData::NewL()
|
|
43 |
{
|
|
44 |
CT_RMobilePhoneData* ret=new (ELeave) CT_RMobilePhoneData();
|
|
45 |
CleanupStack::PushL(ret);
|
|
46 |
ret->ConstructL();
|
|
47 |
CleanupStack::Pop(ret);
|
|
48 |
return ret;
|
|
49 |
}
|
|
50 |
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Protected constructor. First phase construction
|
|
54 |
*/
|
|
55 |
CT_RMobilePhoneData::CT_RMobilePhoneData()
|
|
56 |
:iMobilePhone(NULL)
|
|
57 |
{
|
|
58 |
}
|
|
59 |
|
|
60 |
/**
|
|
61 |
* Second phase construction
|
|
62 |
*
|
|
63 |
* @internalComponent
|
|
64 |
*
|
|
65 |
* @return N/A
|
|
66 |
*
|
|
67 |
* @pre None
|
|
68 |
* @post None
|
|
69 |
*
|
|
70 |
* @leave system wide error
|
|
71 |
*/
|
|
72 |
void CT_RMobilePhoneData::ConstructL()
|
|
73 |
{
|
|
74 |
iMobilePhone = new (ELeave) RMobilePhone();
|
|
75 |
}
|
|
76 |
|
|
77 |
/**
|
|
78 |
* Public destructor
|
|
79 |
*/
|
|
80 |
CT_RMobilePhoneData::~CT_RMobilePhoneData()
|
|
81 |
{
|
|
82 |
if(iMobilePhone)
|
|
83 |
{
|
|
84 |
delete iMobilePhone;
|
|
85 |
iMobilePhone = NULL;
|
|
86 |
}
|
|
87 |
}
|
|
88 |
|
|
89 |
/**
|
|
90 |
* Return a pointer to the object that the data wraps
|
|
91 |
*
|
|
92 |
* @return pointer to the object that the data wraps
|
|
93 |
*/
|
|
94 |
TAny* CT_RMobilePhoneData::GetObject()
|
|
95 |
{
|
|
96 |
return iMobilePhone;
|
|
97 |
}
|
|
98 |
|
|
99 |
TBool CT_RMobilePhoneData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
|
|
100 |
{
|
|
101 |
TBool ret = ETrue;
|
|
102 |
|
|
103 |
if ( aCommand==KCmdOpen )
|
|
104 |
{
|
|
105 |
DoCmdOpen(aSection);
|
|
106 |
}
|
|
107 |
else if ( aCommand==KCmdClose )
|
|
108 |
{
|
|
109 |
DoCmdClose();
|
|
110 |
}
|
|
111 |
else if ( aCommand==KCmdInitialise )
|
|
112 |
{
|
|
113 |
DoCmdInitialise();
|
|
114 |
}
|
|
115 |
else
|
|
116 |
{
|
|
117 |
ret = EFalse;
|
|
118 |
ERR_PRINTF1(_L("Unknown command"));
|
|
119 |
}
|
|
120 |
|
|
121 |
return ret;
|
|
122 |
}
|
|
123 |
|
|
124 |
//== Mobile Line functions
|
|
125 |
void CT_RMobilePhoneData::DoCmdOpen(const TDesC& aSection)
|
|
126 |
{
|
|
127 |
INFO_PRINTF1(_L("*START*CT_RMobilePhoneData::DoCmdOpen"));
|
|
128 |
// Check that first phone is available and log phone name.
|
|
129 |
RTelServer::TPhoneInfo info;
|
|
130 |
// Reading phone info for the first available phone
|
|
131 |
TInt error(0);
|
|
132 |
TBool dataOk = ETrue;
|
|
133 |
TInt parPhone = 0;
|
|
134 |
if ( !GetIntFromConfig(aSection, KPhone(), parPhone) )
|
|
135 |
{
|
|
136 |
ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KPhone);
|
|
137 |
SetBlockResult(EFail);
|
|
138 |
dataOk = EFalse;
|
|
139 |
}
|
|
140 |
TPtrC telServerName;
|
|
141 |
if ( !GetStringFromConfig(aSection, KTelServerKey(), telServerName) )
|
|
142 |
{
|
|
143 |
ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KTelServerKey);
|
|
144 |
SetBlockResult(EFail);
|
|
145 |
dataOk = EFalse;
|
|
146 |
}
|
|
147 |
if ( dataOk )
|
|
148 |
{
|
|
149 |
RTelServer* telServerObject = static_cast<RTelServer*>(GetDataObjectL(telServerName));
|
|
150 |
INFO_PRINTF1(_L("Check if phone info was found."));
|
|
151 |
error = telServerObject->GetPhoneInfo(parPhone, info);
|
|
152 |
if (error != KErrNone)
|
|
153 |
{
|
|
154 |
ERR_PRINTF2(_L("Failed to read phone info for phone KFirstPhone with error %d"), error);
|
|
155 |
SetError(error);
|
|
156 |
}
|
|
157 |
else
|
|
158 |
{
|
|
159 |
// Connect to RMobilePhone interface.
|
|
160 |
INFO_PRINTF1(_L("Opening connection to phone"));
|
|
161 |
error = iMobilePhone->Open(*telServerObject, info.iName);
|
|
162 |
if (error != KErrNone)
|
|
163 |
{
|
|
164 |
ERR_PRINTF2(_L("Connection to phone failed with error %d"), error);
|
|
165 |
SetError(error);
|
|
166 |
}
|
|
167 |
else
|
|
168 |
{
|
|
169 |
INFO_PRINTF1(_L("Opening connection to phone sucessfull"));
|
|
170 |
}
|
|
171 |
}
|
|
172 |
}
|
|
173 |
INFO_PRINTF1(_L("*END*CT_RMobilePhoneData::DoCmdOpen"));
|
|
174 |
}
|
|
175 |
|
|
176 |
void CT_RMobilePhoneData::DoCmdInitialise()
|
|
177 |
{
|
|
178 |
TInt error(0);
|
|
179 |
INFO_PRINTF1(_L("*START*CT_RMobilePhoneData::DoCmdInitialise"));
|
|
180 |
INFO_PRINTF1(_L("Initialising the phone"));
|
|
181 |
error = iMobilePhone->Initialise();
|
|
182 |
if (error != KErrNone)
|
|
183 |
{
|
|
184 |
ERR_PRINTF2(_L("Failed to initalise the phone with error %d"), error);
|
|
185 |
SetError(error);
|
|
186 |
}
|
|
187 |
INFO_PRINTF1(_L("*END*CT_RMobilePhoneData::DoCmdInitialise"));
|
|
188 |
}
|
|
189 |
|
|
190 |
void CT_RMobilePhoneData::DoCmdClose()
|
|
191 |
{
|
|
192 |
INFO_PRINTF1(_L("*START*CT_RMobilePhoneData::DoCmdClosePhone"));
|
|
193 |
INFO_PRINTF1(_L("Closing mobile phone session..."));
|
|
194 |
iMobilePhone->Close();
|
|
195 |
INFO_PRINTF1(_L("*END*CT_RMobilePhoneData::DoCmdInitialise"));
|
|
196 |
}
|
|
197 |
|