Esempio n. 1
0
static void release_component(void *data)
{
    input_handler_s *input_handler = data;
    for(int i = 0; i < MAX_JOYSTICKS; i++)
    {
        array_release(input_handler->joysticks[i].axes);
        array_release(input_handler->joysticks[i].buttons);
    }
    free(input_handler);
}
Esempio n. 2
0
void closedown(struct running *rr) {
  log_debug(("closedown"));
  rotator_release(rr->rot);
  array_release(rr->src);
  array_release(rr->icc);
  assoc_release(rr->src_shop);
  assoc_release(rr->ic_shop);
  si_release(rr->si);
  event_del(rr->stat_timer);
  event_free(rr->stat_timer);
  event_del(rr->sigkill_timer);
  event_free(rr->sigkill_timer);
  evdns_base_free(rr->edb,1);
  event_base_free(rr->eb);
}
Esempio n. 3
0
DEFINEFN
bool PsycoLong_AsDouble(PsycoObject* po, vinfo_t* v, vinfo_t** vd1, vinfo_t** vd2)
{
	/* XXX implement me */
	vinfo_array_t* result;
	result = array_new(2);
	if (psyco_generic_call(po, cimpl_lng_as_double,
				  CfPyErrCheck,
				  "va", v, result) == NULL) {
		array_release(result);
		return false;
	}
        *vd1 = result->items[0];
        *vd2 = result->items[1]; 
	array_release(result);
	return true;
}
Esempio n. 4
0
void textures_release(void* textures) {
    char** keys = map_keys(textures);
    for (int i = 0; i < array_count(keys); i++) {
        char* key = keys[i];
        texture_t* texture = map_get(textures, key);
        free(texture);
    }
    array_release(keys);
}
Esempio n. 5
0
int rotate_log(struct rotator *rr,char *filename) {
  char *dir,*base,*oldname,*newname;
  DIR *dirh;
  struct dirent des,*de;
  struct array *names;
  struct assoc *changes,*orders;
  int order,i,n;

  dirbasename(filename,&dir,&base);
  log_debug(("Rotating in '%s'",dir));
  dirh = opendir(dir);
  if(!dirh) {
    log_error(("Could not rotate log file"));
    return 1;
  }
  names = array_create(type_free,0);
  changes = assoc_create(0,0,type_free,0);
  orders = assoc_create(0,0,type_free,0);
  while(1) {
    if(readdir_r(dirh,&des,&de)) {
      log_error(("Problem reading directory during log rotation"));
      break;
    }
    if(!de) { break; }
    order = matching_file(rr,filename,de->d_name,&newname);
    if(order == MATCH_IGNORE) { continue; }
    if(order == MATCH_DELETE) {
      log_debug(("delete %s",de->d_name));
      unlink(de->d_name);
    } else {
      oldname = strdup(de->d_name);
      array_insert(names,oldname);
      assoc_set(changes,oldname,newname);
      assoc_set(orders,oldname,make_int(order));
    }
  }
  if(closedir(dirh)) {
    log_error(("Could not closedir during log rotation!"));
    /* But continue: what else to do? */
  }
  array_sort(names,sort_names,orders);
  n = array_length(names);
  for(i=0;i<n;i++) {
    oldname = array_index(names,i);
    newname = assoc_lookup(changes,oldname);
    log_warn(("name=%s -> %s",oldname,newname));
    rename_file(rr,dir,oldname,newname);
  }
  assoc_release(changes);
  assoc_release(orders);
  array_release(names);
  free(dir);
  free(base);
  return 0;
}
Esempio n. 6
0
static void interfaces_quit(void *arg) {
  struct running *rr = (struct running *)arg;
  struct array *icc;

  log_debug(("All interfaces quit"));
  /* Release the interfaces */
  icc = rr->icc;
  rr->icc = array_create(0,0);
  array_release(icc);
  ref_release(&(rr->need_loop)); /* Ifs don't need event loop any more */
  sl_release(rr->sl); /* Don't need sources any more */
}
Esempio n. 7
0
void mesh_release(mesh_s *mesh)
{
    if(mesh->elements.buffer != 0)
        glDeleteBuffers(1, &mesh->elements.buffer);

    for(int i = 0; i < array_length(mesh->attributes); i++)
    {
        mesh_attribute_s *attribute = array_get_ptr(mesh->attributes) + i;
        free((char *)attribute->name);
        glDeleteBuffers(1, &attribute->buffer);
    }
    array_release(mesh->attributes);

    free(mesh);
}
Esempio n. 8
0
#include <stdio.h>
#include <event2/event.h>
#include <event2/thread.h>
#include <pthread.h>
#include <signal.h>
#include <string.h>

