コード例 #1
0
ファイル: message-test.c プロジェクト: chixq/snippets
void *
producer(void *arg)
{
  long i = 0;
  struct msg_category *mc;
  struct timeval tv;
  long long begin, end;

  block_sighup();

  __sync_add_and_fetch(&ready_threads, 1);

  while (ready_threads < THREAD_MAX)
    sched_yield();

  m_info("Go!");

  mc = message_get_category(arg);

  gettimeofday(&tv, NULL);
  begin = tv.tv_sec * 1000000 + tv.tv_usec;

  while (1) {
    i++;
    if (i % 100 == 0) {
      gettimeofday(&tv, NULL);
      end = tv.tv_sec * 1000000 + tv.tv_usec;

      if (end - begin > 5000000)
        break;
    }
    message_c(mc, (i % 5 + 1) * 100, "producing %ld", i);
#if 0
    //sleep(1);
    if (i % 100 == 0)
      sched_yield();
#endif  /* 0 */
  }
  message_unget_category(mc);
  m_info("END: %ld", i);

  pthread_exit(NULL);
  return NULL;
}
コード例 #2
0
ファイル: message-test.c プロジェクト: chixq/snippets
// kill -HUP `ps -ef | awk '$8 ~ /a\.out/ { print $2 }'`
int
main(int argc, char *argv[])
{
  if (argc > 1)
    message_init(argv[1], NULL);
  else
    message_init(NULL, NULL);

  message_thread_init(NULL);

  //mc_file = message_get_category("log");

#if 0
  mc_stdout = message_file_category("stdout", "/dev/stdout");
  mc_file = message_file_category("file", "msg.out");
  mc_sink = message_multiplex_category("multiplex",
                                       mc_stdout, mc_file, MC_DEFAULT, NULL);
  mc_sink->fmt_prologue = strdup("[%P:%h] (%t) ");
  mc_sink->fmt_time = strdup("%FT%T");

  m_info("hello");
  test_multiplex();
#endif  /* 0 */

  mc_mux = message_get_category("multi");

#if 1
  m_info("before multithreads..");
  test_multithreads("log");
  m_info("after multithreads..");
#endif  /* 0 */

  //benchmark(mc_file);
  message_unget_category(mc_mux);

  return 0;
}
コード例 #3
0
// --- Open ---
bool SndFileHandler::m_open(const char *in_medium, int mode)
{
	medium = (char*)in_medium;
	s_file = sf_open(medium, mode, &file_info);

	if (s_file != NULL)
	{
		// -- Static Frame Allocation --
		f = new MediumFrame;
		f->samples = new int16_t[AUDIO_BUFFER_SIZE * file_info.channels];

		m_info();
	}

	return (s_file != NULL);
}
コード例 #4
0
ファイル: u-blox.c プロジェクト: a1ien/nuttx
void ubxmdm_unregister(FAR void *handle)
{
  FAR struct ubxmdm_upper *upper;
  FAR struct ubxmdm_lower *lower;

  upper = (FAR struct ubxmdm_upper*) handle;
  lower = upper->lower;
  DEBUGASSERT(upper && lower);

  m_info("Unregistering: %s\n", upper->path);

  DEBUGASSERT(lower->ops->poweroff);
  (void) lower->ops->poweroff(lower);

  (void) unregister_driver(upper->path);

  kmm_free(upper->path);
  kmm_free(upper);
}
コード例 #5
0
CStarNetSet::CStarNetSet(wxWindow* parent, int id, const wxString& title, const wxString& band, const wxString& callsign, const wxString& logoff, const wxString& info, const wxString& permanent, unsigned int userTimeout, unsigned int groupTimeout, STARNET_CALLSIGN_SWITCH callsignSwitch, bool txMsgSwitch, const wxString& reflector) :
#else
CStarNetSet::CStarNetSet(wxWindow* parent, int id, const wxString& title, const wxString& band, const wxString& callsign, const wxString& logoff, const wxString& info, const wxString& permanent, unsigned int userTimeout, unsigned int groupTimeout, STARNET_CALLSIGN_SWITCH callsignSwitch, bool txMsgSwitch) :
#endif
wxPanel(parent, id),
m_title(title),
m_band(NULL),
m_callsign(NULL),
m_logoff(NULL),
m_info(NULL),
m_permanent(NULL),
m_userTimeout(NULL),
m_groupTimeout(NULL),
m_callsignSwitch(NULL),
m_txMsgSwitch(NULL)
#if defined(DEXTRA_LINK) || defined(DCS_LINK)
,m_reflector(NULL)
#endif
{
	wxFlexGridSizer* sizer = new wxFlexGridSizer(3);

	wxStaticText* bandLabel = new wxStaticText(this, -1, _("Band"));
	sizer->Add(bandLabel, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	m_band = new wxChoice(this, -1, wxDefaultPosition, wxSize(BAND_WIDTH, -1));
	m_band->Append(wxT("A"));
	m_band->Append(wxT("B"));
	m_band->Append(wxT("C"));
	m_band->Append(wxT("D"));
	sizer->Add(m_band, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);
	bool res = m_band->SetStringSelection(band);
	if (!res)
		m_band->SetSelection(0);

	wxStaticText* dummy1Label = new wxStaticText(this, -1, wxEmptyString);
	sizer->Add(dummy1Label, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	wxStaticText* callsignLabel = new wxStaticText(this, -1, _("Group Call"));
	sizer->Add(callsignLabel, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	wxString call = callsign;
	call.Truncate(LONG_CALLSIGN_LENGTH);

	m_callsign = new CCallsignTextCtrl(this, -1, call, wxDefaultPosition, wxSize(CALLSIGN_WIDTH, -1));
	m_callsign->SetMaxLength(LONG_CALLSIGN_LENGTH);
	sizer->Add(m_callsign, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);

	wxStaticText* dummy2Label = new wxStaticText(this, -1, wxEmptyString);
	sizer->Add(dummy2Label, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	wxStaticText* logoffLabel = new wxStaticText(this, -1, _("Logoff Call"));
	sizer->Add(logoffLabel, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	call = logoff;
	call.Truncate(LONG_CALLSIGN_LENGTH);

	m_logoff = new CCallsignTextCtrl(this, -1, call, wxDefaultPosition, wxSize(CALLSIGN_WIDTH, -1));
	m_logoff->SetMaxLength(LONG_CALLSIGN_LENGTH);
	sizer->Add(m_logoff, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);

	wxStaticText* dummy3Label = new wxStaticText(this, -1, wxEmptyString);
	sizer->Add(dummy3Label, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	wxStaticText* infoLabel = new wxStaticText(this, -1, _("Information"));
	sizer->Add(infoLabel, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	m_info = new wxTextCtrl(this, -1, info, wxDefaultPosition, wxSize(INFO_WIDTH, -1));
	m_info->SetMaxLength(INFO_LENGTH);
	sizer->Add(m_info, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);

	wxStaticText* dummy4Label = new wxStaticText(this, -1, wxEmptyString);
	sizer->Add(dummy4Label, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	wxStaticText* permanentLabel = new wxStaticText(this, -1, _("Permanent Call"));
	sizer->Add(permanentLabel, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	call = permanent;
	call.Truncate(LONG_CALLSIGN_LENGTH);

	m_permanent = new CCallsignTextCtrl(this, -1, call, wxDefaultPosition, wxSize(CALLSIGN_WIDTH, -1));
	m_permanent->SetMaxLength(LONG_CALLSIGN_LENGTH);
	sizer->Add(m_permanent, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);

	wxStaticText* dummy4ALabel = new wxStaticText(this, -1, wxEmptyString);
	sizer->Add(dummy4ALabel, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	wxStaticText* userTimeoutLabel = new wxStaticText(this, -1, _("User Timeout"));
	sizer->Add(userTimeoutLabel, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	m_userTimeout = new wxChoice(this, -1, wxDefaultPosition, wxSize(TIMEOUT_WIDTH, -1));
	m_userTimeout->Append(_("Never"));
	m_userTimeout->Append(_("30 mins"));
	m_userTimeout->Append(_("60 mins"));
	m_userTimeout->Append(_("120 mins"));
	m_userTimeout->Append(_("180 mins"));
	m_userTimeout->Append(_("240 mins"));
	m_userTimeout->Append(_("300 mins"));
	sizer->Add(m_userTimeout, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);

	switch (userTimeout) {
		case 0U:   m_userTimeout->SetSelection(0); break;
		case 30U:  m_userTimeout->SetSelection(1); break;
		case 60U:  m_userTimeout->SetSelection(2); break;
		case 120U: m_userTimeout->SetSelection(3); break;
		case 180U: m_userTimeout->SetSelection(4); break;
		case 240U: m_userTimeout->SetSelection(5); break;
		default:   m_userTimeout->SetSelection(6); break;
	}

	wxStaticText* dummy5Label = new wxStaticText(this, -1, wxEmptyString);
	sizer->Add(dummy5Label, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	wxStaticText* groupTimeoutLabel = new wxStaticText(this, -1, _("Group Timeout"));
	sizer->Add(groupTimeoutLabel, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	m_groupTimeout = new wxChoice(this, -1, wxDefaultPosition, wxSize(TIMEOUT_WIDTH, -1));
	m_groupTimeout->Append(_("Never"));
	m_groupTimeout->Append(_("30 mins"));
	m_groupTimeout->Append(_("60 mins"));
	m_groupTimeout->Append(_("120 mins"));
	m_groupTimeout->Append(_("180 mins"));
	m_groupTimeout->Append(_("240 mins"));
	m_groupTimeout->Append(_("300 mins"));
	sizer->Add(m_groupTimeout, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);

	switch (groupTimeout) {
		case 0U:   m_groupTimeout->SetSelection(0); break;
		case 30U:  m_groupTimeout->SetSelection(1); break;
		case 60U:  m_groupTimeout->SetSelection(2); break;
		case 120U: m_groupTimeout->SetSelection(3); break;
		case 180U: m_groupTimeout->SetSelection(4); break;
		case 240U: m_groupTimeout->SetSelection(5); break;
		default:   m_groupTimeout->SetSelection(6); break;
	}

	wxStaticText* dummy6Label = new wxStaticText(this, -1, wxEmptyString);
	sizer->Add(dummy6Label, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	wxStaticText* callsignSwitchLabel = new wxStaticText(this, -1, _("MYCALL Setting"));
	sizer->Add(callsignSwitchLabel, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	m_callsignSwitch = new wxChoice(this, -1, wxDefaultPosition, wxSize(CALLSIGN_WIDTH, -1));
	m_callsignSwitch->Append(_("Group"));
	m_callsignSwitch->Append(_("User"));
	sizer->Add(m_callsignSwitch, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);

	switch (callsignSwitch) {
		case SCS_GROUP_CALLSIGN: m_callsignSwitch->SetSelection(0); break;
		case SCS_USER_CALLSIGN:  m_callsignSwitch->SetSelection(1); break;
		default:                 m_callsignSwitch->SetSelection(0); break;
	}

	wxStaticText* dummy7Label = new wxStaticText(this, -1, wxEmptyString);
	sizer->Add(dummy7Label, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	wxStaticText* txMsgSwitchLabel = new wxStaticText(this, -1, _("TX Message"));
	sizer->Add(txMsgSwitchLabel, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

	m_txMsgSwitch = new wxChoice(this, -1, wxDefaultPosition, wxSize(CALLSIGN_WIDTH, -1));
	m_txMsgSwitch->Append(_("Off"));
	m_txMsgSwitch->Append(_("On"));
	sizer->Add(m_txMsgSwitch, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);
	m_txMsgSwitch->SetSelection(txMsgSwitch ? 1 : 0);

	wxStaticText* dummy8Label = new wxStaticText(this, -1, wxEmptyString);
	sizer->Add(dummy8Label, 0, wxALL | wxALIGN_RIGHT, BORDER_SIZE);

#if defined(DEXTRA_LINK)
	wxStaticText* reflectorLabel = new wxStaticText(this, -1, _("Reflector"));
	sizer->Add(reflectorLabel, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);

	m_reflector = new wxChoice(this, -1, wxDefaultPosition, wxSize(CONTROL_WIDTH1, -1));
	m_reflector->Append(_("None"));

	wxFileName fileName(wxFileName::GetHomeDir(), DEXTRA_HOSTS_FILE_NAME);
	if (!fileName.IsFileReadable()) {
		wxLogMessage(wxT("File %s not readable"), fileName.GetFullPath().c_str());
#if defined(__WINDOWS__)
		fileName.Assign(::wxGetCwd(), DEXTRA_HOSTS_FILE_NAME);
#else
		fileName.Assign(wxT(DATA_DIR), DEXTRA_HOSTS_FILE_NAME);
#endif
		if (!fileName.IsFileReadable())
			wxLogMessage(wxT("File %s not readable"), fileName.GetFullPath().c_str());
	}

	CHostFile file(fileName.GetFullPath(), false);

	for (unsigned int i = 0U; i < file.getCount(); i++)
		m_reflector->Append(file.getName(i));

	sizer->Add(m_reflector, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);

	if (reflector.IsEmpty()) {
		m_reflector->SetSelection(0);
	} else {
		wxString name = reflector;
		name.SetChar(LONG_CALLSIGN_LENGTH - 1U, wxT(' '));
		bool res = m_reflector->SetStringSelection(name);
		if (!res)
			m_reflector->SetSelection(0);
	}

	m_channel = new wxChoice(this, -1, wxDefaultPosition, wxSize(CONTROL_WIDTH2, -1));
	m_channel->Append(wxT("A"));
	m_channel->Append(wxT("B"));
	m_channel->Append(wxT("C"));
	m_channel->Append(wxT("D"));
	m_channel->Append(wxT("E"));
	sizer->Add(m_channel, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);
	res = m_channel->SetStringSelection(reflector.Right(1U));
	if (!res)
		m_channel->SetSelection(0);
#endif

#if defined(DCS_LINK)
	wxStaticText* reflectorLabel = new wxStaticText(this, -1, _("Reflector"));
	sizer->Add(reflectorLabel, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);

	m_reflector = new wxChoice(this, -1, wxDefaultPosition, wxSize(CONTROL_WIDTH1, -1));
	m_reflector->Append(_("None"));

	wxFileName fileName(wxFileName::GetHomeDir(), DCS_HOSTS_FILE_NAME);
	if (!fileName.IsFileReadable()) {
		wxLogMessage(wxT("File %s not readable"), fileName.GetFullPath().c_str());
#if defined(__WINDOWS__)
		fileName.Assign(::wxGetCwd(), DCS_HOSTS_FILE_NAME);
#else
		fileName.Assign(wxT(DATA_DIR), DCS_HOSTS_FILE_NAME);
#endif
		if (!fileName.IsFileReadable())
			wxLogMessage(wxT("File %s not readable"), fileName.GetFullPath().c_str());
	}

	CHostFile file(fileName.GetFullPath(), false);

	for (unsigned int i = 0U; i < file.getCount(); i++)
		m_reflector->Append(file.getName(i));

	sizer->Add(m_reflector, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);

	if (reflector.IsEmpty()) {
		m_reflector->SetSelection(0);
	} else {
		wxString name = reflector;
		name.SetChar(LONG_CALLSIGN_LENGTH - 1U, wxT(' '));
		bool res = m_reflector->SetStringSelection(name);
		if (!res)
			m_reflector->SetSelection(0);
	}

	m_channel = new wxChoice(this, -1, wxDefaultPosition, wxSize(CONTROL_WIDTH2, -1));
	m_channel->Append(wxT("A"));
	m_channel->Append(wxT("B"));
	m_channel->Append(wxT("C"));
	m_channel->Append(wxT("D"));
	m_channel->Append(wxT("E"));
	m_channel->Append(wxT("F"));
	m_channel->Append(wxT("G"));
	m_channel->Append(wxT("H"));
	m_channel->Append(wxT("I"));
	m_channel->Append(wxT("J"));
	m_channel->Append(wxT("K"));
	m_channel->Append(wxT("L"));
	m_channel->Append(wxT("M"));
	m_channel->Append(wxT("N"));
	m_channel->Append(wxT("O"));
	m_channel->Append(wxT("P"));
	m_channel->Append(wxT("Q"));
	m_channel->Append(wxT("R"));
	m_channel->Append(wxT("S"));
	m_channel->Append(wxT("T"));
	m_channel->Append(wxT("U"));
	m_channel->Append(wxT("V"));
	m_channel->Append(wxT("W"));
	m_channel->Append(wxT("X"));
	m_channel->Append(wxT("Y"));
	m_channel->Append(wxT("Z"));
	sizer->Add(m_channel, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE);
	res = m_channel->SetStringSelection(reflector.Right(1U));
	if (!res)
		m_channel->SetSelection(0);
#endif

	SetAutoLayout(true);

	SetSizer(sizer);
}


CStarNetSet::~CStarNetSet()
{
}

bool CStarNetSet::Validate()
{
	int n = m_band->GetCurrentSelection();
	if (n == wxNOT_FOUND) {
		wxMessageDialog dialog(this, _("The StarNet Band is not set"), m_title + _(" Error"), wxICON_ERROR);
		dialog.ShowModal();
		return false;
	}

	n = m_userTimeout->GetCurrentSelection();
	if (n == wxNOT_FOUND) {
		wxMessageDialog dialog(this, _("The StarNet user timeout is not set"), m_title + _(" Error"), wxICON_ERROR);
		dialog.ShowModal();
		return false;
	}

	n = m_groupTimeout->GetCurrentSelection();
	if (n == wxNOT_FOUND) {
		wxMessageDialog dialog(this, _("The StarNet group timeout is not set"), m_title + _(" Error"), wxICON_ERROR);
		dialog.ShowModal();
		return false;
	}

	n = m_callsignSwitch->GetCurrentSelection();
	if (n == wxNOT_FOUND) {
		wxMessageDialog dialog(this, _("The MYCALL Setting is not set"), m_title + _(" Error"), wxICON_ERROR);
		dialog.ShowModal();
		return false;
	}

	n = m_txMsgSwitch->GetCurrentSelection();
	if (n == wxNOT_FOUND) {
		wxMessageDialog dialog(this, _("The TX Message switch is not set"), m_title + _(" Error"), wxICON_ERROR);
		dialog.ShowModal();
		return false;
	}

#if defined(DEXTRA_LINK) || defined(DCS_LINK)
	n = m_reflector->GetCurrentSelection();
	if (n == wxNOT_FOUND) {
		wxMessageDialog dialog(this, _("The StarNet reflector link is not set"), m_title + _(" Error"), wxICON_ERROR);
		dialog.ShowModal();
		return false;
	}
#endif

	return true;
}
コード例 #6
0
ファイル: u-blox.c プロジェクト: a1ien/nuttx
static int ubxmdm_ioctl(FAR struct file* filep,
                        int cmd,
                        unsigned long arg)
{
  FAR struct inode*         inode = filep->f_inode;
  FAR struct ubxmdm_upper*  upper = inode->i_private;
  FAR struct ubxmdm_lower*  lower = upper->lower;
  int                       ret;
  FAR struct ubxmdm_status* status;

  m_info("cmd: %d arg: %ld\n", cmd, arg);
  DEBUGASSERT(upper && lower);

  switch (cmd)
    {
      /* cmd:         UBXMDM_IOC_START
       * Description:
       * arg:         Ignored
       */

    case MODEM_IOC_POWERON:
      if (lower->ops->poweron)
        {
          ret = lower->ops->poweron(lower);
        }
      else
        {
          ret = -ENOSYS;
        }

      break;

      /* cmd:         UBXMDM_IOC_STOP
       * Description:
       * arg:         Ignored
       */

    case MODEM_IOC_POWEROFF:
      if (lower->ops->poweroff)
        {
          ret = lower->ops->poweroff(lower);
        }
      else
        {
          ret = -ENOSYS;
        }

      break;

      /* cmd:         UBXMDM_IOC_RESET
       * Description:
       * arg:         Ignored
       */

    case MODEM_IOC_RESET:
      if (lower->ops->reset)
        {
          ret = lower->ops->reset(lower);
        }
      else
        {
          ret = -ENOSYS;
        }

      break;

      /* cmd:         UBXMDM_IOC_GETSTATUS
       * Description:
       * arg:         Writeable pointer to struct ubxmdm_status.
       */

    case MODEM_IOC_GETSTATUS:
      if (lower->ops->getstatus)
        {
          status = (FAR struct ubxmdm_status*) ((uintptr_t) arg);
          if (status)
            {
              ret = lower->ops->getstatus(lower, status);
            }
          else
            {
              ret = -EINVAL;
            }
        }
      else
        {
          ret = -ENOSYS;
        }

      break;

      /* Unrecognized IOCTL commands are forwarded to the lower-half IOCTL
       * handler, if defined.
       */

    default:
      m_info("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);

      if (lower->ops->ioctl)
        {
          ret = lower->ops->ioctl(lower, cmd, arg);
        }
      else
        {
          ret = -ENOSYS;
        }

      break;
    }

  return ret;
}