Loading...
Searching...
No Matches
ipc_string
// vi:set ft=cpp: -*- Mode: C++ -*-
/*
* (c) 2014 Alexander Warg <alexander.warg@kernkonzept.com>
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include "types"
#include "ipc_basics"
#include "ipc_array"
namespace L4 { namespace Ipc {
template<typename CHAR = char const, typename LEN = unsigned long>
struct String : Array<CHAR, LEN>
{
static LEN strlength(CHAR *d) { LEN l = 0; while (d[l]) ++l; return l; }
String() {}
String(CHAR *d) : Array<CHAR, LEN>(strlength(d) + 1, d) {}
String(LEN len, CHAR *d) : Array<CHAR, LEN>(len, d) {}
void copy_in(CHAR const *s)
{
if (this->length < 1)
return;
LEN i;
for (i = 0; i < this->length - 1 && s[i]; ++i)
this->data[i] = s[i];
this->length = i + 1;
this->data[i] = CHAR();
}
};
#if __cplusplus >= 201103L
template< typename CHAR = char, typename LEN_TYPE = unsigned long,
LEN_TYPE MAX = (L4_UTCB_GENERIC_DATA_SIZE *
sizeof(l4_umword_t)) / sizeof(CHAR) >
using String_in_buf = Array_in_buf<CHAR, LEN_TYPE, MAX>;
#endif
namespace Msg {
template<typename A, typename LEN>
struct Clnt_xmit< String<A, LEN> > : Clnt_xmit< Array<A, LEN> > {};
template<typename A, typename LEN, typename CLASS>
struct Svr_val_ops< String<A, LEN>, Dir_in, CLASS >
: Svr_val_ops< Array_ref<A, LEN>, Dir_in, CLASS >
{
typedef Svr_val_ops< Array_ref<A, LEN>, Dir_in, CLASS > Base;
typedef typename Base::svr_type svr_type;
using Base::to_svr;
static int to_svr(char *msg, unsigned offset, unsigned limit,
svr_type &a, Dir_in dir, Cls_data cls)
{
int r = Base::to_svr(msg, offset, limit, a, dir, cls);
if (r < 0)
return r;
// correct clients send at least the zero terminator
if (a.length < 1)
return -L4_EMSGTOOSHORT;
typedef typename L4::Types::Remove_const<A>::type elem_type;
const_cast<elem_type*>(a.data)[a.length - 1] = A();
return r;
}
};
template<typename A, typename LEN>
struct Clnt_xmit<String<A, LEN> &> : Clnt_xmit<Array<A, LEN> &>
{
typedef Array<A, LEN> &type;
using Clnt_xmit<type>::from_msg;
static int from_msg(char *msg, unsigned offset, unsigned limit, long ret,
Array<A, LEN> &a, Dir_out dir, Cls_data cls)
{
int r = Clnt_xmit<type>::from_msg(msg, offset, limit, ret, a, dir, cls);
if (r < 0)
return r;
// check for a bad servers
if (a.length < 1)
return -L4_EMSGTOOSHORT;
a.data[a.length - 1] = A();
return r;
};
};
template<typename A, typename LEN>
struct Clnt_xmit<String<A, LEN> *> : Clnt_xmit<String<A, LEN> &> {};
template<typename A, typename LEN, typename CLASS>
struct Svr_val_ops<String<A, LEN>, Dir_out, CLASS>
: Svr_val_ops<Array_ref<A, LEN>, Dir_out, CLASS>
{};
template<typename A, typename LEN>
struct Is_valid_rpc_type<String<A, LEN> const *> : L4::Types::False {};
template<typename A, typename LEN>
struct Is_valid_rpc_type<String<A, LEN> const &> : L4::Types::False {};
} // namespace Msg
}}
l4_umword_t
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
L4_EMSGTOOSHORT
@ L4_EMSGTOOSHORT
Message too short.
Definition err.h:56
L4_UTCB_GENERIC_DATA_SIZE
@ L4_UTCB_GENERIC_DATA_SIZE
Total number of message register (MRs) available.
Definition utcb.h:36
L4::Ipc::Msg
IPC Message related functionality.
Definition ipc_array:154
L4::Ipc
IPC related functionality.
Definition ipc_array:13
L4
L4 low-level kernel interface.
Definition l4sys-l4f-groups.dox:50
L4::Ipc::Array_in_buf
Server-side copy in buffer for Array.
Definition ipc_array:127
L4::Ipc::Array
Array data type for dynamically sized arrays in RPCs.
Definition ipc_array:82
L4::Ipc::Array< char const, unsigned long >::Array
Array()
Definition ipc_array:84
L4::Ipc::Msg::Cls_data
Marker type for data values.
Definition ipc_basics:150
L4::Ipc::Msg::Dir_in
Marker type for input values.
Definition ipc_basics:145
L4::Ipc::Msg::Dir_out
Marker type for output values.
Definition ipc_basics:147
L4::Ipc::Msg::Is_valid_rpc_type
Type trait defining a valid RPC parameter type.
Definition ipc_basics:339
L4::Ipc::Msg::Svr_val_ops
Defines client-side handling of `MTYPE' as RPC argument.
Definition ipc_basics:264
types