dbgagents/trkagent/xtidriver/TrkXtiDriver.cpp
author bdonegan
Thu, 30 Sep 2010 16:15:48 +0100
changeset 3 b667e5204120
parent 0 c6b0df440bee
permissions -rw-r--r--
Remove reference to cinidata in order to allow TrkEngine to build
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     1
/*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     2
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     3
* All rights reserved.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     4
* This component and the accompanying materials are made available
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     6
* which accompanies this distribution, and is available
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     8
*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     9
* Initial Contributors:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    11
*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    12
* Contributors:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    13
*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    14
* Description: 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    15
*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    16
*/
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    17
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    18
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    19
#ifdef __WINS__
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    20
#error - this driver cannot be built for emulation
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    21
#endif
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    22
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    23
#include <e32def.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    24
#include <e32cmn.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    25
#include <kernel.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    26
#include <kern_priv.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    27
#include <arm.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    28
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    29
#include "TrkXtiComm.h"
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    30
#include "TrkXtiDriver.h"
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    31
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    32
#define KTrkAppSecurUid 0x200170BB
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    33
#define KTrkExeSecurUid 0x200159E2
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    34
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    35
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    36
// Static function definitions
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    37
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    38
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    39
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    40
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    41
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    42
// DTrkXtiDriverFactory implementation
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    43
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    44
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    45
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    46
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    47
// DTrkXtiDriverFactory constructor
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    48
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    49
DTrkXtiDriverFactory::DTrkXtiDriverFactory()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    50
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    51
    iVersion = TVersion(KMajorXtiVersionNumber, KMinorXtiVersionNumber, KBuildXtiVersionNumber);    
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    52
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    53
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    54
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    55
// DTrkXtiDriverFactory::Create
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    56
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    57
TInt DTrkXtiDriverFactory::Create(DLogicalChannelBase*& aChannel)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    58
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    59
	if (iOpenChannels != 0)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    60
		return KErrInUse; // a channel is already open
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    61
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    62
	aChannel = new DTrkXtiChannel(this);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    63
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    64
	return aChannel ? KErrNone : KErrNoMemory;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    65
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    66
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    67
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    68
// DTrkXtiDriverFactory::Install
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    69
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    70
TInt DTrkXtiDriverFactory::Install()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    71
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    72
    return(SetName(&KTrkXtiDriverName));
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    73
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    74
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    75
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    76
// DTrkXtiDriverFactory::Install
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    77
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    78
void DTrkXtiDriverFactory::GetCaps(TDes8& aDes) const
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    79
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    80
    TCapsTrkXtiDriver b;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    81
    b.iVersion = TVersion(KMajorXtiVersionNumber, KMinorXtiVersionNumber, KBuildXtiVersionNumber);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    82
    
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    83
    Kern::InfoCopy(aDes,(TUint8*)&b, sizeof(b));
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    84
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    85
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    86
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    87
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    88
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    89
// DTrkXtiChannel implementation
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    90
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    91
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    92
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    93
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    94
// DTrkXtiChannel constructor
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    95
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    96
DTrkXtiChannel::DTrkXtiChannel(DLogicalDevice* aLogicalDevice)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    97
					: iRxPendingMsg(EFalse),
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    98
					  iInterruptId(76)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    99
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   100
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   101
	LOG_MSG("DTrkXtiChannel::DTrkXtiChannel()");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   102
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   103
	iDevice = aLogicalDevice;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   104
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   105
	iClientThread = &Kern::CurrentThread();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   106
	TInt err = iClientThread->Open();	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   107
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   108
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   109
	LOG_MSG("DTrkXtiChannel::DTrkXtiChannel() End"); 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   110
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   111
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   112
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   113
// DTrkXtiChannel destructor
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   114
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   115
DTrkXtiChannel::~DTrkXtiChannel()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   116
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   117
	LOG_MSG("DTrkXtiChannel::~DTrkXtiChannel()");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   118
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   119
	Kern::SafeClose((DObject*&)iClientThread, NULL);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   120
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   121
	if (iLock)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   122
		iLock->Close(NULL);	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   123
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   124
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   125
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   126
// DTrkXtiChannel::DoCreate
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   127
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   128
TInt DTrkXtiChannel::DoCreate(TInt /*aUnit*/, const TDesC* /*anInfo*/, const TVersion& aVer)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   129
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   130
	LOG_MSG("DTrkXtiChannel::DoCreate()");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   131
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   132
  	if (!Kern::QueryVersionSupported(TVersion(KMajorXtiVersionNumber, KMinorXtiVersionNumber, KBuildXtiVersionNumber), aVer))
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   133
		return KErrNotSupported; 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   134
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   135
	//Setup the driver for receiving client messages
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   136
	iDFCQue = NULL;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   137
	TBuf8<KMaxInfoName> xtiDFC = _L8("XTI DFC");;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   138
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   139
	TInt err = Kern::DfcQCreate(iDFCQue, 27, &xtiDFC);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   140
	if (err == KErrNone)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   141
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   142
		SetDfcQ(iDFCQue);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   143
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   144
	else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   145
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   146
		SetDfcQ(Kern::DfcQue0());
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   147
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   148
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   149
	iMsgQ.Receive();  	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   150
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   151
	// create subscriber and subscribe to receive trk messages from TraceCore
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   152
	iTrkXtiSubscriber = new DTrkXtiSubscriber;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   153
 	if (!iTrkXtiSubscriber)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   154
		return KErrNoMemory;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   155
 	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   156
	err = iTrkXtiSubscriber->Create(this, iClientThread);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   157
	if (err != KErrNone)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   158
		return err;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   159
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   160
	err = Kern::SemaphoreCreate(iLock, _L("TrkXtiDriverWriteLock"), 1 /* Initial count */);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   161
	if (err != KErrNone)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   162
		return err;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   163
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   164
	return KErrNone;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   165
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   166
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   167
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   168
// DTrkXtiChannel::DoCancel
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   169
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   170
void DTrkXtiChannel::DoCancel(TInt aReqNo)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   171
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   172
	LOG_MSG("DTrkXtiChannel::DoCancel()");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   173
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   174
	switch(aReqNo)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   175
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   176
		case RTrkXtiDriver::ERequestReadCancel:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   177
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   178
			Kern::RequestComplete(iClientThread, iRxRequestStatus, KErrCancel);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   179
			iRxClientBuffer = NULL;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   180
			iRxRequestStatus = NULL;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   181
			iRxClientBufferLength = 0;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   182
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   183
		break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   184
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   185
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   186
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   187
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   188
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   189
// DTrkXtiChannel::DoRequest
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   190
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   191
void DTrkXtiChannel::DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   192
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   193
	LOG_MSG("DTrkXtiChannel::DoRequest()");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   194
		
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   195
	switch(aReqNo)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   196
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   197
		case RTrkXtiDriver::ERequestRead:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   198
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   199
			iRxRequestStatus = aStatus;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   200
			iRxClientBuffer = a1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   201
			iRxClientBufferLength = (TUint32)a2;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   202
			
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   203
			if (iRxPendingMsg)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   204
			{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   205
				TInt err = Kern::ThreadDesWrite(iClientThread, iRxClientBuffer, iRxPendingMsgBuffer, 0, KChunkShiftBy0, iClientThread);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   206
				Kern::RequestComplete(iClientThread, iRxRequestStatus, err);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   207
		
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   208
				iRxRequestStatus = NULL;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   209
				iRxPendingMsg = EFalse;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   210
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   211
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   212
			break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   213
		}		
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   214
		default:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   215
			Kern::RequestComplete(iClientThread, aStatus, KErrNotSupported);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   216
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   217
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   218
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   219
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   220
// DTrkXtiChannel::DoControl
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   221
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   222
TInt DTrkXtiChannel::DoControl(TInt aFunction, TAny* a1, TAny* a2)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   223
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   224
	LOG_MSG("DTrkXtiChannel::DoControl()");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   225
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   226
	TInt err = KErrNone;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   227
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   228
	switch(aFunction)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   229
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   230
		case RTrkXtiDriver::EControlWrite:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   231
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   232
			//lock the Semaphore so that write doesn't happen when a write is already in progress.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   233
			Kern::SemaphoreWait(*iLock);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   234
			err = DoWrite((TUint32)a1, a2);			
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   235
			Kern::SemaphoreSignal(*iLock);			
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   236
			break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   237
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   238
		default:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   239
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   240
			return KErrGeneral;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   241
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   242
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   243
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   244
	if (KErrNone != err)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   245
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   246
		LOG_MSG2("Error %d from control function", err);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   247
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   248
	return err;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   249
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   250
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   251
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   252
// DTrkXtiChannel::HandleMsg
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   253
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   254
void DTrkXtiChannel::HandleMsg(TMessageBase* aMsg)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   255
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   256
	LOG_MSG("DTrkXtiChannel::HandleMsg()");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   257
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   258
	TThreadMessage& m = *(TThreadMessage*)aMsg;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   259
	TInt id = m.iValue;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   260
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   261
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   262
	if (id == (TInt)ECloseMsg)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   263
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   264
        if (iTrkXtiSubscriber)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   265
        {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   266
            Kern::SemaphoreWait(*iLock);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   267
            delete iTrkXtiSubscriber;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   268
            iTrkXtiSubscriber = NULL;   
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   269
            Kern::SemaphoreSignal(*iLock);              
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   270
        }
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   271
		m.Complete(KErrNone, EFalse);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   272
		return;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   273
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   274
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   275
	if (id == KMaxTInt)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   276
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   277
		// DoCancel
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   278
		DoCancel(m.Int0());
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   279
		m.Complete(KErrNone, ETrue); 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   280
		return;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   281
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   282
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   283
	if (id < 0)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   284
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   285
		// DoRequest
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   286
		TRequestStatus* pStatus = (TRequestStatus*)m.Ptr0();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   287
		DoRequest(~id, pStatus, m.Ptr1(), m.Ptr2());
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   288
		m.Complete(KErrNone, ETrue);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   289
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   290
	else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   291
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   292
		// DoControl
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   293
		TInt err = DoControl(id, m.Ptr0(), m.Ptr1());
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   294
		m.Complete(err, ETrue);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   295
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   296
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   297
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   298
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   299
// DTrkXtiChannel::DoWrite
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   300
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   301
TInt DTrkXtiChannel::DoWrite(TUint32 aLength, TAny* a2)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   302
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   303
	LOG_MSG("DTrkXtiChannel::DoWrite()");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   304
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   305
	TInt err = KErrNone;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   306
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   307
	err = Kern::ThreadDesRead(iClientThread, a2, iTxBuffer, 0, KChunkShiftBy0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   308
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   309
	if (err == KErrNone)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   310
	{	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   311
		err = WriteXtiChannel(iTxBuffer);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   312
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   313
	return err;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   314
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   315
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   316
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   317
// DTrkXtiChannel::WriteXtiChannel
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   318
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   319
// This function writes all the data in the descriptor in one message
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   320
TInt DTrkXtiChannel::WriteXtiChannel(TDesC8& aDes)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   321
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   322
	TInt err = KErrNone;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   323
		err = iTrkXtiSubscriber->Send(aDes);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   324
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   325
	return err;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   326
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   327
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   328
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   329
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   330
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   331
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   332
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   333
// DTrkXtiChannel::DoCompleteRx
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   334
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   335
void DTrkXtiChannel::DoCompleteRx(const TDesC8& aMessage)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   336
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   337
	LOG_MSG("DTrkXtiChannel::DoCompleteRx()");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   338
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   339
	// If there is a pending read request, complete the request with this message.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   340
	// Otherwise store the message, ideally we should queue the messages, but having 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   341
	// a large buffer is failing to initialize at the startup.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   342
	// For now, we will just store only one message
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   343
	// If for some reason, TRK is waiting on something and doesn't read for a while, 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   344
	// then its possible that we will loose messages. 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   345
	Kern::SemaphoreWait(*iLock);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   346
	if (iRxRequestStatus)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   347
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   348
		TInt err = Kern::ThreadDesWrite(iClientThread, iRxClientBuffer, aMessage, 0, KChunkShiftBy0, iClientThread);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   349
		Kern::RequestComplete(iClientThread, iRxRequestStatus, err);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   350
		
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   351
		iRxRequestStatus = NULL;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   352
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   353
	else if (!iRxPendingMsg)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   354
	{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   355
		iRxPendingMsgBuffer.Copy(aMessage);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   356
		iRxPendingMsg = ETrue;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   357
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   358
	Kern::SemaphoreSignal(*iLock);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   359
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   360
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   361
DECLARE_STANDARD_LDD()
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   362
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   363
    return new DTrkXtiDriverFactory;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   364
}