60
|
1 |
/*
|
|
2 |
* Component Name: Headset Simulator
|
|
3 |
* Author: Comarch S.A.
|
|
4 |
* Version: 1.0
|
|
5 |
* Copyright (c) 2010 Comarch S.A.
|
|
6 |
*
|
|
7 |
* This Software is submitted by Comarch S.A. to Symbian Foundation Limited on
|
|
8 |
* the basis of the Member Contribution Agreement entered between Comarch S.A.
|
|
9 |
* and Symbian Foundation Limited on 5th June 2009 (“Agreement”) and may be
|
|
10 |
* used only in accordance with the terms and conditions of the Agreement.
|
|
11 |
* Any other usage, duplication or redistribution of this Software is not
|
|
12 |
* allowed without written permission of Comarch S.A.
|
|
13 |
*
|
|
14 |
*/
|
|
15 |
|
|
16 |
#include "hsclientmanager.h"
|
|
17 |
#include "hsclientobservers.h"
|
|
18 |
#include "hsclient.h"
|
|
19 |
#include "debug.h"
|
|
20 |
|
|
21 |
CHsClientManager* CHsClientManager::NewL()
|
|
22 |
{
|
|
23 |
|
|
24 |
CHsClientManager *self = CHsClientManager::NewLC();
|
|
25 |
CleanupStack::Pop( self );
|
|
26 |
return self;
|
|
27 |
}
|
|
28 |
|
|
29 |
CHsClientManager* CHsClientManager::NewLC()
|
|
30 |
{
|
|
31 |
CHsClientManager *self = new ( ELeave ) CHsClientManager;
|
|
32 |
CleanupStack::PushL( self );
|
|
33 |
self->ConstructL();
|
|
34 |
return self;
|
|
35 |
}
|
|
36 |
|
|
37 |
CHsClientManager::~CHsClientManager()
|
|
38 |
{
|
|
39 |
TRACE_FUNC_ENTRY
|
|
40 |
|
|
41 |
iClientArray.ResetAndDestroy();
|
|
42 |
iObserverArray.Close();
|
|
43 |
|
|
44 |
TRACE_FUNC_EXIT
|
|
45 |
}
|
|
46 |
|
|
47 |
void CHsClientManager::SetClientStateNotfierL(
|
|
48 |
MHsClientStateNotifier &aClientStateNotifier, TInt aNumber )
|
|
49 |
{
|
|
50 |
TRACE_FUNC_ENTRY
|
|
51 |
TRACE_INFO( ( _L("aNumber = %d"), aNumber) );
|
|
52 |
|
|
53 |
if ( aNumber < 0 )
|
|
54 |
{
|
|
55 |
User::Leave( KErrUnderflow );
|
|
56 |
}
|
|
57 |
else if ( aNumber >= iClientArray.Count() )
|
|
58 |
{
|
|
59 |
User::Leave( KErrOverflow );
|
|
60 |
}
|
|
61 |
iClientArray[aNumber]->SetClientStateNotfier( aClientStateNotifier );
|
|
62 |
iObserverArray.InsertL( &aClientStateNotifier, aNumber );
|
|
63 |
|
|
64 |
TRACE_FUNC_EXIT
|
|
65 |
}
|
|
66 |
|
|
67 |
TInt CHsClientManager::Send( const TDesC8 &aAt, TInt aNumber )
|
|
68 |
{
|
|
69 |
TRACE_FUNC_ENTRY
|
|
70 |
TRACE_INFO((_L8("Data to be send: %S"), &aAt))
|
|
71 |
|
|
72 |
TInt err = KErrNone;
|
|
73 |
|
|
74 |
if ( aNumber >= 0 && aNumber < iClientArray.Count() )
|
|
75 |
{
|
|
76 |
iClientArray[aNumber]->Send( aAt );
|
|
77 |
}
|
|
78 |
else
|
|
79 |
{
|
|
80 |
err = KErrNotFound;
|
|
81 |
}
|
|
82 |
|
|
83 |
TRACE_INFO( ( _L("Returned value = %d"), err) );
|
|
84 |
TRACE_FUNC_EXIT
|
|
85 |
return err;
|
|
86 |
}
|
|
87 |
|
|
88 |
void CHsClientManager::DisconnectClients()
|
|
89 |
{
|
|
90 |
TRACE_FUNC_ENTRY
|
|
91 |
//free memory
|
|
92 |
iClientArray.ResetAndDestroy();
|
|
93 |
iObserverArray.Reset();
|
|
94 |
TRACE_FUNC_EXIT
|
|
95 |
}
|
|
96 |
|
|
97 |
void CHsClientManager::HandleNewClientL( CHsClient *aClient, TInt aErr )
|
|
98 |
{
|
|
99 |
TRACE_FUNC_ENTRY
|
|
100 |
TRACE_INFO( ( _L("aErr = %d"), aErr) );
|
|
101 |
|
|
102 |
if ( aClient && aErr == KErrNone )
|
|
103 |
{
|
|
104 |
iClientArray.AppendL( aClient );
|
|
105 |
aClient->SetClientDisconnectNotfier( *this );
|
|
106 |
iObserverArray.AppendL( aClient->GetClientStateNotifer() );
|
|
107 |
}
|
|
108 |
|
|
109 |
TRACE_FUNC_EXIT
|
|
110 |
}
|
|
111 |
|
|
112 |
void CHsClientManager::HandleClientDisconnect( CHsClient *aClient,
|
|
113 |
TInt /** aErr */)
|
|
114 |
{
|
|
115 |
TRACE_FUNC_ENTRY
|
|
116 |
TInt idx = iClientArray.Find( aClient );
|
|
117 |
if ( KErrNotFound != idx )
|
|
118 |
{
|
|
119 |
iClientArray.Remove( idx );
|
|
120 |
iObserverArray.Remove( idx );
|
|
121 |
}
|
|
122 |
|
|
123 |
delete aClient;
|
|
124 |
|
|
125 |
TRACE_FUNC_EXIT
|
|
126 |
}
|
|
127 |
|
|
128 |
CHsClientManager::CHsClientManager() :
|
|
129 |
iClientArray( KHsClientManagerArrayMinSize ), iObserverArray(
|
|
130 |
KHsClientManagerArrayMinSize )
|
|
131 |
{
|
|
132 |
|
|
133 |
}
|
|
134 |
|
|
135 |
void CHsClientManager::ConstructL()
|
|
136 |
{
|
|
137 |
|
|
138 |
}
|
|
139 |
|