⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gsdpserver.h

📁 Symbian mobile os C++ GSDP编程
💻 H
字号:
// gsdpserver.h
//
// Definitions for the server classes
//
// Copyright (c) 2002 Symbian Ltd.  All rights reserved.
//

#ifndef __GSDPSERVER_H
#define __GSDPSERVER_H

#include <gsdp.h>
#include "gsdpdef.h"
#include <gdp.h>
#include "gsdpqueue.h"
#include <ecom/ImplementationInformation.h>
#include <ecom/ecom.h>
#include <f32file.h>

class CGsdpServer;
class CGsdpScheduler;
class TGsdpPacket;
class CGsdpReceiveQueue;
class CGsdpSession;
class CGsdpGdpAdapter;
class CGsdpDelayedShutdown;
class CGsdpProtocolUpdater;
class CGsdpPortAllocator;


class CGsdpServer : public CServer
	{
public:
	// construct
	CGsdpServer();
	void ConstructL();
	~CGsdpServer();
	// from CServer
	CSharableSession* NewSessionL(const TVersion& aVersion) const;
	// session counting
	void IncrementSessions();
	void DecrementSessions();
	// receive queue support
	CGsdpSession* SessionForPacket(const TGsdpPacket& aPacket);
	// port allocation
	TUint32 MyNextPort();
	// Protocol loading
	TInt CountProtocols();
	void GetProtocolInfoL(TInt aProto, TGdpProtocolInfo& aInfo);
	CGsdpGdpAdapter* GetProtocolL(TUid aUid);
	void UpdateProtocolInfo();
	// utility
	void PanicClient(TInt aPanic) const;
public:
	CGsdpReceiveQueue* iReceiveQueue;
private:
	TInt RunError(TInt aErr);
	void InitProtocolsL();
private:
	TInt iSessionCount;
	CGsdpDelayedShutdown* iShutdown;
	CGsdpProtocolUpdater* iProtoUpdater;
	CGsdpPortAllocator* iPortAllocator;
	RImplInfoPtrArray iProtocolInfo;
	RPointerArray<CGsdpGdpAdapter> iAdapters;
	};

class CGsdpScheduler : public CActiveScheduler
	{
public:
	class TServerStart
		{
	public:
		TServerStart(TRequestStatus& aStatus);
		TPtrC AsCommand() const;
		inline TServerStart() {};
		TInt GetCommand();
		void SignalL();
	private:
		TThreadId iId;
		TRequestStatus* iStatus;
		};
	// launch
	
	static TInt LaunchFromClient();
#ifdef __WINS__
	static TInt ThreadFunction(TAny* aThreadParms);
#endif
	IMPORT_C static TInt ThreadStart(TServerStart& aSignal);
	static void ConstructL(TServerStart& aStart);
	~CGsdpScheduler();
	void Error(TInt aError) const; // from CActiveScheduler
private:
	CGsdpServer* iServer;
	};

inline CGsdpScheduler::TServerStart::TServerStart(TRequestStatus& aStatus)
	:iId(RThread().Id()),iStatus(&aStatus)
	{aStatus=KRequestPending;}
inline TPtrC CGsdpScheduler::TServerStart::AsCommand() const
	{return TPtrC(reinterpret_cast<const TText*>(this),sizeof(TServerStart)/sizeof(TText));}

class CGsdpProtocolUpdater : public CActive
	{
public:
	static CGsdpProtocolUpdater* NewL(CGsdpServer& aServer);
	~CGsdpProtocolUpdater();
	void Start();
private:
	CGsdpProtocolUpdater(CGsdpServer& aServer);
	void ConstructL();
	void RunL();
	void DoCancel();
private:
	CGsdpServer& iServer;
	REComSession iEcomSession;
	};
	

class CGsdpDelayedShutdown : public CActive
	{
public:
	CGsdpDelayedShutdown();
	void ConstructL();
	~CGsdpDelayedShutdown();
	void Start();
private:
	void DoCancel();
	void RunL();
private:
	RTimer iTimer;
	};

