Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafMethodHandle.h
1 // ##################################################################################################
2 //
3 // Caffa
4 // Copyright (C) Kontur As
5 //
6 // GNU Lesser General Public License Usage
7 // This library is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation; either version 2.1 of the License, or
10 // (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
17 // for more details.
18 //
19 // ##################################################################################################
20 #pragma once
21 
22 #include <string>
23 #include <vector>
24 
25 namespace caffa
26 {
27 class MethodHandle;
28 class ObjectHandle;
29 class ObjectFactory;
30 class Session;
31 
33 {
34 public:
35  MethodAccessorInterface( const ObjectHandle* selfHandle, const MethodHandle* methodHandle, ObjectFactory* objectFactory )
36  : m_selfHandle( selfHandle )
37  , m_methodHandle( methodHandle )
38  , m_objectFactory( objectFactory )
39  {
40  }
41  virtual ~MethodAccessorInterface() = default;
42  virtual std::string execute( const std::string& argumentString ) const = 0;
43 
44  ObjectFactory* objectFactory() const { return m_objectFactory; }
45 
46 protected:
47  const ObjectHandle* m_selfHandle;
48  const MethodHandle* m_methodHandle;
49  ObjectFactory* m_objectFactory;
50 };
51 
53 {
54 public:
55  MethodHandle() = default;
56  ~MethodHandle() = default;
57 
58  std::string keyword() const { return m_name; }
59  void setArgumentNames( const std::vector<std::string>& argumentNames ) { m_argumentNames = argumentNames; }
60  const std::vector<std::string>& argumentNames() const { return m_argumentNames; }
61 
62  bool isConst() const { return m_isConst; }
63  void setConst( bool isConst ) { m_isConst = isConst; }
64  const std::string& documentation() const { return m_documentation; }
65  void setDocumentation( const std::string& documentation ) { m_documentation = documentation; }
66 
67  virtual std::string execute( std::shared_ptr<Session> session, const std::string& argumentsString ) const = 0;
68  virtual std::string schema() const = 0;
69 
70  MethodAccessorInterface* accessor() const { return m_accessor.get(); }
71  void setAccessor( std::unique_ptr<MethodAccessorInterface> accessor ) { m_accessor = std::move( accessor ); }
72 
73 private:
74  friend class ObjectHandle;
75  void setName( const std::string& name ) { m_name = name; }
76 
77  std::string m_name;
78  std::vector<std::string> m_argumentNames;
79  bool m_isConst;
80  std::string m_documentation;
81 
82  std::unique_ptr<MethodAccessorInterface> m_accessor;
83 };
84 } // namespace caffa
Definition: cafMethodHandle.h:32
Definition: cafMethodHandle.h:52
Definition: cafObjectFactory.h:36
Definition: cafObjectHandle.h:47
Main Caffa namespace.
Definition: cafApplication.h:30