• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_TYPED_METHOD_CALL_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_TYPED_METHOD_CALL_H_
7 
8 #include <memory>
9 #include <string>
10 
11 namespace flutter {
12 
13 // An object encapsulating a method call from Flutter whose arguments are of
14 // type T.
15 template <typename T>
16 class MethodCall {
17  public:
18   // Creates a MethodCall with the given name and arguments.
MethodCall(const std::string & method_name,std::unique_ptr<T> arguments)19   MethodCall(const std::string& method_name, std::unique_ptr<T> arguments)
20       : method_name_(method_name), arguments_(std::move(arguments)) {}
21 
22   virtual ~MethodCall() = default;
23 
24   // Prevent copying.
25   MethodCall(MethodCall<T> const&) = delete;
26   MethodCall& operator=(MethodCall<T> const&) = delete;
27 
28   // The name of the method being called.
method_name()29   const std::string& method_name() const { return method_name_; }
30 
31   // The arguments to the method call, or NULL if there are none.
arguments()32   const T* arguments() const { return arguments_.get(); }
33 
34  private:
35   std::string method_name_;
36   std::unique_ptr<T> arguments_;
37 };
38 
39 }  // namespace flutter
40 
41 #endif  // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_TYPED_METHOD_CALL_H_
42