/usr/include/BALL/VIEW/KERNEL/serverWidget.h is in libballview1.4-dev 1.4.3~beta1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | // -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_VIEW_KERNEL_SERVERWIDGET_H
#define BALL_VIEW_KERNEL_SERVERWIDGET_H
#ifndef BALL_COMMON_H
# include <BALL/common.h>
#endif
#ifndef BALL_DATATYPE_HASHMAP_H
# include <BALL/DATATYPE/hashMap.h>
#endif
#ifndef BALL_VIEW_KERNEL_MODULARWIDGET_H
# include <BALL/VIEW/KERNEL/modularWidget.h>
#endif
#ifndef BALL_CONCEPT_OBJECTCREATOR_H
# include <BALL/CONCEPT/objectCreator.h>
#endif
#ifndef BALL_SYSTEM_NETWORKING_H
# include <BALL/SYSTEM/networking.h>
#endif
#ifndef BALL_VIEW_KERNEL_THREADS_H
# include <BALL/VIEW/KERNEL/threads.h>
#endif
#include <QtCore/QTimer>
#include <QtGui/QLabel>
class QLabel;
namespace BALL
{
class Composite;
namespace VIEW
{
class ServerPreferences;
class Preferences;
/** ServerWidget class.
The class ServerWidget handles all incoming PersistentObject objects,
converts them into Composite objects (if possible) and sents
them through the ConnectionObject tree with the message
NewCompositeMessage. Also it stores all received Composite objects
and replaces them if the same Composite object is received again.
If a Composite object is replaced the message
RemovedCompositeMessage will be sent through the ConnectionObject
tree and after that the the message NewCompositeMessage with the new
received composite will be sent.
\ingroup ViewKernelClient
*/
class BALL_VIEW_EXPORT ServerWidget
: public QObject,
public ModularWidget
{
Q_OBJECT
public:
BALL_EMBEDDABLE(ServerWidget,ModularWidget)
/** @name Exceptions
*/
//@{
/** NotCompositeObject Exception class.
This exeption will be thrown if a PersistentObject was received
that was not a Composite object.
\see GeneralException
*/
class BALL_VIEW_EXPORT NotCompositeObject: public Exception::GeneralException
{
public:
NotCompositeObject(const char* file, int line);
};
//@}
/** BALLView server thread.
* This class handles the incoming connections for the simple
* BALL-protocol for sending composites over the net.
*/
class BALLViewServer
: public virtual BALLThread,
public virtual TCPServerThread
{
public:
BALLViewServer(ServerWidget* parent, Size port, bool restart = true);
/** private methodes used for reacting to client requests.
*/
void sendObject()
throw(NotCompositeObject);
virtual void run();
/** Handler for successful connections.
Virtually overridden method.
This method handles the socket stream. When a connection has been
made, this function is automatically called through our base classes.
Then, the socket stream will be passed onto the object creator and
incoming objects will be received.
At the moment only Composite objects will be accepted. If
another object is received the exception NotCompositeObject
will be thrown.
\exception NotCompositeObject thrown if another object than Composite object is received
*/
virtual void handleConnection();
/** Used for communication with the parent **/
void setLocked(bool is_locked);
protected:
ServerWidget* parent_widget_;
Composite* received_composite_;
typedef HashMap<unsigned long, Composite *> CompositeHashMap;
CompositeHashMap composite_hashmap_;
Size port_;
bool is_locked_;
};
/** @name Constructors
*/
//@{
/** Default Constructor.
The state of this server is:
- no object creator registered
- server listening on <tt> VIEW_DEFAULT_PORT</tt> if activated
\par
\see ModularWidget
*/
ServerWidget(QWidget* parent = 0, const char* name = 0);
// only for Python interface
ServerWidget(const ServerWidget& server);
//@}
/** @name Destructors
*/
//@{
/** Destructor.
*/
virtual ~ServerWidget();
/** Explicit default initialization.
Calls ConnectionObject::clear.
\see ConnectionObject::clear
*/
virtual void clear();
//@}
/** @name Accessors: inspectors and mutators
*/
//@{
/** Start the server.
*/
virtual void activate() {};
/** Stop the server.
*/
virtual void deactivate() {};
/** Set the server port.
\param port the new port
*/
void setPort(const int port);
/** Return the server port.
Return the port of this server.
\return int the port of this server
*/
int getPort() const;
/** Register a ObjectCreator that is used for converting
PersistentObject objects into Composite objects.
Every ObjectCreator, that is still registered, when a ServerWidget instance is destructed, will be deleted.
\see ObjectCreator
*/
void registerObjectCreator(const ObjectCreator& s);
/** Reset the ObjectCreator.
After calling this method PersistentObject objects will be converted
using the default ObjectCreator.
\see ObjectCreator
*/
void unregisterObjectCreator();
/** Return the ObjectCreator.
*/
ObjectCreator& getObjectCreator();
/** Return the ObjectCreator, const version.
*/
const ObjectCreator& getObjectCreator() const;
/** Initialize the server widget.
This method initializes the icon of this server and adds it
to MainControl. This method will be called by show of
the class MainControl.
\see ModularWidget
\see show
*/
virtual void initializeWidget(MainControl& main_control);
/** Remove the server widget.
This method deletes the icon of this server and removes it
from MainControl.
This method will be called by aboutToExit of
the class MainControl.
\see ModularWidget
\see aboutToExit
*/
virtual void finalizeWidget(MainControl& main_control);
/** Initialize a preferences tab for the server.
This method creates the preferences tab ServerPreferences for
this server and inserts it into the Preferences dialog
of the MainControl.
This method is called automatically by the method show of
the class MainControl at the start of the application.
See ModularWidget for more information concerning preferences tabs.\par
\param preferences the Preferences dialog of the MainControl
\see show
\see ServerPreferences
\see Preferences
*/
virtual void initializePreferencesTab(Preferences &preferences);
/** Remove the preferences tab.
This method removes the ServerPreferences tab of this server
from the Preferences dialog of the MainControl.
This method is called automatically by the method aboutToExit
method of the class MainControl at the end of the application.
See ModularWidget
for more information concerning preferences tabs.\par
\param preferences the Preferences dialog of the MainControl
\see aboutToExit
\see ServerPreferences
\see Preferences
*/
virtual void finalizePreferencesTab(Preferences &preferences);
/** Apply the preferences of the specific tab.
This method applies the preferences of the own tab ServerPreferences
to this server.
This method is called automatically by the method applyPreferencesTab of
the class MainControl.
See ModularWidget for more information concerning preferences tabs.\par
\param preferences the Preferences dialog of the MainControl
\see applyPreferencesTab
\see ServerPreferences
\see Preferences
*/
virtual void applyPreferences();
//@}
/** @name debuggers and diagnostics
*/
//@{
/** Internal state and consistency self-validation.
Calls {ConnectionObject::isValid}.
\return bool <tt> true</tt> if the internal state of this server is correct
\see ConnectionObject::isValid
*/
virtual bool isValid() const;
/** Dump the current state of this server to
the output ostream with a dumping depth.
\param s output stream where to output the state of this server
\param depth the dumping depth
\see ConnectionObject::dump
*/
virtual void dump(std::ostream& s = std::cout, Size depth = 0) const;
/** This function is used by the server thread to handle locking of composites across several threads.
*
* The protocol is rather complicated: the server thread reacts to a connection, creates a composite,
* calls changeLock(), this emits the signal "lockRequested", which is finally handled in the slot
* handleLocking(). The reason for this involved setup is the separation of server and GUI threads,
* which does not allow to safely lock the composites in the server thread.
*/
virtual void changeLock(bool lock);
//@}
/** @name Signals and Slots
*/
//@{
public slots:
void handleLocking(bool lock);
signals:
void lockRequested(bool lock);
//@}
private:
/** The actual server thread **/
BALLViewServer server_;
/** private storage variables.
*/
ObjectCreator *object_creator_;
// the port to bind to
int port_;
ServerPreferences *server_preferences_;
QLabel *server_icon_;
static const char *mini_ray_xpm_[];
};
# ifndef BALL_NO_INLINE_FUNCTIONS
# include <BALL/VIEW/KERNEL/serverWidget.iC>
# endif
}// namespace VIEW
}// namespace BALL
#endif // BALL_VIEW_KERNEL_SERVER_H
|