]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/meta
update
[l4.git] / l4 / pkg / l4sys / include / meta
1 // vi:ft=cpp
2 /**
3  * \file
4  * \brief Meta interface for getting dynamic type information
5  *        about objects behind capabilities.
6  * \ingroup l4_api
7  */
8 /*
9  * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>
10  *     economic rights: Technische Universität Dresden (Germany)
11  *
12  * This file is part of TUD:OS and distributed under the terms of the
13  * GNU General Public License 2.
14  * Please see the COPYING-GPL-2 file for details.
15  *
16  * As a special exception, you may use this file as part of a free software
17  * library without restriction.  Specifically, if other files instantiate
18  * templates or use macros or inline functions from this file, or you compile
19  * this file and link it with other files to produce an executable, this
20  * file does not by itself cause the resulting executable to be covered by
21  * the GNU General Public License.  This exception does not however
22  * invalidate any other reasons why the executable file might be covered by
23  * the GNU General Public License.
24  */
25
26 #pragma once
27
28 #include <l4/sys/capability>
29
30 namespace L4 {
31 /**
32  * \addtogroup l4_kernel_object_api
33  */
34 /*@{*/
35
36 /**
37  * \brief Meta interface that shall be implemented by each L4Re object
38  *        and gives access to the dynamic type information for
39  *        L4Re objects.
40  */
41 class Meta : public Kobject_t<Meta, Kobject, L4_PROTO_META>
42 {
43   L4_KOBJECT(Meta)
44
45 public:
46   enum Op
47   {
48     O_num_ifaces = 0,
49     O_iface      = 1,
50     O_supports   = 2,
51   };
52
53   /**
54    * \brief Get the number of interfaces implemented by this object.
55    * \param utcb is the utcb to use for sending the message.
56    * \return The message tag for the operation, the label (l4_msgtag_t::label())
57    *         is set to the number of interfaces if successful, or to -error
58    *         when an error occured.
59    */
60   l4_msgtag_t num_interfaces(l4_utcb_t *utcb = l4_utcb()) throw();
61
62   /**
63    * \brief Get the protocol number that must be used for the interface with
64    *        the index \a idx.
65    * \param idx is the index of the interface to get the protocol number for.
66    *            \a idx must be \>= 0 and \< the return value of
67    *            num_interfaces().
68    * \param utcb is the utcb to use for sending the message.
69    * \return System call return tag. Negative label on error,
70    *         success with value 0 in label.
71    */
72   l4_msgtag_t interface(int idx, l4_utcb_t *u = l4_utcb()) throw();
73
74   /**
75    * \brief Figure out if the object supports the given \a protocol (number).
76    * \param protocol is the protocol number to check for.
77    * \param utcb is the utcb to use for sending the message.
78    * \return The message tag for the operation, the label (l4_msgtag_t::label())
79    *         is set to 1 if \a protocol is supported to 0 if not.
80    *
81    * This method is intended to be used for statically assigned protocol
82    * numbers.
83    */
84   l4_msgtag_t supports(long protocol, l4_utcb_t *u = l4_utcb()) throw();
85 };
86
87 /*@}*/
88
89 inline l4_msgtag_t
90 Meta::num_interfaces(l4_utcb_t *u) throw()
91 {
92   l4_msg_regs_t *mr = l4_utcb_mr_u(u);
93   mr->mr[0] = O_num_ifaces;
94   return l4_ipc_call(cap(), u, l4_msgtag(Protocol, 1, 0, 0),
95                      L4_IPC_NEVER);
96 }
97
98 inline l4_msgtag_t
99 Meta::interface(int idx, l4_utcb_t *u) throw()
100 {
101   l4_msg_regs_t *mr = l4_utcb_mr_u(u);
102   mr->mr[0] = O_iface;
103   mr->mr[1] = idx;
104   return l4_ipc_call(cap(), u, l4_msgtag(Protocol, 2, 0, 0),
105                      L4_IPC_NEVER);
106 }
107
108 inline l4_msgtag_t
109 Meta::supports(long protocol, l4_utcb_t *u) throw()
110 {
111   l4_msg_regs_t *mr = l4_utcb_mr_u(u);
112   mr->mr[0] = O_supports;
113   mr->mr[1] = protocol;
114   return l4_ipc_call(cap(), u, l4_msgtag(Protocol, 2, 0, 0),
115                      L4_IPC_NEVER);
116 }
117
118 }