Пример #1
0
void env_cleanup() {
	int envState = kEnvCleanup;

	rlBufferClear(&theBuffer);
	rlSendBufferData(rlGetEnvironmentConnection(), &theBuffer, envState);

	rlBufferClear(&theBuffer);
	rlRecvBufferData(rlGetEnvironmentConnection(), &theBuffer, &envState);
	assert(envState == kEnvCleanup);

	rlBufferDestroy(&theBuffer);

	freeRLStructPointer(theObservation);
	theObservation=0;
	
	if (theTaskSpec != 0) {
		free(theTaskSpec);
		theTaskSpec = 0;
	}

	if (theOutMessage != 0) {
		free(theOutMessage);
		theOutMessage = 0;
	}
}
Пример #2
0
int main(int argc, char** argv) {
	int theConnection = 0;

	const char *usage = "The following environment variables are used by the agent to control its function:\n"
	  	"RLGLUE_HOST  : If set the agent will use this ip or hostname to connect to rather than %s\n"
		"RLGLUE_PORT  : If set the agent will use this port to connect on rather than %d\n";

	struct hostent *host_ent;

	char* host = kLocalHost;
	short port = kDefaultPort;

	char* envptr = 0;

	if (argc > 1) {
		fprintf(stderr, usage, kLocalHost, kDefaultPort);
		exit(1);
	}

	host = getenv("RLGLUE_HOST");
	if (host == 0) {
		host = kLocalHost;
	}

	envptr = getenv("RLGLUE_PORT");  
	if (envptr != 0) {
		port = strtol(envptr, 0, 10);
		if (port == 0) {
			port = kDefaultPort;
		}
	}

	if (isalpha(host[0])) {
		/*This method is apparently deprecated, we should update at some point*/
		host_ent = gethostbyname(host); 
		if(host_ent==0){
			fprintf(stderr,"Couldn't find IP address for host: %s\n",host);
			exit(55);
		}
	  	host = inet_ntoa(*(struct in_addr*)host_ent->h_addr_list[0]);
	}

	fprintf(stdout, "RL-Glue C Agent Codec Version %s, Build %s\n\tConnecting to host=%s on port=%d...\n", VERSION,__rlglue_get_codec_svn_version(),host, port);
	fflush(stdout);

/* Allocate what should be plenty of space for the buffer - it will dynamically resize if it is too small */
	rlBufferCreate(&theBuffer, 4096);

	theConnection = rlWaitForConnection(host, port, kRetryTimeout);
	fprintf(stdout, "\tRL-Glue C Agent Codec :: Connected\n");
	rlBufferClear(&theBuffer);
	rlSendBufferData(theConnection, &theBuffer, kAgentConnection);
	runAgentEventLoop(theConnection);
	rlClose(theConnection);

	rlBufferDestroy(&theBuffer);

	return 0;
}
Пример #3
0
void rlCloseEnvironmentConnection()
{
  rlBuffer theBuffer = {0};
  rlBufferCreate(&theBuffer, 8);
  rlSendBufferData(envConnection, &theBuffer, kRLTerm);

  rlClose(envConnection);
  envConnection = 0;

  rlBufferDestroy(&theBuffer);
}
Пример #4
0
/* Tell the agent that we're cleaning up */
void agent_cleanup() {
	int agentState = kAgentCleanup;

	rlBufferClear(&theBuffer);
	rlSendBufferData(rlGetAgentConnection(), &theBuffer, agentState);

	rlBufferClear(&theBuffer);
	rlRecvBufferData(rlGetAgentConnection(), &theBuffer, &agentState);
	assert(agentState == kAgentCleanup);

        rlBufferDestroy(&theBuffer);
	
	freeRLStructPointer(globalAction);
	globalAction=0;

	if (theOutMessage != 0) {
	  free(theOutMessage);
	  theOutMessage = 0;
	}
}
Пример #5
0
void cleanupExperimentAtExit(void)
{
  rlBufferDestroy(&clientexp_rlbuffer);
}