datacommsserver/esockserver/csock/cs_mobility_apiext.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 1997-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18 */
       
    19 
       
    20 #include <comms-infras/mobilitymessages_internal.h>
       
    21 
       
    22 #include <comms-infras/es_mobility_apiext.h>
       
    23 #include <comms-infras/mobilitymessagesecom.h>
       
    24 #include <comms-infras/mobilitymessages.h>
       
    25 
       
    26 
       
    27 
       
    28 using namespace ESock;
       
    29 
       
    30 
       
    31 /**
       
    32 Default empty constructor, and is present only to support virtual
       
    33 function table export.
       
    34 
       
    35 @publishedPartner
       
    36 @released
       
    37 */
       
    38 EXPORT_C RCommsMobilityApiExt::RCommsMobilityApiExt()
       
    39 	{
       
    40 	}
       
    41 
       
    42 /**
       
    43 Closes the extension after it has been used. It is not possible to use 
       
    44 an extension after it has been closed.
       
    45 
       
    46 @publishedPartner
       
    47 @released
       
    48 */
       
    49 EXPORT_C void RCommsMobilityApiExt::Close()
       
    50 	{
       
    51 	RCommsApiExtensionBase::Close();
       
    52 	}
       
    53 
       
    54 /**
       
    55 This API is used to register (subscribe) for Mobility notifications from the Implementation. 
       
    56 
       
    57 @param aResponseEventBuf	Will be filled with a corresponding response message before aStatus is completed.
       
    58 @param aReqStatus 			Returns the result code after the asynchronous call completes.
       
    59 
       
    60 @publishedPartner
       
    61 @released
       
    62 */
       
    63 EXPORT_C void RCommsMobilityApiExt::RegisterForMobilityNotification(TDes8& aResponseEventBuf, TRequestStatus& aStatus)
       
    64 	{
       
    65 	TMobilitySubscriptionMsg msg;
       
    66 	SendRequest(msg, aResponseEventBuf, aStatus);
       
    67 	}
       
    68 
       
    69 /**
       
    70 Cancels previously requested subscription for Mobility notifications.
       
    71 
       
    72 @publishedPartner
       
    73 @released
       
    74 */
       
    75 EXPORT_C void RCommsMobilityApiExt::CancelMobilityNotification()
       
    76 	{
       
    77 	TMobilitySubscriptionCancelMsg msg;	
       
    78 	SendMessage(msg);
       
    79 	}
       
    80 
       
    81 /**
       
    82 Instructs the Implementation that it should migrate the Client to the newly 
       
    83 available preferred carrier (or, in case of the current carrier becoming unavailable, 
       
    84 to the less preferred but available carrier).
       
    85 
       
    86 @publishedPartner
       
    87 @released
       
    88 */
       
    89 EXPORT_C void RCommsMobilityApiExt::MigrateToPreferredCarrier()
       
    90 	{
       
    91 	TMigrateToPreferredCarrier msg;
       
    92 	SendMessage(msg);
       
    93 	}
       
    94 
       
    95 /**
       
    96 Instructs the Implementation that it should not migrate the Client to the newly 
       
    97 available preferred carrier and that the Client wishes to continue using the current carrier.
       
    98 
       
    99 @publishedPartner
       
   100 @released
       
   101 */
       
   102 EXPORT_C void RCommsMobilityApiExt::IgnorePreferredCarrier()
       
   103 	{
       
   104 	TIgnorePreferredCarrier msg;
       
   105 	SendMessage(msg);
       
   106 	}
       
   107 
       
   108 /**
       
   109 Instructs the Implementation that the Client wishes to use the new carrier it has been migrated to.
       
   110 
       
   111 @publishedPartner
       
   112 @released
       
   113 */
       
   114 EXPORT_C void RCommsMobilityApiExt::NewCarrierAccepted()
       
   115 	{
       
   116 	TNewCarrierAccepted msg;
       
   117 	SendMessage(msg);
       
   118 	}
       
   119 
       
   120 /**
       
   121 Instructs the Implementation that the Client wishes to reject the new carrier it has been 
       
   122 migrated to and be offered another preferred carrier unless nothing else is available. 
       
   123 In case nothing else is available the request completes with an error.
       
   124 
       
   125 @publishedPartner
       
   126 @released
       
   127 */
       
   128 EXPORT_C void RCommsMobilityApiExt::NewCarrierRejected()
       
   129 	{
       
   130 	TNewCarrierRejected msg;
       
   131 	SendMessage(msg);
       
   132 	}
       
   133 
       
   134 
       
   135 
       
   136 void CActiveCommsMobilityApiExt::DoCancel()
       
   137     {
       
   138     iExtApi.CancelMobilityNotification();
       
   139     iProtocol.Error(KErrCancel);
       
   140     }
       
   141 
       
   142 void CActiveCommsMobilityApiExt::RunL()
       
   143     {
       
   144     if(iStatus.Int() == KErrNone)
       
   145         {
       
   146         CCommsApiExtRespMsg* msg = CCommsApiExtRespMsg::NewL(iResponseBuf);
       
   147 
       
   148         // Re-register for the next message.
       
   149         iExtApi.RegisterForMobilityNotification(iResponseBuf,iStatus);
       
   150         SetActive();
       
   151 
       
   152         //check types
       
   153         STypeId preferredCarrierAvailableTid = STypeId::CreateSTypeId(KMobilityMessagesImplementationUid,EPreferredCarrierAvailable);
       
   154         STypeId newCarrierActiveTid = STypeId::CreateSTypeId(KMobilityMessagesImplementationUid,ENewCarrierActive);
       
   155 
       
   156         if (msg->IsTypeOf(preferredCarrierAvailableTid))
       
   157            {
       
   158            CPreferredCarrierAvailable& pca = reinterpret_cast<CPreferredCarrierAvailable&>(*msg);
       
   159            iProtocol.PreferredCarrierAvailable(pca.OldAPInfo(),pca.NewAPInfo(),pca.IsUpgrade(),pca.IsSeamless());
       
   160            }
       
   161         else if (msg->IsTypeOf(newCarrierActiveTid))
       
   162            {
       
   163            CNewCarrierActive& nca = reinterpret_cast<CNewCarrierActive&>(*msg);
       
   164            iProtocol.NewCarrierActive(nca.NewAPInfo(),nca.IsSeamless());
       
   165            }
       
   166         delete msg;
       
   167         }
       
   168 	else
       
   169 		{
       
   170         iProtocol.Error(iStatus.Int());
       
   171 		}
       
   172     }
       
   173 
       
   174 TInt CActiveCommsMobilityApiExt::RunError(TInt aError)
       
   175     {
       
   176     //The notification has not been sent to the client because of KErrNoMemory
       
   177     //We may need to provide an inplace construction for the messages to exclude this possibility.
       
   178     return aError;
       
   179     }
       
   180 
       
   181 /**
       
   182 This call is used to construct the Mobility extension, initialised with the MMobilityProtocolResp 
       
   183 implementation provided as a parameter. MMobilityProtocolResp implementation is used when a Mobility 
       
   184 notification arrives to the Client and is being dispatched on one of the call back APIs of MMobilityProtocolResp.
       
   185 
       
   186 @param aExtensionProvider	The corresponding RCommsSubSession under which the extension is to be opened
       
   187 							(in case of Mobility this is the RConnection or RCommsManager instance).
       
   188 @param aProtocol			Handles the response communication between the implementation and the client.
       
   189 
       
   190 @publishedPartner
       
   191 @released
       
   192 */
       
   193 EXPORT_C CActiveCommsMobilityApiExt* CActiveCommsMobilityApiExt::NewL(RCommsSubSession& aExtensionProvider,MMobilityProtocolResp& aProtocol)
       
   194     {
       
   195     CActiveCommsMobilityApiExt* self = new (ELeave) CActiveCommsMobilityApiExt(aProtocol);
       
   196     CleanupStack::PushL(self);
       
   197     self->ConstructL(aExtensionProvider);
       
   198     CleanupStack::Pop(self);
       
   199     return self;
       
   200     }
       
   201 
       
   202 /**
       
   203 Cancels the outstanding notification request and deletes the Mobility extension.
       
   204 
       
   205 @publishedPartner
       
   206 @released
       
   207 */
       
   208 EXPORT_C CActiveCommsMobilityApiExt::~CActiveCommsMobilityApiExt()
       
   209 	{
       
   210 	Cancel();
       
   211 	iExtApi.Close();
       
   212 	iResponseBuf.Close();
       
   213 	}
       
   214 
       
   215 void CActiveCommsMobilityApiExt::ConstructL(RCommsSubSession& aExtensionProvider)
       
   216     {
       
   217     User::LeaveIfError(iExtApi.Open(aExtensionProvider));
       
   218     iResponseBuf.CreateL(KMaxExtApiIpcMsgLength);
       
   219     iExtApi.RegisterForMobilityNotification(iResponseBuf,iStatus);
       
   220     SetActive();
       
   221     }
       
   222 
       
   223 CActiveCommsMobilityApiExt::CActiveCommsMobilityApiExt(MMobilityProtocolResp& aProtocol)
       
   224 :   CActive(CActive::EPriorityUserInput),
       
   225     iProtocol(aProtocol)
       
   226 	{
       
   227 	CActiveScheduler::Add(this);
       
   228 	}
       
   229 
       
   230 /**
       
   231 Instructs the Implementation that it should migrate the Client to the newly 
       
   232 available preferred carrier (or, in case of the current carrier becoming 
       
   233 unavailable, to the less preferred but available carrier).
       
   234 
       
   235 @publishedPartner
       
   236 @released
       
   237 */
       
   238 EXPORT_C void CActiveCommsMobilityApiExt::MigrateToPreferredCarrier()
       
   239 	{
       
   240 	iExtApi.MigrateToPreferredCarrier();
       
   241 	}
       
   242 
       
   243 /**
       
   244 Instructs the Implementation that it should not migrate the Client to the 
       
   245 newly available preferred carrier and that the Client wishes to continue using 
       
   246 the current carrier.
       
   247 
       
   248 @publishedPartner
       
   249 @released
       
   250 */
       
   251 EXPORT_C void CActiveCommsMobilityApiExt::IgnorePreferredCarrier()
       
   252 	{
       
   253     iExtApi.IgnorePreferredCarrier();
       
   254 	}
       
   255 
       
   256 /**
       
   257 Instructs the Implementation that the Client wishes to use the new carrier it has been migrated to.
       
   258 
       
   259 @publishedPartner
       
   260 @released
       
   261 */
       
   262 EXPORT_C void CActiveCommsMobilityApiExt::NewCarrierAccepted()
       
   263 	{
       
   264     iExtApi.NewCarrierAccepted();
       
   265 	}
       
   266 
       
   267 /**
       
   268 Instruct the Implementation that the Client wishes to reject the new carrier 
       
   269 it has been migrated to be offered another preferred carrier unless nothing else is available. 
       
   270 In case nothing else is available the request completes with an error.
       
   271 
       
   272 @publishedPartner
       
   273 @released
       
   274 */
       
   275 EXPORT_C void CActiveCommsMobilityApiExt::NewCarrierRejected()
       
   276 	{
       
   277     iExtApi.NewCarrierRejected();
       
   278 	}
       
   279