code cleanup/optimization
[enigma2.git] / lib / service / iservice.h
index 01c61fcc77947d364e8310f64feafa119781fed4..b7b34fe211a3df553b6eadf59815990f12fa1bac 100644 (file)
@@ -1,19 +1,12 @@
 #ifndef __lib_dvb_iservice_h
 #define __lib_dvb_iservice_h
 
+#include <lib/python/swig.h>
 #include <lib/base/object.h>
 #include <string>
 #include <connection.h>
 #include <list>
 
-#ifdef SWIG
-#define TEMPLATE_TYPEDEF(x, y) \
-%template(y) x; \
-typedef x y
-#else
-#define TEMPLATE_TYPEDEF(x, y) typedef x y
-#endif
-
 class eServiceReference
 {
 public:
@@ -51,6 +44,10 @@ public:
        int data[8];
        std::string path;
 
+// only for override service names in bouquets or to give servicerefs a name which not have a
+// real existing service ( for dvb eServiceDVB )
+       std::string name;
+
        eServiceReference()
                : type(idInvalid), flags(0)
        {
@@ -112,7 +109,7 @@ public:
        {
                if (type != c.type)
                        return 0;
-               return /* (flags == c.flags) && */ (memcmp(data, c.data, sizeof(int)*8)==0) && (path == c.path);
+               return (memcmp(data, c.data, sizeof(int)*8)==0) && (path == c.path);
        }
        bool operator!=(const eServiceReference &c) const
        {
@@ -125,11 +122,6 @@ public:
 
                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)
@@ -137,23 +129,64 @@ public:
                return path < c.path;
        }
        operator bool() const
+       {
+               return valid();
+       }
+       
+       int valid() const
        {
                return type != idInvalid;
        }
 };
 
+SWIG_ALLOW_OUTPUT_SIMPLE(eServiceReference);
+
+typedef long long pts_t;
+
        /* the reason we have the servicereference as additional argument is
           that we don't have to create one object for every entry in a possibly
           large list, provided that no state information is nessesary to deliver
           the required information. Anyway - ref *must* be the same as the argument
           to the info() or getIServiceInformation call! */
+
+       /* About the usage of SWIG_VOID:
+          SWIG_VOID(real_returntype_t) hides a return value from swig. This is used for
+          the "superflouus" RESULT return values.
+          
+          Python code has to check the returned pointer against 0. This works,
+          as all functions returning instances in smartpointers AND having a 
+          RESULT have to BOTH return non-zero AND set the pointer to zero.
+          
+          Python code thus can't check for the reason, but the reason isn't
+          user-servicable anyway. If you want to return a real reason which
+          goes beyong "it just doesn't work", use extra variables for this,
+          not the RESULT.
+          
+          Hide the result only if there is another way to check for failure! */
+          
+class iStaticServiceInformation: public iObject
+{
+public:
+       virtual SWIG_VOID(RESULT) getName(const eServiceReference &ref, std::string &SWIG_OUTPUT)=0;
+       
+               // doesn't need to be implemented, should return -1 then.
+       virtual int getLength(const eServiceReference &ref)=0;
+};
+
+TEMPLATE_TYPEDEF(ePtr<iStaticServiceInformation>, iStaticServiceInformationPtr);
+
+class eServiceEvent;
+
+TEMPLATE_TYPEDEF(ePtr<eServiceEvent>, eServiceEventPtr);
+
 class iServiceInformation: public iObject
 {
 public:
-       virtual RESULT getName(const eServiceReference &ref, std::string &name)=0;
+       virtual SWIG_VOID(RESULT) getName(std::string &SWIG_OUTPUT)=0;
+       virtual SWIG_VOID(RESULT) getEvent(ePtr<eServiceEvent> &SWIG_OUTPUT, int nownext);
 };
 
-typedef ePtr<iServiceInformation> iServiceInformationPtr;
+TEMPLATE_TYPEDEF(ePtr<iServiceInformation>, iServiceInformationPtr);
 
 class iPauseableService: public iObject
 {
@@ -162,7 +195,37 @@ public:
        virtual RESULT unpause()=0;
 };
 
-typedef ePtr<iPauseableService> iPauseableServicePtr;
+TEMPLATE_TYPEDEF(ePtr<iPauseableService>, iPauseableServicePtr);
+
+class iSeekableService: public iObject
+{
+public:
+       virtual RESULT getLength(pts_t &SWIG_OUTPUT)=0;
+       virtual RESULT seekTo(pts_t to)=0;
+       enum { dirForward = +1, dirBackward = -1 };
+       virtual RESULT seekRelative(int direction, pts_t to)=0;
+       virtual RESULT getPlayPosition(pts_t &SWIG_OUTPUT)=0;
+};
+
+TEMPLATE_TYPEDEF(ePtr<iSeekableService>, iSeekableServicePtr);
+
+struct iAudioTrackInfo
+{
+       std::string m_description;
+       std::string getDescription() { return m_description; }
+};
+
+SWIG_ALLOW_OUTPUT_SIMPLE(iAudioTrackInfo);
+
+class iAudioTrackSelection: public iObject
+{
+public:
+       virtual int getNumberOfTracks()=0;
+       virtual RESULT selectTrack(unsigned int i)=0;
+       virtual SWIG_VOID(RESULT) getTrackInfo(struct iAudioTrackInfo &SWIG_OUTPUT, unsigned int n)=0;
+};
+
+TEMPLATE_TYPEDEF(ePtr<iAudioTrackSelection>, iAudioTrackSelectionPtr);
 
 class iPlayableService: public iObject
 {
@@ -171,13 +234,19 @@ public:
        enum
        {
                evStart,
-               evEnd
+               evEnd,
+               
+               evTuneFailed,
+               // when iServiceInformation is implemented:
+               evUpdatedEventInfo
        };
        virtual RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)=0;
        virtual RESULT start()=0;
        virtual RESULT stop()=0;
