|
1 // Copyright (c) 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 the License "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 // rusbhostmsdevice.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalTechnology |
|
23 */ |
|
24 |
|
25 |
|
26 #include <e32std.h> |
|
27 #include <f32file.h> |
|
28 |
|
29 #include "msmanclientserver.h" |
|
30 #include "rusbotgsession.h" |
|
31 #include "tmslog.h" |
|
32 #include "debug.h" |
|
33 |
|
34 |
|
35 TVersion RUsbOtgSession::Version() const |
|
36 { |
|
37 __MSFNSLOG |
|
38 return(TVersion(KUsbOtgSrvMajorVersionNumber, |
|
39 KUsbOtgSrvMinorVersionNumber, |
|
40 KUsbOtgSrvBuildVersionNumber)); |
|
41 } |
|
42 |
|
43 |
|
44 EXPORT_C RUsbOtgSession::RUsbOtgSession() |
|
45 { |
|
46 __MSFNSLOG |
|
47 } |
|
48 |
|
49 |
|
50 EXPORT_C RUsbOtgSession::RUsbOtgSession(TInt /* aParam */) |
|
51 { |
|
52 __MSFNSLOG |
|
53 } |
|
54 |
|
55 EXPORT_C TInt RUsbOtgSession::Connect() |
|
56 { |
|
57 __MSFNSLOG |
|
58 |
|
59 TInt retry = 2; |
|
60 for (;;) |
|
61 { |
|
62 TInt r = CreateSession(KUsbOtgServerName, Version()); |
|
63 if ((r != KErrNotFound) && (r != KErrServerTerminated)) |
|
64 { |
|
65 return r; |
|
66 } |
|
67 if (--retry == 0) |
|
68 { |
|
69 return r; |
|
70 } |
|
71 |
|
72 r = StartServer(); |
|
73 if ((r != KErrNone) && (r != KErrAlreadyExists)) |
|
74 { |
|
75 return r; |
|
76 } |
|
77 } |
|
78 } |
|
79 |
|
80 |
|
81 TInt RUsbOtgSession::StartServer() |
|
82 { |
|
83 __MSFNSLOG |
|
84 |
|
85 const TUidType serverUid(KNullUid, KNullUid, KUsbOtgServerUid3); |
|
86 |
|
87 // Create the server process |
|
88 RProcess server; |
|
89 TInt r = server.Create(KUsbOtgServerName, KNullDesC, serverUid); |
|
90 if (r != KErrNone) |
|
91 { |
|
92 return r; |
|
93 } |
|
94 |
|
95 // Create the rendezvous request with the server process |
|
96 TRequestStatus status; |
|
97 server.Rendezvous(status); |
|
98 if (status != KRequestPending) |
|
99 { |
|
100 User::WaitForRequest(status); |
|
101 server.Kill(0); // If the outstanding request is not pending then kill the server |
|
102 server.Close(); |
|
103 return status.Int(); |
|
104 } |
|
105 |
|
106 server.SetPriority(EPriorityHigh); |
|
107 server.Resume(); // start the server |
|
108 |
|
109 // Test whether the process has ended and if it has ended, return how it ended. |
|
110 User::WaitForRequest(status); |
|
111 |
|
112 if (status == KRequestPending) |
|
113 { |
|
114 server.Close(); |
|
115 return status.Int(); |
|
116 } |
|
117 |
|
118 server.Close(); |
|
119 return KErrNone; |
|
120 } |
|
121 |
|
122 |
|
123 EXPORT_C TBool RUsbOtgSession::DeviceInserted() |
|
124 { |
|
125 __MSFNSLOG |
|
126 TPckgBuf<TBool> pckg; |
|
127 TIpcArgs args(&pckg); |
|
128 |
|
129 SendReceive(EUsbOtgDeviceInserted, args); |
|
130 TBool res = pckg(); |
|
131 return res; |
|
132 } |
|
133 |
|
134 |
|
135 EXPORT_C void RUsbOtgSession::NotifyChange(TBool& /* aChanged */, TRequestStatus& aStatus) |
|
136 { |
|
137 __MSFNSLOG |
|
138 TPckgBuf<TBool> pckg; |
|
139 TIpcArgs args(&pckg); |
|
140 |
|
141 SendReceive(EUsbOtgNotifyChange, args, aStatus); |
|
142 } |
|
143 |
|
144 |
|
145 EXPORT_C TInt RUsbOtgSession::NotifyChangeCancel() |
|
146 { |
|
147 __MSFNSLOG |
|
148 return SendReceive(EUsbOtgNotifyChangeCancel); |
|
149 } |
|
150 |
|
151 |
|
152 EXPORT_C TInt RUsbOtgSession::BusDrop() |
|
153 { |
|
154 __MSFNSLOG |
|
155 return SendReceive(EUsbOtgBusDrop); |
|
156 } |