-
Notifications
You must be signed in to change notification settings - Fork 16
/
renderer-state.h
88 lines (70 loc) · 2.98 KB
/
renderer-state.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
// This file is part of UPnP LCD Display
//
// Copyright (C) 2013 Henner Zeller <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef RENDERER_STATE_H
#define RENDERER_STATE_H
#include <map>
#include <string>
#include <vector>
#include <pthread.h>
#include <ixml.h>
#include <time.h>
#include <upnp.h>
// Representing the state for a particular renderer.
class RendererState {
public:
typedef std::map<std::string, RendererState *> SubscriptionMap;
RendererState(const char *uuid, FILE *logstream);
~RendererState();
// -- method calls interesting for users.
// Returns the human readable name of the renderer (e.g. "Living Room")
const std::string friendly_name() const { return friendly_name_; }
// Get variable with given name. Text is encoded in UTF-8.
// Thread safe.
std::string GetVar(const std::string &name) const;
time_t last_event_update() const;
// -- method calls used for internal upnp subscription management.
// Initialize from descriptor url that points to an XML file describing
// the renderer web-service.
bool InitDescription(const char *descriptior_url);
// Register interest in variables.
// TODO: this needs to be handled by a subscription manager or something.
// It breaks the encapsulation that this stores itself in the subscription_map.
bool SubscribeTo(UpnpClient_Handle upnp_controller,
SubscriptionMap *subscription_map);
// Callback from controller when changed variables arrive.
void ReceiveEvent(const UpnpEvent *data);
private:
bool Subscribe(UpnpClient_Handle upnp_controller,
const char *service_type,
const char *event_url);
// Decode DIDL data and insert as Meta_Title, Meta_Artist, Meta_Composer.
// requires variable_mutex_ to be locked.
void DecodeMetaAndInsertData_Locked(const char *xml);
const std::string uuid_;
FILE* const logstream_;
std::string friendly_name_;
std::string base_url_;
IXML_Document *descriptor_; // owned. Initialized in InitDescription()
SubscriptionMap *subscriptions_; // not owned. Initialized in SubscribeTo()
std::vector<std::string> subscription_ids_;
mutable pthread_mutex_t variable_mutex_;
typedef std::map<std::string, std::string> VariableMap;
time_t last_event_update_;
VariableMap variables_;
};
#endif // RENDERER_STATE_H