NptInterfaces.h

00001 /*****************************************************************
00002 |
00003 |   Neptune - Interfaces
00004 |
00005 |   (c) 2001-2006 Gilles Boccon-Gibod
00006 |   Author: Gilles Boccon-Gibod (bok@bok.net)
00007 |
00008  ****************************************************************/
00009 
00010 #ifndef _NPT_INTERFACES_H_
00011 #define _NPT_INTERFACES_H_
00012 
00013 /*----------------------------------------------------------------------
00014 |   includes
00015 +---------------------------------------------------------------------*/
00016 #include "NptTypes.h"
00017 #include "NptCommon.h"
00018 #include "NptResults.h"
00019 
00020 /*----------------------------------------------------------------------
00021 |   constants
00022 +---------------------------------------------------------------------*/
00023 const int NPT_ERROR_NO_SUCH_INTERFACE = NPT_ERROR_BASE_INTERFACES - 0;
00024 
00025 #if 0 // disabled, use NPT_Reference instead
00026 /*----------------------------------------------------------------------
00027 |   macros
00028 +---------------------------------------------------------------------*/
00029 #define NPT_RELEASE(o) do { if (o) (o)->Release(); (o) = NULL; } while (0)
00030 #define NPT_ADD_REFERENCE(o) do { if (o) (o)->AddReference(); } while (0)
00031 
00032 /*----------------------------------------------------------------------
00033 |   NPT_Referenceable
00034 +---------------------------------------------------------------------*/
00035 class NPT_Referenceable
00036 {
00037  public:
00038     // methods
00039     virtual void AddReference() = 0;
00040     virtual void Release() = 0;
00041 
00042 protected:
00043     // constructors and destructor
00044     NPT_Referenceable() {}
00045     virtual ~NPT_Referenceable() {}
00046 };
00047 #endif
00048 
00049 /*----------------------------------------------------------------------
00050 |   NPT_InterfaceId
00051 +---------------------------------------------------------------------*/
00052 class NPT_InterfaceId
00053 {
00054  public:
00055     // methods
00056     bool operator==(const NPT_InterfaceId& id) const {
00057         return ((id.m_Id == m_Id) && (id.m_Version == m_Version));
00058     }
00059 
00060     // members
00061     unsigned long m_Id;
00062     unsigned long m_Version;
00063 };
00064 
00065 /*----------------------------------------------------------------------
00066 |   NPT_Polymorphic
00067 +---------------------------------------------------------------------*/
00068 class NPT_Polymorphic
00069 {
00070 public:
00071     // destructor
00072     virtual ~NPT_Polymorphic() {}
00073      
00074     // methods
00075     virtual NPT_Result GetInterface(const NPT_InterfaceId& id, 
00076                                     NPT_Interface*&        iface) = 0;
00077 };
00078 
00079 /*----------------------------------------------------------------------
00080 |   NPT_Interruptible
00081 +---------------------------------------------------------------------*/
00082 class NPT_Interruptible
00083 {
00084 public:
00085     // destructor
00086     virtual ~NPT_Interruptible() {}
00087 
00088     // methods
00089     virtual NPT_Result Interrupt() = 0;
00090 };
00091 
00092 /*----------------------------------------------------------------------
00093 |   NPT_Configurable
00094 +---------------------------------------------------------------------*/
00095 class NPT_Configurable
00096 {
00097 public:
00098     // destructor
00099     virtual ~NPT_Configurable() {}
00100      
00101     // methods
00102     virtual NPT_Result SetProperty(const char* /*name*/, 
00103                                    const char* /*value*/) { 
00104         return NPT_ERROR_NO_SUCH_PROPERTY;
00105     }
00106     virtual NPT_Result SetProperty(const char* /*name*/, 
00107                                    NPT_Integer /*value*/) { 
00108         return NPT_ERROR_NO_SUCH_PROPERTY;
00109     }
00110     virtual NPT_Result GetProperty(const char*        /*name*/, 
00111                                    NPT_PropertyValue& /*value*/) {
00112         return NPT_ERROR_NO_SUCH_PROPERTY;
00113     }
00114 };
00115 
00116 #endif // _NPT_INTERFACES_H_