Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafRpcDataFieldAccessor.h
1 // ##################################################################################################
2 //
3 // Caffa
4 // Copyright (C) Gaute Lindkvist
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 #pragma once
20 
21 #include "cafDataFieldAccessor.h"
22 #include "cafRpcClient.h"
23 
24 namespace caffa::rpc
25 {
26 template <class DataType>
28 {
29 public:
30  DataFieldAccessor( Client* client, caffa::ObjectHandle* fieldOwner, const std::string& fieldName )
32  , m_client( client )
33  , m_fieldOwner( fieldOwner )
34  , m_fieldName( fieldName )
35  {
36  }
37 
38  std::unique_ptr<caffa::DataFieldAccessor<DataType>> clone() const override
39  {
40  return std::make_unique<DataFieldAccessor<DataType>>( m_client, m_fieldOwner, m_fieldName );
41  }
42 
43  DataType value() override { return m_client->get<DataType>( m_fieldOwner, m_fieldName ); }
44 
45  void setValue( const DataType& value ) override
46  {
47  return m_client->set<DataType>( m_fieldOwner, m_fieldName, value );
48  }
49 
50 private:
51  Client* m_client;
52 
53  caffa::ObjectHandle* m_fieldOwner;
54  std::string m_fieldName;
55 };
56 
57 } // namespace caffa::rpc
Abstract but typed data field accessor. Inherit to create different storage mechanisms.
Definition: cafDataFieldAccessor.h:43
Definition: cafObjectHandle.h:55
Definition: cafRpcClient.h:38
DataType get(const caffa::ObjectHandle *objectHandle, const std::string &fieldName) const
Get a value through RPC.
Definition: cafRpcClient.h:116
void set(const caffa::ObjectHandle *objectHandle, const std::string &fieldName, const DataType &value)
Set a value through RPC.
Definition: cafRpcClient.h:126
Definition: cafRpcDataFieldAccessor.h:28
void setValue(const DataType &value) override
Set the value with the accessor. Will throw a std::runtime_exception if the accessor has limits and t...
Definition: cafRpcDataFieldAccessor.h:45
DataType value() override
Get the field value.
Definition: cafRpcDataFieldAccessor.h:43
std::unique_ptr< caffa::DataFieldAccessor< DataType > > clone() const override
Clone the accessor using polymorphism.
Definition: cafRpcDataFieldAccessor.h:38