NativeModule.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #pragma once
  8. #include <string>
  9. #include <vector>
  10. #include <folly/Optional.h>
  11. #include <folly/dynamic.h>
  12. namespace facebook {
  13. namespace react {
  14. struct MethodDescriptor {
  15. std::string name;
  16. // type is one of js MessageQueue.MethodTypes
  17. std::string type;
  18. MethodDescriptor(std::string n, std::string t)
  19. : name(std::move(n)), type(std::move(t)) {}
  20. };
  21. using MethodCallResult = folly::Optional<folly::dynamic>;
  22. class NativeModule {
  23. public:
  24. virtual ~NativeModule() {}
  25. virtual std::string getName() = 0;
  26. virtual std::vector<MethodDescriptor> getMethods() = 0;
  27. virtual folly::dynamic getConstants() = 0;
  28. virtual void
  29. invoke(unsigned int reactMethodId, folly::dynamic &&params, int callId) = 0;
  30. virtual MethodCallResult callSerializableNativeHook(
  31. unsigned int reactMethodId,
  32. folly::dynamic &&args) = 0;
  33. };
  34. } // namespace react
  35. } // namespace facebook