summaryrefslogtreecommitdiff
path: root/src/bindings/cxx/eldbus_cxx/eldbus_message_arguments.hh
blob: 6c57b0216bc282e9a3655581d67467eb393010c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef ELDBUS_CXX_ELDBUS_MESSAGE_ARGUMENTS_HH
#define ELDBUS_CXX_ELDBUS_MESSAGE_ARGUMENTS_HH

#include <Eldbus.h>

#include <tuple>
#include <iostream>

namespace efl { namespace eldbus { namespace _detail {

template <std::size_t I, typename Seq, typename Tuple>
bool _init_raw_tuple(Eldbus_Message_Iter*, Tuple const&, std::true_type)
{
  return true;
}

template <std::size_t I, typename Seq, typename Tuple>
bool _init_raw_tuple(Eldbus_Message_Iter* iterator, Tuple const& tuple, std::false_type)
{
  typedef signature_traits<typename std::tuple_element<I, Seq>::type> traits;
  typedef typename traits::value_type element_type;

  char* c = eldbus_message_iter_signature_get(iterator);
  if(c[0] != signature_traits<element_type>::sig)
    {
      return false;
    }

  eldbus_message_iter_get_and_next(iterator, *c, &std::get<I>(tuple));

  return _init_raw_tuple<I+1, Seq>
    (iterator, tuple, std::integral_constant<bool, (I+1 == std::tuple_size<Tuple>::value)>());
}

template <std::size_t I, typename Tuple>
bool _append_tuple(Eldbus_Message*, Tuple const&, std::true_type)
{
  return true;
}

template <std::size_t I, typename Tuple>
bool _append_tuple(Eldbus_Message* message, Tuple const& tuple, std::false_type)
{
  typedef signature_traits<typename std::tuple_element<I, Tuple>::type> traits;

  char signature[2] = {traits::sig, 0};
  if(!eldbus_message_arguments_append(message, signature, traits::to_raw(std::get<I>(tuple))))
    return false;

  return _append_tuple<I+1>
    (message, tuple, std::integral_constant<bool, (I+1 == std::tuple_size<Tuple>::value)>());
}

} } }

#endif