Open main menu

CDOT Wiki β

XPCOM

Paul St-Denis & Michael Lau

Short Description

XPCOM stands for Cross Platform Component Object Model. XPCOM is a framework for developing cross platform software.

Detailed Discussion

XPCOM is a framework for developing cross platform software that can be written in C, C++, JavaScript with extensions for Perl and Python. It supports any platform with a C++ compiler.


You can access the XPCOM component through the web or any Mozilla application (similar to the idea of accessing web services).


Some of the tools needed for development are:

  • a C++ compiler
  • a Perl interpreter
  • some GNU tools


XPCOM provides the following features for cross platform development:

  • Component management
  • File abstraction
  • Object message passing
  • Memory management


Application that want to access Mozilla XPCOM libraries can use an XPCOM layer called XPConnect.

External Links

Examples

nsFileInputStream on LXR Sample code for XPCOM component

 77 class nsFileInputStream : public nsFileStream,
 78                           public nsIFileInputStream,
 79                           public nsILineInputStream
 80 {
 81 public:
 82     NS_DECL_ISUPPORTS_INHERITED
 83     NS_DECL_NSIINPUTSTREAM
 84     NS_DECL_NSIFILEINPUTSTREAM
 85     NS_DECL_NSILINEINPUTSTREAM
 86     
 87     // Overrided from nsFileStream
 88     NS_IMETHOD Seek(PRInt32 aWhence, PRInt64 aOffset);
 89 
 90     nsFileInputStream() : nsFileStream() 
 91     {
 92         mLineBuffer = nsnull;
 93         mBehaviorFlags = 0;
 94     }
 95     virtual ~nsFileInputStream() 
 96     {
 97         Close();
 98     }
...
135     nsresult Reopen() { return Open(mFile, mIOFlags, mPerm); }
136 };

Sample use of XPCOM component

var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"]
                        .createInstance(Components.interfaces.nsIFileInputStream);