Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafObject.h
1 // ##################################################################################################
2 //
3 // Caffa
4 // Copyright (C) 2020- 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 
21 #pragma once
22 
23 #include "cafField.h"
24 #include "cafFieldInitHelper.h"
25 #include "cafFieldJsonCapabilitySpecializations.h"
26 #include "cafMethodInitHelper.h"
27 #include "cafObjectHandle.h"
28 #include "cafObjectMacros.h"
29 
30 namespace caffa
31 {
32 class Object : public ObjectHandle
33 {
34 public:
35  CAFFA_HEADER_INIT( Object, ObjectHandle )
36 
37  Object( bool generateUuid = true );
38  ~Object() noexcept override;
39 
40 protected:
46  template <typename FieldType>
47  FieldInitHelper<FieldType> initField( FieldType& field, const std::string& keyword )
48  {
49  AddIoCapabilityToField( &field );
50  addField( &field, keyword );
51  return FieldInitHelper( field, keyword );
52  }
53 
60  template <typename MethodType, typename CallbackT>
61  MethodInitHelper<MethodType> initMethod( MethodType& method, const std::string& keyword, CallbackT&& callback )
62  {
63  method.setCallback( callback );
64  addMethod( &method, keyword );
65 
66  return MethodInitHelper<MethodType>( method, keyword );
67  }
68 
76  template <typename MethodType, typename CallbackT>
77  MethodInitHelper<MethodType> initMethodWithSession( MethodType& method, const std::string& keyword, CallbackT&& callback )
78  {
79  method.setCallbackWithSession( callback );
80  addMethod( &method, keyword );
81 
82  return MethodInitHelper<MethodType>( method, keyword );
83  }
84 };
85 
86 } // End of namespace caffa
MethodInitHelper< MethodType > initMethod(MethodType &method, const std::string &keyword, CallbackT &&callback)
Definition: cafObject.h:61
MethodInitHelper< MethodType > initMethodWithSession(MethodType &method, const std::string &keyword, CallbackT &&callback)
Definition: cafObject.h:77
Definition: cafFieldInitHelper.h:41
Definition: cafObject.h:32
void addField(FieldHandle *field, const std::string &keyword)
Definition: cafObjectHandle.cpp:80
Definition: cafObjectHandle.h:47
void addMethod(MethodHandle *method, const std::string &keyword)
Definition: cafObjectHandle.cpp:95
FieldInitHelper< FieldType > initField(FieldType &field, const std::string &keyword)
Definition: cafObject.h:47
Definition: cafMethodInitHelper.h:37
Main Caffa namespace.
Definition: cafApplication.h:30