예제 #1
0
bool Module::Load()
{
   wxLogNull logNo;

   if (mLib->IsLoaded()) {
      if (mDispatch) {
         return true;
      }
      return false;
   }

   if (!mLib->Load(mName, wxDL_LAZY)) {
      return false;
   }

   mDispatch = (fnModuleDispatch) mLib->GetSymbol(wxT(ModuleDispatchName));

   if (!mDispatch) {
      return false;
   }

   bool res = ((mDispatch(ModuleInitialize))!=0);
   if (res) {
      return true;
   }

   mDispatch = NULL;

   return false;
}
예제 #2
0
int Module::Dispatch(ModuleDispatchTypes type)
{
   if (mLib->IsLoaded()) {
      return mDispatch(type);
   }

   return 0;
}
예제 #3
0
void Module::Unload()
{
   if (mLib->IsLoaded()) {
      mDispatch(ModuleTerminate);
   }

   mLib->Unload();
}
예제 #4
0
int Module::Dispatch(ModuleDispatchTypes type)
{
   if (mLib->IsLoaded())
      if( mDispatch != NULL )
         return mDispatch(type);

   return 0;
}
예제 #5
0
bool Module::Load()
{
   if (mLib->IsLoaded()) {
      if (mDispatch) {
         return true;
      }
      return false;
   }

   if (!mLib->Load(mName, wxDL_LAZY)) {
      return false;
   }

   // Check version string matches.  (For now, they must match exactly)
   tVersionFn versionFn = (tVersionFn)(mLib->GetSymbol(wxT(versionFnName)));
   if (versionFn == NULL){
      wxString ShortName = wxFileName( mName ).GetName();
      wxMessageBox(wxString::Format(_("The module %s does not provide a version string.\nIt will not be loaded."), ShortName.c_str()), _("Module Unsuitable"));
      wxLogMessage(wxString::Format(_("The module %s does not provide a version string.  It will not be loaded."), mName.c_str()));
      mLib->Unload();
      return false;
   }

   wxString moduleVersion = versionFn();
   if( !moduleVersion.IsSameAs(AUDACITY_VERSION_STRING)) {
      wxString ShortName = wxFileName( mName ).GetName();
      wxMessageBox(wxString::Format(_("The module %s is matched with Audacity version %s.\n\nIt will not be loaded."), ShortName.c_str(), moduleVersion.c_str()), _("Module Unsuitable"));
      wxLogMessage(wxString::Format(_("The module %s is matched with Audacity version %s.  It will not be loaded."), mName.c_str(), moduleVersion.c_str()));
      mLib->Unload();
      return false;
   }

   mDispatch = (fnModuleDispatch) mLib->GetSymbol(wxT(ModuleDispatchName));
   if (!mDispatch) {
      // Module does not provide a dispatch function...
      // That can be OK, as long as we never try to call it.
      return true;
   }

   // However if we do have it and it does not work, 
   // then the module is bad.
   bool res = ((mDispatch(ModuleInitialize))!=0);
   if (res) {
      return true;
   }

   mDispatch = NULL;
   return false;
}
예제 #6
0
파일: ServerCore.cpp 프로젝트: 0x0d/kraken
void ServerCore::Serve()
{
    fd_set sockets;
    struct timeval timeout;
    int max_desc;
    int readsocks;

    while(mRunning) {
        /* Build select list */
        FD_ZERO(&sockets);
        FD_SET(mListener, &sockets);
        max_desc = mListener;
        sem_wait(&mMutex);
        map<unsigned int, ClientConnection*>::iterator it = mClientMap.begin();
        while(it != mClientMap.end())
        {
            int fd = (*it).second->getFd();
            FD_SET(fd, &sockets);
            if (fd>max_desc) {
                max_desc = fd;
            }
            it++;
        }
        sem_post(&mMutex);

		timeout.tv_sec = 1;
		timeout.tv_usec = 0;
        readsocks = select(max_desc+1, &sockets, (fd_set*)0, (fd_set*)0,
                           &timeout);

		if (readsocks < 0) {
			printf("ERROR: select failed");
			break;
		}

        if(readsocks) {
            if(FD_ISSET(mListener, &sockets)) {
                /* New connection */
                int conn = accept(mListener, NULL, NULL);
                if (mClientMap.size()<MAX_CLIENTS) {
                    ClientConnection* client = new ClientConnection(conn);
                    mClientMap[mClientCount++] = client;
                } else {
                    close(conn);
                }
            }

            sem_wait(&mMutex);
            it = mClientMap.begin();
            while(it != mClientMap.end())
            {
                ClientConnection* client = (*it).second;
                if (FD_ISSET(client->getFd(), &sockets)) {
                    string data;
                    int status = client->Read(data);
                    if (status<0) {
                        /* Error , close */
                        map<unsigned int, ClientConnection*>::iterator it2 = it;
                        it2++;
                        delete client;
                        close(client->getFd());
                        mClientMap.erase(it);
                        it = it2;
                        continue;
                    }
                    if (status>0) {
                        if (mDispatch) {
                            /* Release the mutex so dispatched calls
                             * can write back to socket.
                             * This is safe, since this is the only thread
                             * that actually modifies the client connection map
                             */
                            sem_post(&mMutex);
                            mDispatch((*it).first,data);
                            sem_wait(&mMutex);
                        }
                    }
                }
                it++;
            }
            sem_post(&mMutex);
        } 
    }
}