|
1 // Copyright (c) 2007-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 // e32test\earlyextension\d_testearlyextension.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <kernel/kernel.h> |
|
19 #include "d_testearlyextension.h" |
|
20 #include "earlyextension.h" |
|
21 |
|
22 _LIT(KTestEarlyExtName, "D_TESTEARLYEXTENSION.LDD"); |
|
23 |
|
24 /** Factory class */ |
|
25 class DTestEarlyExtLddFactory : public DLogicalDevice |
|
26 { |
|
27 public: |
|
28 DTestEarlyExtLddFactory(); |
|
29 virtual TInt Install(); |
|
30 virtual void GetCaps(TDes8 &aDes) const; |
|
31 virtual TInt Create(DLogicalChannelBase*& aChannel); |
|
32 static TTimeK* iTimeArray; //Pointer to store the time stamps. |
|
33 }; |
|
34 |
|
35 /** Logical channel */ |
|
36 class DTestEarlyExtension : public DLogicalChannelBase |
|
37 { |
|
38 public: |
|
39 DTestEarlyExtension(); |
|
40 ~DTestEarlyExtension(); |
|
41 protected: |
|
42 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
43 virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2); |
|
44 virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType); |
|
45 private: |
|
46 DThread* iClient; |
|
47 }; |
|
48 |
|
49 TTimeK* DTestEarlyExtLddFactory::iTimeArray = NULL; |
|
50 |
|
51 /** Factory class */ |
|
52 DTestEarlyExtLddFactory::DTestEarlyExtLddFactory() |
|
53 { |
|
54 iParseMask=0; |
|
55 iUnitsMask=0; |
|
56 } |
|
57 |
|
58 /** Entry point for this driver */ |
|
59 DECLARE_EXTENSION_WITH_PRIORITY(LATE_EXTENSION_PRIORITY) |
|
60 { |
|
61 // - In extension init1 create and installing ldd factory |
|
62 // - Allocating space for 2 array of time stamps |
|
63 // - Calling early extension export to get the time stamp stored during its entry point |
|
64 // - Taking another time stamp and storing. |
|
65 DTestEarlyExtLddFactory* device = new DTestEarlyExtLddFactory; |
|
66 if(!device) |
|
67 return KErrNoMemory; |
|
68 device->iTimeArray = (TTimeK*)new(TTimeK[2]); |
|
69 if(!device->iTimeArray) |
|
70 { |
|
71 Kern::Printf("Memory not allocated"); |
|
72 delete device; |
|
73 return KErrNoMemory; |
|
74 } |
|
75 TInt r = Kern::InstallLogicalDevice(device); |
|
76 if(r == KErrNone) |
|
77 { |
|
78 TTimeK temp; |
|
79 TestEarlyExtension::GetTimeStamp(temp); |
|
80 device->iTimeArray[0] = temp; |
|
81 device->iTimeArray[1] = Kern::SystemTime(); |
|
82 } |
|
83 return r; |
|
84 } |
|
85 |
|
86 DECLARE_EXTENSION_LDD() |
|
87 { |
|
88 return new DTestEarlyExtLddFactory; |
|
89 } |
|
90 /** Second stage constuctor */ |
|
91 TInt DTestEarlyExtLddFactory::Install() |
|
92 { |
|
93 return(SetName(&KTestEarlyExtName)); |
|
94 } |
|
95 |
|
96 /** Device capabilities */ |
|
97 void DTestEarlyExtLddFactory::GetCaps(TDes8& aDes)const |
|
98 { |
|
99 } |
|
100 |
|
101 /** Create logical channel, only open of one channel is allowed at a time */ |
|
102 TInt DTestEarlyExtLddFactory::Create(DLogicalChannelBase*& aChannel) |
|
103 { |
|
104 if (iOpenChannels != 0) //A Channel is already open |
|
105 return KErrInUse; |
|
106 aChannel = new DTestEarlyExtension; |
|
107 if(!aChannel) |
|
108 return KErrNoMemory; |
|
109 return KErrNone; |
|
110 } |
|
111 |
|
112 /** Create channel */ |
|
113 TInt DTestEarlyExtension::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/) |
|
114 { |
|
115 return KErrNone; |
|
116 } |
|
117 |
|
118 /** Constructor of Logical channel */ |
|
119 DTestEarlyExtension::DTestEarlyExtension() |
|
120 { |
|
121 iClient = &Kern::CurrentThread(); |
|
122 ((DObject*)iClient)->Open();; |
|
123 } |
|
124 |
|
125 /** Destructor */ |
|
126 DTestEarlyExtension::~DTestEarlyExtension() |
|
127 { |
|
128 // Close our reference on the client thread |
|
129 Kern::SafeClose((DObject*&)iClient,NULL); |
|
130 } |
|
131 |
|
132 /** Handle user side requests */ |
|
133 TInt DTestEarlyExtension::Request(TInt aReqNo, TAny* a1, TAny* a2) |
|
134 { |
|
135 switch(aReqNo) |
|
136 { |
|
137 case (RLddEarlyExtensionTest::EGET_SYSTEM_TIME_STAMPS): |
|
138 { //Get time stamps |
|
139 kumemput(a1, &(((DTestEarlyExtLddFactory*)iDevice)->iTimeArray[0]), sizeof(Int64)); |
|
140 kumemput(a2, &(((DTestEarlyExtLddFactory*)iDevice)->iTimeArray[1]), sizeof(Int64)); |
|
141 return KErrNone; |
|
142 } |
|
143 } |
|
144 return KErrNotSupported; |
|
145 } |
|
146 |
|
147 /** Restricting handle duplication */ |
|
148 TInt DTestEarlyExtension::RequestUserHandle(DThread* aThread, TOwnerType aType) |
|
149 { |
|
150 if (aType!=EOwnerThread || aThread!=iClient) |
|
151 return KErrAccessDenied; |
|
152 return KErrNone; |
|
153 } |
|
154 |
|
155 |