|
1 /* |
|
2 * Copyright (c) 2005 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: Implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "CTcSerialManager.h" |
|
19 #include "TTcSerialFactory.h" |
|
20 |
|
21 #include "debuglog.h" |
|
22 |
|
23 _LIT(LDD_NAME,"ECOMM"); |
|
24 |
|
25 #if defined (__WINS__) |
|
26 _LIT(PDD_NAME,"ECDRV"); |
|
27 #else |
|
28 _LIT(PDD_NAME,"EUART1"); |
|
29 #endif |
|
30 |
|
31 CTcSerialManager* CTcSerialManager::NewL( const TTcSerialFactory& aFactory ) |
|
32 { |
|
33 CTcSerialManager* self = new( ELeave ) CTcSerialManager( aFactory ); |
|
34 |
|
35 CleanupStack::PushL( self ); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop( self ); |
|
38 |
|
39 return self; |
|
40 } |
|
41 |
|
42 CTcSerialManager::~CTcSerialManager() |
|
43 { |
|
44 LOG( _L("CTcSerialManager::~CTcSerialManager()") ); |
|
45 |
|
46 Close(); |
|
47 delete iConn; |
|
48 iCommServ.Close(); |
|
49 } |
|
50 |
|
51 CTcSerialManager::CTcSerialManager( const TTcSerialFactory& aFactory ) : |
|
52 iFactory( aFactory ) |
|
53 { |
|
54 } |
|
55 |
|
56 void CTcSerialManager::ConstructL() |
|
57 { |
|
58 LOG( _L("CTcSerialManager::ConstructL()") ); |
|
59 |
|
60 LoadDriversAndCommModuleL(); |
|
61 |
|
62 iConn = new ( ELeave ) CTcSerialConnection( iCommServ, |
|
63 iFactory.iPortName, |
|
64 iFactory.iPortSpeed ); |
|
65 |
|
66 iConn->SetObserver( this ); |
|
67 |
|
68 LOG( _L("CTcSerialManager::ConstructL() end") ); |
|
69 } |
|
70 |
|
71 void CTcSerialManager::ConnectL( TInetAddr* /*aRemoteAddr*/ ) |
|
72 { |
|
73 LOG( _L("CTcSerialManager::ConnectL()") ); |
|
74 |
|
75 iConn->ConnectL(); |
|
76 |
|
77 LOG( _L("CTcSerialManager::ConnectL() end") ); |
|
78 } |
|
79 |
|
80 void CTcSerialManager::Close() |
|
81 { |
|
82 LOG( _L("CTcSerialManager::Close()") ); |
|
83 |
|
84 iConn->Close(); |
|
85 } |
|
86 |
|
87 void CTcSerialManager::Send( const TDesC8& aDes ) |
|
88 { |
|
89 iConn->Send( aDes ); |
|
90 } |
|
91 |
|
92 void CTcSerialManager::Receive( TDes8& aDes ) |
|
93 { |
|
94 iConn->Receive( aDes ); |
|
95 } |
|
96 |
|
97 void CTcSerialManager::ReceiveOneOrMore( TDes8& aDes ) |
|
98 { |
|
99 iConn->ReceiveOneOrMore( aDes ); |
|
100 } |
|
101 |
|
102 void CTcSerialManager::SetObserver( MTcBearerObserver* aObserver ) |
|
103 { |
|
104 iObserver = aObserver; |
|
105 } |
|
106 |
|
107 void CTcSerialManager::GetLocalAddressL( TDes& /*aDes*/ ) |
|
108 { |
|
109 User::Leave( KErrNotSupported ); |
|
110 } |
|
111 |
|
112 void CTcSerialManager::BearerCompletion( |
|
113 MTcBearerObserver::TOperation aOp, |
|
114 TInt aStatus ) |
|
115 { |
|
116 LOG( _L("CTcSerialManager::BearerCompletion( %d, %d ) start"), aOp, aStatus ); |
|
117 if( ( aOp == MTcBearerObserver::EConnect ) && !aStatus ) |
|
118 { |
|
119 // A client has connected |
|
120 |
|
121 } |
|
122 |
|
123 if( iObserver ) |
|
124 { |
|
125 iObserver->BearerCompletion( aOp, aStatus ); |
|
126 } |
|
127 LOG( _L("CTcSerialManager::BearerCompletion() end") ); |
|
128 } |
|
129 |
|
130 void CTcSerialManager::LoadDriversAndCommModuleL() |
|
131 { |
|
132 TInt err = User::LoadPhysicalDevice( PDD_NAME ); |
|
133 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
134 { |
|
135 User::Leave( err ); |
|
136 } |
|
137 |
|
138 err = User::LoadLogicalDevice( LDD_NAME ); |
|
139 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
140 { |
|
141 User::Leave( err ); |
|
142 } |
|
143 |
|
144 // Both WINS and EIKON will have started the comms server process. |
|
145 // (this is only really needed for ARM hardware development racks) |
|
146 |
|
147 #if !defined (__WINS__) |
|
148 err = StartC32 (); |
|
149 if ( err != KErrNone && err != KErrAlreadyExists ) |
|
150 { |
|
151 User::Leave( err ); |
|
152 } |
|
153 #endif |
|
154 |
|
155 |
|
156 User::LeaveIfError( iCommServ.Connect() ); |
|
157 |
|
158 // Load the CSY module |
|
159 // Symbian OS will automatically search \System\Libs |
|
160 // on all drives starting from C: |
|
161 |
|
162 User::LeaveIfError( iCommServ.LoadCommModule( iFactory.iCSYName ) ); |
|
163 } |
|
164 |
|
165 // End of file |