Пример #1
0
/**
 * スレッドの勢い値を計算する
 * 勢い=書き込み数÷(スレが立ってからの秒数÷86400)
 * @param itemResponse レス数
 * @param itemOid      スレがたった時間を表すUNIX Time
 * @return momentum    勢い
 */
wxString XrossBoardUtil::CalcThreadMomentum(wxString& itemResponse, wxString& itemOid) {

     unsigned long response;
     unsigned long oid;
     unsigned long now;
     itemResponse.ToULong(&response);
     itemOid.ToULong(&oid);
     now = ::wxGetUTCTime();

     // レス数が1の場合勢い値は1
     if (response == 1) return wxT("1.0");

     // 勢い値の計算
     try {
	  double elapsed = now - oid;
	  double momentum = response / elapsed * 86400;
	  return wxString::Format(wxT("%.1f"), momentum);

     } catch (std::range_error& e) {
	  return wxT("std::range_error");
     } catch (std::overflow_error& e) {
	  return wxT("std::overflow_error");
     } catch (std::underflow_error& e) {
	  return wxT("std::underflow_error");
     }
}
Пример #2
0
bool wxSockAddressImpl::SetPortName(const wxString& name, const char *protocol)
{
    // test whether it's a number first
    unsigned long port;
    if ( name.ToULong(&port) )
    {
        if ( port > 65535 )
            return false;
    }
    else // it's a service name
    {
        wxGetservBuf buffer;
        servent se;
        if ( !wxGetservbyname_r(name.utf8_str(), protocol, &se,
                                buffer, sizeof(buffer)) )
            return false;

        // s_port is in network byte order and SetPort() uses the host byte
        // order and we prefer to reuse it from here instead of assigning to
        // sin_port directly
        port = ntohs(se.s_port);
    }

    return SetPort(port);
}
Пример #3
0
void RegRichTextCtrl::EditRegister( const char *RegNames, const wxString &value )
{
	unsigned long tmp;
	value.ToULong(&tmp, 16);

	wxString newStr = wxGetTextFromUser(RegNames, wxT("Edit register value"),
				wxString::Format(wxT("%X"), tmp), this);

	// if user press cancel then newStr will be empty
	if (!newStr.empty())
	{
		Context ctx;
		trc_get_thread_ctx(m_sesId, m_tid, &ctx);

		newStr.ToULong(&tmp, 16);

		WhatBasicRegister(RegNames, tmp, ctx);

		// TODO: to complete output for all warnings and errors to wxLog
		if (0 == trc_set_thread_ctx(m_sesId, m_tid, &ctx) )
			wxLogError(wxString(wxT("Can't set ")) + RegNames + wxString(wxT(" value")));
		Context ctx_new;
		if (0 == trc_get_thread_ctx(m_sesId, m_tid, &ctx_new) )
			wxLogError(wxString(wxT("Can't get ")) + RegNames + wxString(wxT(" value")));

		OutputBasic(ctx_new);
	}
}
Пример #4
0
bool Camera_DSIClass::Connect(const wxString& camId)
{
    bool retval = false;

    if (!MeadeCam)
        MeadeCam = new DsiDevice();

    unsigned int NDevices = MeadeCam->EnumDsiDevices();
    if (!NDevices) {
        wxMessageBox(_T("No DSIs found"), _("Error"));
        return true;
    }

    unsigned long DevNum = 0;
    if (camId == DEFAULT_CAMERA_ID)
        DevNum = 1;
    else
        camId.ToULong(&DevNum);

    if (DevNum < 1 || DevNum > NDevices)
    {
        Debug.AddLine(wxString::Format("DSI: invalid camera id: '%s', ncams = %u", camId, NDevices));
        return true;
    }

    retval = !(MeadeCam->Open(DevNum));
//  wxMessageBox(wxString::Format("Color: %d\n%u x %u",
//      MeadeCam->IsColor,MeadeCam->GetWidth(),MeadeCam->GetHeight()));
    if (!retval) {
        FullSize = wxSize(MeadeCam->GetWidth(),MeadeCam->GetHeight());
//      wxMessageBox(wxString::Format("%s\n%s (%d)\nColor: %d\n-II: %d\n%u x %u",MeadeCam->CcdName,MeadeCam->ModelName, MeadeCam->ModelNumber,
//          MeadeCam->IsColor,MeadeCam->IsDsiII, FullSize.GetWidth(), FullSize.GetHeight()) + "\n" + MeadeCam->ErrorMessage);
//      wxMessageBox(wxString::Format("%s\n%s (%d)\nColor: %d\n-USB2: %d\n%u x %u",MeadeCam->CcdName,MeadeCam->ModelName, MeadeCam->ModelNumber,
//                                    MeadeCam->IsColor,MeadeCam->IsUSB2, FullSize.GetWidth(), FullSize.GetHeight()) + "\n" + MeadeCam->ErrorMessage);
        MeadeCam->Initialize();
        MeadeCam->SetHighGain(true);
        if (!MeadeCam->IsDsiIII) MeadeCam->SetDualExposureThreshold(501);
        else MeadeCam->SetBinMode(1);

        MeadeCam->SetOffset(255);
        MeadeCam->SetFastReadoutSpeed(true);
        Connected = true;
        // Set the PixelSize property for cients.  If the pixels aren't square, use the smaller dimension because the image
        // is "squared up" by scaling to the smaller dimension
        if (MeadeCam->IsDsiIII)
            PixelSize = 6.6;
        else
        if (MeadeCam->IsDsiII)
            PixelSize = 8.3;
        else
            PixelSize = 7.5;

    }

    return retval;
}
Пример #5
0
    // Return the number of files handling special value "many". Notice that
    // the returned value is signed to allow using it in subtraction above.
    int GetNumFilesFromText(const wxString& text) const
    {
        unsigned long n;
        if ( !text.ToULong(&n) )
        {
            if ( text == "many" )
                n = 9999;
            else
                n = 0;
        }

        return n;
    }
