Line |
Branch |
Exec |
Source |
1 |
|
|
/***************************************************************************** |
2 |
|
|
* |
3 |
|
|
* $Id$ |
4 |
|
|
* |
5 |
|
|
* Copyright 2010 Richard Hacker (lerichi at gmx dot net) |
6 |
|
|
* |
7 |
|
|
* This file is part of the pdserv library. |
8 |
|
|
* |
9 |
|
|
* The pdserv library is free software: you can redistribute it and/or modify |
10 |
|
|
* it under the terms of the GNU Lesser General Public License as published |
11 |
|
|
* by the Free Software Foundation, either version 3 of the License, or (at |
12 |
|
|
* your option) any later version. |
13 |
|
|
* |
14 |
|
|
* The pdserv library is distributed in the hope that it will be useful, but |
15 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
16 |
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
17 |
|
|
* License for more details. |
18 |
|
|
* |
19 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
20 |
|
|
* along with the pdserv library. If not, see <http://www.gnu.org/licenses/>. |
21 |
|
|
* |
22 |
|
|
*****************************************************************************/ |
23 |
|
|
|
24 |
|
|
#ifndef MSRSERVER_H |
25 |
|
|
#define MSRSERVER_H |
26 |
|
|
|
27 |
|
|
#include <set> |
28 |
|
|
#include <list> |
29 |
|
|
#include <commoncpp/thread.h> |
30 |
|
|
#include <log4cplus/logger.h> |
31 |
|
|
|
32 |
|
|
#include "../SessionStatistics.h" |
33 |
|
|
#include "../Config.h" |
34 |
|
|
#include "Parameter.h" |
35 |
|
|
#include "Channel.h" |
36 |
|
|
|
37 |
|
|
namespace PdServ { |
38 |
|
|
class Main; |
39 |
|
|
class Task; |
40 |
|
|
class Parameter; |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
namespace MsrProto { |
44 |
|
|
|
45 |
|
|
class Session; |
46 |
|
|
class Event; |
47 |
|
|
|
48 |
|
|
class Server: public DirectoryNode, public ost::Thread { |
49 |
|
|
public: |
50 |
|
|
Server(const PdServ::Main *main, const PdServ::Config &config); |
51 |
|
|
~Server(); |
52 |
|
|
|
53 |
|
|
void broadcast(Session *s, const struct timespec& ts, |
54 |
|
|
const std::string& action, const std::string& text); |
55 |
|
|
|
56 |
|
|
void setAic(const Parameter*); |
57 |
|
|
void parameterChanged(const PdServ::Parameter*, |
58 |
|
|
size_t startIndex, size_t n); |
59 |
|
|
|
60 |
|
|
void sessionClosed(Session *s); |
61 |
|
|
|
62 |
|
|
void getSessionStatistics( |
63 |
|
|
std::list<PdServ::SessionStatistics>& stats) const; |
64 |
|
|
|
65 |
|
|
const PdServ::Main * const main; |
66 |
|
|
const log4cplus::Logger log; |
67 |
|
|
|
68 |
|
|
typedef std::vector<const Channel*> Channels; |
69 |
|
|
typedef std::vector<const Parameter*> Parameters; |
70 |
|
|
typedef std::vector<const Event*> Events; |
71 |
|
|
|
72 |
|
|
const Channels& getChannels() const; |
73 |
|
|
const Channel * getChannel(size_t) const; |
74 |
|
|
|
75 |
|
|
const Parameters& getParameters() const; |
76 |
|
|
const Parameter * getParameter(size_t) const; |
77 |
|
|
const Parameter * find(const PdServ::Parameter *p) const; |
78 |
|
|
|
79 |
|
|
const Events& getEvents() const; |
80 |
|
|
|
81 |
|
|
template <typename T> |
82 |
|
|
const T * find(const std::string& path) const; |
83 |
|
|
|
84 |
|
|
private: |
85 |
|
|
std::set<Session*> sessions; |
86 |
|
|
int port; |
87 |
|
|
bool itemize; // Split multidimensional variables to scalars |
88 |
|
|
|
89 |
|
|
Events events; |
90 |
|
|
|
91 |
|
|
Channels channels; |
92 |
|
|
Parameters parameters; |
93 |
|
|
typedef std::map<const PdServ::Parameter *, const Parameter *> |
94 |
|
|
ParameterMap; |
95 |
|
|
ParameterMap parameterMap; |
96 |
|
|
|
97 |
|
|
mutable ost::Semaphore mutex; |
98 |
|
|
|
99 |
|
|
// Reimplemented from ost::Thread |
100 |
|
|
void initial(); |
101 |
|
|
void run(); |
102 |
|
|
void final(); |
103 |
|
|
|
104 |
|
|
void createChannels(DirectoryNode* baseDir, size_t taskNum); |
105 |
|
|
void createParameters(DirectoryNode* baseDir); |
106 |
|
|
void createEvents(); |
107 |
|
|
|
108 |
|
|
void createChildren(Variable* var); |
109 |
|
|
DirectoryNode* createChild(Variable* var, |
110 |
|
|
DirectoryNode *dir, const std::string& name, |
111 |
|
|
const PdServ::DataType& dtype, |
112 |
|
|
size_t nelem, size_t offset); |
113 |
|
|
size_t createChildren(Variable* var, DirectoryNode* dir, |
114 |
|
|
const PdServ::DataType& dtype, |
115 |
|
|
const PdServ::DataType::DimType& dim, size_t dimIdx, |
116 |
|
|
size_t offset); |
117 |
|
|
size_t createCompoundChildren(Variable* var, DirectoryNode* dir, |
118 |
|
|
const PdServ::DataType& dtype, |
119 |
|
|
const PdServ::DataType::DimType& dim, size_t dimIdx, |
120 |
|
|
size_t offset); |
121 |
|
|
size_t createVectorChildren(Variable* var, |
122 |
|
|
DirectoryNode* dir, const std::string& name, |
123 |
|
|
const PdServ::DataType& dtype, |
124 |
|
|
const PdServ::DataType::DimType& dim, size_t dimIdx, |
125 |
|
|
size_t offset); |
126 |
|
|
|
127 |
|
|
}; |
128 |
|
|
|
129 |
|
|
///////////////////////////////////////////////////////////////////////////// |
130 |
|
|
template <typename T> |
131 |
|
✗ |
const T *Server::find(const std::string &p) const |
132 |
|
|
{ |
133 |
|
✗ |
if (p.empty() or p[0] != '/') |
134 |
|
✗ |
return 0; |
135 |
|
|
|
136 |
|
✗ |
const DirectoryNode *node = DirectoryNode::find(p, 1); |
137 |
|
✗ |
return node ? dynamic_cast<const T*>(node) : 0; |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
} |
141 |
|
|
#endif //MSRSERVER_H |
142 |
|
|
|