1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 // Based on the official usbostrouter header, modified to remove dependancy on
50 typedef int TOstProtIds;
52 class RUsbOstComm : public RSessionBase
60 TInt RegisterProtocolID(TOstProtIds aId, TBool aNeedHeader);
61 void ReadMessage(TRequestStatus& aStatus, TDes8& aDes);
63 void WriteMessage(TRequestStatus& aStatus, const TDesC8& aDes, TBool aHasHeader=EFalse);
64 TVersion Version() const;
72 EUsbOstCmdCodeGetAcmConfig,
73 EUsbOstCmdCodeSetAcmConfig,
76 EUsbOstCmdCodeRegisterId,
77 EUsbOstCmdCodeRegisterIds,
78 EUsbOstCmdCodeUnRegisterId,
79 EUsbOstCmdCodeUnRegisterIds,
80 EUsbOstCmdCodeReadMsg,
81 EUsbOstCmdCodeReadCancel,
82 EUsbOstCmdCodeWriteMsg,
83 EUsbOstCmdCodeWriteCancel,
88 RUsbOstComm::RUsbOstComm()
92 TInt RUsbOstComm::Connect()
94 _LIT(KUsbOstServerName, "!UsbOstRouter");
95 _LIT(KUsbOstServerImageName, "usbostrouter");
96 const TUid KUsbOstServerUid = { 0x200170BE };
97 TInt startupAttempts = 2;
99 TInt ret = CreateSession(KUsbOstServerName, TVersion(1,0,0));
100 if (ret != KErrNotFound && ret != KErrServerTerminated) {
104 if (startupAttempts-- == 0) {
109 ret = server.Create(KUsbOstServerImageName, KNullDesC, KUsbOstServerUid);
113 TRequestStatus serverDiedRequestStatus;
114 server.Rendezvous(serverDiedRequestStatus);
116 if (serverDiedRequestStatus != KRequestPending) {
118 server.Kill(KErrNone);
120 // Logon OK - start the server
123 User::WaitForRequest(serverDiedRequestStatus);
124 ret = (server.ExitType() == EExitPanic) ? KErrGeneral : serverDiedRequestStatus.Int();
127 if (ret != KErrNone && ret != KErrAlreadyExists) {
133 TInt RUsbOstComm::Disconnect()
135 return SendReceive(EUsbOstCmdDisconnect);
138 TInt RUsbOstComm::Open()
140 return SendReceive(EUsbOstCmdCodeOpen);
143 TInt RUsbOstComm::Close()
145 TInt err = SendReceive(EUsbOstCmdCodeClose);
146 RHandleBase::Close();
150 TInt RUsbOstComm::RegisterProtocolID(const TOstProtIds aId, TBool aNeedHeader)
152 TIpcArgs args(aId, aNeedHeader);
153 return SendReceive(EUsbOstCmdCodeRegisterId, args);
156 void RUsbOstComm::ReadMessage(TRequestStatus& aStatus, TDes8& aDes)
158 TIpcArgs args(aDes.MaxLength(), &aDes);
159 SendReceive(EUsbOstCmdCodeReadMsg, args, aStatus);
162 TInt RUsbOstComm::ReadCancel()
164 return SendReceive(EUsbOstCmdCodeReadCancel);
167 void RUsbOstComm::WriteMessage(TRequestStatus& aStatus, const TDesC8& aDes, TBool aHasHeader)
169 TIpcArgs args(aHasHeader, aDes.Length(), &aDes);
170 SendReceive(EUsbOstCmdCodeWriteMsg, args, aStatus);
173 typedef TVersion (*TVersionFunction)(const RUsbOstComm*);
174 const TInt KVersionOrdinal = 17;
176 TVersion RUsbOstComm::Version() const
178 // This function has to go to the DLL, unfortunately
179 TVersion result; // Return 0.0.0 on any error
181 TInt err = lib.Load(_L("usbostcomm"));
182 if (err) return result;
184 TLibraryFunction fn = lib.Lookup(KVersionOrdinal);
186 result = ((TVersionFunction)fn)(this);
191 #endif //USBHOSTCOMM_H