]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re/util/include/vcon_svr
6e9e0a06d3ec5520d22dce9be2910d0ae531468b
[l4.git] / l4 / pkg / l4re / util / include / vcon_svr
1 // vi:ft=cpp
2 /*
3  * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>,
4  *               Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
5  *     economic rights: Technische Universität Dresden (Germany)
6  *
7  * This file is part of TUD:OS and distributed under the terms of the
8  * GNU General Public License 2.
9  * Please see the COPYING-GPL-2 file for details.
10  *
11  * As a special exception, you may use this file as part of a free software
12  * library without restriction.  Specifically, if other files instantiate
13  * templates or use macros or inline functions from this file, or you compile
14  * this file and link it with other files to produce an executable, this
15  * file does not by itself cause the resulting executable to be covered by
16  * the GNU General Public License.  This exception does not however
17  * invalidate any other reasons why the executable file might be covered by
18  * the GNU General Public License.
19  */
20
21 #pragma once
22
23 #include <l4/sys/vcon>
24
25 #include <l4/sys/capability>
26 #include <l4/cxx/ipc_server>
27
28 namespace L4Re { namespace Util {
29
30 /**
31  * \brief Framebuffer server class.
32  * \ingroup api_l4re_util
33  */
34 template< typename SVR >
35 class Vcon_svr
36 {
37 public:
38 #if 0
39   /**
40    * \brief Write data to console
41    *
42    * \param buffer Buffer with the output data.
43    * \param size   Size of the buffer.
44    *
45    * \return Negative error code on error,
46    *         <= size bytes written.
47    */
48   int vcon_write(const char *buffer, unsigned size) = 0;
49   
50   /**
51    * \brief Read data from console
52    *
53    * \param buffer Buffer for the input data.
54    * \param size   Size of the buffer.
55    *
56    * \return Negative error code on error,
57    *         > size if more to read, size bytes are in the buffer,
58    *         <= size bytes read
59    */
60   virtual int vcon_read(char *buffer, unsigned size) = 0;
61   
62   /**
63    * \brief Return status of input stream
64    * \return true if end of input is reached
65    */
66   virtual bool vcon_end() = 0;
67 #endif
68   /**
69    * \brief Server dispatch function.
70    *
71    * \param obj Server object ID to work on.
72    * \param ios Input/Output stream.
73    *
74    * \return error code.
75    */
76   int dispatch(l4_umword_t obj, L4::Ipc_iostream &ios);
77
78 private:
79   SVR *__self() { return static_cast<SVR*>(this); }
80 };
81
82 template< typename SVR >
83 int
84 Vcon_svr<SVR>::dispatch(l4_umword_t, L4::Ipc_iostream &ios)
85 {
86   l4_msgtag_t tag;
87   ios >> tag;
88
89   if (tag.label() != L4_PROTO_LOG)
90     return -L4_EBADPROTO;
91   
92   long size;
93   ios >> size;
94   if (size == 0)
95     {
96       unsigned long size = 0;
97       const char *buf = 0;
98       ios >> L4::ipc_buf_in(buf, size);
99       __self()->vcon_write(buf, size);
100       return -L4_ENOREPLY;
101     }
102   else
103     {
104       // shift down to get real size
105       size = size >> 16;
106       char buf[size];
107       size = __self()->vcon_read(buf, size);
108       // don't use stream operators, because we need to set eof bit!
109       ios.put(__self()->vcon_end() ? size | 1UL << 31 : size);
110       ios.put(buf, size);
111       return 0;
112     }
113 }
114
115 }}