667
edits
Changes
no edit summary
The final line, the constructor, is the name of the constructor automatically generated by '''NS_GENERIC_FACTORY_CONSTRUCTOR'''. It will be the name of your concrete class followed by "Constructor," in our case '''FirstXpcomConstructor'''.
And that's it! for the module/factory code. Now all we need is our implementation of the methods. Here is the final version of '''FirstXpcom.cpp''' (emphasis added to highlight changes): '''#include <stdio.h> // for printf()''' #include "IFirstXpcom.h" #include "nsIGenericFactory.h" #include "nsStringAPI.h" class FirstXpcom : public IFirstXpcom { public: NS_DECL_ISUPPORTS NS_DECL_IFIRSTXPCOM FirstXpcom(); private: ~FirstXpcom(); protected: '''nsString mName;''' }; NS_IMPL_ISUPPORTS1(FirstXpcom, IFirstXpcom) FirstXpcom::FirstXpcom() We{ /* member initializers and constructor code */ 've done it''mName. Assign(L"FirstXpcom Component");''' } FirstXpcom::~FirstXpcom() { /* destructor code */ } /* attribute AString name; */ NS_IMETHODIMP FirstXpcom::GetName(nsAString & aName) { '''aName.Assign(mName);''' '''printf("FirstXpcom::GetName\n");''' '''return NS_OK;''' } NS_IMETHODIMP FirstXpcom::SetName(const nsAString & aName) { '''mName.Assign(aName);''' '''printf("FirstXpcom::SetName\n");''' '''return NS_OK;''' } /* long add (in long a, in long b); */ NS_IMETHODIMP FirstXpcom::Add(PRInt32 a, PRInt32 b, PRInt32 *_retval) { '''printf("FirstXpcom::Add(%d, %d)", a, b);''' '''*_retval = a + b;''' '''return NS_OK;''' } // This will result in a function named FirstXpcomConstructor. '''NS_GENERIC_FACTORY_CONSTRUCTOR(FirstXpcom)''' '''// 19f3ef5e-759f-49a4-88e3-ed27f9c83011 ''' '''#define FIRSTXPCOM_CID \''' '''{0x19f3ef5e, 0x759f, 0x49a4, \''' '''{ 0x88, 0xe3, 0xed, 0x27, 0xf9, 0xc8, 0x30, 0x11} }''' '''static const nsModuleComponentInfo components[] =''' '''{''' '''{ "FirstXpcom",''' '''FIRSTXPCOM_CID,''' '''"@senecac.on.ca/firstxpcom;1",''' '''FirstXpcomConstructor''' '''}''' '''};''' '''NS_IMPL_NSGETMODULE(FirstXpcomModule, components)''' Time to call make again:
$ cd $(objdir)/extensions/firstxpcom