Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsPluginThread Class Reference

#include <plugin.h>

Inheritance diagram for nsPluginThread:
Inheritance graph
[legend]
Collaboration diagram for nsPluginThread:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsPluginThread (DWORD aP1)
 ~nsPluginThread ()
DWORD callNPP (npapiAction aAction, DWORD aP1=NULL, DWORD aP2=NULL, DWORD aP3=NULL, DWORD aP4=NULL, DWORD aP5=NULL, DWORD aP6=NULL, DWORD aP7=NULL)

Private Member Functions

BOOL init ()
void shut ()
void dispatch ()
BOOL setInitEvent ()
BOOL setShutEvent ()
BOOL isAlive ()
BOOL isBusy ()
HANDLE getHandle ()
void run ()
BOOL open (CThread *aThread)
void close (CThread *aThread)
BOOL tryAction (int aAction)
BOOL doAction (int aAction)

Private Attributes

DWORD mP1
DWORD mP2
DWORD mP3
DWORD mP4
DWORD mP5
DWORD mP6
DWORD mP7
int mAction

Detailed Description

Definition at line 44 of file plugin.h.


Constructor & Destructor Documentation

Definition at line 57 of file plugin.cpp.

                                        : CThread(),
  mP1(aP1),
  mP2(0),
  mP3(0),
  mP4(0),
  mP5(0),
  mP6(0),
  mP7(0)
{
  dbgOut1("nsPluginThread::nsPluginThread");

  open(this);
}

Here is the call graph for this function:

Definition at line 71 of file plugin.cpp.

{
  dbgOut1("nsPluginThread::~nsPluginThread");

  close(this);
}

Here is the call graph for this function:


Member Function Documentation

DWORD nsPluginThread::callNPP ( npapiAction  aAction,
DWORD  aP1 = NULL,
DWORD  aP2 = NULL,
DWORD  aP3 = NULL,
DWORD  aP4 = NULL,
DWORD  aP5 = NULL,
DWORD  aP6 = NULL,
DWORD  aP7 = NULL 
)

Definition at line 149 of file plugin.cpp.

