IMessageHandler.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright The kNet Project.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License. */
  11. #pragma once
  12. /** @file IMessageHandler.h
  13. @brief The \ref kNet::IMessageHandler IMessageHandler interface. Implementable by the client application. */
  14. // Modified by Yao Wei Tjong for Urho3D
  15. // Urho3D: use relative path
  16. #include "Types.h"
  17. namespace kNet
  18. {
  19. class MessageConnection;
  20. /// IMessageHandler is a callback object used by the MessageConnection to invoke the main application
  21. /// whenever a message has been received.
  22. class IMessageHandler
  23. {
  24. public:
  25. virtual ~IMessageHandler() {}
  26. /// Called whenever the network stack has received a message that the application
  27. /// needs to process.
  28. /// @param source The kNet connection this message originates from.
  29. /// @param packetId A unique incrementing id counter that identifies the number of the UDP packet this message originated from. Use this
  30. /// to prune out-of-order messages if necessary. kNet automatically discards duplicate messages, and can do out-of-order discarding
  31. /// automatically as well, if you use message content ID's. Otherwise, you can use the packetId to do the pruning manually.
  32. /// @param messageId Contains the id (or the "type") of the message. This is the one you specified when sending the message
  33. /// @param data Points to the raw data buffer. This buffer may be zero if numBytes == 0.
  34. /// @param numBytes The length of the raw data buffer, in bytes.
  35. virtual void HandleMessage(MessageConnection *source, packet_id_t packetId, message_id_t messageId, const char *data, size_t numBytes) = 0;
  36. /// Called by the network library to ask the application to produce a content ID
  37. /// associated with the given message. If the application returns 0, the message doesn't
  38. /// have a ContentID and it is processed normally.
  39. /// The ContentID of the message is used to determine if a message replaces another.
  40. virtual u32 ComputeContentID(message_id_t UNUSED(messageId), const char * UNUSED(data), size_t UNUSED(numBytes))
  41. {
  42. // The default behavior is to not have a content ID on any message.
  43. return 0;
  44. }
  45. };
  46. } // ~kNet