#include "running.h"
#include "jpf/jpf.h"
#include "config.h"
#include "util/misc.h"
#include "util/strbuf.h"
#include "util/array.h"
#include "util/assoc.h"
#include "util/path.h"
#include "util/logging.h"
#include "util/rotate.h"
#include "sourcelist.h"
#include "syncsource.h"
#include "syncif.h"
#include "source.h"
#include "interface.h"
#include "request.h"
#include "sources/http/http.h"
#include "sources/file2.h"
#include "sources/cache/file.h"
#include "sources/cache/mmap.h"
#include "sources/meta.h"
#include "interfaces/fuse.h"

CONFIG_LOGGING(running);

// XXX stats to sourcelist for sources
// XXX int numbers in jpf
// XXX nl in stats emission for clarity
// XXX leaks when mount fails
// XXX periodic hang-up-and-reopen
static void stat_timer_tick(evutil_socket_t fd,short what,void *arg) {
  struct running *rr = (struct running *)arg;
  struct source *src;
  struct interface *ic;
  struct jpf_value *out,*out_srcs,*out_src,*out_ics,*out_ic,*out_mem;
  struct jpf_callbacks jpf_emitter_cb;
  struct jpf_emitter jpf_emitter;
  char *time_str;
  int i;

  if(rr->stats_fd==-1) { return; }
  log_debug(("main stat collection loop"));
  out_srcs = jpfv_important_assoc(0);
  for(i=0;i<array_length(rr->src);i++) {
    src = (struct source *)array_index(rr->src,i);
    out_src = jpfv_assoc();
    src_global_stats(src,out_src);
    if(src->stats) { src->stats(src,out_src); }
    jpfv_assoc_add(out_srcs,src->name,out_src);
  }
  out_ics = jpfv_important_assoc(0);
  for(i=0;i<array_length(rr->icc);i++) {
    ic = (struct interface *)array_index(rr->icc,i);
    out_ic = jpfv_assoc();
    ic_global_stats(ic,out_ic);
    jpfv_assoc_add(out_ics,ic->name,out_ic);
  }
  out = jpfv_important_assoc(0);
  time_str= iso_localtime(0);
  jpfv_assoc_add(out,"time",jpfv_string(time_str));
  free(time_str);
  jpfv_assoc_add(out,"sources",out_srcs);
  jpfv_assoc_add(out,"interfaces",out_ics);
  out_mem = jpfv_important_array(1);
  jpfv_array_add(out_mem,out);
  jpf_emit_fd(&jpf_emitter_cb,&jpf_emitter,rr->stats_fd);
  jpf_emit_df(out_mem,&jpf_emitter_cb,&jpf_emitter);
  jpf_emit_done(&jpf_emitter);
  jpfv_free(out_mem);
}

static void do_exit(void *eb) {
  log_info(("All interfaces have exited: stopping event loop"));
  event_base_loopexit((struct event_base *)eb,0);
}

static void sigkill_self(evutil_socket_t fd,short what,void *arg) {
  log_warn(("Did not quit nicely, sending SIGKILL to self"));
  kill(getpid(),SIGKILL);
}

// XXX cond for regular exit
// XXX -9 after delay
#define SIGKILL_DELAY 90 /* sec */
static void user_quit(evutil_socket_t fd,short what,void *arg) {
  struct running *rr = (struct running *)arg;
  int i;
  struct array *icc;
  struct timeval sigkill_delay = { SIGKILL_DELAY, 0 };

  icc = rr->icc;
  array_acquire(icc);
  log_info(("Sending quit to interfaces (%d)",array_length(icc)));
  for(i=0;i<array_length(icc);i++) {
    ic_quit((struct interface *)array_index(icc,i));
  }
  array_release(icc);
  event_del(rr->stat_timer);
  event_add(rr->sigkill_timer,&sigkill_delay);
}
Esempio n. 9
0
static AstarArray* search(AstarNode *current, int dst, Set *open_set, Set *close_set, void *ud) {
    AstarArray *adjs = NULL;
    if (!current)
        return NULL;

    adjs = get_adjs(ud, current->index);
    int j;
    for (j = 0; j < adjs->len; j++) {
        int i = adjs->arr[j];

        if (i == dst) {
            return path_backtrace(current, dst);
        }

        if (set_find(close_set, i) != -1)
            continue;
        int new_g = gscore(ud, current->index, i) + current->g;

        int index;
        if ((index = set_find(open_set, i)) != -1) {
            AstarNode *node = set_index(open_set, index);
            if (node->g < new_g) {
                continue;
            }
            node->g = new_g;
            node->parent = current;
            set_bubble(open_set, index);
        } else {
            AstarNode *node = create_node(ud, i, dst, current);
            set_insert(open_set, node);
        }
    }
    array_release(&adjs);
    int x = current->index % 30;
    int y = current->index / 30;
    printf("current is %d %d\n",x,y );
    fflush(stdout);
    set_push(close_set, current);
    AstarNode *next = set_pop(open_set);
    return search(next, dst, open_set, close_set, ud);
}
Esempio n. 10
0
void array_release_v(void *a) { array_release((struct array *)a); }
Esempio n. 11
0
void test_array(void)
{
  int i;
  double* d;
  void* A = array_create(0);
  fprintf(stdout, "call function : %s\n", __func__);
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_push_back ===>\n");
  {
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      NEW0(d);
      *d = (i + 1) * (i + 1) * rand() % 5555 * 0.123;
      fprintf(stdout, "\tappend into array {object=>0x%p, value=>%.3f}\n", d, *d);
      array_push_back(A, d);
    }
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    array_for_each(A, array_element_destroy, NULL);
    array_object_show(A);
    array_clear(A);
  }
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_pop_back ===>\n");
  {
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      NEW0(d);
      *d = (i + 1) * (i + 1) * rand() % 5555 * 0.123;
      fprintf(stdout, "\tappend into array {object=>0x%p, value=>%.3f}\n", d, *d);
      array_push_back(A, d);
    }
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    d = (double*)array_pop_back(A);
    fprintf(stdout, "  the pop element {object=>0x%p,value=>%.3f}\n", d, *d);
    FREE(d);
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    array_for_each(A, array_element_destroy, NULL);
    array_object_show(A);
    array_clear(A);
  }
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_erase ===>\n");
  {
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      NEW0(d);
      *d = (i + 1) * (i + 1) * rand() % 5555 * 0.123;
      fprintf(stdout, "\tappend into array {object=>0x%p, value=>%.3f}\n", d, *d);
      array_push_back(A, d);
    }
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    d = (double*)array_erase(A, array_begin(A));
    fprintf(stdout, "  the erased begin element {object=>0x%p,value=>%.3f}\n", d, *d);
    FREE(d);
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);
    d = (double*)array_erase(A, array_end(A));
    fprintf(stdout, "  the erased end element {object=>0x%p,value=>%.3f}\n", d, *d);
    FREE(d);
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    array_for_each(A, array_element_destroy, NULL);
    array_object_show(A);
    array_clear(A);
  }
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_remove ===>\n");
  {
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      NEW0(d);
      *d = (i + 1) * (i + 1) * rand() % 5555 * 0.123;
      fprintf(stdout, "\tappend into array {object=>0x%p, value=>%.3f}\n", d, *d);
      array_push_back(A, d);
    }
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    d = (double*)array_remove(A, 3);
    fprintf(stdout, "  the removed [3] -> {object=>0x%p,value=>%.3f}\n", d, *d);
    FREE(d);
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    array_for_each(A, array_element_destroy, NULL);
    array_object_show(A);
    array_clear(A);
  }
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_copy ===>\n");
  {
    void* copy_A;
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      NEW0(d);
      *d = (i + 1) * (i + 1) * rand() % 5555 * 0.123;
      fprintf(stdout, "\tappend into array {object=>0x%p, value=>%.3f}\n", d, *d);
      array_push_back(A, d);
    }
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    copy_A = array_copy(A, 10);
    array_object_show(copy_A);
    array_for_each(copy_A, array_element_display, NULL);
    array_release(&copy_A);

    array_for_each(A, array_element_destroy, NULL);
    array_clear(A);
  }
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_resize ===>\n");
  {
    srand((unsigned int)time(0));
    for (i = 0; i < 5; ++i)
    {
      NEW0(d);
      *d = (i + 1) * (i + 1) * rand() % 5555 * 0.123;
      fprintf(stdout, "\tappend into array {object=>0x%p, value=>%.3f}\n", d, *d);
      array_push_back(A, d);
    }
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    array_resize(A, 20);
    array_object_show(A);
    array_for_each(A, array_element_display, NULL);

    array_for_each(A, array_element_destroy, NULL);
    array_clear(A);
  }
  array_object_show(A);

  fprintf(stdout, "\ntest function - array_release ===>\n");
  array_release(&A);
  array_object_show(A);
}