Exemple #1
0
/**
 * snmp_bc_close: 
 * @hnd: Pointer to handler structure.
 * 
 * Close an SNMP BladeCenter/RSA plugin handler instance.
 *
 * Returns:
 * Void
 **/
void snmp_bc_close(void *hnd)
{
        struct oh_handler_state *handle = (struct oh_handler_state *)hnd;
        oh_el_close(handle->elcache);

	if (is_simulator()) {
		sim_close();
	}
	else {
		struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data;

		/* FIXME:: Should we free handle->config - same question on A.1.1 code? */
		snmp_close(custom_handle->ss);
		/* Windows32 specific net-snmp cleanup (noop on unix) */
		SOCK_CLEANUP;
	}

	/* Cleanup event2hpi hash table */
	event2hpi_hash_free(handle);

	/* Cleanup str2event hash table */
	/* FIXME:: Add RSA free here */
	bc_xml2event_hash_use_count--;
	if (bc_xml2event_hash_use_count == 0) {
		xml2event_hash_free(&bc_xml2event_hash);
	}
}
Exemple #2
0
/**
 * snmp_bc_close: 
 * @hnd: Pointer to handler structure.
 * 
 * Close an SNMP BladeCenter/RSA plugin handler instance.
 *
 * Returns:
 * Void
 **/
