Shadowrun: Awakened 29 September 2011 - Build 871
ReadyEvent.h
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include "NativeFeatureIncludes.h"
00009 #if _RAKNET_SUPPORT_ReadyEvent==1
00010 
00011 #ifndef __READY_EVENT_H
00012 #define __READY_EVENT_H
00013 
00014 #include "PluginInterface2.h"
00015 #include "DS_OrderedList.h"
00016 
00017 namespace RakNet {
00018 
00019 class RakPeerInterface;
00020 
00025 
00028 enum ReadyEventSystemStatus
00029 {
00033     RES_NOT_WAITING,
00035     RES_WAITING,
00037     RES_READY,
00040     RES_ALL_READY,
00041 
00043     RES_UNKNOWN_EVENT,
00044 };
00045 
00055 class ReadyEvent : public PluginInterface2
00056 {
00057 public:
00058     // GetInstance() and DestroyInstance(instance*)
00059     STATIC_FACTORY_DECLARATIONS(ReadyEvent)
00060 
00061     // Constructor
00062     ReadyEvent();
00063 
00064     // Destructor
00065     virtual ~ReadyEvent();
00066 
00067     // --------------------------------------------------------------------------------------------
00068     // User functions
00069     // --------------------------------------------------------------------------------------------
00079     bool SetEvent(int eventId, bool isReady);
00080 
00086     bool ForceCompletion(int eventId);
00087 
00092     bool DeleteEvent(int eventId);
00093 
00096     bool IsEventSet(int eventId);
00097 
00103     bool IsEventCompletionProcessing(int eventId) const;
00104 
00110     bool IsEventCompleted(int eventId) const;
00111 
00116     bool HasEvent(int eventId);
00117 
00120     unsigned GetEventListSize(void) const;
00121 
00125     int GetEventAtIndex(unsigned index) const;
00126 
00134     bool AddToWaitList(int eventId, SystemAddress address);
00135     
00140     bool RemoveFromWaitList(int eventId, SystemAddress address);
00141 
00146     bool IsInWaitList(int eventId, SystemAddress address);
00147     
00152     unsigned GetRemoteWaitListSize(int eventId) const;
00153 
00158     SystemAddress GetFromWaitListAtIndex(int eventId, unsigned index) const;
00159         
00164     ReadyEventSystemStatus GetReadyStatus(int eventId, SystemAddress address);
00165 
00168     void SetSendChannel(unsigned char newChannel);
00169 
00170     // ---------------------------- ALL INTERNAL AFTER HERE ----------------------------
00173     struct RemoteSystem
00174     {
00175         MessageID lastSentStatus, lastReceivedStatus;
00176         SystemAddress systemAddress;
00177     };
00178     static int RemoteSystemCompBySystemAddress( const SystemAddress &key, const RemoteSystem &data );
00181     struct ReadyEventNode
00182     {
00183         int eventId; // Sorted on this
00184         MessageID eventStatus;
00185         DataStructures::OrderedList<SystemAddress,RemoteSystem,ReadyEvent::RemoteSystemCompBySystemAddress> systemList;
00186     };
00187     static int ReadyEventNodeComp( const int &key, ReadyEvent::ReadyEventNode * const &data );
00188 
00189 
00190 protected:
00191     // --------------------------------------------------------------------------------------------
00192     // Packet handling functions
00193     // --------------------------------------------------------------------------------------------
00194     virtual PluginReceiveResult OnReceive(Packet *packet);
00195     virtual void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
00196     virtual void OnRakPeerShutdown(void);
00197     
00198     void Clear(void);
00199     /*
00200     bool AnyWaitersCompleted(unsigned eventIndex) const;
00201     bool AllWaitersCompleted(unsigned eventIndex) const;
00202     bool AllWaitersReady(unsigned eventIndex) const;
00203     void SendAllReady(unsigned eventId, SystemAddress address);
00204     void BroadcastAllReady(unsigned eventIndex);
00205     void SendReadyStateQuery(unsigned eventId, SystemAddress address);
00206     void BroadcastReadyUpdate(unsigned eventIndex);
00207     bool AddToWaitListInternal(unsigned eventIndex, SystemAddress address);
00208     bool IsLocked(unsigned eventIndex) const;
00209     bool IsAllReadyByIndex(unsigned eventIndex) const;
00210     */
00211 
00212     void SendReadyStateQuery(unsigned eventId, SystemAddress address);
00213     void SendReadyUpdate(unsigned eventIndex, unsigned systemIndex, bool forceIfNotDefault);
00214     void BroadcastReadyUpdate(unsigned eventIndex, bool forceIfNotDefault);
00215     void RemoveFromAllLists(SystemAddress address);
00216     void OnReadyEventQuery(Packet *packet);
00217     void PushCompletionPacket(unsigned eventId);
00218     bool AddToWaitListInternal(unsigned eventIndex, SystemAddress address);
00219     void OnReadyEventForceAllSet(Packet *packet);
00220     void OnReadyEventPacketUpdate(Packet *packet);
00221     void UpdateReadyStatus(unsigned eventIndex);
00222     bool IsEventCompletedByIndex(unsigned eventIndex) const;
00223     unsigned CreateNewEvent(int eventId, bool isReady);
00224     bool SetEventByIndex(int eventIndex, bool isReady);
00225 
00226     DataStructures::OrderedList<int, ReadyEventNode*, ReadyEvent::ReadyEventNodeComp> readyEventNodeList;
00227     unsigned char channel;
00228 };
00229 
00230 } // namespace RakNet
00231 
00232 #endif
00233 
00234 #endif // _RAKNET_SUPPORT_*

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net