serialserver/c32serialserver/INC/cs_msgs.h
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2005-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  @internalComponent
       
    19 */
       
    20 
       
    21 #ifndef CS_MSGS_H
       
    22 #define CS_MSGS_H
       
    23 
       
    24 #include <cfmsgs.h>
       
    25 #include <elements/cftransport.h>
       
    26 #include <cfshared.h>
       
    27 #include <cfutil.h>
       
    28 
       
    29 
       
    30 
       
    31 /** Messages from Main Thread to Worker Threads (with Resp messages being responses
       
    32 sent back from Worker)
       
    33 */
       
    34 class TC32WorkerMsg : public CommsFW::TCFMessage
       
    35 	{
       
    36 public:
       
    37 	enum
       
    38 		{
       
    39 		/** Number of messages reserved for C32 internal usage. Currently bigger than the actual
       
    40 		number of messages to provide space for more in the future since player msgs being after this block.
       
    41 		The number is fairly arbitrary and is a guess at being "big enough" to accomodate a
       
    42 		reasonable multiplicity of future messages given we only use a couple at the moment.
       
    43 		@see TC32WorkerMsg::TCode::ELasTC32WorkerMsgCode
       
    44 		*/
       
    45 		KC32MessageCodeReserveSize = 15
       
    46 		};
       
    47 	enum TCode {
       
    48 
       
    49 		/** This is the first message between worker thread and the main thread. It is sent from
       
    50 		the main thread when receiving a bind request and starts the initialisation sequence.
       
    51 		The receiver is expected to respond with a EMainIntroductionResp message.
       
    52 		@see TC32WorkerMsg::EMainIntroductionResp
       
    53 		*/
       
    54 		EMainIntroduction = CommsFW::TCFCommsMessage::ECodePrivateFlag,
       
    55 
       
    56 		/** This is sent from a worker to the main thread in response to the
       
    57 		introduction message from the main thread. Once received the main thread will notify
       
    58 		the Root Server that the binding is complete.
       
    59 		@see TC32WorkerMsg::EMainIntroduction
       
    60 		*/
       
    61 		EMainIntroductionResp,
       
    62 
       
    63 		/** Dummy trailer code to give reference point for starting a following sequence of message codes. */
       
    64 		ELasTC32WorkerMsgCode = CommsFW::TCFCommsMessage::ECodePrivateFlag + KC32MessageCodeReserveSize
       
    65 		};
       
    66 	inline TC32WorkerMsg(TInt aCode)
       
    67 		{
       
    68 		Code(aCode);
       
    69 		}
       
    70 	};
       
    71 
       
    72 class CC32Dealer;
       
    73 
       
    74 /**
       
    75 @class
       
    76 TC32WorkerMainIntroductionMsg
       
    77 @see TC32WorkerMsg::EMainIntroduction
       
    78 */
       
    79 class TC32WorkerMainIntroductionMsg : public TC32WorkerMsg
       
    80 	{
       
    81 public:
       
    82 	enum {KCode = EMainIntroduction};//< Message code
       
    83 	inline TC32WorkerMainIntroductionMsg(CC32Dealer* aDealer)
       
    84 	: TC32WorkerMsg(KCode)
       
    85 		{
       
    86 		TParams* params = reinterpret_cast<TParams*>(TCFMessage::ParamBlock());
       
    87 		params->iDealer=aDealer;
       
    88 		}
       
    89 	inline CC32Dealer* Dealer() const
       
    90 		{
       
    91 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
    92 		return params->iDealer;
       
    93 		}
       
    94 private:
       
    95 	struct TParams
       
    96 		{
       
    97 		CC32Dealer* iDealer;					//< The Dealer
       
    98 		};
       
    99 	};
       
   100 
       
   101 /**
       
   102 @class
       
   103 TC32WorkerMainIntroductionRespMsg
       
   104 @see TC32WorkerMsg::EMainIntroductionResp
       
   105 */
       
   106 class TC32WorkerMainIntroductionRespMsg : public TC32WorkerMsg
       
   107 	{
       
   108 public:
       
   109 	enum {KCode = TC32WorkerMsg::EMainIntroductionResp};//< Message code
       
   110 	inline TC32WorkerMainIntroductionRespMsg(const TC32WorkerThreadPublicInfo& aWorkerInfo)
       
   111 	: TC32WorkerMsg(KCode)
       
   112 		{
       
   113 		TParams* params=reinterpret_cast<TParams*>(TCFMessage::ParamBlock());
       
   114 		params->iWorkerInfo=aWorkerInfo;
       
   115 #ifdef _DEBUG
       
   116   		params->iFailType = RAllocator::ENone;
       
   117   		params->iFailRate = 0;
       
   118 #endif
       
   119 		}
       
   120 
       
   121 	inline const TC32WorkerThreadPublicInfo& WorkerInfo() const
       
   122 		{
       
   123 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   124 		return params->iWorkerInfo;
       
   125 		}
       
   126 #ifdef _DEBUG
       
   127   	inline void SetFailType(RAllocator::TAllocFail aFailType)
       
   128   		{
       
   129   		TParams* params = reinterpret_cast<TParams*>(TCFMessage::ParamBlock());
       
   130   		params->iFailType = aFailType;
       
   131   		}
       
   132   	inline RAllocator::TAllocFail FailType() const
       
   133   		{
       
   134   		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   135   		return params->iFailType;
       
   136   		}
       
   137   	inline void SetFailRate(TInt aFailRate)
       
   138   		{
       
   139   		TParams* params = reinterpret_cast<TParams*>(TCFMessage::ParamBlock());
       
   140   		params->iFailRate = aFailRate;
       
   141   		}
       
   142  	inline TInt FailRate() const
       
   143   		{
       
   144   		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   145   		return params->iFailRate;
       
   146   		}
       
   147 #endif
       
   148 
       
   149 private:
       
   150 	struct TParams
       
   151 		{
       
   152 		TC32WorkerThreadPublicInfo iWorkerInfo;	//< Crucial information the Dealer needs about the worker thread/server
       
   153 #ifdef _DEBUG
       
   154   		RAllocator::TAllocFail iFailType;
       
   155   		TInt iFailRate;
       
   156 #endif
       
   157 		};
       
   158 	};
       
   159 
       
   160 
       
   161 
       
   162 
       
   163 /**
       
   164 @class
       
   165 TC32PlayerMsg
       
   166 Messages from a Dealer to a Player in another thread
       
   167 */
       
   168 class TC32PlayerMsg : public CommsFW::TCFMessage
       
   169 	{
       
   170 public:
       
   171 	enum TCode {
       
   172 		/** This is the most common message. It is used to forward IPC requests
       
   173 		from a Dealer to a Player. */
       
   174 		EForwardRequest = TC32WorkerMsg::ELasTC32WorkerMsgCode + 1,
       
   175 
       
   176 		/** When a session is closed by a client the Dealer will send this message to all Players
       
   177 		that might have relations (sub-sessions) to this session.
       
   178 		@note The receiver is expected to response with a ESessionCloseResp message.
       
   179 		@see TC32PlayerMsg::ESessionCloseResp
       
   180 		*/
       
   181 		ESessionClose,
       
   182 
       
   183 		/** Notify the Dealer that cleanup related to the ESessionClose message is completed.
       
   184 		@see TC32PlayerMsg::ESessionClose
       
   185 		*/
       
   186 		ESessionCloseResp,
       
   187 
       
   188 		/** This message is sent from dealer to player on load request. Response message is sent from
       
   189 		player back.
       
   190 		@see TC32PlayerMsg::ELoadCommModuleSuccessResp
       
   191 		@see TC32PlayerMsg::ELoadCommModuleFailureResp
       
   192 		*/
       
   193 		ELoadCommModuleMsg,
       
   194 
       
   195 		/** This message is sent from the player to dealer in response to ELoadCommModuleMsg
       
   196 		msg. On success, CSerial* with RMessage2 is sent to dealer. CSerial* is used by dealer to
       
   197 		update the ThreadManager entry of PortPrefix, while csyfilename is retrieved from message again.
       
   198 		After updation, the message is completed by dealer
       
   199 		*/
       
   200 		ELoadCommModuleSuccessResp,
       
   201 
       
   202 		/** This message is sent from player to dealer when CSY load fails. The load failure
       
   203 		result is also sent with the message which the dealer completes the message with.
       
   204 		*/
       
   205 		ELoadCommModuleFailureResp,
       
   206 
       
   207 		/**
       
   208 		Message sent from deale to player to unload Comm Module
       
   209 		*/
       
   210 		EUnLoadCommModuleMsg,
       
   211 		/**
       
   212 		This is the message used specifically for RCommServ::GetPortInfo (aIndex) API as
       
   213 		global index which is sent via aMessage is no longer valid in player, which maintains
       
   214 		its local index.
       
   215 		*/
       
   216 		EGetPortInfoMsg,
       
   217 		};
       
   218 	inline TC32PlayerMsg(TInt aCode)
       
   219 		{
       
   220 		Code(aCode);
       
   221 		}
       
   222 	};
       
   223 
       
   224 /**
       
   225 @class
       
   226 TC32PlayerForwardRequestMsg
       
   227 @see TC32PlayerMsg::EForwardRequest
       
   228 */
       
   229 class TC32PlayerForwardRequestMsg : public TC32PlayerMsg
       
   230 	{
       
   231 public:
       
   232 	enum {KCode = TC32PlayerMsg::EForwardRequest};//< Message code
       
   233 	inline TC32PlayerForwardRequestMsg(const RMessage2& aMsg, CCommSubSession* aSubSession):TC32PlayerMsg(KCode)
       
   234 		{
       
   235 		TParams* params = reinterpret_cast<TParams*>(TCFMessage::ParamBlock());
       
   236 		params->iMsg=aMsg;
       
   237 		params->iSubSession=aSubSession;
       
   238 		}
       
   239 	inline const RMessage2& Message() const
       
   240 		{
       
   241 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   242 		return params->iMsg;
       
   243 		}
       
   244 	inline CCommSubSession* SubSession() const
       
   245 		{
       
   246 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   247 		return params->iSubSession;
       
   248 		}
       
   249 private:
       
   250 	struct TParams
       
   251 		{
       
   252 		/** The IPC message to process. The Player must complete this itself when ready.
       
   253 		When sent to a Player the Dealer will have forgotten completely about it and left
       
   254 		the responsibility to the Player.
       
   255 		*/
       
   256 		RMessage2 iMsg;
       
   257 		CCommSubSession* iSubSession;
       
   258 		};
       
   259 	};
       
   260 
       
   261 /**
       
   262 @class
       
   263 TC32PlayerSessionCloseMsg
       
   264 @see TC32PlayerMsg::ESessionClose
       
   265 */
       
   266 class TC32PlayerSessionCloseMsg : public TC32PlayerMsg
       
   267 	{
       
   268 public:
       
   269 	enum {KCode = TC32PlayerMsg::ESessionClose};//< Message code
       
   270 	inline TC32PlayerSessionCloseMsg(CCommSession* aSession, const TInt64& aSessionCloseDeadline):TC32PlayerMsg(KCode)
       
   271 		{
       
   272 		TParams* params = reinterpret_cast<TParams*>(TCFMessage::ParamBlock());
       
   273 		params->iSession=aSession;
       
   274 		params->iSessionCloseDeadline=aSessionCloseDeadline;
       
   275 		}
       
   276 
       
   277 	inline CCommSession* Session() const
       
   278 		{
       
   279 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   280 		return params->iSession;
       
   281 		}
       
   282 	inline TInt64 SessionCloseDeadline() const
       
   283 		{
       
   284 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   285 		return params->iSessionCloseDeadline;
       
   286 		}
       
   287 private:
       
   288 	struct TParams
       
   289 		{
       
   290 		CCommSession* iSession;			//< The session that is being closed.
       
   291 
       
   292 		/** The session pointer is only valid if TTime.HomeTime() returns a value smaller than
       
   293 		the value stored here, otherwise the Dealer will have timed out and deleted the session. */
       
   294 		TInt64 iSessionCloseDeadline;
       
   295 		};
       
   296 	};
       
   297 
       
   298 /**
       
   299 @class
       
   300 TC32PlayerSessionCloseRespMsg
       
   301 @see TC32PlayerMsg::ESessionCloseResp
       
   302 */
       
   303 class TC32PlayerSessionCloseRespMsg : public TC32PlayerMsg
       
   304 	{
       
   305 public:
       
   306 	enum {KCode = TC32PlayerMsg::ESessionCloseResp};//< Message code
       
   307 	inline TC32PlayerSessionCloseRespMsg(CommsFW::TWorkerId aPlayerId, const TC32PlayerSessionCloseMsg& aCloseMsg):TC32PlayerMsg(KCode)
       
   308 		{
       
   309 		TParams* params = reinterpret_cast<TParams*>(TCFMessage::ParamBlock());
       
   310 		params->iSession=aCloseMsg.Session();
       
   311 		params->iPlayerId=aPlayerId;
       
   312 		params->iSessionCloseDeadline=aCloseMsg.SessionCloseDeadline();
       
   313 		}
       
   314 	inline CCommSession* Session() const
       
   315 		{
       
   316 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   317 		return params->iSession;
       
   318 		}
       
   319 	inline CommsFW::TWorkerId WorkerId() const
       
   320 		{
       
   321 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   322 		return params->iPlayerId;
       
   323 		}
       
   324 	inline TInt64 SessionCloseDeadline() const
       
   325 		{
       
   326 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   327 		return params->iSessionCloseDeadline;
       
   328 		}
       
   329 private:
       
   330 	struct TParams
       
   331 		{
       
   332 		CCommSession* iSession;			//< The session which was closed
       
   333 		CommsFW::TWorkerId iPlayerId;			//< Id of the sending worker thread
       
   334 
       
   335 		/** Must contain the session close deadline from the session close
       
   336         message which this message is responding to. */
       
   337 		TInt64 iSessionCloseDeadline;
       
   338 		};
       
   339 	};
       
   340 
       
   341 /**
       
   342 @class
       
   343 TC32PlayerLoadCommModuleMsg
       
   344 @see TC32PlayerMsg::ELoadCommModuleMsg
       
   345 */
       
   346 class TC32PlayerLoadCommModuleMsg : public TC32PlayerMsg
       
   347 	{
       
   348 public:
       
   349 	enum {KCode = TC32PlayerMsg::ELoadCommModuleMsg};//< Message code
       
   350 	inline TC32PlayerLoadCommModuleMsg(const RMessage2& aMsg):TC32PlayerMsg(KCode)
       
   351 		{
       
   352 		TParams* params = reinterpret_cast<TParams*>(TCFMessage::ParamBlock());
       
   353 		params->iMsg=aMsg;
       
   354 		}
       
   355 	inline const RMessage2& Message() const
       
   356 		{
       
   357 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   358 		return params->iMsg;
       
   359 		}
       
   360 private:
       
   361 	struct TParams
       
   362 		{
       
   363 		/** The IPC message to process. The Player must complete this itself when ready.
       
   364 		When sent to a Player the Dealer will have forgotten completely about it and left
       
   365 		the responsibility to the Player.
       
   366 		*/
       
   367 		RMessage2 iMsg;
       
   368 		};
       
   369 	};
       
   370 
       
   371 /**
       
   372 @class
       
   373 TC32PlayerLoadCommModuleSuccessResp
       
   374 @see TC32PlayerMsg::ELoadCommModuleSuccessResp
       
   375 */
       
   376 class TC32PlayerLoadCommModuleSuccessResp : public TC32PlayerMsg
       
   377 	{
       
   378 public:
       
   379 	enum {KCode = TC32PlayerMsg::ELoadCommModuleSuccessResp};//< Message code
       
   380 	inline TC32PlayerLoadCommModuleSuccessResp(const RMessage2& aMsg, CSerial* aSerial):TC32PlayerMsg(KCode)
       
   381 		{
       
   382 		TParams* params = reinterpret_cast<TParams*>(TCFMessage::ParamBlock());
       
   383 		params->iMsg=aMsg;
       
   384 		params->iSerial=aSerial;
       
   385 		}
       
   386 	inline const RMessage2& Message() const
       
   387 		{
       
   388 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   389 		return params->iMsg;
       
   390 		}
       
   391 	inline CSerial* SerialPtr() const
       
   392 		{
       
   393 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   394 		return params->iSerial;
       
   395 		}
       
   396 private:
       
   397 	struct TParams
       
   398 		{
       
   399 		/** The IPC message to process. The Player must complete this itself when ready.
       
   400 		When sent to a Player the Dealer will have forgotten completely about it and left
       
   401 		the responsibility to the Player.
       
   402 		*/
       
   403 		RMessage2 iMsg;
       
   404 		CSerial* iSerial;	//< used in PortInfo(aIndex)
       
   405 		};
       
   406 	};
       
   407 
       
   408 
       
   409 /**
       
   410 @class
       
   411 TC32PlayerLoadCommModuleMsg
       
   412 @see TC32PlayerMsg::ELoadCommModuleFailureResp
       
   413 */
       
   414 class TC32PlayerLoadCommModuleFailureResp : public TC32PlayerMsg
       
   415 	{
       
   416 public:
       
   417 	enum {KCode = TC32PlayerMsg::ELoadCommModuleFailureResp};//< Message code
       
   418 	inline TC32PlayerLoadCommModuleFailureResp(const RMessage2& aMsg, TInt aFailReason):TC32PlayerMsg(KCode)
       
   419 		{
       
   420 		TParams* params = reinterpret_cast<TParams*>(TCFMessage::ParamBlock());
       
   421 		params->iMsg=aMsg;
       
   422 		params->iFailReason=aFailReason;
       
   423 		}
       
   424 	inline const RMessage2& Message() const
       
   425 		{
       
   426 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   427 		return params->iMsg;
       
   428 		}
       
   429 	inline TInt FailureReason() const
       
   430 		{
       
   431 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   432 		return params->iFailReason;
       
   433 		}
       
   434 private:
       
   435 	struct TParams
       
   436 		{
       
   437 		RMessage2 iMsg;
       
   438 		TInt iFailReason;
       
   439 		};
       
   440 	};
       
   441 /*
       
   442 @class
       
   443 TC32PlayerUnLoadCommModuleMsg
       
   444 @see TC32PlayerMsg::EUnLoadCommModuleMsg
       
   445 */
       
   446 class TC32PlayerUnLoadCommModuleMsg : public TC32PlayerMsg
       
   447 	{
       
   448 public:
       
   449 	enum {KCode = TC32PlayerMsg::EUnLoadCommModuleMsg};//< Message code
       
   450 	inline TC32PlayerUnLoadCommModuleMsg(CSerial* aSerial):TC32PlayerMsg(KCode)
       
   451 		{
       
   452 		TParams* params = reinterpret_cast<TParams*>(TCFMessage::ParamBlock());
       
   453 		params->iSerial=aSerial;
       
   454 		}
       
   455 	inline CSerial* SerialPtr() const
       
   456 		{
       
   457 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   458 		return params->iSerial;
       
   459 		}
       
   460 private:
       
   461 	struct TParams
       
   462 		{
       
   463 		CSerial* iSerial; //< CSerial to call Close()
       
   464 		};
       
   465 	};
       
   466 
       
   467 
       
   468 /**
       
   469 @class
       
   470 TC32PlayerGetPortInfoMsg
       
   471 @see TC32PlayerMsg::EGetPortInfoMsg
       
   472 */
       
   473 class TC32PlayerGetPortInfoMsg : public TC32PlayerMsg
       
   474 	{
       
   475 public:
       
   476 	enum {KCode = TC32PlayerMsg::EGetPortInfoMsg};//< Message code
       
   477 	inline TC32PlayerGetPortInfoMsg(const RMessage2& aMsg, CSerial* aSerial):TC32PlayerMsg(KCode)
       
   478 		{
       
   479 		TParams* params = reinterpret_cast<TParams*>(TCFMessage::ParamBlock());
       
   480 		params->iMsg=aMsg;
       
   481 		params->iSerial=aSerial;
       
   482 		}
       
   483 	inline const RMessage2& Message() const
       
   484 		{
       
   485 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   486 		return params->iMsg;
       
   487 		}
       
   488 	inline CSerial* SerialPtr() const
       
   489 		{
       
   490 		const TParams* params = reinterpret_cast<const TParams*>(TCFMessage::ParamBlock());
       
   491 		return params->iSerial;
       
   492 		}
       
   493 private:
       
   494 	struct TParams
       
   495 		{
       
   496 		/** The IPC message to process. The Player must complete this itself when ready.
       
   497 		When sent to a Player the Dealer will have forgotten completely about it and left
       
   498 		the responsibility to the Player.
       
   499 		*/
       
   500 		RMessage2 iMsg;
       
   501 		CSerial* iSerial;
       
   502 		};
       
   503 	};
       
   504 
       
   505 #endif	// CS_MSGS_H
       
   506