0
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <e32std.h>
|
|
19 |
// User includes
|
|
20 |
#include "trksrvcmdcodes.h"
|
|
21 |
#include "trksrvserver.h"
|
|
22 |
#include "trkdebugmanager.h"
|
|
23 |
#include "TrkConnData.h"
|
|
24 |
#include "TrkEngine.h"
|
|
25 |
|
|
26 |
TTrkConnType GetCmdLineConnTypeL();
|
|
27 |
void RunServerL();
|
|
28 |
|
|
29 |
TTrkConnType GetCmdLineConnTypeL()
|
|
30 |
{
|
|
31 |
TTrkConnType connType = ETrkConnInvalid;
|
|
32 |
|
|
33 |
// Get command line argument
|
|
34 |
if (User::CommandLineLength() > 0)
|
|
35 |
{
|
|
36 |
TBuf<512> commandLineArguments;
|
|
37 |
User::CommandLine( commandLineArguments );
|
|
38 |
|
|
39 |
// Check command line argument
|
|
40 |
if (0 == commandLineArguments.Compare(KCmdLineConnTypeUsb))
|
|
41 |
{
|
|
42 |
connType = ETrkUsbDbgTrc;
|
|
43 |
}
|
|
44 |
else if (0 == commandLineArguments.Compare(KCmdLineConnTypeXti))
|
|
45 |
{
|
|
46 |
connType = ETrkXti;
|
|
47 |
}
|
|
48 |
}
|
|
49 |
|
|
50 |
return connType;
|
|
51 |
}
|
|
52 |
|
|
53 |
//
|
|
54 |
// RunServerL()
|
|
55 |
// Creates trk server, signals the client and starts the server
|
|
56 |
//
|
|
57 |
|
|
58 |
void RunServerL()
|
|
59 |
{
|
|
60 |
RProcess().SetPriority(EPriorityHigh);
|
|
61 |
RThread().SetPriority(EPriorityAbsoluteHigh);
|
|
62 |
|
|
63 |
// Create and install the active scheduler we need
|
|
64 |
CActiveScheduler* scheduler = new CActiveScheduler;
|
|
65 |
if (scheduler == 0)
|
|
66 |
User::Leave(KErrNoMemory);
|
|
67 |
// now push the scheduler onto the cleanup stack
|
|
68 |
CleanupStack::PushL(scheduler);
|
|
69 |
|
|
70 |
CActiveScheduler::Install(scheduler);
|
|
71 |
|
|
72 |
CTrkDebugManager* trkDebugMgr = CTrkDebugManager::NewLC();
|
|
73 |
// Create server
|
|
74 |
CTrkSrvServer::NewLC(trkDebugMgr);
|
|
75 |
TTrkConnType connType = GetCmdLineConnTypeL();
|
|
76 |
if (connType != ETrkConnInvalid)
|
|
77 |
{
|
|
78 |
TRAPD(error, trkDebugMgr->StartDebuggingL(connType));
|
|
79 |
if (error != KErrNone)
|
|
80 |
{
|
|
81 |
// We just ignore the error here since the error is managed by the debug manager
|
|
82 |
}
|
|
83 |
}
|
|
84 |
else
|
|
85 |
{
|
|
86 |
TRAPD(error, trkDebugMgr->StartDebuggingL());
|
|
87 |
if (error != KErrNone)
|
|
88 |
{
|
|
89 |
// We just ignore the error here since the error is managed by the debug manager
|
|
90 |
}
|
|
91 |
}
|
|
92 |
|
|
93 |
// Initialisation complete, now signal the client
|
|
94 |
#ifdef EKA2
|
|
95 |
User::LeaveIfError(User::RenameThread(KTrkServerName));
|
|
96 |
#else
|
|
97 |
User::LeaveIfError(RThread().RenameMe(KTrkServerName));
|
|
98 |
#endif
|
|
99 |
RProcess::Rendezvous(KErrNone);
|
|
100 |
|
|
101 |
// Ready to run
|
|
102 |
CActiveScheduler::Start();
|
|
103 |
|
|
104 |
trkDebugMgr->StopDebugging();
|
|
105 |
|
|
106 |
// Cleanup the server and scheduler
|
|
107 |
CleanupStack::PopAndDestroy(3, scheduler);
|
|
108 |
}
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
//
|
|
113 |
// Main Entry Point
|
|
114 |
//
|
|
115 |
|
|
116 |
TInt E32Main()
|
|
117 |
{
|
|
118 |
__UHEAP_MARK;
|
|
119 |
|
|
120 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
|
121 |
if (cleanup == 0)
|
|
122 |
User::Panic(_L("Trk Server failed to allocate CTrapCleanup"), __LINE__);
|
|
123 |
|
|
124 |
TInt error = KErrNone;
|
|
125 |
|
|
126 |
if (cleanup)
|
|
127 |
{
|
|
128 |
TRAP(error, RunServerL());
|
|
129 |
delete cleanup;
|
|
130 |
}
|
|
131 |
|
|
132 |
if (error != KErrNone)
|
|
133 |
{
|
|
134 |
User::Panic(_L("Trk Server failed to start"), __LINE__);
|
|
135 |
}
|
|
136 |
|
|
137 |
__UHEAP_MARKEND;
|
|
138 |
|
|
139 |
return error;
|
|
140 |
}
|
|
141 |
|