void snmp_bc_close(void *hnd)
{
        struct oh_handler_state *handle = (struct oh_handler_state *)hnd;
        oh_el_close(handle->elcache);

	if (is_simulator()) {
		sim_close();
	}
	else {
		struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data;

		snmp_sess_close(custom_handle->sessp);
		/* Windows32 specific net-snmp cleanup (noop on unix) */
		SOCK_CLEANUP;
	}

	/* Cleanup event2hpi hash table */
	event2hpi_hash_free(handle);

	/* Cleanup errlog2event_hash table */
	errlog2event_hash_use_count--;
	if (errlog2event_hash_use_count == 0) {
		errlog2event_hash_free();
	}
}
Exemple #3
0
static void dev_close(enum device dev)
{
	if (dev == dev_wii) {
		wii_set_leds(&wii, 1, 0, 0, 0);
		wii_disconnect(&wii);			
		printf("Disconnected.\n");
		fflush(stdout);
		if (g_mode == graphical) {
			percentage += 0.1;
			if (percentage < 0.7) {
				update_gui("Gesture was created", percentage);
			} else {
				update_gui("Gesture was trained", percentage);
			}
		}
	} else if ((dev == dev_neo2) || (dev == dev_neo3)) 	{
		neo_close(&neo);
		printf("Closed.\n");
		fflush(stdout);
		if (g_mode == graphical) {
			percentage += 0.1;
			if (percentage < 0.7) {
				update_gui("Gesture was created", percentage);
			} else {
				update_gui("Gesture was trained", percentage);
			}
		}
	} else if (dev == dev_sim) {
		sim_close(&sim);
		printf("Closed.\n");
		fflush(stdout);
	}
}
Exemple #4
0
void snmp_bc_close(void *hnd)
{
        struct oh_handler_state *handle = (struct oh_handler_state *)hnd;
        oh_sel_close(handle->selcache);

	if (is_simulator()) {
		sim_close();
	}
	else {
		struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data;

		/* Should we free handle->config? */
		/* windows32 specific net-snmp cleanup (is a noop on unix) */
		snmp_close(custom_handle->ss);
		SOCK_CLEANUP;
	}

	/* Cleanup event2hpi hash table */
	event2hpi_hash_free(handle);

	/* Cleanup str2event hash table */
	str2event_use_count--;
	if (str2event_use_count == 0) 
		str2event_hash_free();

}
Exemple #5
0
int main(int argc, char **argv)
{
        SaErrorT err;
        SaHpiSessionIdT sessionid;

        err = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL);
        if (err) {
	  printf("  Error! Testcase failed. Line=%d\n", __LINE__);
	  printf("  Received error=%s\n", oh_lookup_error(err));
	  return -1;
        }
	// regular sim_init is part of saHpiSessionOpen, here we close it
	sim_close();
	// env variable OPENHPI_SIMTEST_FILE is now defined in Makefile.am
	// setenv("OPENHPI_SIMTEST_FILE","./sim_test_file", 1);
	// create hash table based on input file
	err = sim_file();
	if (err != SA_OK) {
	  printf(" Error! sim_file failed\n");
	  return -1;
	} 

	/****************** 
	 * End of testcases 
         ******************/

        err = saHpiSessionClose(sessionid);
        if (err) {
	  printf("Error! saHpiSessionClose: err=%d\n", err);
	  return -1;
        }

        return 0;
}
Exemple #6
0
int main(int argc, const char * argv[])
{
    n_int   counter = 0;

    printf(" --- test sim --- start -----------------------------------------------\n");
    
    sim_init(2, 0x12738291, MAP_AREA, 0);
    
    {
        noble_simulation * local_sim = sim_sim();
        noble_being      * first_being = &(local_sim->beings[0]);
        noble_being      * second_being = &(local_sim->beings[1]);
        noble_being_constant * first_being_constant = &(first_being->constant);
        noble_being_delta * first_being_delta = &(first_being->delta);
        noble_being_events * first_being_events = &(first_being->events);
        noble_being_brain * first_being_brain = &(first_being->braindata);
        noble_immune_system * first_being_immune = &(first_being->immune_system);
        noble_being_volatile * first_being_volatile = &(first_being->changes);
        
        n_uint being_hash1 = math_hash((n_byte *)first_being, sizeof(noble_being));
        n_uint being_constant_hash1 = math_hash((n_byte *)first_being_constant, sizeof(noble_being_constant));
        n_uint being_delta_hash1 = math_hash((n_byte *)first_being_delta, sizeof(noble_being_delta));
        n_uint being_events_hash1 = math_hash((n_byte *)first_being_events, sizeof(noble_being_events));
        n_uint being_brain_hash1 = math_hash((n_byte *)first_being_brain, sizeof(noble_being_brain));
        n_uint being_immune_hash1 = math_hash((n_byte*)first_being_immune, sizeof(noble_immune_system));
        n_uint being_volatile_hash1 = math_hash((n_byte*)first_being_volatile, sizeof(noble_being_volatile));

        while (counter < 1000)
        {
            sim_cycle();
            counter ++;
        }
 
        n_uint being_hash2 = math_hash((n_byte *)first_being, sizeof(noble_being));
        n_uint being_constant_hash2 = math_hash((n_byte *)first_being_constant, sizeof(noble_being_constant));
        n_uint being_delta_hash2 = math_hash((n_byte *)first_being_delta, sizeof(noble_being_delta));
        n_uint being_events_hash2 = math_hash((n_byte *)first_being_events, sizeof(noble_being_events));
        n_uint being_brain_hash2 = math_hash((n_byte *)first_being_brain, sizeof(noble_being_brain));
        n_uint being_immune_hash2 = math_hash((n_byte*)first_being_immune, sizeof(noble_immune_system));
        n_uint being_volatile_hash2 = math_hash((n_byte*)first_being_volatile, sizeof(noble_being_volatile));

        printf("hash %lx\n", being_hash1 ^ being_hash2);
        printf("constant %lx\n", being_constant_hash1 ^ being_constant_hash2);

        printf("delta %lx\n", being_delta_hash1 ^ being_delta_hash2);
        printf("events %lx\n", being_events_hash1 ^ being_events_hash2);

        printf("brain %lx\n", being_brain_hash1 ^ being_brain_hash2);
        printf("immune %lx\n", being_immune_hash1 ^ being_immune_hash2);

        printf("volatile %lx\n", being_volatile_hash1 ^ being_volatile_hash2);

    }
    sim_close();
    
    printf(" --- test sim ---  end  -----------------------------------------------\n");
    
    return 1;
}
Exemple #7
0
void snmp_bc_close(void *hnd)
{
        /*        struct oh_handler_state *handle = (struct oh_handler_state *)hnd;
        struct snmp_bc_hnd *custom_handle =
                (struct snmp_bc_hnd *)handle->data;
        */
        /* clean up the simulator */
        sim_close();
}
Exemple #8
0
static void
gdbsim_close (int quitting)
{
  if (sr_get_debug ())
    printf_filtered ("gdbsim_close: quitting %d\n", quitting);

  program_loaded = 0;

  if (gdbsim_desc != NULL)
    {
      sim_close (gdbsim_desc, quitting);
      gdbsim_desc = NULL;
    }

  end_callbacks ();
  generic_mourn_inferior ();
}
Exemple #9
0
static void
gdbsim_close (int quitting)
{
  if (remote_debug)
    printf_filtered ("gdbsim_close: quitting %d\n", quitting);

  program_loaded = 0;

  if (gdbsim_desc != NULL)
    {
      sim_close (gdbsim_desc, quitting);
      gdbsim_desc = NULL;
    }

  end_callbacks ();
  generic_mourn_inferior ();
  delete_thread_silent (remote_sim_ptid);
  delete_inferior_silent (ptid_get_pid (remote_sim_ptid));
}
Exemple #10
0
int command_line_run(void)
{
    printf("\n *** %sConsole, %s ***\n", SHORT_VERSION_NAME, FULL_DATE);
    printf("      For a list of commands type 'help'\n\n");
    
    sprintf(simulation_filename,"%s","realtime.txt");
    
#ifdef AUDIT_FILE
    audit();
#endif
    
    local_sim = sim_sim();
    io_command_line_execution_set();
    
    srand((unsigned int) time(NULL) );
    sim_init(KIND_START_UP, rand(), MAP_AREA, 0);
    
    cle_load(local_sim, (n_string)simulation_filename, io_console_out);
    
#ifndef    _WIN32
    do
    {
        sim_thread_console();
    }
    while (sim_thread_console_quit() == 0);
#else
    {
        n_int return_value = 0;
        do
        {
            return_value = io_console(local_sim,
                                      (noble_console_command *)control_commands,
                                      io_console_entry,
                                      io_console_out);
        }
        while (return_value == 0);
    }
#endif
    
    sim_close();
    
    return(1);
}
Exemple #11
0
/**
 * snmp_bc_close:
 * @hnd: Pointer to handler structure.
 *
 * Close an SNMP BladeCenter/RSA plugin handler instance.
 *
 * Returns:
 * Void
 **/
