Back to index

lightning-sunbird  0.9+nobinonly
Converters.h
Go to the documentation of this file.
00001 #include "nsIStreamConverter.h"
00002 #include "nsString.h"
00003 #include "nsIFactory.h"
00004 #include "nsCOMPtr.h"
00005 
00006 /* This file defines stream converter components, and their accompanying factory class.
00007  * These converters implement the nsIStreamConverter interface and support both
00008  * asynchronous and synchronous stream conversion.
00009  */
00010 
00012 // TestConverter
00013 #define NS_TESTCONVERTER_CID                         \
00014 { /* B8A067B0-4450-11d3-A16E-0050041CAF44 */         \
00015     0xb8a067b0,                                      \
00016     0x4450,                                          \
00017     0x11d3,                                          \
00018     {0xa1, 0x6e, 0x00, 0x50, 0x04, 0x1c, 0xaf, 0x44} \
00019 }
00020 static NS_DEFINE_CID(kTestConverterCID,          NS_TESTCONVERTER_CID);
00021 
00022 class TestConverter : public nsIStreamConverter {
00023 public:
00024     NS_DECL_ISUPPORTS
00025     NS_DECL_NSIREQUESTOBSERVER
00026     NS_DECL_NSISTREAMLISTENER
00027 
00028     TestConverter();
00029     virtual ~TestConverter() {}
00030 
00031     // nsIStreamConverter methods
00032     NS_IMETHOD Convert(nsIInputStream *aFromStream, const char *aFromType, 
00033                        const char *aToType, nsISupports *ctxt, nsIInputStream **_retval);
00034 
00035 
00036     NS_IMETHOD AsyncConvertData(const char *aFromType, const char *aToType, 
00037                                 nsIStreamListener *aListener, nsISupports *ctxt);
00038 
00039     // member data
00040     nsCOMPtr<nsIStreamListener> mListener;
00041     nsCString fromType;
00042     nsCString toType;
00043 };
00044 
00046 // FACTORY
00047 class TestConverterFactory : public nsIFactory
00048 {
00049 public:
00050     TestConverterFactory(const nsCID &aClass, const char* className, const char* contractID);
00051 
00052     // nsISupports methods
00053     NS_DECL_ISUPPORTS
00054 
00055     // nsIFactory methods
00056     NS_IMETHOD CreateInstance(nsISupports *aOuter,
00057                               const nsIID &aIID,
00058                               void **aResult);
00059 
00060     NS_IMETHOD LockFactory(PRBool aLock);
00061 
00062 protected:
00063     virtual ~TestConverterFactory();
00064 
00065 protected:
00066     nsCID       mClassID;
00067     const char* mClassName;
00068     const char* mContractID;
00069 };