class CGsdpReceiveQueue : public CGsdpQueueBase
	{
public:
	enum TReceiveCheck { EAllowZero, EDontAllowZero };
public:
	// construct
	static CGsdpReceiveQueue* NewL(CGsdpServer& aServer);
	// functions
	void Receive(TUint32 aGameProtocol, TUint32 aToPort, const TDesC8& aFromAddress, TUint32 aFromPort, const TDesC8& aData);
	void CheckPackets(CGsdpSession* aSession);
private:
	CGsdpReceiveQueue(CGsdpServer& aServer);
private:
	CGsdpServer& iServer;
	};

class CGsdpTransmitQueue : public CGsdpQueueBase
	{
public:
	static CGsdpTransmitQueue* NewL(CGsdpGdpAdapter& aAdapter);
	void Transmit(TUint32 aGameProtocol, TUint32 aToPort, const TDesC8& aFromAddress, TUint32 aFromPort, const TDesC8& aData);
	void TryToSend();
private:
	CGsdpTransmitQueue(CGsdpGdpAdapter& aAdapter);
private:
	CGsdpGdpAdapter& iAdapter;
	};

class CGsdpPortAllocator : public CBase
	{
public:
	// construct/destruct
	void ConstructL();
	~CGsdpPortAllocator();
	// utility
	TUint32 NextPortId();
private:
	TUint32 iNextPortId;
	RFs iFs;
	};


class CGsdpSession : public CSharableSession
	{
public:
	// construct/destruct
	CGsdpSession();
	void ConstructL(CGsdpServer& aServer);
	~CGsdpSession();
	// service dispatcher - from CSession
	void ServiceL(const RMessage& aMessage);
	// client service functions
	void GetProtocolInfoL(TInt aProto, const TAny* aDes);
	void SetGameProtocol(TUint32 aProtocol);
	TUint32 GetGameProtocol();
	void SetGdpProtocolL(TUid aProtocol);
	TUid GetGdpProtocol();
	TBool GdpIsNetworked();
	void SetMyPort(TUint32 aPort);
	TUint32 GetMyPort();
	TUint32 AllocMyNextPort();
	void SetOtherAddress(const TAny* aAddress);
	void GetOtherAddress(const TAny* aAddress);
	void SetOtherPort(TUint32 aPort);
	TUint32 GetOtherPort();
	TInt Send(const TAny* aData);
	void ReceiveAll();
	void Receive(const TAny* aBuffer);
	void CancelReceive();
	// receive queue support
	TBool CanReceivePacket(const TGsdpPacket& aPacket) const;
	void ReceivePacket(TGsdpPacket& aPacket);
private:
	CGsdpServer* Server() const;
	// game protocol
	TUint32 iGameProtocol;
	// addresses
	TUint32 iMyPort;
	TBuf8<KMaxGsdpAddress> iOtherAddress;
	TUint32 iOtherPort;
	// protocol adapter
	CGsdpGdpAdapter* iGdpProtocol;
	// receive support
	TBool iReceiveActive;
	RMessage iReceiveMessage;
	const TAny* iReceiveBuffer;
	};


class CGsdpGdpAdapter : public CBase, public MGdpPacketHandler
	{
public:
	// construct/destruct
	static CGsdpGdpAdapter* NewL(CGsdpServer& aServer);
	~CGsdpGdpAdapter();
	void SetProtocolL(CGdpSession* aGdpSession);
	// interrogate
	TBool IsNetworked();
	TUid ProtocolUid() const;
	// protocol adapters
	void SendL(TUint32 aGameProtocol,
			   TUint32 aFromPort,
			   const TDesC8& aToAddress, TUint32 aToPort,
			   const TDesC8& aData);
	void ReceiveAll();
	// from MGdpPacketHandler
	void GdpHandleL(const TDesC8& aFromAddress, const TDesC8& aData);
	void SendComplete(TInt aErr);

	// interface for Q
	TBool CanSendPacket(TGsdpPacket& aPacket);
	void SendPacket(TGsdpPacket& aPacket);
private:
	CGsdpGdpAdapter(CGsdpServer& aServer);
	void ConstructL();
private:
	// pointers elsewhere
	CGsdpServer& iServer;
	CGdpSession* iGdpSession;  // Owns this
	CGsdpTransmitQueue* iTransmitQueue;
	// buffers
	TBuf8<KMaxGsdpGdpData> iSendBuffer; // complete TGsdpPacket
	// Send state
	TBool iSendActive;
	TInt  iLastError;
	};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -