First public contribution.
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 "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "uloggerclient.h"
17 #include "uloggershared.h"
18 #include "uloggertools.h"
19 #include "uloggercommands.h"
29 static const TUint KMessageSlots = 32;
31 ///////////////////////////////////////////////////////////////////
33 // Definition of RULogger methods...
35 ///////////////////////////////////////////////////////////////////
38 EXPORT_C RULogger::RULogger()
44 EXPORT_C RULogger::~RULogger()
49 EXPORT_C TInt RULogger::Connect()
51 TInt retVal = StartServer();
53 if((KErrNone == retVal) || (KErrAlreadyExists == retVal))
55 retVal = CreateSession(KServerName, this->Version(), KMessageSlots);
61 EXPORT_C TInt RULogger::RunAsService(TBool /*aRunAsService*/)
65 retVal = KErrNotSupported; // Replace with SendReceive call once functionality implemented in server
67 // // Replace above with following, once functionality implemented in server:
70 // retVal = SendReceive(ERunAsService);
72 // retVal = SendReceive(EDontRunAsService);
78 EXPORT_C TInt RULogger::Start()
80 return SendReceive(EStart);
83 EXPORT_C TInt RULogger::Stop()
85 return SendReceive(EStop);
88 EXPORT_C TInt RULogger::Restart()
90 return SendReceive(ERestart);
93 EXPORT_C TInt RULogger::SetPrimaryFiltersEnabled(const CArrayFixFlat<TUint8>& aFilters, TBool aEnabled)
95 TInt retVal = KErrNone;
97 //externalize filters array to string to send it in either a
98 //ESetPrimaryFilter or ERemovePrimaryFilter message, but only if at least
99 //one filter was actually specified in the filters array
102 //prepare data to send
104 TRAP(retVal, des = ExternalizeToBufL((const CArrayFix<TUint8>&) aFilters, sizeof(TUint8)));
105 if(KErrNone == retVal)
108 TPtr8 dataPtr(des->Des());
109 TIpcArgs args(&dataPtr, aFilters.Count());
111 retVal = SendReceive(ESetPrimaryFilter, args);
113 retVal = SendReceive(ERemovePrimaryFilter, args);
119 retVal = KErrArgument;
122 if(retVal == KErrAlreadyExists)
128 EXPORT_C TInt RULogger::GetPrimaryFiltersEnabled(CArrayFixFlat<TUint8>& aFilters)
130 TInt retVal = KErrNone;
132 HBufC8 *buf = HBufC8::New(256);
135 TPtr8 ptr(buf->Des());
137 retVal = SendReceive(EGetPrimaryFilters, args);
138 if (KErrNone == retVal)
141 TRAP(retVal, InternalizeFromBufL(*buf, aFilters, tmp));
155 EXPORT_C TInt RULogger::SetSecondaryFiltersEnabled(const RArray<TUint32>& aFilters, TBool aEnabled)
157 TInt retVal = KErrNone;
159 //ensure max secondary filters limit isn't exceeded, otherwise return error
160 if (aFilters.Count() > KMaxSecondaryFiltersLimit)
162 retVal = KErrArgument;
166 //externalize filters array to string to send it in either a
167 //ESetSecondaryFilter or ERemoveSecondaryFilter message, but only if at least
168 //one filter was actually specified in the filters array
171 //prepare data to send
174 TRAP(retVal, des = ExternalizeToBufL(aFilters, sizeof(TUint32)));
175 if(KErrNone == retVal)
178 TPtr8 dataPtr(des->Des());
179 TIpcArgs args(&dataPtr, aFilters.Count());
181 retVal = SendReceive(ESetSecondaryFilter, args);
183 retVal = SendReceive(ERemoveSecondaryFilter, args);
186 //clean up string if necessary
190 retVal = KErrArgument;
196 EXPORT_C TInt RULogger::GetSecondaryFiltersEnabled(RArray<TUint32>& aFilters)
198 TInt retVal = KErrNone;
200 HBufC8 *buf = HBufC8::New(KMaxSecondaryFiltersLimit*sizeof(TUint32));
203 TPtr8 ptr(buf->Des());
205 retVal = SendReceive(EGetSecondaryFilters, args);
206 if(KErrNone == retVal)
209 TRAP(retVal, InternalizeFromBufL(*buf, aFilters, tmp));
217 retVal = KErrNoMemory;
223 EXPORT_C TInt RULogger::SetSecondaryFilteringEnabled(TBool aEnabled)
228 retVal = SendReceive(EEnableSecondaryFiltering);
230 retVal = SendReceive(EDisableSecondaryFiltering);
235 EXPORT_C TInt RULogger::GetSecondaryFilteringEnabled(TBool& aEnabled)
237 //this code is a copy of GetModuleUidFiltering && GetBuffer && Notification etc etc....
238 //should put all of it in a separate method...
239 TInt retVal = KErrNone;
241 HBufC8 *buf = HBufC8::New(200);
244 //send request to server
245 TPtr8 ptr(buf->Des());
247 retVal = SendReceive(EGetSecondaryFiltering, args);
252 retVal = val.Val(aEnabled);
259 retVal = KErrNoMemory;
265 EXPORT_C TInt RULogger::ActivateOutputPlugin(const TDesC8& aPluginName)
267 TIpcArgs iArgs; //Ipc arguments
268 iArgs.Set(0, &aPluginName);
269 return SendReceive(ESetActivePlugin, iArgs);
272 EXPORT_C TInt RULogger::GetActiveOutputPlugin(TDes8& aPluginName)
274 TInt retVal = KErrNone;
276 HBufC8 *buf = HBufC8::New(2048); // Need to push on stack in that case
277 // does it matter if its 8 or 16 buf?
280 //send get active output plug-in message
281 TPtr8 ptr(buf->Des());
284 retVal = SendReceive(EGetActivePlugin, args);
286 //parse response buffer
288 if(pos != KErrNotFound)
290 pos = buf->Des().Find(KSeparator); // Find separator
291 //just don't send the separator?
294 TPtrC8 ptrVal(buf->Des().Left(pos));
295 if (aPluginName.MaxLength() < pos)
296 retVal = KErrOverflow;
298 aPluginName.Copy(ptrVal);
307 retVal = KErrNoMemory;
313 EXPORT_C TInt RULogger::GetInstalledOutputPlugins(CArrayPtrFlat<HBufC8>& aPluginNames)
315 TInt retVal = KErrNone;
317 HBufC8 *buf = HBufC8::New(2048);
320 TPtr8 ptr(buf->Des());
323 retVal = SendReceive(EGetInstalledPlugins, args);
328 while(pos != KErrNotFound)
330 pos = buf->Des().Find(KSeparator);
333 TPtrC8 ptrVal(buf->Des().Left(pos));
334 HBufC8 *bufDes = HBufC8::New(ptrVal.Length()+8);
337 bufDes->Des().Copy(ptrVal);
338 TRAP(err, aPluginNames.AppendL(bufDes));
340 buf->Des().Delete(0,pos+1);
351 EXPORT_C TInt RULogger::ActivateInputPlugin(const TDesC8& aPluginName)
354 iArgs.Set(0, &aPluginName);
355 return SendReceive(ESetActiveInputPlugin, iArgs);
358 EXPORT_C TInt RULogger::GetActiveInputPlugin(TDes8& aPluginName)
360 TInt retVal = KErrNone;
362 HBufC8 *buf = HBufC8::New(1024);// Push on stack in that case
365 //send get active input plug-in message
366 TPtr8 ptr(buf->Des());
369 retVal = SendReceive(EGetActiveInputPlugin, args);
371 //parse response buffer
373 if(pos != KErrNotFound)
375 pos = buf->Des().Find(KSeparator);
378 buf->Des().Delete(0, pos+1); // Get rid of media number + separator
379 pos = buf->Des().Find(KSeparator); // Find separator after plug-in name
383 TPtrC8 ptrVal(buf->Des().Left(pos));
384 if (aPluginName.MaxLength() < pos)
385 retVal = KErrOverflow;
387 aPluginName.Copy(ptrVal);
397 retVal = KErrNoMemory;
403 EXPORT_C TInt RULogger::DeActivateInputPlugin()
405 TInt retVal = KErrNone;
407 //get currently active input plug-in name
408 TBuf8<KMaxPath> activePluginName;
409 retVal = GetActiveInputPlugin(activePluginName);
411 //deactivate currently active input plug-in
412 if (KErrNone == retVal)
415 iArgs.Set(0, &activePluginName);
416 retVal = SendReceive(EDeactivateInputPlugin, iArgs);
422 EXPORT_C TInt RULogger::GetInstalledInputPlugins(CArrayPtrFlat<HBufC8>& aPluginNames)
424 TInt retVal = KErrNone;
426 HBufC8 *buf = HBufC8::New(2048);//Push on stack in that case
429 TPtr8 ptr(buf->Des());
432 retVal = SendReceive(EGetInputPlugins, args);
437 while(pos != KErrNotFound)
439 pos = buf->Des().Find(KSeparator);
442 TPtrC8 ptrVal(buf->Des().Left(pos));
443 HBufC8 *bufDes = HBufC8::New(ptrVal.Length()+8);//push on stack
446 bufDes->Des().Copy(ptrVal);
447 TRAP(err, aPluginNames.AppendL(bufDes));
449 buf->Des().Delete(0,pos+1);
460 EXPORT_C TInt RULogger::SetPluginConfigurations(const TDesC8& aPluginName, const TPluginConfiguration& aConfiguration)
462 TInt retVal = KErrNone;
464 if(aConfiguration.Key().Length()==0||aConfiguration.Value().Length()==0)
467 //count total_length + separators
469 length+=aConfiguration.Key().Length()+aConfiguration.Value().Length()+2;
471 HBufC *configs = HBufC::New(length);// Push on stack in that case
474 TPtr formatConfigs(configs->Des());
475 formatConfigs.AppendFormat(KConfigFormat, &(aConfiguration.Key()), &(aConfiguration.Value()));
476 HBufC8 *settings= HBufC8::NewLC(configs->Length());//Push on stack in that case
479 settings->Des().Copy(configs->Des());
480 TPtr8 arg2(settings->Des());
482 TIpcArgs args; //Ipc arguments
483 args.Set(0, &aPluginName);
485 retVal = SendReceive(ESetPluginSettings,args);
486 CleanupStack::PopAndDestroy(settings);
499 EXPORT_C TInt RULogger::GetPluginConfigurations(const TDesC8& aPluginName, RPointerArray<TPluginConfiguration>& aConfigurations)
501 TInt retVal = KErrNone;
503 HBufC8 *buf = HBufC8::New(2048);//Push on stack in that case
506 TPtr8 ptr(buf->Des());
507 HBufC8 *mediaBuf = HBufC8::New(1+aPluginName.Length());// push on stack if we need to alloc this. Don't hardcode!!
510 mediaBuf->Des().Copy(aPluginName);
511 TPtr8 mediaPtr(mediaBuf->Des());
515 args.Set(0, &mediaPtr);
517 retVal = SendReceive(EGetPluginSettings, args);
519 //parse received buffer
520 TInt pos = buf->Des().Find(KSeparator);
521 while((pos != KErrNotFound) && (retVal == KErrNone))
523 TPluginConfiguration* pluginConfig = new TPluginConfiguration();// Push on stack in that case
524 //memory leak? not always deleted?
527 TPtrC8 ptrKey(buf->Des().Left(pos));
528 pluginConfig->SetKey(ptrKey);
529 buf->Des().Delete(0, pos+1);
530 pos = buf->Des().Find(KSeparator);
531 if (pos != KErrNotFound)
533 TPtrC8 ptrVal(buf->Des().Left(pos));
534 pluginConfig->SetValue(ptrVal);
535 buf->Des().Delete(0, pos+1);
536 retVal = aConfigurations.Append(pluginConfig);
540 delete pluginConfig; // Ignore trailing key
545 retVal = KErrNoMemory;
547 pos = buf->Des().Find(KSeparator);
555 retVal = KErrNoMemory;
563 retVal = KErrNoMemory;
569 EXPORT_C TInt RULogger::RemovePluginConfigurations(const TDesC8& aPluginName)
571 TInt retVal = KErrNone;
572 HBufC8 *mediaBuf = HBufC8::New(1+aPluginName.Length());// Push on stack at least
575 mediaBuf->Des().Copy(aPluginName);
576 TPtr8 mediaPtr(mediaBuf->Des());
580 args.Set(0, &mediaPtr);
581 retVal = SendReceive(ERemovePluginSettings, args);
587 retVal = KErrNoMemory;
593 EXPORT_C TInt RULogger::SetBufferSize(TInt aSize)
597 if( (aSize > KMaxBufferSize) || (aSize < 1) )
599 retVal = KErrArgument;
603 retVal = SendReceive(EResizeTraceBuffer, TIpcArgs(aSize));
609 EXPORT_C TInt RULogger::GetBufferSize(TInt& aSize)
611 TInt retVal = KErrNone;
613 HBufC8 *buf = HBufC8::New(32);// push on stack if we need to alloc this. Don't hardcode!!
616 TPtr8 ptr(buf->Des());
618 retVal = SendReceive(EGetTraceBufferSize,args);
619 if(retVal == KErrNone )
622 retVal = val.Val(aSize);
633 EXPORT_C TInt RULogger::SetNotificationSize(TInt aSize)
637 if( (aSize > KMaxBufferSize) || (aSize < 0) )
639 retVal = KErrArgument;
643 retVal = SendReceive(ESetDataNotificationSize, TIpcArgs(aSize));
649 EXPORT_C TInt RULogger::GetNotificationSize(TInt& aSize)
651 TInt retVal = KErrNone;
653 HBufC8 *buf = HBufC8::New(32);// push on stack if we need to alloc this. Don't hardcode!!
656 TPtr8 ptr(buf->Des());
658 retVal = SendReceive(EGetDataNotificationSize,args);
659 if(retVal == KErrNone )
662 retVal = val.Val(aSize);
669 retVal = KErrNoMemory;
675 EXPORT_C TInt RULogger::SetBufferMode(TInt aMode)
679 if( (aMode == EStraightBuffer) || (aMode==ECircularBuffer) )
681 retVal = SendReceive(ESetBufferMode, TIpcArgs(aMode));
685 retVal = KErrArgument;
691 EXPORT_C TInt RULogger::GetBufferMode(TInt& aMode)
693 TInt retVal = KErrNone;
695 HBufC8 *buf = HBufC8::New(32);// push on stack if we need to alloc this. Don't hardcode!!
698 TPtr8 ptr(buf->Des());
700 retVal = SendReceive(EGetBufferMode,args);
701 if(retVal == KErrNone)
704 retVal = val.Val(aMode);
711 retVal = KErrNoMemory;
717 EXPORT_C TVersion RULogger::Version()
719 return TVersion(KULoggerSrvMajorVersionNumber,KULoggerSrvMinorVersionNumber,KULoggerSrvBuildVersionNumber);
723 Internal Function - Starts the server
725 TInt RULogger::StartServer()
727 TInt retVal = KErrNone;
729 TFullName serverName;
730 TFindServer serverFinder(KServerName);
731 retVal = serverFinder.Next(serverName);
732 if(KErrNone == retVal)
734 retVal = KErrAlreadyExists;
740 retVal = server.Create(KServerName, _L(""), EOwnerProcess);
741 if(KErrNone == retVal)
743 // Synchronise with the server
744 TRequestStatus reqStatus;
745 server.Rendezvous(reqStatus);
747 // Start the test harness
749 // Server will call the reciprocal static synchronise call
750 User::WaitForRequest(reqStatus);
752 retVal = reqStatus.Int();