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