dcmofw/dcmoclient/src/dcmoclient.cpp
changeset 0 b497e44ab2fc
child 24 13d7c31c74e0
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     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:  DCMO Client implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32svr.h>
       
    19 #include <featmgr.h>
       
    20 #include "dcmoclientserver.h"
       
    21 #include "dcmoconst.h"
       
    22 #include "dcmoclient.h"
       
    23 #include "dcmodebug.h"
       
    24 
       
    25 
       
    26 // Standard server startup code
       
    27 // 
       
    28 static TInt StartServerL()
       
    29 	{
       
    30 	RDEBUG("DCMOServer: Starting server...");
       
    31 	
       
    32 	// EPOC and EKA 2 is easy, we just create a new server process. Simultaneous
       
    33 	// launching of two such processes should be detected when the second one
       
    34 	// attempts to create the server object, failing with KErrAlreadyExists.
       
    35 	RProcess server;
       
    36 	TInt r=server.Create(KDCMOServerName,KNullDesC);
       
    37 
       
    38 	if (r!=KErrNone)
       
    39 		{
       
    40 		RDEBUG_2("DCMOClient: server start failed %d",r);
       
    41 		return r;
       
    42 		}
       
    43 	TRequestStatus stat;
       
    44 	server.Rendezvous(stat);
       
    45 	if (stat!=KRequestPending)
       
    46 		server.Kill(0);		// abort startup
       
    47 	else
       
    48 		server.Resume();	// logon OK - start the server
       
    49 	RDEBUG("DCMOClient: Started");
       
    50 	User::WaitForRequest(stat);		// wait for start or death
       
    51 	// we can't use the 'exit reason' if the server panicked as this
       
    52 	// is the panic 'reason' and may be '0' which cannot be distinguished
       
    53 	// from KErrNone
       
    54 	r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
       
    55 	server.Close();
       
    56 	return r;
       
    57 	}
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // RDCMOClient::NewL() 
       
    61 // ---------------------------------------------------------------------------	
       
    62 EXPORT_C RDCMOClient* RDCMOClient::NewL()
       
    63 	{
       
    64 	RDEBUG(" RDCMOClient::NewL--Begin");
       
    65 	FeatureManager::InitializeLibL();
       
    66 	TBool featureSupport = FeatureManager::FeatureSupported( KFeatureIdFfRuntimeDeviceCapabilityConfiguration );
       
    67 	FeatureManager::UnInitializeLib();
       
    68 	
       
    69 	if ( ! featureSupport )  
       
    70   {
       
    71 		// feature is not supported
       
    72 		RDEBUG(" RDCMOClient::NewL-- DCMO Feature is Not Supported" );	
       
    73 		User::Leave(KErrNotSupported);
       
    74 	}
       
    75 		
       
    76 	RDCMOClient* self = new( ELeave ) RDCMOClient( );
       
    77 	CleanupStack::PushL( self );
       
    78 	TInt err = self->OpenL();
       
    79   CleanupStack::Pop();
       
    80   RDEBUG_2(" RDCMOClient::NewL--End error as %d",err);  	
       
    81   return self;
       
    82   
       
    83 	}
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // RDCMOClient::~RDCMOClient()
       
    87 // Destructor.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 RDCMOClient::~RDCMOClient()
       
    91 {
       
    92     Close();
       
    93 }	
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // RDCMOClient::OpenL()
       
    97 // ---------------------------------------------------------------------------
       
    98 TInt RDCMOClient::OpenL()
       
    99 	{	
       
   100 	RDEBUG("RDCMOClient::OpenL()- Begin");
       
   101 	TInt res = KErrNone;	
       
   102 	res = CreateSession( KDCMOServerName,TVersion(KDCMOServerMajorVersionNumber, KDCMOServerMinorVersionNumber, KDCMOServerBuildVersionNumber), KDCMOServerMessageSlotNumber );
       
   103 	if ( res == KErrNotFound || res == KErrServerTerminated )
       
   104 		{
       
   105 		RDEBUG("RDCMOClient::OpenL()- session not created");
       
   106 		res = StartServerL();
       
   107 		User::LeaveIfError( res );
       
   108 		res = CreateSession( KDCMOServerName,TVersion(KDCMOServerMajorVersionNumber, KDCMOServerMinorVersionNumber, KDCMOServerBuildVersionNumber), KDCMOServerMessageSlotNumber );
       
   109 		}
       
   110 	User::LeaveIfError( res );
       
   111 	RDEBUG_2("RDCMOClient::OpenL()- End with Errorcode as %d",res);	
       
   112 	return res;
       
   113 	}
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // RDCMOClient::Close()
       
   117 // ---------------------------------------------------------------------------
       
   118 void RDCMOClient::Close()
       
   119 	{
       
   120 	RDEBUG(" RDCMOClient::Close");
       
   121 	RSessionBase::Close();  //basecall
       
   122 	}
       
   123 
       
   124 
       
   125 // ----------------------------------------------------------------------------
       
   126 // RDCMOClient::GetDCMOIntAttributeValue()
       
   127 // ----------------------------------------------------------------------------	
       
   128 TDCMOStatus RDCMOClient::GetDCMOIntAttributeValue(TDes& aCategory, TDCMONode aId, TInt& aValue)
       
   129 	{		
       
   130     RDEBUG(" RDCMOClient::GetDCMOIntAttributeValue--Begin");
       
   131 	TPckg<TDCMONode> p(aId);
       
   132 	TPckg<TInt> intValue(aValue);
       
   133 	TDCMOStatus status(EDcmoSuccess);
       
   134 	TPckg<TDCMOStatus> statusValue(status);
       
   135 	TInt err = SendReceive( EDcmoGetAttrInt, TIpcArgs(&aCategory, &p, &intValue, &statusValue));
       
   136 	if(err != KErrNone)
       
   137 	    status = EDcmoFail;  	
       
   138 	RDEBUG_2(" RDCMOClient::GetDCMOIntAttributeValue--End error as %d",err);
       
   139 	return status;
       
   140 	}
       
   141 
       
   142 // ----------------------------------------------------------------------------
       
   143 // RDCMOClient::GetDCMOStrAttributeValue()
       
   144 // ----------------------------------------------------------------------------	
       
   145 TDCMOStatus RDCMOClient::GetDCMOStrAttributeValue(TDes& aCategory, TDCMONode aId, TDes& aStrValue)
       
   146 	{		
       
   147 	RDEBUG(" RDCMOClient::GetDCMOStrAttributeValue--Begin");
       
   148 	TPckg<TDCMONode> p(aId);
       
   149 	TDCMOStatus status(EDcmoSuccess);
       
   150 	TPckg<TDCMOStatus> statusValue(status);
       
   151 	TInt err = SendReceive( EDcmoGetAttrStr, TIpcArgs(&aCategory, &p, &aStrValue, &statusValue));
       
   152 	if(err != KErrNone)
       
   153 	    status = EDcmoFail;
       
   154 	RDEBUG_2(" RDCMOClient::GetDCMOStrAttributeValue--End error as %d",err);
       
   155 	return status;
       
   156 	}
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // RDCMOClient::SetDCMOIntAttributeValue()
       
   160 // ----------------------------------------------------------------------------	
       
   161 TDCMOStatus RDCMOClient::SetDCMOIntAttributeValue(TDes& aCategory, TDCMONode aId, TInt aValue)
       
   162 	{		
       
   163 	RDEBUG(" RDCMOClient::SetDCMOIntAttributeValue--Begin");
       
   164 	TPckg<TDCMONode> p(aId);
       
   165 	TPckg<TInt> intValue(aValue);
       
   166 	TDCMOStatus status(EDcmoSuccess);
       
   167 	TPckg<TDCMOStatus> statusValue(status);
       
   168 	TInt err = SendReceive( EDcmoSetAttrInt, TIpcArgs(&aCategory, &p, &intValue, &statusValue));
       
   169 	if(err != KErrNone)
       
   170 	    status = EDcmoFail;
       
   171 	RDEBUG_2(" RDCMOClient::SetDCMOIntAttributeValue--End error as %d",err);
       
   172 	return status;
       
   173 	}
       
   174 	
       
   175 // ----------------------------------------------------------------------------
       
   176 // RDCMOClient::SetDCMOStrAttributeValue()
       
   177 // ----------------------------------------------------------------------------	
       
   178 TDCMOStatus RDCMOClient::SetDCMOStrAttributeValue(TDes& aCategory, TDCMONode aId, TDes& aStrValue)
       
   179 	{		
       
   180 	RDEBUG(" RDCMOClient::SetDCMOStrAttributeValue--Begin");
       
   181 	TPckg<TDCMONode> p(aId);
       
   182 	TDCMOStatus status(EDcmoSuccess);
       
   183 	TPckg<TDCMOStatus> statusValue(status);
       
   184 	TInt err = SendReceive( EDcmoSetAttrStr, TIpcArgs(&aCategory, &p, &aStrValue, &statusValue));
       
   185 	if(err != KErrNone)
       
   186 	    status = EDcmoFail;
       
   187 	RDEBUG_2(" RDCMOClient::SetDCMOStrAttributeValue--End error as %d",err);
       
   188 	return status;
       
   189 	}	
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // RDCMOClient::SearchByGroupValue()
       
   193 // ----------------------------------------------------------------------------	
       
   194 void RDCMOClient::SearchByGroupValue(TDes& aGroup, TDes& aAdapterList)
       
   195 	{		
       
   196 	RDEBUG(" RDCMOClient::SearchByGroupValue--Begin");
       
   197 	TInt err = SendReceive( EDcmoSearchAdapter, TIpcArgs(&aGroup, &aAdapterList));
       
   198 	RDEBUG_2(" RDCMOClient::SearchByGroupValue--End error as %d",err);
       
   199 	}