Difference between revisions of "XPCOM"

From CDOT Wiki
Jump to: navigation, search
 
m (Examples)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
placeholder (paul stdenis / michael lau)
+
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 =
 +
*[http://developer.mozilla.org/en/docs/XPCOM_API_Reference#Overview API Reference]
 +
*[http://developer.mozilla.org/en/docs/XPCOM MDC - XPCOM]
 +
*[http://www-128.ibm.com/developerworks/webservices/library/co-xpcom.html IBM - An introduction to XPCOM]
 +
*[http://en.wikipedia.org/wiki/XPCOM Wikipedia - XPCOM]
 +
*[http://kb.mozillazine.org/File_IO MozillaZine - File IO Sample]
 +
*[http://lxr.mozilla.org/seamonkey/source/netwerk/base/src/nsFileStreams.h#77 LXR - nsFileInputStream.h]
 +
 
 +
= Examples =
 +
[http://lxr.mozilla.org/seamonkey/source/netwerk/base/src/nsFileStreams.h#77 nsFileInputStream on LXR] Sample code for XPCOM component
 +
<pre>
 +
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 };
 +
</pre>
 +
 
 +
[http://kb.mozillazine.org/File_IO Sample use of XPCOM component]
 +
<pre>
 +
var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"]
 +
                        .createInstance(Components.interfaces.nsIFileInputStream);
 +
</pre>

Latest revision as of 12:21, 4 October 2006

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);