summaryrefslogtreecommitdiff
path: root/include/server.h
blob: 349239c639dcb1d127c87846192aeb4de429723c (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * server.h
 *
 *  Created on: 31.07.2012
 *      Author: savop
 */

#ifndef SERVER_H_
#define SERVER_H_

#include <string>
#include <upnp/upnp.h>
#include "../include/webserver.h"
#include "../include/config.h"
#include "../include/service.h"

using namespace std;

namespace upnp {

class cMediaManager;

class cMediaServer {
public:

  struct Description {
    Description(string, string, string , string, string, string , string, string);
    string friendlyName;
    string manufacturer;
    string manufacturerURL;
    string modelDescription;
    string modelName;
    string modelNumber;
    string modelURL;
    string serialNumber;
  };

  struct ServerIcon {
    ServerIcon(image::cIcon, string);
    image::cIcon  profile;
    string filename;
  };

  typedef map<string, cUPnPService*> serviceMap;
  typedef list<ServerIcon> iconList;

	virtual ~cMediaServer();

	bool Initialize();
	bool Start();
	bool Stop();

	bool IsRunning() const;

  static cMediaServer* GetInstance();

  void SetConfiguration(upnp::cConfig newConfig);
  upnp::cConfig GetConfiguration() const;

  const char* GetServerIPAddress() const;
  uint16_t GetServerPort() const;

  int GetAnnounceMaxAge() const { return mAnnounceMaxAge; }
  size_t GetMaxContentLength() const { return mMaxContentLength; }

  const cWebserver& GetWebserver() const { return *mWebserver; }
  cMediaManager& GetManager() const { return *mMediaManager; }

  const string GetDeviceUUID() const { return string("uuid:") + mCurrentConfiguration.deviceUUID; }

  const Description& GetServerDescription() const { return mServerDescription; }
  const iconList& GetServerIcons() const { return mServerIcons; }
  const serviceMap& GetServices() const { return mServices; }

  static void RegisterService(cUPnPService* service);

private:
  class RuntimeException : public std::exception {
  public:
    virtual const char* what() const throw();
  };

	cMediaServer();

	string GetDeviceDescriptionUrl() const;
	void SetAnnounceMaxAge(int announceMaxAge);
	void SetMaxContentLength(size_t maxContentLength);
	bool CheckDeviceUUID(string deviceUUID) const;

	static int ActionCallback(Upnp_EventType eventtype, void *event, void *cookie);

	Description         mServerDescription;
	iconList            mServerIcons;
	upnp::cConfig       mCurrentConfiguration;
	UpnpDevice_Handle   mDeviceHandle;
	int                 mAnnounceMaxAge;
	size_t              mMaxContentLength;
	bool                mIsRunning;

	cWebserver*         mWebserver;
	cMediaManager*      mMediaManager;

  static serviceMap   mServices;

};

}


#endif /* SERVER_H_ */