| 1 |
/* |
| 2 |
* This program is free software; you can redistribute it and/or modify |
| 3 |
* it under the terms of the GNU General Public License as published by |
| 4 |
* the Free Software Foundation; either version 2 of the License, or |
| 5 |
* (at your option) any later version. |
| 6 |
* |
| 7 |
* This program is distributed in the hope that it will be useful, |
| 8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 |
* GNU Library General Public License for more details. |
| 11 |
* |
| 12 |
* You should have received a copy of the GNU General Public License |
| 13 |
* along with this program; if not, write to the Free Software |
| 14 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 15 |
* |
| 16 |
* Client.h |
| 17 |
* Header file for the olad Client class. |
| 18 |
* Copyright (C) 2005 Simon Newton |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifndef OLAD_PLUGIN_API_CLIENT_H_ |
| 22 |
#define OLAD_PLUGIN_API_CLIENT_H_ |
| 23 |
|
| 24 |
#include <map> |
| 25 |
#include <memory> |
| 26 |
#include "common/rpc/RpcController.h" |
| 27 |
#include "ola/base/Macro.h" |
| 28 |
#include "ola/rdm/UID.h" |
| 29 |
#include "olad/DmxSource.h" |
| 30 |
|
| 31 |
namespace ola { |
| 32 |
namespace proto { |
| 33 |
class OlaClientService_Stub; |
| 34 |
class Ack; |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
namespace ola { |
| 39 |
|
| 40 |
/** |
| 41 |
* @brief Represents a connected OLA client on the OLA server side. |
| 42 |
* |
| 43 |
* This stores the state of the client (i.e. DMX data) and allows us to push |
| 44 |
* DMX updates to the client via the OlaClientService_Stub. |
| 45 |
*/ |
| 46 |
class Client { |
| 47 |
public : |
| 48 |
/** |
| 49 |
* @brief Create a new client. |
| 50 |
* @param client_stub The OlaClientService_Stub to use to communicate with |
| 51 |
* the client. Ownership is transferred to the client. |
| 52 |
* @param uid The default UID to use for this client. The client may set its |
| 53 |
* own UID later. |
| 54 |
*/ |
| 55 |
Client(ola::proto::OlaClientService_Stub *client_stub, |
| 56 |
const ola::rdm::UID &uid); |
| 57 |
|
| 58 |
virtual ~Client(); |
| 59 |
|
| 60 |
/** |
| 61 |
* @brief Push a DMX update to this client. |
| 62 |
* @param universe_id the universe the DMX data belongs to |
| 63 |
* @param priority the priority of the DMX data |
| 64 |
* @param buffer the DMX data. |
| 65 |
* @return true if the update was sent, false otherwise |
| 66 |
*/ |
| 67 |
virtual bool SendDMX(unsigned int universe_id, uint8_t priority, |
| 68 |
const DmxBuffer &buffer); |
| 69 |
|
| 70 |
/** |
| 71 |
* @brief Called when this client sends us new data |
| 72 |
* @param universe the id of the universe for the new data |
| 73 |
* @param source the new DMX data. |
| 74 |
*/ |
| 75 |
void DMXReceived(unsigned int universe, const DmxSource &source); |
| 76 |
|
| 77 |
/** |
| 78 |
* @brief Get the most recent DMX data received from this client. |
| 79 |
* @param universe the id of the universe we're interested in |
| 80 |
*/ |
| 81 |
const DmxSource SourceData(unsigned int universe) const; |
| 82 |
|
| 83 |
/** |
| 84 |
* @brief Return the UID associated with this client. |
| 85 |
* @returns The client's UID. |
| 86 |
* |
| 87 |
* This is normally the UID passed in the constructor, unless the client |
| 88 |
* itself overrides the UID. |
| 89 |
*/ |
| 90 |
ola::rdm::UID GetUID() const; |
| 91 |
|
| 92 |
/** |
| 93 |
* @brief Set the UID for the client. |
| 94 |
* @param uid the new UID to use for this client. |
| 95 |
*/ |
| 96 |
void SetUID(const ola::rdm::UID &uid); |
| 97 |
|
| 98 |
private: |
| 99 |
void SendDMXCallback(ola::rpc::RpcController *controller, |
| 100 |
ola::proto::Ack *ack); |
| 101 |
|
| 102 |
std::auto_ptr<class ola::proto::OlaClientService_Stub> m_client_stub; |
| 103 |
std::map<unsigned int, DmxSource> m_data_map; |
| 104 |
ola::rdm::UID m_uid; |
| 105 |
|
| 106 |
DISALLOW_COPY_AND_ASSIGN(Client); |
| 107 |
}; |
| 108 |
} // namespace ola |
| 109 |
#endif // OLAD_PLUGIN_API_CLIENT_H_ |