Hi Darin ,

I have used NS_DECL_CLASSINFO(nsQEngineImpl) in the module definition.(i have attached the module defenition cpp)

below is the code snippet. A thread will be spawn on xpcom-startup notification.

In the thread, it will try to connect to a Server Socket (opened by an java application). If serversocket doesn't exists , after three tries it will end.


NS_IMPL_THREADSAFE_ISUPPORTS4(nsQEngineImpl, nsIQEngine, nsISupportsWeakReference, nsIObserver, nsIRunnable)


nsQEngineImpl::nsQEngineImpl()
{
    NS_INIT_ISUPPORTS();
}

nsQEngineImpl::~nsQEngineImpl()
{
}


NS_IMETHODIMP nsQEngineImpl::OpenSocket()
{
    nsresult connectionStatus;
    const char* eVar = getenv("QE_SERVER_PORT");
    if(eVar==NULL)
        return NS_ERROR_FAILURE;
    int port = atoi(eVar);
    char* hostname = getenv("QE_SERVER_HOST");
    if (hostname==NULL)
        return NS_ERROR_FAILURE;

    cli.create();
    PRUint32 noOfTimes = 0;

    while(noOfTimes<3)
    {
        connectionStatus  = cli.connect(hostname,port);
        if(NS_SUCCEEDED(connectionStatus))
        {
            break;
        }
        else
        {
            PR_Sleep(PR_MillisecondsToInterval(3000));
            noOfTimes++;
        }
    }
    return connectionStatus;
}


NS_IMETHODIMP nsQEngineImpl::Run()
{
    nsresult connectionStatus = OpenSocket();
    nsresult webProgServiceStatus;
    if(NS_SUCCEEDED(connectionStatus))
    {
                cli>>(message);
                processServerInstructions(message);
    }
    return NS_ERROR_FAILURE;
}


NS_IMETHODIMP nsQEngineImpl::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
    if (nsCRT::strcmp(aTopic, NS_XPCOM_STARTUP_OBSERVER_ID)==0 && !xpcominitialized)
    {
        xpcominitialized = PR_TRUE;
        nsCOMPtr<nsIThread> thread;
                NS_NewThread(getter_AddRefs(thread),NS_STATIC_CAST(nsIRunnable*,this),0,PR_JOINABLE_THREAD,PR_PRIORITY_NORMAL,PR_GLOBAL_THREAD);
       
    }
    return NS_OK;
}




Thanks
Raghavan

Darin Fisher wrote:
Hmm... I took a look in LXR, and nsQEngineImpl_GetInterfacesHelper is probably being defined by the nsIClassInfo related macros.  NS_DECL_CLASSINFO, NS_IMPL_CI_INTERFACE_GETTER1, etc.

Are you using any of these nsIClassInfo related macros?

-Darin



Srinivasa Raghavan wrote:

Hi,

While registering a XPCOM component with THREADSAFE macro ,it throws the following error,

nsNativeComponentLoader: GetFactory(libqecomp.so) Load FAILED with error: /advent1/srinivasar/mozilla/mozilla/components/libqecomp.so: undefined symbol: _Z33nsQEngineImpl_GetInterfacesHelperPjPPP4nsID
nsNativeComponentLoader: SelfRegisterDll(libqecomp.so) Load FAILED with error: /advent1/srinivasar/mozilla/mozilla/components/libqecomp.so: undefined symbol: _Z33nsQEngineImpl_GetInterfacesHelperPjPPP4nsID

if the same component registered without THREADSAFE macro it is getting registered properly.

Please help me to sort out the problem.

Thanks & Regards
S.Srinivasa Raghavan



#include "nsIGenericFactory.h"
#include "nsQEngine.h"
#include "nsCOMPtr.h"
#include "nsICategoryManager.h"
#include "nsIServiceManagerUtils.h"

NS_GENERIC_FACTORY_CONSTRUCTOR(nsQEngineImpl)
static NS_METHOD nsQEngineRegistrationProc(nsIComponentManager *aCompMgr,
                                          nsIFile *aPath,
                                          const char *registryLocation,
                                          const char *componentType,
                                          const nsModuleComponentInfo *info)
{
        nsresult rv;
        nsCOMPtr<nsIServiceManager> server = 
do_QueryInterface((nsISupports*)aCompMgr,&rv);
        nsCOMPtr<nsICategoryManager> catman;
        
server->GetServiceByContractID(NS_CATEGORYMANAGER_CONTRACTID,NS_GET_IID(nsICategoryManager),getter_AddRefs(catman));
        if(NS_SUCCEEDED(rv))
        {
                char* previous = nsnull;
                
catman->AddCategoryEntry("xpcom-startup","nsQEngineImpl",NS_QENGINE_CONTRACTID,PR_TRUE,PR_TRUE,&previous);
                
catman->AddCategoryEntry("xpcom-shutdown","nsQEngineImpl",NS_QENGINE_CONTRACTID,PR_TRUE,PR_TRUE,&previous);
        }
        
        
    return NS_OK;
}
static NS_METHOD nsQEngineUnregistrationProc(nsIComponentManager *aCompMgr,
                                            nsIFile *aPath,
                                            const char *registryLocation,
                                            const nsModuleComponentInfo *info)
{

        nsresult rv;
        nsCOMPtr<nsIServiceManager> server = 
do_QueryInterface((nsISupports*)aCompMgr,&rv);
        nsCOMPtr<nsICategoryManager> catman;
        
server->GetServiceByContractID(NS_CATEGORYMANAGER_CONTRACTID,NS_GET_IID(nsICategoryManager),getter_AddRefs(catman));
        if(NS_SUCCEEDED(rv))
        {
                char* previous = nsnull;
                rv = 
catman->DeleteCategoryEntry("xpcom-shutdown","nsQEngineImpl",PR_TRUE);
                rv = 
catman->DeleteCategoryEntry("xpcom-startup","nsQEngineImpl",PR_TRUE);
                
//catman->AddCategoryEntry("xpcom-shutdown","nsQEngineImpl",NS_QENGINE_CONTRACTID,PR_TRUE,PR_TRUE,&previous);
        }
        

    return NS_OK;
}
// For each class that wishes to support nsIClassInfo, add a line like this
NS_DECL_CLASSINFO(nsQEngineImpl)
static nsModuleComponentInfo components[ ] =
{
  { "A Simple xpcom component",    // a message to display when component is loaded
    NS_QENGINE_CID,           // our UUID 
    NS_QENGINE_CONTRACTID,    // our human readable PROGID or CLSID
    nsQEngineImplConstructor,
    nsQEngineRegistrationProc      /* NULL if you dont need one */,
    nsQEngineUnregistrationProc    /* NULL if you dont need one */,
    NULL /* no factory destructor */,
    NS_CI_INTERFACE_GETTER_NAME(nsQEngineImpl),
    NULL /* no language helper */,
    &NS_CLASSINFO_NAME(nsQEngineImpl)
  }
};
NS_IMPL_NSGETMODULE(nsQEngineModule, components)

Reply via email to