1/*
2 * This file is part of the PolKit1-qt project
3 * Copyright (C) 2009 Jaroslav Reznik <jreznik@redhat.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef POLKITQT1_SUBJECT_H
22#define POLKITQT1_SUBJECT_H
23
24#include "polkitqt1-export.h"
25
26#include <QtCore/QObject>
27#include <QtCore/QSharedData>
28
29typedef struct _PolkitSubject PolkitSubject;
30typedef struct _PolkitUnixProcess PolkitUnixProcess;
31typedef struct _PolkitSystemBusName PolkitSystemBusName;
32
33/**
34 * \namespace PolkitQt1 PolkitQt
35 *
36 * \brief Namespace wrapping PolicyKit-Qt classes
37 *
38 * This namespace wraps all PolicyKit-Qt classes.
39 */
40namespace PolkitQt1
41{
42
43/**
44 * \class Subject polkitqt1-subject.h Subject
45 * \author Jaroslav Reznik <jreznik@redhat.com>
46 *
47 * \brief This class represents PolicyKit subjects
48 *
49 * This class encapsulates the PolkitSubject interface.
50 *
51 * \see UnixProcess
52 * \see SystemBusName
53 * \see UnixSession
54 */
55class POLKITQT1_EXPORT Subject
56{
57public:
58 Subject();
59 Subject(const Subject &other);
60 ~Subject();
61
62 Subject &operator=(const Subject &other);
63
64 bool isValid() const;
65
66 /**
67 * Serialization of object to the string
68 *
69 * \return Serialized Subject object
70 */
71 QString toString() const;
72
73 /**
74 * Creates the Subject object from string reprezentation
75 *
76 * \param string string reprezentation of the object
77 *
78 * \return Pointer to new Subject instance
79 */
80 static Subject fromString(const QString &string);
81
82 /**
83 * Gets PolkitSubject object.
84 *
85 * \warning It shouldn't be used directly unless you are completely aware of what are you doing
86 *
87 * \return Pointer to PolkitSubject instance
88 */
89 PolkitSubject *subject() const;
90
91protected:
92 Subject(PolkitSubject *subject);
93
94 void setSubject(PolkitSubject *subject);
95
96private:
97 class Data;
98 QExplicitlySharedDataPointer< Data > d;
99};
100
101/**
102 * \class UnixProcessSubject polkitqt1-subject.h Subject
103 * \author Jaroslav Reznik <jreznik@redhat.com>
104 *
105 * \brief A class for representing a UNIX process.
106 *
107 * To uniquely identify processes, both the process
108 * id and the start time of the process (a monotonic
109 * increasing value representing the time since the
110 * kernel was started) is used.
111 *
112 * \sa Subject
113 */
114class POLKITQT1_EXPORT UnixProcessSubject : public Subject
115{
116public:
117 /**
118 * Subject constructor, takes one parameter - PID. The start time
119 * of process will be looked automatically.
120 *
121 * \param pid An Unix process PID.
122 */
123 explicit UnixProcessSubject(qint64 pid);
124
125 /**
126 * Subject constructor, takes two parameters - PID and start time.
127 *
128 * \param pid An Unix process PID.
129 * \param startTime An Unix process start time.
130 */
131 UnixProcessSubject(qint64 pid, quint64 startTime);
132
133 /**
134 * Subject constructor, it creates UnixProcess object from PolkitUnixProcess object
135 *
136 * \warning Use this only if you are completely aware of what are you doing!
137 *
138 * \param process PolkitUnixProcess object
139 */
140 explicit UnixProcessSubject(PolkitUnixProcess *process);
141
142 /**
143 * Returns Unix process PID.
144 *
145 * \return A PID of associated Unix process.
146 */
147 qint64 pid() const;
148
149 /**
150 * Returns Unix process start time.
151 *
152 * \return A start time of associated Unix process.
153 */
154 qint64 startTime() const;
155
156 /**
157 * Returns Unix process UID.
158 *
159 * \return A UID of associated Unix process.
160 */
161 qint64 uid() const;
162
163 /**
164 * Sets Unix process PID.
165 *
166 * \param pid An Unix process PID.
167 */
168 void setPid(qint64 pid);
169};
170
171/**
172 * \class SystemBusNameSubject polkitqt1-subject.h Subject
173 * \author Jaroslav Reznik <jreznik@redhat.com>
174 *
175 * \brief A class for representing a process owning a unique name on the system bus.
176 *
177 * \sa Subject
178 */
179class POLKITQT1_EXPORT SystemBusNameSubject : public Subject
180{
181public:
182 /**
183 * Subject constructor, takes one parameter - system bus name.
184 *
185 * \param name A unique system bus name.
186 */
187 explicit SystemBusNameSubject(const QString &name);
188
189 /**
190 * Subject constructor, it creates SystemBusName object from PolkitSystemBusName object
191 *
192 * \warning Use this only if you are completely aware of what are you doing!
193 *
194 * \param pkSystemBusName PolkitSystemBusName object
195 */
196 explicit SystemBusNameSubject(PolkitSystemBusName *pkSystemBusName);
197
198 /**
199 * Returns system bus name.
200 *
201 * \return A unique system bus name.
202 */
203 QString name() const;
204
205 /**
206 * Sets system bus name.
207 *
208 * \param name System bus name.
209 */
210 void setName(const QString &name);
211};
212
213/**
214 * \class UnixSessionSubject polkitqt1-subject.h Subject
215 * \author Jaroslav Reznik <jreznik@redhat.com>
216 *
217 * \brief A class for representing unix session.
218 *
219 * The session id is an opaque string obtained from
220 * ConsoleKit.
221 *
222 * \sa Subject
223 */
224class POLKITQT1_EXPORT UnixSessionSubject : public Subject
225{
226public:
227 /**
228 * Subject constructor, takes one parameter - session id.
229 *
230 * \param sessionId The session id.
231 */
232 explicit UnixSessionSubject(const QString &sessionId);
233
234 /**
235 * Subject constructor, takes one parameter - pid of process.
236 *
237 * Synchronous!
238 *
239 * \param pid The session's process pid.
240 */
241 explicit UnixSessionSubject(qint64 pid);
242
243 /**
244 * Subject constructor, it creates UnixSession object from PolkitUnixSession object
245 *
246 * \warning Use this only if you are completely aware of what are you doing!
247 *
248 * \param pkUnixSession PolkitUnixSession object
249 */
250 explicit UnixSessionSubject(PolkitSystemBusName *pkUnixSession);
251
252 /**
253 * Returns session id.
254 *
255 * \return A session id.
256 */
257 QString sessionId() const;
258
259 /**
260 * Sets session id.
261 *
262 * \param sessionId A session id.
263 */
264 void setSessionId(const QString &sessionId);
265};
266
267}
268
269#endif
270