syncmlfw/common/sosserver_privateapi/src/NSmlPrivateAPI.cpp
changeset 0 b497e44ab2fc
child 73 ae69c2e8bc34
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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 
       
    19 #include <f32file.h>
       
    20 #include <s32mem.h>
       
    21 
       
    22 #include <nsmldebug.h>
       
    23 #include <nsmldmauthinfo.h>
       
    24 #include <NSmlPrivateAPI.h>
       
    25 #include "NSmlClientAPIDefs.h"
       
    26 #include "nsmlsosserverdefs.h"
       
    27 
       
    28 //------------------------------------------------------------
       
    29 // Launches the server.
       
    30 //------------------------------------------------------------
       
    31 //
       
    32 TInt LaunchServer()
       
    33 	{	
       
    34 	DBG_BEGIN();
       
    35 	_DBG_FILE("RNSmlPrivateAPI LaunchServer(): begin");
       
    36 	TInt res = KErrNone;
       
    37 
       
    38 	// DLL launch
       
    39 	RProcess server;
       
    40 	res = server.Create(KServerExeName, KNullDesC);
       
    41 
       
    42 	// Loading failed.
       
    43 	if ( res != KErrNone )
       
    44 		{
       
    45 		return res;
       
    46 		}
       
    47 	
       
    48 	TRequestStatus status;
       
    49 	server.Rendezvous(status);
       
    50 
       
    51 	if (status != KRequestPending)
       
    52 		{
       
    53 		server.Kill(0);		// abort startup
       
    54 		server.Close();
       
    55 		return KErrGeneral;   // status can be KErrNone: don't return status.Int()
       
    56 		}
       
    57 	else
       
    58 		{
       
    59 		server.Resume();	// logon OK - start the server
       
    60 		}
       
    61 		
       
    62 	User::WaitForRequest(status);
       
    63 	
       
    64 	server.Close();
       
    65 
       
    66 	_DBG_FILE("RNSmlPrivateAPI LaunchServer(): end");
       
    67 	
       
    68 	return status.Int();
       
    69 	}
       
    70 
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // RNSmlPrivateAPI::RNSmlPrivateAPI()
       
    74 // Constructor
       
    75 // ---------------------------------------------------------
       
    76 //
       
    77 EXPORT_C RNSmlPrivateAPI::RNSmlPrivateAPI()
       
    78 	{
       
    79 
       
    80 	}
       
    81 
       
    82 // ---------------------------------------------------------
       
    83 // RNSmlPrivateAPI::OpenL()
       
    84 // Creates connection to server
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 EXPORT_C void RNSmlPrivateAPI::OpenL()
       
    88 	{
       
    89 	_DBG_FILE("RNSmlPrivateAPI::OpenL(): begin");
       
    90 	TVersion version(KNSmlSOSServerVersionMajor, KNSmlSOSServerVersionMinor, 0);
       
    91 	
       
    92 	TInt res = CreateSession( KSOSServerName, version, KDefaultMessageSlots );
       
    93 	
       
    94 	if ( res != KErrNone )
       
    95 		{
       
    96 		res = LaunchServer();
       
    97 		User::LeaveIfError( res );
       
    98 		res = CreateSession( KSOSServerName, version, KDefaultMessageSlots );
       
    99 		}
       
   100 
       
   101 	User::LeaveIfError( res );
       
   102 	
       
   103 	_DBG_FILE("RNSmlPrivateAPI::OpenL(): end");
       
   104 	}
       
   105 
       
   106 // ---------------------------------------------------------
       
   107 // RNSmlPrivateAPI::SendL( const TDesC8& aData, TSmlUsageType aType, 
       
   108 // TSmlProtocolVersion aVersion )
       
   109 // Passes message to server
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 EXPORT_C void RNSmlPrivateAPI::SendL(
       
   113     const TDesC8& aData, 
       
   114     TSmlUsageType aType, 
       
   115     TSmlProtocolVersion aVersion, 
       
   116     TUid aTransportId )
       
   117 	{
       
   118 	_DBG_FILE("RNSmlPrivateAPI::SendL(): begin");
       
   119 	
       
   120 	TIpcArgs args( &aData, aType, aVersion, aTransportId.iUid );    
       
   121     User::LeaveIfError( SendReceive( ECmdServerAlert, args ) );
       
   122     
       
   123     _DBG_FILE("RNSmlPrivateAPI::SendL(): end");
       
   124 	}
       
   125 
       
   126 // ---------------------------------------------------------
       
   127 // RNSmlPrivateAPI::Close()
       
   128 // Passes message to server
       
   129 // ---------------------------------------------------------
       
   130 //		
       
   131 EXPORT_C void RNSmlPrivateAPI::Close()
       
   132 	{
       
   133 	_DBG_FILE("RNSmlPrivateAPI::Close(): begin");
       
   134 	
       
   135 	// close session	
       
   136 	RSessionBase::Close();
       
   137 	
       
   138 	_DBG_FILE("RNSmlPrivateAPI::Close(): end");
       
   139 	}
       
   140 
       
   141 // ---------------------------------------------------------
       
   142 // RNSmlPrivateAPI::SetDMAuthInfoL( const CNSmlDMAuthInfo& aAuthInfo )
       
   143 // Sends DM auhentication info to be saved
       
   144 // ---------------------------------------------------------
       
   145 //	
       
   146 EXPORT_C void RNSmlPrivateAPI::SetDMAuthInfoL( const CNSmlDMAuthInfo& aAuthInfo )
       
   147 	{
       
   148 	CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity );
       
   149 	CleanupStack::PushL( buffer );
       
   150 	
       
   151 	RBufWriteStream stream( *buffer );	
       
   152 	CleanupClosePushL( stream );
       
   153 	
       
   154 	aAuthInfo.ExternalizeL( stream );
       
   155 	
       
   156 	TPtr8 pBuffer(0, NULL, 0);
       
   157 	pBuffer.Set( buffer->Ptr(0) );
       
   158 	
       
   159 	CleanupStack::PopAndDestroy(); // stream
       
   160 	
       
   161 	TIpcArgs args(aAuthInfo.iProfileId, &pBuffer);
       
   162 	User::LeaveIfError( SendReceive( ECmdSetDMAuthInfo, args) );
       
   163 	
       
   164 	CleanupStack::PopAndDestroy(); // buffer
       
   165 	}
       
   166 
       
   167 // ---------------------------------------------------------
       
   168 // RNSmlPrivateAPI::GetDMAuthInfoL( CNSmlDMAuthInfo& aAuthInfo )
       
   169 // Retrieves DM auhentication info from settings
       
   170 // ---------------------------------------------------------
       
   171 //	
       
   172 EXPORT_C void RNSmlPrivateAPI::GetDMAuthInfoL( CNSmlDMAuthInfo& aAuthInfo )
       
   173 	{
       
   174 	TPckgBuf<TInt> buf;
       
   175 	TIpcArgs args(aAuthInfo.iProfileId, &buf);
       
   176 	
       
   177 	User::LeaveIfError( SendReceive( ECmdInitDMAuthInfo, args) );
       
   178 	
       
   179 	CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity );
       
   180 	CleanupStack::PushL( buffer );
       
   181 	buffer->ResizeL( buf() );
       
   182 	
       
   183 	TPtr8 pBuffer(0, NULL, 0);
       
   184 	pBuffer.Set( buffer->Ptr(0) );
       
   185 	                
       
   186 	TIpcArgs argsGet( &pBuffer );
       
   187 	User::LeaveIfError( SendReceive( ECmdGetDMAuthInfo, argsGet) );
       
   188 	
       
   189 	RDesReadStream stream;
       
   190 	stream.Open( pBuffer );
       
   191 	CleanupClosePushL( stream );
       
   192 	
       
   193 	aAuthInfo.InternalizeL( stream );
       
   194 	
       
   195 	CleanupStack::PopAndDestroy(2); // stream, buffer	
       
   196 	}
       
   197 
       
   198 
       
   199 // FOTA
       
   200 
       
   201 // ---------------------------------------------------------
       
   202 // RNSmlPrivateAPI::AddDMGenericAlertRequestL()
       
   203 // Adds a Generic Alert to DM Agent if it is found in the 
       
   204 // server.
       
   205 // ---------------------------------------------------------
       
   206 //	
       
   207 EXPORT_C TInt RNSmlPrivateAPI::AddDMGenericAlertRequestL( const TDesC8& aMgmtUri, const TDesC8& aMetaType, const TDesC8& aMetaFormat, TInt aFinalResult, const TDesC8& aCorrelator ) const
       
   208 	{
       
   209 	TInt err = KErrNone;
       
   210 	
       
   211 	// create buffer
       
   212 	CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity );
       
   213 	CleanupStack::PushL( buffer );
       
   214 	
       
   215 	// open stream to buffer
       
   216 	RBufWriteStream stream( *buffer );	
       
   217 	CleanupClosePushL( stream );
       
   218 	
       
   219     // externalize data to stream
       
   220 	stream.WriteInt32L( aMgmtUri.Length() );
       
   221 	stream.WriteL( aMgmtUri );
       
   222 
       
   223 	stream.WriteInt32L( aMetaType.Length() );
       
   224 	stream.WriteL( aMetaType );
       
   225 	
       
   226 	stream.WriteInt32L( aMetaFormat.Length() );
       
   227 	stream.WriteL( aMetaFormat );
       
   228 	
       
   229 	stream.WriteInt32L( aCorrelator.Length() );
       
   230 	stream.WriteL( aCorrelator );
       
   231 	
       
   232 	stream.WriteInt32L( aFinalResult );
       
   233 	
       
   234 	// get modifiable pointer to buffer
       
   235 	TPtr8 bufPtr( buffer->Ptr(0) );
       
   236 	
       
   237 	CleanupStack::PopAndDestroy( &stream );
       
   238 	
       
   239 	// send the data to sos server
       
   240 	TIpcArgs args( &bufPtr );
       
   241 	err = SendReceive( ECmdAddDMGenericAlert, args );
       
   242 	
       
   243 	CleanupStack::PopAndDestroy( buffer );
       
   244 	
       
   245 	return err;
       
   246 	}
       
   247 
       
   248 // FOTA end
       
   249 
       
   250 
       
   251 // SCOMO
       
   252 
       
   253 // ---------------------------------------------------------
       
   254 // RNSmlPrivateAPI::AddDMGenericAlertRequestL()
       
   255 // Adds a Generic Alert to DM Agent if it is found in the 
       
   256 // server.
       
   257 // ---------------------------------------------------------
       
   258 //	
       
   259 EXPORT_C TInt RNSmlPrivateAPI::AddDMGenericAlertRequestL( const TDesC8& aCorrelator, RArray<CNSmlDMAlertItem>& aItemList ) const
       
   260 	{
       
   261 	TInt err = KErrNone;
       
   262 	
       
   263 	// create buffer
       
   264 	CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity );
       
   265 	CleanupStack::PushL( buffer );
       
   266 	
       
   267 	// open stream to buffer
       
   268 	RBufWriteStream stream( *buffer );	
       
   269 	CleanupClosePushL( stream );
       
   270 	
       
   271     // externalize data to stream
       
   272 	stream.WriteInt32L( aCorrelator.Length() );
       
   273 	stream.WriteL( aCorrelator );
       
   274 
       
   275 	TInt count = aItemList.Count();
       
   276 	stream.WriteInt32L( count );
       
   277 	
       
   278 	if(count > 0)
       
   279 	{		
       
   280 		for(TInt i =0 ; i <count; i++)
       
   281 		{
       
   282 			stream.WriteInt32L( (aItemList[i].iSource)->Length() );
       
   283 			stream.WriteL( (aItemList[i].iSource)->Des() );
       
   284 	
       
   285 			stream.WriteInt32L( (aItemList[i].iTarget)->Length() );
       
   286 			stream.WriteL( aItemList[i].iTarget->Des() );
       
   287 	
       
   288 			stream.WriteInt32L( (aItemList[i].iMetaType)->Length() );
       
   289 			stream.WriteL( aItemList[i].iMetaType->Des() );
       
   290 
       
   291 			stream.WriteInt32L( (aItemList[i].iMetaFormat)->Length()  );
       
   292 			stream.WriteL( aItemList[i].iMetaFormat->Des());
       
   293 
       
   294 			stream.WriteInt32L( (aItemList[i].iMetaMark)->Length() );
       
   295 			stream.WriteL( aItemList[i].iMetaMark->Des() );
       
   296 			
       
   297 			stream.WriteInt32L( (aItemList[i].iData)->Length() );
       
   298 			stream.WriteL( aItemList[i].iData->Des() );
       
   299 		}		
       
   300 	}
       
   301 	
       
   302 	// get modifiable pointer to buffer
       
   303 	TPtr8 bufPtr( buffer->Ptr(0) );
       
   304 	
       
   305 	CleanupStack::PopAndDestroy( &stream );
       
   306 	
       
   307 	// send the data to sos server
       
   308 	TIpcArgs args( &bufPtr );
       
   309 	err = SendReceive( ECmdAddGenericAlert, args );
       
   310 	
       
   311 	CleanupStack::PopAndDestroy( buffer );
       
   312 	
       
   313 	return err;
       
   314 	}
       
   315 
       
   316 // SCOMO
       
   317 
       
   318 
       
   319 //End of File