Overte C++ Documentation
Assignment.h
1 //
2 // Assignment.h
3 // libraries/networking/src
4 //
5 // Created by Stephen Birarda on 8/22/13.
6 // Copyright 2013 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_Assignment_h
13 #define hifi_Assignment_h
14 
15 #include <QtCore/QUuid>
16 
17 
18 #include "ReceivedMessage.h"
19 
20 #include "NodeList.h"
21 
22 
23 const int MAX_PAYLOAD_BYTES = 1024;
24 
25 const QString emptyPool = QString();
26 
28 class Assignment : public QObject {
29  Q_OBJECT
30 public:
31 
32  enum Type : uint8_t {
33  FirstType = 0,
34  AudioMixerType = 0,
35  AvatarMixerType = 1,
36  AgentType = 2,
37  AssetServerType = 3,
38  MessagesMixerType = 4,
39  EntityScriptServerType = 5,
40  EntityServerType = 6,
41  AllTypes = 7
42  };
43 
44  enum Command {
45  CreateCommand,
46  DeployCommand,
47  RequestCommand
48  };
49 
50  enum Location {
51  GlobalLocation,
52  LocalLocation
53  };
54 
55  static Assignment::Type typeForNodeType(NodeType_t nodeType);
56 
57  Assignment();
58  Assignment(Assignment::Command command,
59  Assignment::Type type,
60  const QString& pool = emptyPool,
61  Assignment::Location location = Assignment::LocalLocation,
62  QString dataDirectory = QString());
63  Assignment(const Assignment& otherAssignment);
64  Assignment& operator=(const Assignment &rhsAssignment);
65 
66  void swap(Assignment& otherAssignment);
67 
70  Assignment(ReceivedMessage& packet);
71 
72  void setUUID(const QUuid& uuid) { _uuid = uuid; }
73  const QUuid& getUUID() const { return _uuid; }
74  void resetUUID() { _uuid = QUuid::createUuid(); }
75 
76  Assignment::Command getCommand() const { return _command; }
77  Assignment::Type getType() const { return _type; }
78  Assignment::Location getLocation() const { return _location; }
79 
80  const QByteArray& getPayload() const { return _payload; }
81  void setPayload(const QByteArray& payload) { _payload = payload.left(MAX_PAYLOAD_BYTES); }
82 
83  void setPool(const QString& pool) { _pool = pool; };
84  const QString& getPool() const { return _pool; }
85 
86  void setIsStatic(bool isStatic) { _isStatic = isStatic; }
87  bool isStatic() const { return _isStatic; }
88 
89  const QString& getNodeVersion() const { return _nodeVersion; }
90 
91  const char* getTypeName() const;
92  static const char* typeToString(Assignment::Type type);
93 
94  friend QDebug operator<<(QDebug debug, const Assignment& assignment);
95  friend QDataStream& operator<<(QDataStream &out, const Assignment& assignment);
96  friend QDataStream& operator>>(QDataStream &in, Assignment& assignment);
97 
98 protected:
106  void commonParseSettingsObject(const QJsonObject &settingsObject);
107 
108 
109  QUuid _uuid;
110  Assignment::Command _command;
111  Assignment::Type _type;
112  QString _pool;
113  Assignment::Location _location;
114  QByteArray _payload;
115  bool _isStatic;
116  QString _nodeVersion;
117  QString _dataDirectory;
118 };
119 
120 uint qHash(const Assignment::Type& key, uint seed);
121 
122 #endif // hifi_Assignment_h
quint8 NodeType_t
An 8-bit value identifying the type of a node - domain server, audio mixer, etc.
Definition: NodeType.h:22
Holds information used for request, creation, and deployment of assignments.
Definition: Assignment.h:28
QString _pool
the type of the assignment, defines what the assignee will do
Definition: Assignment.h:112
void commonParseSettingsObject(const QJsonObject &settingsObject)
Parse the part of the settings object common to all assignment clients.
Definition: Assignment.cpp:158
Assignment::Location _location
the destination pool for this assignment
Definition: Assignment.h:113
QByteArray _payload
the location of the assignment, allows a domain to preferentially use local ACs
Definition: Assignment.h:114
QString _nodeVersion
defines if this assignment needs to be re-queued in the domain-server if it stops being fulfilled
Definition: Assignment.h:116
Assignment::Command _command
the 16 byte UUID for this assignment
Definition: Assignment.h:110
bool _isStatic
an optional payload attached to this assignment, a maximum for 1024 bytes will be packed
Definition: Assignment.h:115
Assignment::Type _type
the command for this assignment (Create, Deploy, Request)
Definition: Assignment.h:111