19 * Stray signal test function |
19 * Stray signal test function |
20 */ |
20 */ |
21 |
21 |
22 #include "locationservice.h" |
22 #include "locationservice.h" |
23 |
23 |
24 #define TRACE 0 |
24 #define TRACE 1 |
25 #define GETLOCATION 1 |
25 #define GETLOCATION 0 |
26 |
26 |
27 |
27 TInt reqErr1;//To share the error value from callback |
28 _LIT(KRequestor,"testapp"); |
28 _LIT(KRequestor,"testapp"); |
29 |
29 |
30 class ASyncCB : public MLocationCallBack |
30 class ASyncCB : public MLocationCallBack |
31 { |
31 { |
32 TInt iCmd ; |
32 TInt iCmd ; |
33 TInt iRetStatus ; |
33 TInt iRetStatus ; |
34 TInt iCount ; |
34 TInt iCount ; |
35 |
35 TInt iRequestType; |
36 CLocationService *iService ; |
36 TInt iTransactionId; |
|
37 |
|
38 CLocationService *iService ; |
37 |
39 |
38 |
40 |
39 public : |
41 public : |
40 |
|
41 |
|
42 TInt HandleNotifyL(HPositionGenericInfo* aPosInfo , TInt aError) ; |
|
43 |
|
44 ASyncCB() :iCmd(0) , iRetStatus(KErrGeneral) , iCount(0) //Default constructor |
|
45 { |
|
46 ; |
|
47 } |
|
48 ASyncCB(TInt aCmd , CLocationService *aService) ; |
|
49 }; |
|
50 |
42 |
51 |
43 |
52 ASyncCB :: ASyncCB(TInt aCmd ,CLocationService *aService):iCount(0) |
44 TInt HandleNotifyL(HPositionGenericInfo* aPosInfo , TInt aError) ; |
53 { |
45 |
54 iCmd = aCmd ; |
46 ASyncCB() :iCmd(0) , iRetStatus(KErrGeneral) , iCount(0) //Default constructor |
55 iService = aService ; |
47 { |
56 |
48 } |
57 } |
49 ASyncCB(TInt transId,TInt aCmd , CLocationService *aService) ; |
|
50 |
|
51 inline TUint GetRequestType(void) |
|
52 { |
|
53 return iRequestType ; |
|
54 } |
|
55 /** |
|
56 * GetTransactionId function returns transcation id associated with current async object |
|
57 * |
|
58 */ |
|
59 inline TInt32 GetTransactionId(void) |
|
60 { |
|
61 return iTransactionId ; |
|
62 } |
|
63 }; |
|
64 |
|
65 |
|
66 ASyncCB :: ASyncCB(TInt transId,TInt aCmd ,CLocationService *aService):iCount(0) |
|
67 { |
|
68 iCmd = aCmd ; |
|
69 iService = aService ; |
|
70 |
|
71 iTransactionId = transId; |
|
72 iRequestType = aCmd; |
|
73 } |
58 |
74 |
59 TInt ASyncCB :: HandleNotifyL (HPositionGenericInfo* aPosInfo , TInt Error ) |
75 TInt ASyncCB :: HandleNotifyL (HPositionGenericInfo* aPosInfo , TInt Error ) |
60 { |
76 { |
61 if(iCmd == TRACE) |
77 if(iCmd == TRACE) |
62 { |
78 { |
63 iService->CancelOnGoingService(ECancelTrace) ; |
79 if(iService->CancelService(this->GetTransactionId())) |
64 } |
80 reqErr1 = KErrGeneral; |
65 else if(iCmd == GETLOCATION) |
81 } |
66 { |
82 else if(iCmd == GETLOCATION) |
67 iService->GetLocationL(this,EBasicInfo) ; |
83 { |
68 iCount++ ; |
84 iCount++; |
69 } |
85 TRAPD(err,iService->GetLocationL(this,EBasicInfo)); |
70 |
86 if(err) |
71 if(iCount > 3) |
87 reqErr1 = KErrGeneral; |
72 { |
88 } |
73 CActiveScheduler *current = CActiveScheduler :: Current() ; |
89 |
74 current->Stop() ; |
90 if(iCount > 2) |
75 } |
91 { |
76 iRetStatus = KErrNone ; |
92 CActiveScheduler *current = CActiveScheduler :: Current() ; |
77 return iRetStatus ; |
93 current->Stop() ; |
78 } |
94 } |
|
95 iRetStatus = KErrNone ; |
|
96 return iRetStatus ; |
|
97 } |
79 |
98 |
80 |
99 |
81 TInt StrayTestL() |
100 TInt StrayTestL() |
82 { |
101 { |
83 |
102 __UHEAP_MARK ; |
84 CActiveScheduler *Scheduler = new CActiveScheduler ; |
103 reqErr1 = KErrNone; |
|
104 CActiveScheduler *Scheduler = new CActiveScheduler ; |
85 |
105 |
86 CActiveScheduler :: Install(Scheduler) ; |
106 CActiveScheduler :: Install(Scheduler) ; |
87 CLocationService *CoreObj = CLocationService ::NewL() ; |
107 CLocationService *CoreObj = CLocationService ::NewL() ; |
88 ASyncCB Updates(TRACE , CoreObj) ; |
108 ASyncCB Updates(12,TRACE , CoreObj) ; |
89 ASyncCB GetLoc(GETLOCATION , CoreObj) ; |
109 ASyncCB GetLoc(13,GETLOCATION , CoreObj) ; |
90 |
110 |
91 // GelocUpdateCallBack MyUpdates(&CmdId , (CLocationService *)NULL) ; |
111 // GelocUpdateCallBack MyUpdates(&CmdId , (CLocationService *)NULL) ; |
92 CoreObj->TraceL(&Updates,EBasicInfo) ; |
112 CoreObj->TraceL(&Updates,EBasicInfo) ; |
93 CoreObj->GetLocationL(&GetLoc,EBasicInfo) ; |
113 CoreObj->GetLocationL(&GetLoc,EBasicInfo) ; |
94 |
114 |
95 CActiveScheduler :: Start() ; |
115 CActiveScheduler :: Start() ; |
96 return 0 ; // Controll never reaches here |
116 delete Scheduler; |
97 } |
117 delete CoreObj; |
|
118 __UHEAP_MARKEND ; |
|
119 return reqErr1 ; |
|
120 } |
98 |
121 |
99 |
122 |
100 TInt StrayTest(TAny */*Arg*/) |
123 TInt StrayTest(TAny */*Arg*/) |
101 { |
124 { |
102 CTrapCleanup* cleanup = CTrapCleanup::New(); |
125 TInt errval; |
103 //Install a new active scheduler to this thread |
126 CTrapCleanup* cleanup = CTrapCleanup::New(); |
104 TRAPD(err , StrayTestL()) ; |
127 //Install a new active scheduler to this thread |
105 delete cleanup ; |
128 TRAPD(err , errval = StrayTestL()) ; |
106 return 0 ; |
129 delete cleanup ; |
107 } |
130 return errval | err ; |
|
131 } |
108 |
132 |
109 |
|