signal_awaiter_utils.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**************************************************************************/
  2. /* signal_awaiter_utils.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef SIGNAL_AWAITER_UTILS_H
  31. #define SIGNAL_AWAITER_UTILS_H
  32. #include "csharp_script.h"
  33. #include "mono_gc_handle.h"
  34. #include "core/object/ref_counted.h"
  35. Error gd_mono_connect_signal_awaiter(Object *p_source, const StringName &p_signal, Object *p_target, GCHandleIntPtr p_awaiter_handle_ptr);
  36. class BaseSignalCallable : public CallableCustom {
  37. public:
  38. virtual StringName get_signal() const = 0;
  39. };
  40. class SignalAwaiterCallable : public BaseSignalCallable {
  41. ObjectID target_id;
  42. MonoGCHandleData awaiter_handle;
  43. StringName signal;
  44. public:
  45. static bool compare_equal(const CallableCustom *p_a, const CallableCustom *p_b);
  46. static bool compare_less(const CallableCustom *p_a, const CallableCustom *p_b);
  47. static constexpr CompareEqualFunc compare_equal_func_ptr = &SignalAwaiterCallable::compare_equal;
  48. static constexpr CompareEqualFunc compare_less_func_ptr = &SignalAwaiterCallable::compare_less;
  49. uint32_t hash() const override;
  50. String get_as_text() const override;
  51. CompareEqualFunc get_compare_equal_func() const override;
  52. CompareLessFunc get_compare_less_func() const override;
  53. ObjectID get_object() const override;
  54. StringName get_signal() const override;
  55. void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override;
  56. SignalAwaiterCallable(Object *p_target, MonoGCHandleData p_awaiter_handle, const StringName &p_signal);
  57. ~SignalAwaiterCallable();
  58. };
  59. class EventSignalCallable : public BaseSignalCallable {
  60. Object *owner = nullptr;
  61. StringName event_signal_name;
  62. public:
  63. static bool compare_equal(const CallableCustom *p_a, const CallableCustom *p_b);
  64. static bool compare_less(const CallableCustom *p_a, const CallableCustom *p_b);
  65. static constexpr CompareEqualFunc compare_equal_func_ptr = &EventSignalCallable::compare_equal;
  66. static constexpr CompareEqualFunc compare_less_func_ptr = &EventSignalCallable::compare_less;
  67. uint32_t hash() const override;
  68. String get_as_text() const override;
  69. CompareEqualFunc get_compare_equal_func() const override;
  70. CompareLessFunc get_compare_less_func() const override;
  71. ObjectID get_object() const override;
  72. StringName get_signal() const override;
  73. void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override;
  74. EventSignalCallable(Object *p_owner, const StringName &p_event_signal_name);
  75. };
  76. #endif // SIGNAL_AWAITER_UTILS_H