Пример #6
0
void wxSMTP::HeloState::onResponse(wxCmdlineProtocol& context, const wxString& line) const
{
   /* Extract smpt code */
   unsigned long smtpCode = 0;
   line.ToULong(&smtpCode);

   /* Check if command was successful */
   if (smtpCode == 250)
   {
      /* Check if this is the last answer */
      if (line.StartsWith(wxT("250-")))
      {
		  if (line.StartsWith(wxT("250-AUTH"))) {
				((wxSMTP&)context).authentication_line = line;
		  }
         /* We shall wait next acceptance answer... */

      }
      else
      {
         if (((wxSMTP&)context).shall_enter_ssl)
         {
            context.ChangeState(g_startTlsState);
         }
         else
         {
            if (((wxSMTP&)context).authentication_scheme == wxSMTP::NoAuthentication)
            {
               context.ChangeState(g_sendMailFromState);
            }
            else
            {
               context.ChangeState(g_authenticateState);
            }
         }
      }
   }
   else
   {
      if ((smtpCode >= 400) && (smtpCode < 500))
      {
         ((wxSMTP&)context).disconnection_status = Listener::StatusRetry;
      }
      else
      {
         ((wxSMTP&)context).disconnection_status = Listener::StatusError;
      }
      context.ChangeState(g_quitState);
   }
}
Пример #7
0
bool CServer::ParseUrl(wxString host, const wxString& port, wxString user, wxString pass, wxString &error, CServerPath &path)
{
	unsigned long nPort = 0;
	if (!port.empty())
	{
		if (port.size() > 5 || !port.ToULong(&nPort) || !nPort || nPort > 65535)
		{
			error = _("Invalid port given. The port has to be a value from 1 to 65535.");
			error += _T("\n");
			error += _("You can leave the port field empty to use the default port.");
			return false;
		}
	}
	return ParseUrl(host, nPort, user, pass, error, path);
}
Пример #8
0
void wxSMTP::QuitState::onResponse(wxCmdlineProtocol& context, const wxString& line) const
{
   /* Extract smpt code */
   unsigned long smtpCode = 0;
   line.ToULong(&smtpCode);

   /* Check if we received an ACK */
   if (smtpCode != 221)
   {
      ((wxSMTP&)context).disconnection_status = Listener::StatusError;
   }

   /* Go to exit state */
   context.ChangeState(g_closedState);
}
Пример #9
0
wxString CDTMF::processCCS(const wxString& command) const
{
	unsigned int len = command.Len();

	if (len != 4U)
		return wxEmptyString;

	unsigned long n;
	command.ToULong(&n);
	if (n == 0UL)
		return wxEmptyString;

	wxString out;
	out.Printf(wxT("CCS*%04lu"), n);

	return out;
}
Пример #10
0
void wxSMTP::AuthenticateState::onResponse(wxCmdlineProtocol& context, const wxString& line) const
{
   /* Extract smpt code */
   unsigned long smtpCode = 0;
   line.ToULong(&smtpCode);

   /* Check if we alreadysent authentication scheme */
   if (((wxSMTP&)context).authentication_digest_sent)
   {
      /* Check if server acknowledged connection */
      if (smtpCode == 235)
      {
         context.ChangeState(g_sendMailFromState);
      }
      else if (smtpCode == 535)
      {
         ((wxSMTP&)context).disconnection_status = Listener::StatusInvalidUserNamePassword;
         context.ChangeState(g_quitState);
      }
      else
      {
         ((wxSMTP&)context).disconnection_status = Listener::StatusError;
         context.ChangeState(g_quitState);
      }
   }
   else
   {
      /* check is server accepted command */
      if (smtpCode == 334)
      {
         /* Extract digest and send answer */
         context.SendLine(((wxSMTP&)context).ComputeAuthenticationDigest(line.AfterFirst(' ')));
      }
      else
      {
         ((wxSMTP&)context).disconnection_status = Listener::StatusError;
         context.ChangeState(g_quitState);
      }
   }
}
Пример #11
0
void wxSMTP::BeginDataState::onResponse(wxCmdlineProtocol& context, const wxString& line) const
{
   /* Extract smpt code */
   unsigned long smtpCode = 0;
   line.ToULong(&smtpCode);

   /* check response type */
   if (smtpCode == 354)
   {
      /* Switch to Data state */
      context.ChangeState(g_dataState);
   }
   else if ((smtpCode >= 400) && (smtpCode < 500))
   {
      /* Abort message with timeout */
      ((wxSMTP&)context).CancelMailSendingProcess(Listener::SendingRetry, true, false, false, (Listener::DisconnectionStatus_t)0);
   }
   else
   {
      /* Abort message with timeout */
      ((wxSMTP&)context).CancelMailSendingProcess(Listener::SendingError, true, false, false, (Listener::DisconnectionStatus_t)0);
   }
}
Пример #12
0
uint64_t cbDebuggerStringToAddress(const wxString &address)
{
    if (address.empty())
        return 0;
#if defined(__WXMSW__)
    // Workaround for the 'ToULongLong' bug in wxWidgets 2.8.12
#if wxCHECK_VERSION(2, 8, 12)
    return strtoull(address.mb_str(), nullptr, 16);
#else
    uint64_t result;
    if (address.ToULongLong(&result))
        return result;
    else
        return 0;
#endif // wxCHECK_VERSION
#else
    uint64_t result;
    if (address.ToULong(&result, 16))
        return result;
    else
        return 0;
#endif
}
Пример #13
0
wxString CDTMF::processCCS(const wxString& command) const
{
	unsigned int len = command.Len();

	unsigned long n;
	command.ToULong(&n);
	if (n == 0UL)
		return wxEmptyString;

	wxString out = wxEmptyString;

	switch (len) {
		case 4U:
			out.Printf(wxT("CCS*%04lu"), n);
			break;
		case 5U:
			out.Printf(wxT("CCS*%05lu"), n);
			break;
		default:
			break;
	}

	return out;
}
Пример #14
0
void wxSMTP::ConnectState::onResponse(wxCmdlineProtocol& context, const wxString& line) const
{
   /* Extract smpt code */
   unsigned long smtpCode = 0;
   line.ToULong(&smtpCode);

   /* Check if server ACK */
   if (smtpCode == 220)
   {
      context.ChangeState(g_heloState);
   }
   else
   {
      if ((smtpCode >= 400) && (smtpCode < 500))
      {
         ((wxSMTP&)context).disconnection_status = Listener::StatusRetry;
      }
      else
      {
         ((wxSMTP&)context).disconnection_status = Listener::StatusError;
      }
      context.ChangeState(g_quitState);
   }
}
Пример #15
0
void wxSMTP::StartTLSState::onResponse(wxCmdlineProtocol& context, const wxString& line) const
{
   /* Extract smpt code */
   unsigned long smtpCode = 0;
   line.ToULong(&smtpCode);

   /* Check if command was successful */
   if (smtpCode == 220)
   {
      context.ChangeState(g_sslNegociationState);
   }
   else
   {
      if ((smtpCode >= 400) && (smtpCode < 500))
      {
         ((wxSMTP&)context).disconnection_status = Listener::StatusRetry;
      }
      else
      {
         ((wxSMTP&)context).disconnection_status = Listener::StatusError;
      }
      context.ChangeState(g_quitState);
   }
}
Пример #16
0
int Serial::Set_baud(const wxString& baud_str)
{
	unsigned long b;
	if (!baud_str.ToULong(&b)) return -1;
	return Set_baud((int)b);
}
Пример #17
0
void wxSMTP::DataState::onResponse(wxCmdlineProtocol& context, const wxString& line) const
{
   /* Extract smpt code */
   unsigned long smtpCode = 0;
   line.ToULong(&smtpCode);

   /* Check if we received an ACK */
   if (smtpCode == 250)
   {
      /* flush all pending recipients */
      while (((wxSMTP&)context).pending_accepted_recipients.size() > 0)
      {
         ((wxSMTP&)context).total_accepted_recipients.push_back(((wxSMTP&)context).pending_accepted_recipients.front());
         ((wxSMTP&)context).pending_accepted_recipients.pop_front();
      }

      /* Check if message has still recipients */
      if (((wxSMTP&)context).messages_to_send.front().HasStillRecipients())
      {
         /* jump to state send mail from */
         context.ChangeState(g_sendMailFromState);
      }
      else
      {
         /* Generate the callback */
         bool shall_retry;
         unsigned long retry_delay;
         bool shall_stop;
         ((wxSMTP&)context).m_pListener->OnMessageStatus(((wxSMTP&)context).messages_to_send.front().GetMessageId(),
                                                         Listener::SendingSucceeded,
                                                         ((wxSMTP&)context).messages_to_send.size()-1,
                                                         ((wxSMTP&)context).GetNbRetryMessages(),
                                                         ((wxSMTP&)context).total_rejected_recipients,
                                                         ((wxSMTP&)context).total_accepted_recipients,
                                                         false,
                                                         shall_retry,
                                                         retry_delay,
                                                         shall_stop);

         /* Remove mail from list */
         ((wxSMTP&)context).messages_to_send.pop_front();

         /* we cannot retry.. */
         wxASSERT(!shall_retry);

         /* Check if we shall leave */
         if (shall_stop)
         {
            ((wxSMTP&)context).disconnection_status = Listener::StatusUserAbort;
            context.ChangeState(g_quitState);
         }
         else
         {
            context.ChangeState(g_sendMailFromState);
         }
      }
   }
   else if ((smtpCode >= 400) &&
            (smtpCode < 500))
   {
      ((wxSMTP&)context).CancelMailSendingProcess(Listener::SendingRetry, true, false, false, (Listener::DisconnectionStatus_t)0);
   }
   else
   {
      ((wxSMTP&)context).CancelMailSendingProcess(Listener::SendingError, true, false, false, (Listener::DisconnectionStatus_t)0);
   }
}
Пример #18
0
void wxSMTP::RcptListState::onResponse(wxCmdlineProtocol& context, const wxString& line) const
{
   /* Extract smpt code */
   unsigned long smtpCode = 0;
   line.ToULong(&smtpCode);

   /* Check if command was successful */
   if ((smtpCode >= 200) &&
       (smtpCode < 300))
   {
      /* Reset timer */
      context.TimerRestart();

      /* update recipients status */
      ((wxSMTP&)context).nb_pending_recipients++;
      ((wxSMTP&)context).pending_accepted_recipients.push_back(((wxSMTP&)context).current_recipient);

      /* Check if there are still recipients to send */
      if (((wxSMTP&)context).messages_to_send.front().GetNextRecipient(((wxSMTP&)context).current_recipient))
      {
         /* Send Rcpt command */
         context.SendLine(_T("RCPT TO: <") + ((wxSMTP&)context).current_recipient.GetAddress() + _T(">"));
      }
      else
      {
         context.ChangeState(g_beginDataState);
      }
   }
   else if (smtpCode == 552)
   {
      /* We probably reached nb recipients limit -> send this mail */
      ((wxSMTP&)context).messages_to_send.front().ReinsertRecipient(((wxSMTP&)context).current_recipient);
      context.ChangeState(g_beginDataState);
   }
   else if ((smtpCode == 550) ||
            (smtpCode == 551) ||
            (smtpCode == 553) ||
            (smtpCode == 555))
   {
      /* Probably an invalid address */
      ((wxSMTP&)context).total_rejected_recipients.push_front(((wxSMTP&)context).current_recipient);

      /* Try sending next recipient */
      if (((wxSMTP&)context).messages_to_send.front().GetNextRecipient(((wxSMTP&)context).current_recipient))
      {
         /* Send Rcpt command */
         context.SendLine(_T("RCPT TO: <") + ((wxSMTP&)context).current_recipient.GetAddress() + _T(">"));
      }
      else
      {
         /* Check if we have at least one recipient */
         if (((wxSMTP&)context).nb_pending_recipients > 0)
         {
            /* Switch to begin state */
            context.ChangeState(g_beginDataState);
         }
         else
         {
            /* Cancel current sending */
            if (((wxSMTP&)context).nb_recipients_successful > 0)
            {
               ((wxSMTP&)context).CancelMailSendingProcess(Listener::SendingSucceeded, false, false, false, (Listener::DisconnectionStatus_t)0);
            }
            else
            {
               ((wxSMTP&)context).CancelMailSendingProcess(Listener::SendingNoValidRecipient, false, false, false, (Listener::DisconnectionStatus_t)0);
            }
         }
      }
   }
   else
   {
      ((wxSMTP&)context).CancelMailSendingProcess(Listener::SendingNoValidRecipient, true, false, false, (Listener::DisconnectionStatus_t)0);
   }
}
Пример #19
0
void wxSMTP::SendMailFromState::onResponse(wxCmdlineProtocol& context, const wxString& line) const
{
   /* Extract smpt code */
   unsigned long smtpCode = 0;
   line.ToULong(&smtpCode);

   /* Check if command was successful */
   if (smtpCode == 250)
   {
      context.ChangeState(g_rcptListState);
   }
   else
   {
      if ((smtpCode >= 400) && (smtpCode < 500))
      {
         ((wxSMTP&)context).disconnection_status = Listener::StatusRetry;
         context.ChangeState(g_quitState);
      }
      else
      {
         /* Message has been rejected -> trigger callback */
         bool shall_retry;
         bool shall_stop;
         unsigned long retry_delay;
         ((wxSMTP&)context).m_pListener->OnMessageStatus(((wxSMTP&)context).messages_to_send.front().GetMessageId(),
                                                         Listener::SendingMessageRejected,
                                                         ((wxSMTP&)context).messages_to_send.size()-1,
                                                         ((wxSMTP&)context).GetNbRetryMessages(),
                                                         std::list<wxEmailMessage::Address>(),
                                                         std::list<wxEmailMessage::Address>(),
                                                         true,
                                                         shall_retry,
                                                         retry_delay,
                                                         shall_stop);

         /* Check if we shall retry sending process */
         if (shall_retry)
         {
            /* Format retry element */
            RetryInfo_t retry_info;
            retry_info.message = ((wxSMTP&)context).messages_to_send.front();
            retry_info.is_reconnection = false;
            retry_info.retry_time = wxDateTime::Now() + wxTimeSpan::Seconds(retry_delay);

            /* Search place where it will be inserted */
            std::list<RetryInfo_t>::iterator it = ((wxSMTP&)context).retry_messages_list.begin();
            while ((it != ((wxSMTP&)context).retry_messages_list.end()) &&
                   (it->retry_time < retry_info.retry_time))
            {
               it++;
            }
            ((wxSMTP&)context).retry_messages_list.insert(it, retry_info);
         }

         /* Remove it from messages list */
         ((wxSMTP&)context).messages_to_send.pop_front();

         /* Check if we shall stop */
         if (shall_stop)
         {
            ((wxSMTP&)context).disconnection_status = Listener::StatusUserAbort;
            context.ChangeState(g_quitState);
         }
         else
         {
            context.ChangeState(g_sendMailFromState);
         }
      }
   }
}
Пример #20
0
static u32 StrToU32(const wxString& str, int base = 10)
{
    unsigned long l;
    str.ToULong(&l, base);
    return l;
}
Пример #21
0
unsigned long WxStrToUL(const wxString& str)
{
  unsigned long value = 0;
  str.ToULong(&value);
  return value;
}