|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef AVRCPUTILS_H |
|
17 #define AVRCPUTILS_H |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalComponent |
|
22 @released |
|
23 */ |
|
24 |
|
25 _LIT(KAvrcpPanicName, "AVRCP Panic"); |
|
26 |
|
27 enum TAvrcpPanic |
|
28 { |
|
29 EAvrcpNoAVCFrame = 0, |
|
30 EAvrcpNotConnected = 1, |
|
31 EAvrcpNoOutstandingSend = 2, |
|
32 EAvrcpHoldExpiryForRelease = 3, |
|
33 EAvrcpReleaseExpiryForRelease = 4, |
|
34 EAvrcpUnknownAvctpTransId = 5, |
|
35 EAvrcpNoResponsesAvailable = 6, |
|
36 EAvrcpResponseToUnknownCommand = 7, |
|
37 EAvrcpBadBTAddr = 8, |
|
38 EAvrcpCommandStillInUse = 9, |
|
39 EAvrcpCommandDataTooLong = 10, |
|
40 EAvrcpFunnyLengthData = 11, |
|
41 EAvrcpTimerNotCancelled = 12, |
|
42 EAvrcpNotVendorDependent = 13, |
|
43 EAvrcpMismatchedConnectDisconnect = 14, |
|
44 EAvrcpDummyCallbackCalled = 15, |
|
45 EAvrcpUnknownButtonAction = 16, |
|
46 EAvrcpPressHasPhantomResponse = 17, |
|
47 EAvrcpReleaseTimerStartedWithoutResponse = 18, |
|
48 EAvrcpReleaseExpiryForOldCommand = 19, |
|
49 EAvrcpSendingMessageFailed = 20, |
|
50 EAvrcpDisconnectRequestWhilePartiallyConstructed = 21, |
|
51 EAvrcpReleaseExpiryForClick = 22, |
|
52 EAvrcpIncomingCommandsNotHandled = 23, |
|
53 EAvrcpCommandStillQueuedForHandling = 24, |
|
54 EAvrcpCommandStillQueuedAsReady = 25, |
|
55 EAvrcpCommandStillQueuedForSending = 26, |
|
56 EAvrcpPressNotPreviousPassthroughCommand = 27, |
|
57 EAvrcpInterfaceUidNotSet = 28, |
|
58 EAvrcpCTypeNotSet = 29, |
|
59 EAvrcpCompanyIDNotSet = 30, |
|
60 EAvrcpNotFullyConstructed = 31, |
|
61 EAvrcpInternalHandlingRequestedOnWrongInterface = 32, |
|
62 EAvrcpVolumeBeyondMaxVolume = 33, |
|
63 EAvrcpInvalidEventId = 34, |
|
64 EAvrcpInvalidPlayerId = 35, |
|
65 EAvrcpConnectConfirmOnBrowseChannel = 36, |
|
66 EAvrcpDisconnectConfirmOnBrowseChannel = 37, |
|
67 EAlreadyWatchingPlayer = 38, |
|
68 ENotWatchingPlayer = 39, |
|
69 EAvctpMessageTypeRequestedForInternalCommand = 40, |
|
70 ELowerInterfaceUsedOnInternalHandler = 41, |
|
71 EFurtherProcessingRequiredForNonSetBrowsedPlayer = 42, |
|
72 ESetBrowsePlayerRequestCorruptedLocally = 43, |
|
73 ESpecificAddressUsedForBrowsingCommand = 44, |
|
74 EUidUpdateRequestWriteFailure = 45, |
|
75 EUnmatchedResponseFromRemCon = 46, |
|
76 EResponseForWrongInterface = 47, |
|
77 EInvalidBtAddrInResponse = 48, |
|
78 EInvalidPlayerId = 49, |
|
79 EMysteryInternalResponse = 50, |
|
80 ECommandAlreadyQueuedForSending = 52, |
|
81 EPassthroughQueueNotEmptyAfterDisconnect = 53, |
|
82 EPreviousPassthroughNonNullReplacing = 54, |
|
83 }; |
|
84 |
|
85 template <typename XAny> |
|
86 struct TAvrcpPanicCodeTypeChecker |
|
87 { |
|
88 inline static void Check(XAny) { } |
|
89 }; |
|
90 |
|
91 #define AVRCP_PANIC(CODE) \ |
|
92 TAvrcpPanicCodeTypeChecker<TAvrcpPanic>::Check(CODE), \ |
|
93 PANIC(KAvrcpPanicName, CODE) |
|
94 |
|
95 |
|
96 class TBTDevAddr; |
|
97 class TRemConAddress; |
|
98 class AvrcpUtils |
|
99 { |
|
100 public: |
|
101 static void Panic(TAvrcpPanic aPanic); // The macro is probably more useful so this can be removed |
|
102 |
|
103 static void SetCommandDataFromInt(RBuf8& aCommandData, TInt aOffset, TInt aLength, TInt aValue); |
|
104 static void ReadCommandDataToInt(const RBuf8& aCommandData, TInt aOffset, TInt aLength, TInt& aValue); |
|
105 |
|
106 static TInt RemConToBTAddr(const TRemConAddress& aRemoteAddress, TBTDevAddr& aBTAddr); |
|
107 static void BTToRemConAddr(const TBTDevAddr& aBTAddr, TRemConAddress& aRemConAddress); |
|
108 }; |
|
109 |
|
110 // |
|
111 // Thread Assertions |
|
112 // |
|
113 |
|
114 enum TAvrcpThreadId |
|
115 { |
|
116 EControlThread = 0x00000001, |
|
117 EBulkThread = 0x00000002, |
|
118 }; |
|
119 |
|
120 #define ASSERT_THREAD(aaa) ASSERT_DEBUG(reinterpret_cast<TUint32>(Dll::Tls()) == aaa) |
|
121 #define WEAK_ASSERT_THREAD(aaa) if(Dll::Tls()) { ASSERT_THREAD(aaa); } |
|
122 #define ASSERT_CONTROL_THREAD ASSERT_THREAD(EControlThread) |
|
123 #define ASSERT_BULK_THREAD ASSERT_THREAD(EBulkThread) |
|
124 #define WEAK_ASSERT_BULK_THREAD WEAK_ASSERT_THREAD(EBulkThread) |
|
125 |
|
126 // |
|
127 // Cleanup Stack utils |
|
128 // |
|
129 |
|
130 template <class T> |
|
131 class CleanupSignal |
|
132 { |
|
133 public: |
|
134 inline static void PushL(T& aRef) {CleanupStack::PushL(TCleanupItem(&Signal,&aRef));}; |
|
135 private: |
|
136 static void Signal(TAny *aPtr) {(static_cast<T*>(aPtr))->Signal();}; |
|
137 }; |
|
138 |
|
139 template <class T> |
|
140 inline void CleanupSignalPushL(T& aRef) |
|
141 {CleanupSignal<T>::PushL(aRef);} |
|
142 |
|
143 template <class T> |
|
144 class CleanupDeleteAndNull |
|
145 { |
|
146 public: |
|
147 inline static void PushL(T*& aRef) {CleanupStack::PushL(TCleanupItem(&DeleteAndNull,&aRef));}; |
|
148 private: |
|
149 static void DeleteAndNull(TAny *aPtr) {T*& ptr = *static_cast<T**>(aPtr); delete ptr; ptr = NULL;}; |
|
150 }; |
|
151 |
|
152 template <class T> |
|
153 inline void CleanupDeleteAndNullPushL(T*& aRef) |
|
154 {CleanupDeleteAndNull<T>::PushL(aRef);} |
|
155 |
|
156 class CSpecificThreadCallBackBody; |
|
157 NONSHARABLE_CLASS(RSpecificThreadCallBack) |
|
158 { |
|
159 public: |
|
160 RSpecificThreadCallBack(); |
|
161 |
|
162 TInt Create(const TCallBack& aCallBack, TInt aPriority); |
|
163 void Close(); |
|
164 |
|
165 TInt Start(); |
|
166 TInt CallBack(); |
|
167 void Cancel(); |
|
168 |
|
169 private: |
|
170 CSpecificThreadCallBackBody* iBody; |
|
171 }; |
|
172 |
|
173 #endif // AVRCPUTILS_H |