aboutsummaryrefslogtreecommitdiff
path: root/lib/service/iservice.h
blob: bedb0d6f583fe148e881e8ad4dda377f37e76e6c (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#ifndef __lib_dvb_iservice_h
#define __lib_dvb_iservice_h

#include <lib/base/object.h>
#include <lib/base/estring.h>
#include <list>

class eServiceReference
{
public:
	enum
	{
		idInvalid=-1,
		idStructure,	// service_id == 0 is root
		idDVB,
		idFile,
		idUser=0x1000
	};
	int type;

	int flags; // flags will NOT be compared.
	enum
	{
		isDirectory=1,		// SHOULD enter  (implies mustDescent)
		mustDescent=2,		// cannot be played directly - often used with "isDirectory" (implies canDescent)
		/*
			for example:
				normal services have none of them - they can be fed directly into the "play"-handler.
				normal directories have both of them set - you cannot play a directory directly and the UI should descent into it.
				playlists have "mustDescent", but not "isDirectory" - you don't want the user to browse inside the playlist (unless he really wants)
				services with sub-services have none of them, instead the have the "canDecsent" flag (as all of the above)
		*/
		canDescent=4,			// supports enterDirectory/leaveDirectory
		flagDirectory=isDirectory|mustDescent|canDescent,
		shouldSort=8,			// should be ASCII-sorted according to service_name. great for directories.
		hasSortKey=16,		// has a sort key in data[3]. not having a sort key implies 0.
		sort1=32					// sort key is 1 instead of 0
	};

	inline int getSortKey() const { return (flags & hasSortKey) ? data[3] : ((flags & sort1) ? 1 : 0); }

	int data[8];
	eString path;

	eServiceReference()
		: type(idInvalid), flags(0)
	{
	}

	eServiceReference(int type, int flags)
		: type(type), flags(flags)
	{
		memset(data, 0, sizeof(data));
	}
	eServiceReference(int type, int flags, int data0)
		: type(type), flags(flags)
	{
		memset(data, 0, sizeof(data));
		data[0]=data0;
	}
	eServiceReference(int type, int flags, int data0, int data1)
		: type(type), flags(flags)
	{
		memset(data, 0, sizeof(data));
		data[0]=data0;
		data[1]=data1;
	}
	eServiceReference(int type, int flags, int data0, int data1, int data2)
		: type(type), flags(flags)
	{
		memset(data, 0, sizeof(data));
		data[0]=data0;
		data[1]=data1;
		data[2]=data2;
	}
	eServiceReference(int type, int flags, int data0, int data1, int data2, int data3)
		: type(type), flags(flags)
	{
		memset(data, 0, sizeof(data));
		data[0]=data0;
		data[1]=data1;
		data[2]=data2;
		data[3]=data3;
	}
	eServiceReference(int type, int flags, int data0, int data1, int data2, int data3, int data4)
		: type(type), flags(flags)
	{
		memset(data, 0, sizeof(data));
		data[0]=data0;
		data[1]=data1;
		data[2]=data2;
		data[3]=data3;
		data[4]=data4;
	}
	eServiceReference(int type, int flags, const eString &path)
		: type(type), flags(flags), path(path)
	{
		memset(data, 0, sizeof(data));
	}
	eServiceReference(const eString &string);
	eString toString() const;
	bool operator==(const eServiceReference &c) const
	{
		if (type != c.type)
			return 0;
		return /* (flags == c.flags) && */ (memcmp(data, c.data, sizeof(int)*8)==0) && (path == c.path);
	}
	bool operator!=(const eServiceReference &c) const
	{
		return !(*this == c);
	}
	bool operator<(const eServiceReference &c) const
	{
		if (type < c.type)
			return 1;

		if (type > c.type)
			return 0;
			
/*		if (flags < c.flags)
			return 1;
		if (flags > c.flags)
			return 0; */

		int r=memcmp(data, c.data, sizeof(int)*8);
		if (r)
			return r < 0;
		return path < c.path;
	}
	operator bool() const
	{
		return type != idInvalid;
	}
};

class iPauseableService: public virtual iObject
{
public:
	virtual RESULT pause()=0;
	virtual RESULT unpause()=0;
};

class iPlayableService: public virtual iObject
{
	friend class iServiceHandler;
public:
		// it's PRIVATE to the class factory
	virtual RESULT start()=0;
	virtual RESULT getIPausableService(ePtr<iPauseableService> &ptr)=0;
};

class iRecordableService: public virtual iObject
{
public:
	virtual RESULT start()=0;
	virtual RESULT stop()=0;
};

class iListableService: public virtual iObject
{
public:
	virtual RESULT getContent(std::list<eServiceReference> &list)=0;
};

class iServiceHandler: public virtual iObject
{
public:
	virtual RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr)=0;
	virtual RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr)=0;
	virtual RESULT list(const eServiceReference &, ePtr<iListableService> &ptr)=0;
};

#endif