|
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 "T_RSocketData.h" |
|
20 #include "T_BTUtil.h" |
|
21 |
|
22 /*@{*/ |
|
23 //Constant Literals used. |
|
24 |
|
25 _LIT(KNamedProtocol, "named_protocol"); |
|
26 |
|
27 _LIT(KCmdRSocketServerConnect, "RSocketServerConnect"); |
|
28 _LIT(KCmdRSocketServerClose, "RSocketServerClose"); |
|
29 _LIT(KCmdRSocketOpen, "RSocketOpen"); |
|
30 _LIT(KCmdRSocketClose, "RSocketClose"); |
|
31 _LIT(KCmdInfo, "Info"); |
|
32 |
|
33 // Other |
|
34 _LIT_SECURITY_POLICY_C2(KProcPolicy, ECapabilityNetworkServices, ECapabilityNetworkControl); |
|
35 /*@}*/ |
|
36 |
|
37 CT_RSocketData* CT_RSocketData::NewL() |
|
38 { |
|
39 CT_RSocketData* ret=new (ELeave) CT_RSocketData(); |
|
40 return ret; |
|
41 } |
|
42 |
|
43 CT_RSocketData::CT_RSocketData() |
|
44 { |
|
45 } |
|
46 |
|
47 CT_RSocketData::~CT_RSocketData() |
|
48 { |
|
49 |
|
50 } |
|
51 |
|
52 |
|
53 TBool CT_RSocketData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
54 { |
|
55 TBool retVal=ETrue; |
|
56 |
|
57 //------------------------------------------------------------------------- |
|
58 // RSocket (This class is not a full test suite just a helper to test CBluetoothSocket) |
|
59 //------------------------------------------------------------------------- |
|
60 |
|
61 if (aCommand==KCmdRSocketServerConnect) |
|
62 { |
|
63 CloseSocketServer(); |
|
64 User::LeaveIfError(iSocketServer.Connect()); |
|
65 } |
|
66 else if (aCommand==KCmdRSocketServerClose) |
|
67 { |
|
68 CloseSocketServer(); |
|
69 } |
|
70 |
|
71 else if (aCommand==KCmdRSocketOpen) |
|
72 { |
|
73 RSocketOpen(aSection); |
|
74 } |
|
75 else if (aCommand==KCmdRSocketClose) |
|
76 { |
|
77 iRSocket.Close(); |
|
78 } |
|
79 else if (aCommand==KCmdInfo) |
|
80 { |
|
81 Info(aSection); |
|
82 } |
|
83 |
|
84 else |
|
85 { |
|
86 retVal=EFalse; |
|
87 } |
|
88 |
|
89 return retVal; |
|
90 } |
|
91 |
|
92 TAny* CT_RSocketData::GetObject() |
|
93 { |
|
94 return &iRSocket; |
|
95 } |
|
96 |
|
97 void CT_RSocketData::CloseSocketServer() |
|
98 { |
|
99 if(iSocketServer.Handle()) |
|
100 { |
|
101 iSocketServer.Close(); |
|
102 } |
|
103 } |
|
104 |
|
105 |
|
106 void CT_RSocketData::RSocketOpen(const TDesC& aSection) |
|
107 { |
|
108 TPtrC namedProtocol; |
|
109 if( GetStringFromConfig(aSection, KNamedProtocol(), namedProtocol)) |
|
110 { |
|
111 INFO_PRINTF2(_L("Opening RSocket with: %S protocol"), &namedProtocol); |
|
112 TProtocolDesc pInfo; |
|
113 User::LeaveIfError(iSocketServer.FindProtocol(namedProtocol,pInfo)); |
|
114 iRSocket.Open(iSocketServer, pInfo.iAddrFamily, pInfo.iSockType, pInfo.iProtocol); |
|
115 iRSocket.SetOpt(KSOEnableTransfer, KSOLSocket, KProcPolicy().Package()); |
|
116 } |
|
117 else |
|
118 { |
|
119 ERR_PRINTF1(_L("GetStringFromConfig failed")); |
|
120 SetBlockResult(EFail); |
|
121 } |
|
122 } |
|
123 |
|
124 void CT_RSocketData::Info(const TDesC& /*aSection*/) |
|
125 { |
|
126 TProtocolDesc protocolDesc; |
|
127 TInt err = iRSocket.Info(protocolDesc); |
|
128 SetError(err); |
|
129 } |