-       virtual RESULT getIPausableService(ePtr<iPauseableService> &ptr)=0;
-       virtual RESULT getIServiceInformation(ePtr<iServiceInformation> &ptr)=0;
+       virtual SWIG_VOID(RESULT) seek(ePtr<iSeekableService> &SWIG_OUTPUT)=0;
+       virtual SWIG_VOID(RESULT) pause(ePtr<iPauseableService> &SWIG_OUTPUT)=0;
+       virtual SWIG_VOID(RESULT) info(ePtr<iServiceInformation> &SWIG_OUTPUT)=0;
+       virtual SWIG_VOID(RESULT) audioTracks(ePtr<iAudioTrackSelection> &SWIG_OUTPUT)=0;
 };
 
 TEMPLATE_TYPEDEF(ePtr<iPlayableService>, iPlayableServicePtr);
@@ -185,32 +254,88 @@ TEMPLATE_TYPEDEF(ePtr<iPlayableService>, iPlayableServicePtr);
 class iRecordableService: public iObject
 {
 public:
+       virtual RESULT prepare(const char *filename)=0;
        virtual RESULT start()=0;
        virtual RESULT stop()=0;
 };
 
-typedef ePtr<iRecordableService> iRecordableServicePtr;
+TEMPLATE_TYPEDEF(ePtr<iRecordableService>, iRecordableServicePtr);
 
 // TEMPLATE_TYPEDEF(std::list<eServiceReference>, eServiceReferenceList);
-typedef std::list<eServiceReference> eServiceReferenceList;
+
+class iMutableServiceList: public iObject
+{
+public:
+               /* flush changes */
+       virtual RESULT flushChanges()=0;
+               /* adds a service to a list */
+       virtual RESULT addService(eServiceReference &ref)=0;
+               /* removes a service from a list */
+       virtual RESULT removeService(eServiceReference &ref)=0;
+               /* moves a service in a list, only if list suppports a specific sort method. */
+               /* pos is the new, absolute position from 0..size-1 */
+       virtual RESULT moveService(eServiceReference &ref, int pos)=0;
+};
+
+TEMPLATE_TYPEDEF(ePtr<iMutableServiceList>, iMutableServiceListPtr);
 
 class iListableService: public iObject
 {
 public:
+               /* legacy interface: get a list */
        virtual RESULT getContent(std::list<eServiceReference> &list)=0;
+       
+               /* new, shiny interface: streaming. */
+       virtual SWIG_VOID(RESULT) getNext(eServiceReference &SWIG_OUTPUT)=0;
+       
+               /* use this for sorting. output is not sorted because of either
+                - performance reasons: the whole list must be buffered or
+                - the interface would be restricted to a list. streaming
+                  (as well as a future "active" extension) won't be possible.
+               */
+       virtual int compareLessEqual(const eServiceReference &, const eServiceReference &)=0;
+       
+       virtual SWIG_VOID(RESULT) startEdit(ePtr<iMutableServiceList> &SWIG_OUTPUT)=0;
 };
 
 TEMPLATE_TYPEDEF(ePtr<iListableService>, iListableServicePtr);
 
+       /* a helper class which can be used as argument to stl's sort(). */
+class iListableServiceCompare
+{
+       ePtr<iListableService> m_list;
+public:
+       iListableServiceCompare(iListableService *list): m_list(list) { }
+       bool operator()(const eServiceReference &a, const eServiceReference &b)
+       {
+               return m_list->compareLessEqual(a, b);
+       }
+};
+
+class iServiceOfflineOperations: public iObject
+{
+public:
+               /* to delete a service, forever. */
+       virtual RESULT deleteFromDisk(int simulate=1)=0;
+       
+               /* for transferring a service... */
+       virtual SWIG_VOID(RESULT) getListOfFilenames(std::list<std::string> &SWIG_OUTPUT)=0;
+       
+               // TODO: additional stuff, like a conversion interface?
+};
+
+TEMPLATE_TYPEDEF(ePtr<iServiceOfflineOperations>, iServiceOfflineOperationsPtr);
+
 class iServiceHandler: public 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;
-       virtual RESULT info(const eServiceReference &, ePtr<iServiceInformation> &ptr);
+       virtual SWIG_VOID(RESULT) play(const eServiceReference &, ePtr<iPlayableService> &SWIG_OUTPUT)=0;
+       virtual SWIG_VOID(RESULT) record(const eServiceReference &, ePtr<iRecordableService> &SWIG_OUTPUT)=0;
+       virtual SWIG_VOID(RESULT) list(const eServiceReference &, ePtr<iListableService> &SWIG_OUTPUT)=0;
+       virtual SWIG_VOID(RESULT) info(const eServiceReference &, ePtr<iStaticServiceInformation> &SWIG_OUTPUT)=0;
+       virtual SWIG_VOID(RESULT) offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &SWIG_OUTPUT)=0;
 };
 
-typedef ePtr<iServiceHandler> iServiceHandlerPtr;
+TEMPLATE_TYPEDEF(ePtr<iServiceHandler>, iServiceHandlerPtr);
 
 #endif