source: trunk/FACT++/src/Dim.h@ 14990

Last change on this file since 14990 was 13896, checked in by tbretz, 13 years ago
Added no-block version of SendCommand.
File size: 2.7 KB
Line 
1#ifndef FACT_Dim
2#define FACT_Dim
3
4#include "DimSetup.h"
5
6#include <string>
7
8#include "dic.hxx"
9
10namespace Dim
11{
12 // --------------------------------------------------------------------------
13 //
14 //! Simplification wrapper to send a command without data
15 //!
16 //! Example:
17 //! - Dim::SendCommand("SERVER/COMMAND");
18 //!
19 //! @param command
20 //! Dim command identifier
21 //!
22 //! @returns
23 //! the return value of DimClient::sendCommand
24 //!
25 inline bool SendCommand(const std::string &command)
26 {
27 return DimClient::sendCommand(command.c_str(), NULL, 0);
28 }
29 inline void SendCommandNB(const std::string &command)
30 {
31 DimClient::sendCommandNB(command.c_str(), NULL, 0);
32 }
33
34 // --------------------------------------------------------------------------
35 //
36 //! Simplification wrapper to send a command with the given data
37 //!
38 //! Example:
39 //! - Dim::SendCommand("SERVER/COMMAND", uint16_t(42));
40 //! - struct tm t; Dim::SendCommand("SERVER/TIME", t);
41 //!
42 //! @param command
43 //! Dim command identifier
44 //!
45 //! @param t
46 //! object to be sent, the pointer to the data to be sent is
47 //! set to &t
48 //!
49 //! @tparam T
50 //! type of the data to be sent. The size of the data to be sent
51 //! is determined as sizeof(T)
52 //!
53 //! @returns
54 //! the return value of DimClient::sendCommand
55 //!
56 template<typename T>
57 inline bool SendCommand(const std::string &command, const T &t)
58 {
59 return DimClient::sendCommand(command.c_str(), const_cast<T*>(&t), sizeof(t));
60 }
61
62 template<>
63 inline bool SendCommand(const std::string &command, const std::string &t)
64 {
65 return DimClient::sendCommand(command.c_str(), const_cast<char*>(t.c_str()), t.length()+1);
66 }
67
68 inline bool SendCommand(const std::string &command, const void *d, size_t s)
69 {
70 return DimClient::sendCommand(command.c_str(), const_cast<void*>(d), s);
71 }
72
73 // -------------------------------------------------------------------------
74
75 template<typename T>
76 inline void SendCommandNB(const std::string &command, const T &t)
77 {
78 DimClient::sendCommandNB(command.c_str(), const_cast<T*>(&t), sizeof(t));
79 }
80
81 template<>
82 inline void SendCommandNB(const std::string &command, const std::string &t)
83 {
84 DimClient::sendCommandNB(command.c_str(), const_cast<char*>(t.c_str()), t.length()+1);
85 }
86
87 inline void SendCommandNB(const std::string &command, const void *d, size_t s)
88 {
89 DimClient::sendCommandNB(command.c_str(), const_cast<void*>(d), s);
90 }
91}
92
93#endif
Note: See TracBrowser for help on using the repository browser.