Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_data_service / ai_service.h
blob4b7c021c99e14f1b58b4ecae71f32657db1bfaf5
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef RYAI_AI_SERVICE_H
20 #define RYAI_AI_SERVICE_H
22 #define RYAI_AI_SERVICE_MAX_SERVICES 256
25 #include "nel/misc/types_nl.h"
26 #include "nel/net/message.h"
27 #include "nel/net/unified_network.h"
29 #include <list>
33 ---------------------------------------------------------------------------
35 This class defines both the singleton that manages the ai services and the
36 class type of the ai services themselves. The singleton interface can be found
37 at the end of the class
39 ---------------------------------------------------------------------------
42 class CAIService
45 //===================================================================
46 // *** START OF THE INSTANTIATED CLASS ***
47 //===================================================================
50 public:
51 //---------------------------------------------------
52 // INSTANTIATED CLASS: Public methods
54 // a few read accessors
55 NLNET::TServiceId id() const;
56 bool isUp() const;
58 uint powerCPU() const;
59 uint powerRAM() const;
61 // assign a given manager to this service (ie open and run it)
62 void assignMgr(sint mgrId);
64 // unassign a manager currently running on this service (ie close it)
65 void unassignMgr(sint mgrId);
67 // reassign a manager currently assigned to this service to another service
68 void reassignMgr(sint mgrId, NLNET::TServiceId serviceId);
71 private:
72 //---------------------------------------------------
73 // INSTANTIATED CLASS: Private methods
75 CAIService(); // may only be instantiated by the singleton
78 private:
79 //---------------------------------------------------
80 // INSTANTIATED CLASS: Private data
82 bool _isUp; // flag says the service is up
84 uint _powerCPU; // maximum CPU weight allowed on service
85 uint _powerRAM; // maximum RAM weight allowed on service
87 uint _unusedPowerCPU; // remaining CPU capacity (after counting weight of running managers)
88 uint _unusedPowerRAM; // remaining RAM capacity (after counting weight of running managers)
90 uint _dataSentCount; // number of data packets sent to service
91 uint _dataAckCount; // number of data acknowledges received from service
93 // vector of buffers of data that are waiting to be sent to the service
94 std::list<NLNET::CMessage> _dataToSend;
96 //===================================================================
97 // *** END OF THE INSTANTIATED CLASS *** START OF THE SINGLETON ***
98 //===================================================================
101 public:
102 //---------------------------------------------------
103 // SINGLETON: Public methods
105 // get the number of valid handles (ie the maximum number of managers allowed)
106 static uint maxServices() { return RYAI_AI_SERVICE_MAX_SERVICES; }
108 // get the number of allocated managers
109 static uint numServices();
111 // get a pointer to the manager with given handle (0..maxManagers-1)
112 static CAIService *getServiceById(NLNET::TServiceId id);
114 // get a pointer to the manager with given index (0..numManagers-1)
115 static CAIService *getServiceByIdx(uint idx);
117 // select a service to assign the manager to and assign it
118 // if no services are available then the manager is queued until one
119 // becomes available
120 // managers opened via this interface are queued back up and re-launched
121 // if their service goes down
122 static void openMgr(sint mgrId);
124 // close a manager (on whichever service its running)
125 static void closeMgr(sint mgrId);
127 // update routine called by service_main update every net loop
128 static void update();
130 private:
131 //---------------------------------------------------
132 // SINGLETON: Private methods
135 private:
136 //---------------------------------------------------
137 // SINGLETON: Private data
138 static class CAIService _services[RYAI_AI_SERVICE_MAX_SERVICES];
141 //===================================================================
142 // *** END OF THE SINGLETON ***
143 //===================================================================
148 #endif