Ejemplo n.º 1
0
/*!
Performs the parts of the Unregistration that are common to all the subclasses
of XlfAbstractCmdDesc. It then calls the pure virtual method DoUnregister for
the subclass dependent parts of the algorithm.
*/
void xlw::XlfAbstractCmdDesc::Unregister() const
{
  std::string dllName = XlfExcel::Instance().GetName();
  if (dllName.empty())
    throw std::runtime_error("Could not get library name");
  int err = DoUnregister(dllName);
  if (err != xlretSuccess)
    std::cerr << XLW__HERE__ << "Error " << err << " while registering " << GetAlias().c_str() << std::endl;
  return;
}
Ejemplo n.º 2
0
void GlobalShortcutBackend::Unregister() {
    DoUnregister();
    active_ = false;
}
/*
** A "local" function of main().  Handles a #messageType# message arrived on
** #sd# accompanied by #dataSize# bytes of data.
*/
static void
ProcessRequest(Socket *sd,
               MessageType messageType,
               size_t dataSize) {

  unsigned long timeOut;
  DataDescriptor timeOutDescriptor = SIMPLE_DATA(UNSIGNED_LONG_TYPE, 1);
  char *matching;
  char *object;
  DataDescriptor objectDescriptor = SIMPLE_DATA(CHAR_TYPE, 0);
  char *pattern;
  DataDescriptor patternDescriptor = SIMPLE_DATA(CHAR_TYPE, 0);

  switch(messageType) {

  case NS_REGISTER:
    objectDescriptor.repetitions =
      dataSize - HomogenousDataSize(UNSIGNED_LONG_TYPE, 1, NETWORK_FORMAT);
    object = (char *)malloc(objectDescriptor.repetitions + 1);
    if(object == NULL) {
      (void)SendMessage(*sd, NS_FAILED, PktTimeOut(*sd));
      ERROR("ProcessRequest: out of memory\n");
    }
    else {
      if(!RecvData(*sd,
                   object,
                   &objectDescriptor,
                   1,
                   PktTimeOut(*sd)) ||
         !RecvData(*sd,
                   &timeOut,
                   &timeOutDescriptor,
                   1,
                   PktTimeOut(*sd))) {
        DROP_SOCKET(sd);
        ERROR("ProcessRequest: receive failed\n");
      }
      else {
        object[objectDescriptor.repetitions] = '\0';
        (void)SendMessage(*sd, NS_REGISTERED, PktTimeOut(*sd));
        /* Change time-out period to an expiration time. */
        if(timeOut != 0) {
          timeOut += (unsigned long)CurrentTime();
        }
        DoRegister(object, timeOut);
      }
      free(object);
    }
    break;

  case NS_SEARCH:
  case NS_UNREGISTER:
    patternDescriptor.repetitions = dataSize;
    pattern = (char *)malloc(dataSize);
    if(pattern == NULL) {
      (void)SendMessage(*sd, NS_FAILED, PktTimeOut(*sd));
      ERROR("ProcessRequest: out of memory\n");
    }
    else {
      if(!RecvData(*sd,
                   pattern,
                   &patternDescriptor,
                   1,
                   PktTimeOut(*sd))) {
        DROP_SOCKET(sd);
        ERROR("ProcessRequest: receive failed\n");
      }
      else if(messageType == NS_SEARCH) {
        matching = DoSearch(pattern);
        if(matching == NULL) {
          (void)SendMessage(*sd, NS_FAILED, PktTimeOut(*sd));
          ERROR("ProcessRequest: out of memory\n");
        }
        else {
          objectDescriptor.repetitions = strlen(matching) + 1;
          (void)SendMessageAndData(*sd,
                                   NS_SEARCHED,
                                   matching,
                                   &objectDescriptor,
                                   1,
                                   PktTimeOut(*sd));
          free(matching);
        }
      }
      else {
        DoUnregister(pattern);
        (void)SendMessage(*sd, NS_UNREGISTERED, PktTimeOut(*sd));
      }
      free(pattern);
    }
    break;

  default:
    ERROR1("ProcessRequest: unknown message %d\n", messageType);

  }

}