{
  // don't enter untill thread is ready
  while (isBusy()) {
    Sleep(0);
  }

  mP1 = aP1;
  mP2 = aP2;
  mP3 = aP3;
  mP4 = aP4;
  mP5 = aP5;
  mP6 = aP6;
  mP7 = aP7;

  doAction(aAction);

  // don't return untill thread is ready
  while (isBusy()) {
    Sleep(0);
  }

  return NPERR_NO_ERROR;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CThread::close ( CThread aThread) [inherited]

Definition at line 104 of file thread.cpp.

{
  switch (mState) {
    case ts_dead:
      break;
    case ts_ready:
      mState = ts_dead;
      SetEvent(mEventDo);
      if(mEventThreadShutdownFinished != NULL)
        WaitForSingleObject(mEventThreadShutdownFinished, mShutTimeOut);
      break;
    case ts_busy:
    {
      aThread->shut();
      DWORD ret;
      GetExitCodeThread(aThread->getHandle(), &ret);
      TerminateThread(mThread, ret);
      mState = ts_dead;
      break;
    }
    default:
      break;
  }

  mThread = NULL;
  CloseHandle(mEventThreadInitializationFinished);
  CloseHandle(mEventThreadShutdownFinished);
  CloseHandle(mEventDo);
  dbgOut1("CThread::close");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsPluginThread::dispatch ( ) [private, virtual]

Implements CThread.

Definition at line 175 of file plugin.cpp.

{
  dbgOut2("nsPluginThread::dispatch: %s", FormatAction(mAction));

  switch (mAction) {
    case action_npp_new:
      pluginNPPFuncs.newp((NPMIMEType)mP1, (NPP)mP2, (uint16)mP3, (int16)mP4, (char**)mP5, (char**)mP6, (NPSavedData*)mP7);
      break;
    case action_npp_destroy:
      pluginNPPFuncs.destroy((NPP)mP1, (NPSavedData**)mP2);
      break;
    case action_npp_set_window:
      pluginNPPFuncs.setwindow((NPP)mP1, (NPWindow*)mP2);
      break;
    case action_npp_new_stream:
      pluginNPPFuncs.newstream((NPP)mP1, (NPMIMEType)mP2, (NPStream*)mP3, (NPBool)mP4, (uint16*)mP5);
      break;
    case action_npp_destroy_stream:
    {
      NPStream * stream = (NPStream *)mP2;
      pluginNPPFuncs.destroystream((NPP)mP1, stream, (NPError)mP3);
      break;
    }
    case action_npp_stream_as_file:
    {
      NPStream * stream = (NPStream *)mP2;
      pluginNPPFuncs.asfile((NPP)mP1, stream, (char*)mP3);
      break;
    }
    case action_npp_write_ready:
      pluginNPPFuncs.writeready((NPP)mP1, (NPStream *)mP2);
      break;
    case action_npp_write:
      pluginNPPFuncs.write((NPP)mP1, (NPStream *)mP2, (int32)mP3, (int32)mP4, (void *)mP5);
      break;
    case action_npp_print:
      pluginNPPFuncs.print((NPP)mP1, (NPPrint*)mP2);
      break;
    case action_npp_handle_event:
      pluginNPPFuncs.event((NPP)mP1, (void *)mP2);
      break;
    case action_npp_url_notify:
      pluginNPPFuncs.urlnotify((NPP)mP1, (const char*)mP2, (NPReason)mP3, (void*)mP4);
      break;
    case action_npp_get_java_class:
      //pluginNPPFuncs.javaClass;
      break;
    case action_npp_get_value:
      pluginNPPFuncs.getvalue((NPP)mP1, (NPPVariable)mP2, (void *)mP3);
      break;
    case action_npp_set_value:
      pluginNPPFuncs.setvalue((NPP)mP1, (NPNVariable)mP2, (void *)mP3);
      break;
    default:
      dbgOut1("Unexpected action!");
      break;
  }
}

Here is the call graph for this function:

BOOL CThread::doAction ( int  aAction) [inherited]

Definition at line 188 of file thread.cpp.

{
  while(mState != ts_ready) {
    //dbgOut2("CThread::doAction %i -- waiting...", aAction);
    if(mState == ts_dead)
      return FALSE;
    Sleep(0);
  }

  mState = ts_busy;
  mAction = aAction;
  //dbgOut2("CThread::doAction -- about to signal %i", aAction);
  SetEvent(mEventDo);

  return TRUE;
}

Here is the caller graph for this function:

HANDLE CThread::getHandle ( ) [inherited]

Definition at line 155 of file thread.cpp.

{
  return mThread;
}

Here is the caller graph for this function:

BOOL nsPluginThread::init ( ) [private, virtual]

Implements CThread.

Definition at line 78 of file plugin.cpp.

{
  dbgOut1("nsPluginThread::init");

  // scan plugins dir for available plugins to see if we have anything 
  // for the given mimetype
  pluginLibrary = LoadRealPlugin((NPMIMEType)mP1);
  if(!pluginLibrary)
    return FALSE;

  NP_GETENTRYPOINTS plugin_NP_GetEntryPoints = (NP_GETENTRYPOINTS)GetProcAddress(pluginLibrary, "NP_GetEntryPoints");
  if(!plugin_NP_GetEntryPoints)
    return FALSE;

  NP_INITIALIZE plugin_NP_Initialize = (NP_INITIALIZE)GetProcAddress(pluginLibrary, "NP_Initialize");
  if(!plugin_NP_Initialize)
    return FALSE;

  plugin_NP_Shutdown = (NP_SHUTDOWN)GetProcAddress(pluginLibrary, "NP_Shutdown");
  if(!plugin_NP_Shutdown)
    return FALSE;

  // fill callbacks structs
  memset(&pluginNPPFuncs, 0, sizeof(NPPluginFuncs));
  pluginNPPFuncs.size = sizeof(NPPluginFuncs);

  plugin_NP_GetEntryPoints(&pluginNPPFuncs);

  // inform the plugin about our entry point it should call
  memset((void *)&wrapperNPNFuncs, 0, sizeof(wrapperNPNFuncs));
  wrapperNPNFuncs.size             = sizeof(wrapperNPNFuncs);
  wrapperNPNFuncs.version          = NPNFuncs.version;
  wrapperNPNFuncs.geturlnotify     = NPN_GetURLNotify;
  wrapperNPNFuncs.geturl           = NPN_GetURL;
  wrapperNPNFuncs.posturlnotify    = NPN_PostURLNotify;
  wrapperNPNFuncs.posturl          = NPN_PostURL;
  wrapperNPNFuncs.requestread      = NPN_RequestRead;
  wrapperNPNFuncs.newstream        = NPN_NewStream;
  wrapperNPNFuncs.write            = NPN_Write;
  wrapperNPNFuncs.destroystream    = NPN_DestroyStream;
  wrapperNPNFuncs.status           = NPN_Status;
  wrapperNPNFuncs.uagent           = NPN_UserAgent;
  wrapperNPNFuncs.memalloc         = NPN_MemAlloc;
  wrapperNPNFuncs.memfree          = NPN_MemFree;
  wrapperNPNFuncs.memflush         = NPN_MemFlush;
  wrapperNPNFuncs.reloadplugins    = NPN_ReloadPlugins;
  wrapperNPNFuncs.getJavaEnv       = NPN_GetJavaEnv;
  wrapperNPNFuncs.getJavaPeer      = NPN_GetJavaPeer;
  wrapperNPNFuncs.getvalue         = NPN_GetValue;
  wrapperNPNFuncs.setvalue         = NPN_SetValue;
  wrapperNPNFuncs.invalidaterect   = NPN_InvalidateRect;
  wrapperNPNFuncs.invalidateregion = NPN_InvalidateRegion;
  wrapperNPNFuncs.forceredraw      = NPN_ForceRedraw;

  plugin_NP_Initialize(&wrapperNPNFuncs);

  return TRUE;
}

Here is the call graph for this function:

BOOL CThread::isAlive ( ) [inherited]

Definition at line 145 of file thread.cpp.

{
  return (mThread != NULL);
}
BOOL CThread::isBusy ( ) [inherited]

Definition at line 150 of file thread.cpp.

{
  return (mState == ts_busy);
}

Here is the caller graph for this function:

BOOL CThread::open ( CThread aThread) [inherited]

Definition at line 83 of file thread.cpp.

{
  dbgOut1("CThread::open");

  mEventThreadInitializationFinished = CreateEvent(NULL, TRUE, FALSE, NULL);
  mEventThreadShutdownFinished = CreateEvent(NULL, TRUE, FALSE, NULL);
  mEventDo = CreateEvent(NULL, TRUE, FALSE, NULL);

  mThread = (HANDLE)::_beginthreadex(0, 1024, (UINT (__stdcall *)(void *))ThreadFunction, aThread, 0L, (UINT *)&mID);

  if(mThread == NULL)
    return FALSE;

  SetThreadPriority(mThread, THREAD_PRIORITY_NORMAL);

  if(mEventThreadInitializationFinished != NULL)
    WaitForSingleObject(mEventThreadInitializationFinished, mInitTimeOut);

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CThread::run ( ) [inherited]

Definition at line 160 of file thread.cpp.

{
  mState = ts_ready;

  while(mState != ts_dead) {
    WaitForSingleObject(mEventDo, INFINITE);
    //dbgOut2("CThread::run(): Do event signalled, %u", mState);
    ResetEvent(mEventDo);
    if(mState == ts_dead)
      return;
    mState = ts_busy;
    dispatch();
    mState = ts_ready;
  }
  mState = ts_dead;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL CThread::setInitEvent ( ) [inherited]

Definition at line 135 of file thread.cpp.

{
  return SetEvent(mEventThreadInitializationFinished);
}

Here is the caller graph for this function:

BOOL CThread::setShutEvent ( ) [inherited]

Definition at line 140 of file thread.cpp.

{
  return SetEvent(mEventThreadShutdownFinished);
}

Here is the caller graph for this function:

void nsPluginThread::shut ( ) [private, virtual]

Implements CThread.

Definition at line 137 of file plugin.cpp.

Here is the call graph for this function:

BOOL CThread::tryAction ( int  aAction) [inherited]

Definition at line 177 of file thread.cpp.

{
  if(mState != ts_ready)
    return FALSE;

  mAction = aAction;
  SetEvent(mEventDo);

  return TRUE;
}

Member Data Documentation

int CThread::mAction [protected, inherited]

Definition at line 60 of file thread.h.

Definition at line 61 of file plugin.h.

Definition at line 62 of file plugin.h.

Definition at line 63 of file plugin.h.

Definition at line 64 of file plugin.h.

Definition at line 65 of file plugin.h.

Definition at line 66 of file plugin.h.

Definition at line 67 of file plugin.h.


The documentation for this class was generated from the following files: