Esempio n. 1
0
void
NetPrefsServerView::AddServer (const ServerData * data)
{
  BAutolock lock (Looper ());
  if (!lock.IsLocked ())
    return;

  BRow *row (new BRow);
  switch (data->state)
    {
      case SERVER_PRIMARY:
        row->SetField (new BStringField ("*"), 0);
        break;

      case SERVER_SECONDARY:
        row->SetField (new BStringField ("+"), 0);
        break;

      case SERVER_DISABLED:
        row->SetField (new BStringField ("-"), 0);
        break;
    }
  BString server ("");
  server = data->serverName;
  BStringField *serverField (new BStringField (server.String ()));
  row->SetField (serverField, 1);
  server = "";
  server << data->port;
  BStringField *portField (new BStringField (server.String ()));
  row->SetField (portField, 2);
  fServerList->AddRow (row);
}
Esempio n. 2
0
void
NetPrefsServerView::RemoveServer ()
{
  BAutolock lock (Looper ());

  if (!lock.IsLocked ())
    return;

  BRow *row (fServerList->CurrentSelection ());
  if (row)
  {
    BStringField *field ((BStringField *) row->GetField (1));

    int32 count;
    ssize_t size;
    type_code type;
    fActiveNetwork->GetInfo ("server", &type, &count);

    const ServerData *data;
    for (int32 i = 0; i < count; i++)
    {
      fActiveNetwork->FindData ("server", B_ANY_TYPE, i, reinterpret_cast < const void **>(&data),
        &size);

      if (!strcmp (data->serverName, field->String ()))
      {
        fActiveNetwork->RemoveData ("server", i);
        break;
      }
	}
    fServerList->RemoveRow (row);
    delete row;
  }
}
	void AutolockLooperTest::TestThread1(void)
{
	BAutolock *theAutolock = new BAutolock(theLooper);

	NextSubTest();
	CPPUNIT_ASSERT(theLooper->IsLocked());
	CPPUNIT_ASSERT(theLooper->LockingThread() == find_thread(NULL));
	CPPUNIT_ASSERT(theAutolock->IsLocked());
	
	NextSubTest();
	delete theAutolock;
	theAutolock = NULL;
	CPPUNIT_ASSERT(theLooper->LockingThread() != find_thread(NULL));
}
Esempio n. 4
0
void
NetPrefsServerView::SetNetworkData (BMessage * msg)
{
  // this shouldn't theoretically be able to happen but better safe than sorry
  BLooper *looper (Looper());
  if (looper == NULL)
    return;
  
  BAutolock lock (Looper ());
  if (!lock.IsLocked ())
    return;
  // clear previous servers (if any)
  while (fServerList->CountRows () > 0)
  {
    BRow *row (fServerList->RowAt (0));
    fServerList->RemoveRow (row);
    delete row;
  }

  BString netString (S_PREFSERVER_SEL_STRING);
  netString += msg->FindString ("name");
  netString += ":";
  type_code type;
  int32 count;
  ssize_t size;
  const ServerData *data;
  msg->GetInfo ("server", &type, &count);
  for (int32 i = 0; i < count; i++)
  {
    msg->FindData ("server", B_ANY_TYPE, i, reinterpret_cast < const void **>(&data), &size);
    AddServer (data);
  }
  fActiveNetwork = msg;
  fSelectTitleString->SetText (netString.String ());
  fSelectTitleString->ResizeToPreferred ();
}