Ejemplo n.º 1
0
/* Callback invoked when ADB host socket gets disconnected. */
static void
_on_adb_host_disconnected(AdbHost* adb_host)
{
    AdbGuest* const adb_guest = adb_host->adb_guest;

    /* Notify the ADB guest that the host got disconnected. */
    if (adb_guest != NULL) {
        D("Disconnecting ADB host %p(so=%d) from ADB guest %p(o=%p)",
          adb_host, adb_host->host_so, adb_guest, adb_guest->opaque);
        adb_host->adb_guest = NULL;
        adb_guest->callbacks->on_disconnect(adb_guest->opaque, adb_guest);
        adb_guest->adb_host = NULL;
    } else {
        D("Disconnecting ADB host %p(so=%d)", adb_host, adb_host->host_so);
    }

    /* Destroy the host. */
    alist_remove(&adb_host->list_entry);
    _adb_host_free(adb_host);

    /* Remove the guest from the list. */
    if (adb_guest != NULL) {
        alist_remove(&adb_guest->list_entry);
    }
}
Ejemplo n.º 2
0
void exampleArrayList()
{
	ArrayList* l = newArrayList(4);

	alist_add(l, "Aye");
	alist_add(l, "Bee");
	alist_add(l, "Sea");
	alist_add(l, "Dee");
	alist_add(l, "Eee");
	alist_add(l, "Eff");
	alist_add(l, "Gee");
	alist_add(l, "Ach");
	alist_add(l, "Eye");
	alist_add(l, "Jay");
	alist_add(l, "Kay");
	alist_add(l, "Ell");

	printf("Size: %d\n", l->size);

	alist_traverseForward(l, &process);
	printf("\n");

	printf("Remove 'Sea'\n");
	alist_remove(l, "Sea", equals);
	alist_traverseForward(l, &process);
	printf("\n");

	printf("Remove at 0\n");
	alist_removeAt(l, 0);
	alist_traverseForward(l, &process);
	printf("\n");

	printf("Remove at size\n");
	alist_removeAt(l, l->size - 1);
	alist_traverseForward(l, &process);
	printf("\n");

	printf("Insert 'Aye' at 0\n");
	alist_insert(l, "Aye", 0);
	alist_traverseForward(l, &process);
	printf("\n");

	printf("Insert 'Ell' at size\n");
	alist_insert(l, "Ell", l->size);
	alist_traverseForward(l, &process);
	printf("\n");

	printf("Insert 'Sea' at 3\n");
	alist_insert(l, "Sea", 2);
	alist_traverseForward(l, &process);
	printf("\n");

	printf("0: '%s'\n", (char*)alist_get(l, 0));
	printf("3: '%s'\n", (char*)alist_get(l, 3));

	alist_free(l);
}
Ejemplo n.º 3
0
void
adb_server_on_guest_closed(void* opaque)
{
    AdbGuest* const adb_guest = (AdbGuest*)opaque;
    AdbHost* const adb_host = adb_guest->adb_host;

    /* Remove the guest from the list */
    if (!alist_is_empty(&adb_guest->list_entry)) {
        alist_remove(&adb_guest->list_entry);
    }

    /* Disassociate the host. */
    if (adb_host != NULL) {
        if (!alist_is_empty(&adb_host->list_entry)) {
            alist_remove(&adb_host->list_entry);
        }
        _adb_host_free(adb_host);
    }
    _adb_guest_free(adb_guest);
}
Ejemplo n.º 4
0
int see_move(int move, const board_t * board) {

   int att, def;
   int from, to;
   alists_t alists[1];
   int value, piece_value;
   int piece, capture;
   alist_t * alist;
   int pos;

   ASSERT(move_is_ok(move));
   ASSERT(board!=NULL);

   // init

   from = MOVE_FROM(move);
   to = MOVE_TO(move);

   // move the piece

   piece_value = 0;

   piece = board->square[from];
   ASSERT(piece_is_ok(piece));

   att = PIECE_COLOUR(piece);
   def = COLOUR_OPP(att);

   // promote

   if (MOVE_IS_PROMOTE(move)) {
      ASSERT(PIECE_IS_PAWN(piece));
      piece = move_promote(move);
      ASSERT(piece_is_ok(piece));
      ASSERT(COLOUR_IS(piece,att));
   }

   piece_value += VALUE_PIECE(piece);

   // clear attacker lists

   ALIST_CLEAR(alists->alist[Black]);
   ALIST_CLEAR(alists->alist[White]);

   // find hidden attackers

   alists_hidden(alists,board,from,to);

   // capture the piece

   value = 0;

   capture = board->square[to];

   if (capture != Empty) {

      ASSERT(piece_is_ok(capture));
      ASSERT(COLOUR_IS(capture,def));

      value += VALUE_PIECE(capture);
   }

   // promote

   if (MOVE_IS_PROMOTE(move)) {
      value += VALUE_PIECE(piece) - ValuePawn;
   }

   // en-passant

   if (MOVE_IS_EN_PASSANT(move)) {
      ASSERT(value==0);
      ASSERT(PIECE_IS_PAWN(board->square[SQUARE_EP_DUAL(to)]));
      value += ValuePawn;
      alists_hidden(alists,board,SQUARE_EP_DUAL(to),to);
   }

   // build defender list

   alist = alists->alist[def];

   alist_build(alist,board,to,def);
   if (alist->size == 0) return value; // no defender => stop SEE

   // build attacker list

   alist = alists->alist[att];

   alist_build(alist,board,to,att);

   // remove the moved piece (if it's an attacker)

   for (pos = 0; pos < alist->size && alist->square[pos] != from; pos++)
      ;

   if (pos < alist->size) alist_remove(alist,pos);

   // SEE search

   value -= see_rec(alists,board,def,to,piece_value);

   return value;
}
Ejemplo n.º 5
0
int stack_remove(stack_t* stack, void* e, comparefct_t compare) {
  return alist_remove(stack, e, compare);
}