void snmp_bc_close(void *hnd)
{

    struct oh_handler_state *handle;

    if (!hnd) {
        dbg("INVALID PARM - NULL handle pointer.");
        return;
    }

    handle = (struct oh_handler_state *)hnd;
    oh_el_close(handle->elcache);

    if (is_simulator()) {
        sim_close();
    }
    else {
        struct snmp_bc_hnd *custom_handle = (struct snmp_bc_hnd *)handle->data;

        snmp_sess_close(custom_handle->sessp);
        /* Windows32 specific net-snmp cleanup (noop on unix) */
        SOCK_CLEANUP;
    }

    /* Cleanup event2hpi hash table */
    event2hpi_hash_free(handle);

    /* Cleanup errlog2event_hash table */
    errlog2event_hash_use_count--;
    if (errlog2event_hash_use_count == 0) {
        errlog2event_hash_free();
    }

    oh_flush_rpt(handle->rptcache);
    g_free(handle->rptcache);

}
Exemple #12
0
int
main (int argc, char **argv)
{
  char *name;
  char **prog_argv = NULL;
  struct bfd *prog_bfd;
  enum sim_stop reason;
  int sigrc = 0;
  int single_step = 0;
  RETSIGTYPE (*prev_sigint) ();

  myname = argv[0] + strlen (argv[0]);
  while (myname > argv[0] && myname[-1] != '/')
    --myname;

  /* INTERNAL: When MYNAME is `step', single step the simulator
     instead of allowing it to run free.  The sole purpose of this
     HACK is to allow the sim_resume interface's step argument to be
     tested without having to build/run gdb. */
  if (strlen (myname) > 4 && strcmp (myname - 4, "step") == 0)
    {
      single_step = 1;
    }

  /* Create an instance of the simulator.  */
  default_callback.init (&default_callback);
  sd = sim_open (SIM_OPEN_STANDALONE, &default_callback, NULL, argv);
  if (sd == 0)
    exit (1);
  if (STATE_MAGIC (sd) != SIM_MAGIC_NUMBER)
    {
      fprintf (stderr, "Internal error - bad magic number in simulator struct\n");
      abort ();
    }

  /* We can't set the endianness in the callback structure until
     sim_config is called, which happens in sim_open.  */
  default_callback.target_endian
    = (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN
       ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);

  /* Was there a program to run?  */
  prog_argv = STATE_PROG_ARGV (sd);
  prog_bfd = STATE_PROG_BFD (sd);
  if (prog_argv == NULL || *prog_argv == NULL)
    usage ();

  name = *prog_argv;

  /* For simulators that don't open prog during sim_open() */
  if (prog_bfd == NULL)
    {
      prog_bfd = bfd_openr (name, 0);
      if (prog_bfd == NULL)
	{
	  fprintf (stderr, "%s: can't open \"%s\": %s\n",
		   myname, name, bfd_errmsg (bfd_get_error ()));
	  exit (1);
	}
      if (!bfd_check_format (prog_bfd, bfd_object))
	{
	  fprintf (stderr, "%s: \"%s\" is not an object file: %s\n",
		   myname, name, bfd_errmsg (bfd_get_error ()));
	  exit (1);
	}
    }

  if (STATE_VERBOSE_P (sd))
    printf ("%s %s\n", myname, name);

  /* Load the program into the simulator.  */
  if (sim_load (sd, name, prog_bfd, 0) == SIM_RC_FAIL)
    exit (1);

  /* Prepare the program for execution.  */
#ifdef HAVE_ENVIRON
  sim_create_inferior (sd, prog_bfd, prog_argv, environ);
#else
  sim_create_inferior (sd, prog_bfd, prog_argv, NULL);
#endif

  /* To accommodate relative file paths, chdir to sysroot now.  We
     mustn't do this until BFD has opened the program, else we wouldn't
     find the executable if it has a relative file path.  */
  if (simulator_sysroot[0] != '\0' && chdir (simulator_sysroot) < 0)
    {
      fprintf (stderr, "%s: can't change directory to \"%s\"\n",
	       myname, simulator_sysroot);
      exit (1);
    }

  /* Run/Step the program.  */
  if (single_step)
    {
      do
	{
	  prev_sigint = signal (SIGINT, cntrl_c);
	  sim_resume (sd, 1/*step*/, 0);
	  signal (SIGINT, prev_sigint);
	  sim_stop_reason (sd, &reason, &sigrc);

	  if ((reason == sim_stopped) &&
	      (sigrc == sim_signal_to_host (sd, SIM_SIGINT)))
	    break; /* exit on control-C */
	}
      /* remain on breakpoint or signals in oe mode*/
      while (((reason == sim_signalled) &&
	      (sigrc == sim_signal_to_host (sd, SIM_SIGTRAP))) ||
	     ((reason == sim_stopped) &&
	      (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT)));
    }
  else
    {
      do
	{
#if defined (HAVE_SIGACTION) && defined (SA_RESTART)
	  struct sigaction sa, osa;
	  sa.sa_handler = cntrl_c;
	  sigemptyset (&sa.sa_mask);
	  sa.sa_flags = 0;
	  sigaction (SIGINT, &sa, &osa);
	  prev_sigint = osa.sa_handler;
#else
	  prev_sigint = signal (SIGINT, cntrl_c);
#endif
	  sim_resume (sd, 0, sigrc);
	  signal (SIGINT, prev_sigint);
	  sim_stop_reason (sd, &reason, &sigrc);

	  if ((reason == sim_stopped) &&
	      (sigrc == sim_signal_to_host (sd, SIM_SIGINT)))
	    break; /* exit on control-C */

	  /* remain on signals in oe mode */
	} while ((reason == sim_stopped) &&
		 (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT));

    }
  /* Print any stats the simulator collected.  */
  if (STATE_VERBOSE_P (sd))
    sim_info (sd, 0);

  /* Shutdown the simulator.  */
  sim_close (sd, 0);

  /* If reason is sim_exited, then sigrc holds the exit code which we want
     to return.  If reason is sim_stopped or sim_signalled, then sigrc holds
     the signal that the simulator received; we want to return that to
     indicate failure.  */

  /* Why did we stop? */
  switch (reason)
    {
    case sim_signalled:
    case sim_stopped:
      if (sigrc != 0)
        fprintf (stderr, "program stopped with signal %d.\n", sigrc);
      break;

    case sim_exited:
      break;

    default:
      fprintf (stderr, "program in undefined state (%d:%d)\n", reason, sigrc);
      break;

    }

  return sigrc;
}
Exemple #13
0
void
kill_inferior (void)
{
  sim_close (gdbsim_desc, 0);
  default_callback.shutdown (&default_callback);
}
Exemple #14
0
SaErrorT sim_init() 
{

	/* ------------------------------------------------ */
	/* snmpwalk-based simulator uses                    */
	/*        sim_file() and file sim_test_file         */
	/* sim_test_file is the output of snmpwalk command  */
	/* snmpwalk $host -On .1  (option -On is important) */
	/* ------------------------------------------------ */
	sim_file();
	
	/* ------------------------------------------------ */
	/* Old snmp_bc simulator uses                       */
	/*        followed code and file sim_resources.c    */
	/* If old method is desired,                        */
	/*    1) comment out sim_file() above               */
	/*    2) remove #if 0/#endif below                  */
	/* ------------------------------------------------ */	
	
#if 0
	int i;

	sim_hash = g_hash_table_new(g_str_hash, g_str_equal);
	if (sim_hash == NULL) {
		err("Cannot allocate simulation hash table");
		return(SA_ERR_HPI_INTERNAL_ERROR);
	}

	for (i=0; sim_resource_array[i].oid != NULL; i++) {
		
		char *key;
		char *key_exists;
		SnmpMibInfoT *mibinfo;
    
		key = g_strdup(sim_resource_array[i].oid);
		if (!key) {
			err("Cannot allocate memory for key for oid=%s",
			      sim_resource_array[i].oid);
			sim_close();
			return(SA_ERR_HPI_INTERNAL_ERROR);
		}
		mibinfo = g_malloc0(sizeof(SnmpMibInfoT));
		if (!mibinfo) {
			err("Cannot allocate memory for hash value for oid=%s", 
			      sim_resource_array[i].oid);
			sim_close();
			return(SA_ERR_HPI_INTERNAL_ERROR);
		}

		key_exists = g_hash_table_lookup(sim_hash, key); 
		if (!key_exists) {
			mibinfo->type = sim_resource_array[i].mib.type;

			switch (mibinfo->type) {
			case ASN_INTEGER:
				mibinfo->value.integer = sim_resource_array[i].mib.value.integer;
				break;
			case ASN_OCTET_STR:
				strcpy(mibinfo->value.string, sim_resource_array[i].mib.value.string);
				break;
			default:
				err("Unknown SNMP type=%d for oid=%s", mibinfo->type, key);
				return(SA_ERR_HPI_INTERNAL_ERROR);
			}
			g_hash_table_insert(sim_hash, key, mibinfo);
		}
		else {
			err("Oid %s is defined twice", sim_resource_array[i].oid);
		}
	}
#endif
	return(SA_OK);
}
Exemple #15
0
static int sim_init() {

	int i;

	dbg("************************************\n");
	dbg("****** Blade Center Simulator ******\n");
	dbg("************************************\n");

	sim_hash = g_hash_table_new(g_str_hash, g_str_equal);

	if (sim_hash == NULL) {
		dbg("Cannot allocate simulation hash table\n");
		return -1;
	}

	for (i=0; sim_resource_array[i].oid != NULL; i++) {
		
		char *key;
		char *key_exists;

		SnmpMibInfoT *mibinfo;
    
		key = g_strdup(sim_resource_array[i].oid);
		if (!key) {
			dbg("Cannot allocate memory for key for oid=%s\n",
			    sim_resource_array[i].oid);
			sim_close();
			return -1;
		}
		mibinfo = g_malloc0(sizeof(SnmpMibInfoT));
		if (!mibinfo) {
			dbg("Cannot allocate memory for hash value for oid=%s", 
			    sim_resource_array[i].oid);
			sim_close();
			return -1;
		}

		key_exists = g_hash_table_lookup(sim_hash, key); 
		if (!key_exists) {
			mibinfo->type = sim_resource_array[i].mib.type;

			switch (mibinfo->type) {
			case ASN_INTEGER:
				mibinfo->value.integer = sim_resource_array[i].mib.value.integer;
				break;
			case ASN_OCTET_STR:
				strcpy(mibinfo->value.string, sim_resource_array[i].mib.value.string);
				break;
			default:
				dbg("Unknown SNMP type=%d for oid=%s\n", mibinfo->type, key);
				return -1;
			}
			g_hash_table_insert(sim_hash, key, mibinfo);
		}
		else {
			dbg("WARNING: Oid %s is defined twice\n", sim_resource_array[i].oid);
		}
	}

	return 0;
}