]> git.vomp.tv Git - vompserver.git/blob - libdvbmpeg/ci.hh
Initial import
[vompserver.git] / libdvbmpeg / ci.hh
1 /*
2  * ci.hh: Common Interface
3  *
4  * Copyright (C) 2000 Klaus Schmidinger
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
20  *
21  * The author can be reached at kls@cadsoft.de
22  *
23  * The project's page is at http://www.cadsoft.de/people/kls/vdr
24  *
25  */
26
27 #ifndef __CI_H
28 #define __CI_H
29
30 #include <stdint.h>
31 #include <stdio.h>
32
33 #include <pthread.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <sys/un.h>
38 #include <sys/stat.h>
39 #include <sys/uio.h>
40
41 #define MAXCASYSTEMIDS 16
42
43 class cMutex {
44   friend class cCondVar;
45 private:
46   pthread_mutex_t mutex;
47   pid_t lockingPid;
48   int locked;
49 public:
50   cMutex(void);
51   ~cMutex();
52   void Lock(void);
53   void Unlock(void);
54   };
55
56 class cMutexLock {
57 private:
58   cMutex *mutex;
59   bool locked;
60 public:
61   cMutexLock(cMutex *Mutex = NULL);
62   ~cMutexLock();
63   bool Lock(cMutex *Mutex);
64   };
65
66
67 class cCiMMI;
68
69 class cCiMenu {
70   friend class cCiMMI;
71 private:
72   enum { MAX_CIMENU_ENTRIES = 64 }; ///< XXX is there a specified maximum?
73   cCiMMI *mmi;
74   bool selectable;
75   char *titleText;
76   char *subTitleText;
77   char *bottomText;
78   char *entries[MAX_CIMENU_ENTRIES];
79   int numEntries;
80   bool AddEntry(char *s);
81   cCiMenu(cCiMMI *MMI, bool Selectable);
82 public:
83   ~cCiMenu();
84   const char *TitleText(void) { return titleText; }
85   const char *SubTitleText(void) { return subTitleText; }
86   const char *BottomText(void) { return bottomText; }
87   const char *Entry(int n) { return n < numEntries ? entries[n] : NULL; }
88   int NumEntries(void) { return numEntries; }
89   bool Selectable(void) { return selectable; }
90   bool Select(int Index);
91   bool Cancel(void);
92   };
93
94 class cCiEnquiry {
95   friend class cCiMMI;
96 private:
97   cCiMMI *mmi;
98   char *text;
99   bool blind;
100   int expectedLength;
101   cCiEnquiry(cCiMMI *MMI);
102 public:
103   ~cCiEnquiry();
104   const char *Text(void) { return text; }
105   bool Blind(void) { return blind; }
106   int ExpectedLength(void) { return expectedLength; }
107   bool Reply(const char *s);
108   bool Cancel(void);
109   };
110
111 class cCiCaPmt {
112   friend class cCiConditionalAccessSupport;
113 private:
114   int length;
115   int esInfoLengthPos;
116   uint8_t capmt[2048]; ///< XXX is there a specified maximum?
117 public:
118   cCiCaPmt(int ProgramNumber);
119   void AddPid(int Pid);
120   void AddCaDescriptor(int Length, uint8_t *Data);
121   };
122
123 #define MAX_CI_SESSION  16 //XXX
124
125 class cCiSession;
126 class cCiTransportLayer;
127 class cCiTransportConnection;
128
129 class cCiHandler {
130 private:
131   cMutex mutex;
132   int numSlots;
133   bool newCaSupport;
134   bool hasUserIO;
135   cCiSession *sessions[MAX_CI_SESSION];
136   cCiTransportLayer *tpl;
137   cCiTransportConnection *tc;
138   int ResourceIdToInt(const uint8_t *Data);
139   bool Send(uint8_t Tag, int SessionId, int ResourceId = 0, int Status = -1);
140   cCiSession *GetSessionBySessionId(int SessionId);
141   cCiSession *GetSessionByResourceId(int ResourceId, int Slot);
142   cCiSession *CreateSession(int ResourceId);
143   bool OpenSession(int Length, const uint8_t *Data);
144   bool CloseSession(int SessionId);
145   int CloseAllSessions(int Slot);
146   cCiHandler(int Fd, int NumSlots);
147 public:
148   ~cCiHandler();
149   static cCiHandler *CreateCiHandler(const char *FileName);
150   int NumSlots(void) { return numSlots; }
151   bool Process(void);
152   bool HasUserIO(void) { return hasUserIO; }
153   bool EnterMenu(int Slot);
154   cCiMenu *GetMenu(void);
155   cCiEnquiry *GetEnquiry(void);
156   bool SetCaPmt(cCiCaPmt &CaPmt);
157   const unsigned short *GetCaSystemIds(int Slot);
158   bool SetCaPmt(cCiCaPmt &CaPmt, int Slot);
159   bool Reset(int Slot);
160   };
161
162 int tcp_listen(struct sockaddr_in *name,int sckt,unsigned long address=INADDR_ANY);
163 int accept_tcp(int ip_sock,struct sockaddr_in *ip_name);
164 int udp_listen(struct sockaddr_un *name,char const * const filename);
165 int accept_udp(int ip_sock,struct sockaddr_un *ip_name);
166
167 #endif //__CI_H