bool agent_get_decryption_key(unsigned char key[KDF_HASH_LEN]) { char *disable_str; if (config_exists("plaintext_key")) { _cleanup_free_ char *key_buffer = NULL; if (config_read_buffer("plaintext_key", &key_buffer) == KDF_HASH_LEN) { _cleanup_free_ char *verify = config_read_encrypted_string("verify", (unsigned char *)key_buffer); if (!verify || strcmp(verify, AGENT_VERIFICATION_STRING)) goto badkey; memcpy(key, key_buffer, KDF_HASH_LEN); secure_clear(key_buffer, KDF_HASH_LEN); mlock(key, KDF_HASH_LEN); return true; } badkey: config_unlink("plaintext_key"); } if (!agent_ask(key)) { if (!agent_load_key(key)) return false; disable_str = getenv("LPASS_AGENT_DISABLE"); if (!disable_str || strcmp(disable_str, "1")) { agent_start(key); } } mlock(key, KDF_HASH_LEN); return true; }
/* Runs an entire episode. */ int performEpisode(int sd) { // Send the INIT command int rc = sendTokenOnSocket(sd, CMD_START); int terminal; double* pStates = (double*)malloc(numStates * sizeof(double)); double* pActions = (double*)malloc(numActions * sizeof(double)); double reward = 0; if(rc >= 0) { // Get terminality flag rc = getFlagFromSocket(sd, &terminal); } if(rc >= 0) { // Get initial states rc = getStatesFromSocket(sd, pStates); } if(rc >= 0) { if(terminal == 1) { // FIXME The reward here is still undefined... rc = agent_end(reward); } else { // Tell agent to start processing states and query // actions... rc = agent_start(pStates, pActions); while(terminal == 0 && rc >= 0) { // Send the step command with the new state rc = sendTokenOnSocket(sd, CMD_STEP); if(rc < 0) break; rc = sendActionsOnSocket(sd, pActions); if(rc < 0) break; // Get the reward, terminality flag and new state of // this step rc = getDoubleFromSocket(sd, &reward); if(rc < 0) break; rc = getFlagFromSocket(sd, &terminal); if(rc < 0) break; rc = getStatesFromSocket(sd, pStates); if(rc < 0) break; // If we are not in a terminal state, tell agent to step if(terminal == 0) rc = agent_step(pStates, reward, pActions); } if(rc >= 0) { // We have reached the terminal state (since there was // no error to get us out of the loop) rc = agent_end(reward); } } } return rc; }
void agent_save(const char *username, int iterations, unsigned const char key[KDF_HASH_LEN]) { _cleanup_free_ char *iterations_str = xultostr(iterations); config_write_string("iterations", iterations_str); config_write_string("username", username); config_write_encrypted_string("verify", AGENT_VERIFICATION_STRING, key); agent_start(key); }
void test_agent_start_stop(void) { lagopus_thread_t *t; lagopus_result_t ret; ret = agent_initialize((void *)dpmgr, &t); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_ALREADY_EXISTS, ret); ret = agent_start(); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_ALREADY_EXISTS, ret); ret = agent_stop(); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret); }
void test_agent_start_shutdown(void) { lagopus_thread_t *t; lagopus_result_t ret; ret = agent_initialize((void *)dpmgr, &t); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret); ret = agent_start(); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret); ret = agent_shutdown(SHUTDOWN_GRACEFULLY); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret); }
static void onAgentStart(int theConnection) { const action_t *theAction; unsigned int offset = 0; /* Read the data in the buffer (data from server) */ offset = rlCopyBufferToADT(&theBuffer, offset, &clientagent_observation); __RL_CHECK_STRUCT(&clientagent_observation) /* Call RL method on the recv'd data */ theAction = agent_start(&clientagent_observation); __RL_CHECK_STRUCT(theAction) /* Prepare the buffer for sending data back to the server */ rlBufferClear(&theBuffer); offset = 0; offset = rlCopyADTToBuffer(theAction, &theBuffer, offset); }
void SimulationLoop() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); test->SetTextLine(30); settings.hz = settingsHz; //////////////////////////////////////////////////////////////////////////////////////////// if(start==0){ last_state_main = env_start(); last_action_main = agent_start(last_state_main); start = 1; }else{ env_step1(last_action_main); test->Step(&settings); ro_main=env_step2(); if(ro_main->terminal == 1){ agent_end(ro_main->reward); start = 0; env_reset(); if(ro_main->reward==100){ success++; printf("success %d\tfail %d\tprob %lf\n",success,fail,(double)success/(double)(success+fail)*100); }else{ fail++; } //test->Step(&settings); }else{ last_action_main = agent_step(ro_main->reward, ro_main->observation); } } //////////////////////////////////////////////////////////////////////////////////////////// /*test->Step(&settings);*/ //////////////////////////////////////////////////////////////////////////////////////////// /*ro = env_step2(); this_reward = ro->reward; last_state = ro->observation; roa.reward = ro->reward; roa.observation = ro->observation; roa.terminal = ro->terminal;*/ //////////////////////////////////////////////////////////////////////////////////////////// test->DrawTitle(5, 15, entry->name); glutSwapBuffers(); if (testSelection != testIndex) { testIndex = testSelection; delete test; entry = g_testEntries + testIndex; test = entry->createFcn(); viewZoom = 1.0f; viewCenter.Set(0.0f, 20.0f); Resize(width, height); } }
/** * Main function */ int main(int argc, char **argv) { int opt = 0; comm_plugin = communication_plugin(); if (argc == 1) { opt = 1; } else if (argc == 2) { if (strstr(argv[1], "--help") != 0) { print_help(); exit(0); } else if (strstr(argv[1], "pulseoximeter") != 0) { opt = 1; } else if (strstr(argv[1], "bloodpressure") != 0) { opt = 2; } else if (strstr(argv[1], "weightscale") != 0) { opt = 3; } else if (strstr(argv[1], "glucometer") != 0) { opt = 4; } else { fprintf(stderr, "ERROR: invalid option: %s\n", argv[1]); fprintf(stderr, "Try `%s --help'" " for more information.\n", argv[0]); exit(1); } } else { fprintf(stderr, "ERROR: invalid option: %s\n", argv[1]); fprintf(stderr, "Try `%s --help'" " for more information.\n", argv[0]); exit(1); } tcp_mode(); fprintf(stderr, "\nIEEE 11073 sample agent\n"); comm_plugin.timer_count_timeout = timer_count_timeout; comm_plugin.timer_reset_timeout = timer_reset_timeout; CommunicationPlugin *plugins[] = {&comm_plugin, 0}; void *event_report_cb; int specialization; if (opt == 2) { /* Blood Pressure */ fprintf(stderr, "Starting Blood Pressure Agent\n"); event_report_cb = blood_pressure_event_report_cb; specialization = 0x02BC; } else if (opt == 3) { /* Weight Scale */ fprintf(stderr, "Starting Weight Scale Agent\n"); event_report_cb = weightscale_event_report_cb; specialization = 0x05DC; } else if (opt == 4) { /* Glucometer */ fprintf(stderr, "Starting Glucometer Agent\n"); event_report_cb = glucometer_event_report_cb; specialization = 0x06A4; } else { /* Default Pulse Oximeter */ fprintf(stderr, "Starting Pulse Oximeter Agent\n"); event_report_cb = oximeter_event_report_cb; // change to 0x0191 if you want timestamps specialization = 0x0190; } agent_init(plugins, specialization, event_report_cb, mds_data_cb); AgentListener listener = AGENT_LISTENER_EMPTY; listener.device_connected = &device_connected; listener.device_associated = &device_associated; listener.device_unavailable = &device_unavailable; agent_add_listener(listener); agent_start(); signal(SIGALRM, sigalrm); agent_connection_loop(CONTEXT_ID); agent_finalize(); return 0; }