Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 186080
Collapse All | Expand All

(-)src-native/src/ACCollector/ACCollector.cpp (-2 / +2 lines)
Lines 1-5 Link Here
1
/************************************************************************
1
/************************************************************************
2
 * Copyright (c) 2005, 2007 Intel Corporation.
2
 * Copyright (c) 2005, 2008 Intel Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 368-374 Link Here
368
    //No command line args hence the env to be picked up.
368
    //No command line args hence the env to be picked up.
369
    this->processCommandLine(0, cargv);
369
    this->processCommandLine(0, cargv);
370
    
370
    
371
    this->registerAgent();
371
    this->asyncRegisterAgent();
372
    if (isControlled) {
372
    if (isControlled) {
373
        while(m_isWaiting) {
373
        while(m_isWaiting) {
374
            Sleep(100);
374
            Sleep(100);
(-)src-native-new/include/tptp/agents/BaseAgentImpl.h (-2 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005-2006 Intel Corporation.
2
 * Copyright (c) 2005-2008 Intel Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 114-123 Link Here
114
		BaseAgentImpl(char* name);
114
		BaseAgentImpl(char* name);
115
		virtual ~BaseAgentImpl();
115
		virtual ~BaseAgentImpl();
116
		int registerAgent();
116
		int registerAgent();
117
		int asyncRegisterAgent();
117
		int deRegisterAgent();
118
		int deRegisterAgent();
118
		int initialize();
119
		int initialize();
119
		virtual int preRegisterInitialization();
120
		virtual int preRegisterInitialization();
120
		void waitForTermination();
121
		void waitForTermination();
122
		static THREAD_USER_FUNC_RET_TYPE registerFunc(void* arg);
121
		static THREAD_USER_FUNC_RET_TYPE handleMessages(void* args);
123
		static THREAD_USER_FUNC_RET_TYPE handleMessages(void* args);
122
		int processRecdMessages(char* buffer, int bytesRead);
124
		int processRecdMessages(char* buffer, int bytesRead);
123
		int processOneMessage(char* buffer);
125
		int processOneMessage(char* buffer);
Lines 201-212 Link Here
201
		                    tptp_int32   lineNum, 
203
		                    tptp_int32   lineNum, 
202
		                    tptp_int32   severity, 
204
		                    tptp_int32   severity, 
203
		                    tptp_string* event );
205
		                    tptp_string* event );
206
		int getAgentRegistrationStatus();
204
207
205
	protected:
208
	protected:
206
		char* _serviceConfigFile;
209
		char* _serviceConfigFile;
207
		char* _raMasterAddress;
210
		char* _raMasterAddress;
208
		char* _raShmBufNameRoot;
211
		char* _raShmBufNameRoot;
209
212
		int registrationStatus;
210
};
213
};
211
214
212
#endif /* __BASEAGENTIMPL_H__ */
215
#endif /* __BASEAGENTIMPL_H__ */
(-)src-native-new/src/agents/agentBase/BaseAgentImpl.cpp (-37 / +66 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 Intel Corporation.
2
 * Copyright (c) 2005, 2008 Intel Corporation.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 280-288 Link Here
280
	return _serviceConfigFile;
280
	return _serviceConfigFile;
281
}
281
}
282
282
283
// registerAgent() establishes a private connection with the Agent Controller
283
284
// and creates a thread to get messages coming in from that connection. Does not
284
// asyncRegisterAgent() establishes a private connection with the Agent Controller
285
// return until the AC's agentRegistered response is received.
285
// and creates a thread to get messages coming in from that connection. It is 
286
// asynchronous method and returns immediately. 
287
// registerFunc executed in dedicated thread and waits until the AC's agentRegistered
288
// response is received.
289
int BaseAgentImpl::asyncRegisterAgent()
290
{
291
	TPTP_HANDLE registerThreadHandle;
292
	TID registerThreadID;
293
	startNewThread(registerFunc, (void *) this, &registerThreadID, &registerThreadHandle);
294
	return 0;
295
}
296
297
// registerFunc register agent at AC.
298
// Does not return until the AC's agentRegistered response is received.
286
//
299
//
287
// 1) Creates a named pipe which this agent will use to receive commands
300
// 1) Creates a named pipe which this agent will use to receive commands
288
// coming from the Agent Controller process. This pipe cannot be used to send
301
// coming from the Agent Controller process. This pipe cannot be used to send
Lines 294-304 Link Here
294
// response being received on the handleMessages thread.
307
// response being received on the handleMessages thread.
295
// 4) Sends a registerAgent command to the AC which will result in a agentRegistered response
308
// 4) Sends a registerAgent command to the AC which will result in a agentRegistered response
296
// being received on the handleMessages thread.
309
// being received on the handleMessages thread.
297
//
310
THREAD_USER_FUNC_RET_TYPE  BaseAgentImpl::registerFunc(void* arg)
298
// returns 0 if successful
299
int BaseAgentImpl::registerAgent()
300
{
311
{
301
312
    BaseAgentImpl* agent = (BaseAgentImpl*)arg;
313
    agent->registrationStatus = -1;
302
	char commandFormat[] = "<Cmd src=\"%d\" dest=\"%d\" ctxt=\"%d\"> <registerAgent iid=\"org.eclipse.tptp.agentManager\"><agentID>%d</agentID><processID>%lu</processID><agentName>%s</agentName></registerAgent></Cmd>";
314
	char commandFormat[] = "<Cmd src=\"%d\" dest=\"%d\" ctxt=\"%d\"> <registerAgent iid=\"org.eclipse.tptp.agentManager\"><agentID>%d</agentID><processID>%lu</processID><agentName>%s</agentName></registerAgent></Cmd>";
303
	char command[BUFFER_LENGTH];
315
	char command[BUFFER_LENGTH];
304
	PID agentProcessID;
316
	PID agentProcessID;
Lines 307-344 Link Here
307
319
308
	// Initialize semaphores that handleMessages() thread will use to let us know
320
	// Initialize semaphores that handleMessages() thread will use to let us know
309
	// when replies arrive from the AC during this registration process.
321
	// when replies arrive from the AC during this registration process.
310
	rc = tptp_initializeSemaphore(&registerAgentConnectedSem);
322
	rc = tptp_initializeSemaphore(&(agent->registerAgentConnectedSem));
311
	if (rc != 0)
323
	if (rc != 0)
312
	{
324
	{
313
		TPTP_LOG_ERROR_MSG(this, "BaseAgent registerAgent: Error - Exiting, failed to create synch event for registerAgentConnected.");
325
		TPTP_LOG_ERROR_MSG(agent, "BaseAgent registerFunc: Error - Exiting, failed to create synch event for registerAgentConnected.");
314
		return -1;
326
		return -1;
315
	}
327
	}
316
328
317
	rc = tptp_initializeSemaphore(&registerAgentCompletedSem);
329
	rc = tptp_initializeSemaphore(&(agent->registerAgentCompletedSem));
318
	if (rc != 0)
330
	if (rc != 0)
319
	{
331
	{
320
		TPTP_LOG_ERROR_MSG(this, "BaseAgent registerAgent: Error - Exiting, failed to create synch event for registerAgentConnected.");
332
		TPTP_LOG_ERROR_MSG(agent, "BaseAgent registerFunc: Error - Exiting, failed to create synch event for registerAgentConnected.");
321
		return -1;
333
		return -1;
322
	}
334
	}
323
335
324
	initializeAgentConfiguration(getServiceConfigFile());
336
	agent->initializeAgentConfiguration(agent->getServiceConfigFile());
325
337
326
	// generate the unique id string for the pipe name
338
	// generate the unique id string for the pipe name
327
	pUniqueId = generateUUID() ;
339
	pUniqueId = generateUUID() ;
328
340
329
	//Create the named pipe that we will use to get msgs from the AC.
341
	//Create the named pipe that we will use to get msgs from the AC.
330
	agentPipeName = (char*)tptp_malloc(strlen(RA_PIPE_NAMESPACE) + strlen(pUniqueId) +1);
342
	agent->agentPipeName = (char*)tptp_malloc(strlen(RA_PIPE_NAMESPACE) + strlen(pUniqueId) +1);
331
	sprintf(agentPipeName, "%s%s", RA_PIPE_NAMESPACE, pUniqueId);
343
	sprintf(agent->agentPipeName, "%s%s", RA_PIPE_NAMESPACE, pUniqueId);
332
	agentNamedPipeHandle = createReadOnlyNamedPipe(RA_PIPE_NAMESPACE, pUniqueId, FALSE) ;
344
	agent->agentNamedPipeHandle = createReadOnlyNamedPipe(RA_PIPE_NAMESPACE, pUniqueId, FALSE) ;
333
	if (agentNamedPipeHandle != INVALID_HANDLE_VALUE)
345
	if (agent->agentNamedPipeHandle != INVALID_HANDLE_VALUE)
334
	{
346
	{
335
		TPTP_LOG_DEBUG_MSG1(this, "BaseAgent registerAgent: Created Agent Named Pipe - %s", agentPipeName);
347
		TPTP_LOG_DEBUG_MSG1(agent, "BaseAgent registerFunc: Created Agent Named Pipe - %s", agent->agentPipeName);
336
	}
348
	}
337
	else
349
	else
338
	{
350
	{
339
		TPTP_LOG_ERROR_MSG1(this, "Error creating Named Pipe - %s", agentPipeName);
351
		TPTP_LOG_ERROR_MSG1(agent, "Error creating Named Pipe - %s", agent->agentPipeName);
340
		// TODO: Send ERROR response; do cleanup
352
		// TODO: Send ERROR response; do cleanup
341
		if (agentPipeName) {tptp_free(agentPipeName); agentPipeName=0;}
353
		if (agent->agentPipeName) {tptp_free(agent->agentPipeName); agent->agentPipeName=0;}
342
		return -1;
354
		return -1;
343
	}
355
	}
344
356
Lines 346-404 Link Here
346
358
347
359
348
	//Start Listening to the named pipe
360
	//Start Listening to the named pipe
349
	TPTP_LOG_DEBUG_MSG(this, "Starting the Listener thread...");
361
	TPTP_LOG_DEBUG_MSG(agent, "Starting the Listener thread...");
350
	startNewThread(handleMessages, (void *) this, &msgHandlerThreadID, &msgHandlerThreadHandle);
362
	startNewThread(handleMessages, (void *) agent, &(agent->msgHandlerThreadID), &(agent->msgHandlerThreadHandle));
351
363
352
	// Tell the AC to connect to this pipe - it knows how to form the name of our pipe
364
	// Tell the AC to connect to this pipe - it knows how to form the name of our pipe
353
	// by using the unique id string we generated.
365
	// by using the unique id string we generated.
354
	rc = sendCONNECTCommand(pUniqueId) ;
366
	rc = agent->sendCONNECTCommand(pUniqueId) ;
355
	if (rc != 0)
367
	if (rc != 0)
356
	{
368
	{
357
		TPTP_LOG_ERROR_MSG1(this, "Error: Attempt to send CONNECT to AC failed (unique ID:""%s"")", pUniqueId );
369
		TPTP_LOG_ERROR_MSG1(agent, "Error: Attempt to send CONNECT to AC failed (unique ID:""%s"")", pUniqueId );
358
		//TODO: Send ERROR; do cleanup
370
		//TODO: Send ERROR; do cleanup
359
		if (agentPipeName) {tptp_free(agentPipeName); agentPipeName=0;}
371
		if (agent->agentPipeName) {tptp_free(agent->agentPipeName); agent->agentPipeName=0;}
360
		CLOSE_TPTP_HANDLE(agentNamedPipeHandle);
372
		CLOSE_TPTP_HANDLE(agent->agentNamedPipeHandle);
361
		return -1;
373
		return -1;
362
	}
374
	}
363
375
364
	// Wait for the handleMessages thread to get a response to the CONNECT request.
376
	// Wait for the handleMessages thread to get a response to the CONNECT request.
365
	rc = tptp_waitSemaphore(&registerAgentConnectedSem);
377
	rc = tptp_waitSemaphore(&(agent->registerAgentConnectedSem));
366
	if (rc != 0)
378
	if (rc != 0)
367
	{
379
	{
368
		TPTP_LOG_ERROR_MSG(this, "BaseAgent registerAgent: Error - wait for registerAgentConnected failed.");
380
		TPTP_LOG_ERROR_MSG(agent, "BaseAgent registerFunc: Error - wait for registerAgentConnected failed.");
369
		return -1;
381
		return -1;
370
	}
382
	}
371
383
372
	TPTP_LOG_DEBUG_MSG1(this, "BaseAgent registerAgent: Agent (%s) connected to AC ", agentName);
384
	TPTP_LOG_DEBUG_MSG1(agent, "BaseAgent registerFunc: Agent (%s) connected to AC ", agent->agentName);
373
	
385
	
374
	// Do pre-registration initialization.  That is, initialization
386
	// Do pre-registration initialization.  That is, initialization
375
	// that requires the AC communication path to be setup but before the agent advertises
387
	// that requires the AC communication path to be setup but before the agent advertises
376
	// that it is here and ready to interact with others - which the registerAgent cmd
388
	// that it is here and ready to interact with others - which the registerAgent cmd
377
	// will do.
389
	// will do.
378
	preRegisterInitialization();
390
	agent->preRegisterInitialization();
379
391
380
	//Send a register message to the AC named pipe
392
	//Send a register message to the AC named pipe
381
	agentProcessID = getCurrentlyRunningProcessId();
393
	agentProcessID = getCurrentlyRunningProcessId();
382
394
383
	sprintf( command, commandFormat, agentID, getAgentControllerID(), getNextContext(), agentID, agentProcessID, agentName);		
395
	sprintf( command, commandFormat, agent->agentID, agent->getAgentControllerID(), agent->getNextContext(), agent->agentID, agentProcessID, agent->agentName);		
384
396
385
	rc = sendCommand((char*)command);  //TODO: Check return code
397
	rc = agent->sendCommand((char*)command);  //TODO: Check return code
386
398
387
	// Wait for a reply to the registerAgent command we just sent to the AC.
399
	// Wait for a reply to the registerAgent command we just sent to the AC.
388
	// When msg handling thread gets it, registration is complete.
400
	// When msg handling thread gets it, registration is complete.
389
	rc = tptp_waitSemaphore(&registerAgentCompletedSem);
401
	rc = tptp_waitSemaphore(&(agent->registerAgentCompletedSem));
390
	if (rc != 0)
402
	if (rc != 0)
391
	{
403
	{
392
		TPTP_LOG_ERROR_MSG(this, "BaseAgent registerAgent: Error - wait for registerAgentCompleted failed.");
404
		TPTP_LOG_ERROR_MSG(agent, "BaseAgent registerFunc: Error - wait for registerAgentCompleted failed.");
393
		return -1;
405
		return -1;
394
	}
406
	}
395
407
396
	TPTP_LOG_DEBUG_MSG1(this, "BaseAgent registerAgent: Agent register with AC completed (%s)", agentName);
408
	TPTP_LOG_DEBUG_MSG1(agent, "BaseAgent registerFunc: Agent register with AC completed (%s)", agent->agentName);
397
	tptp_deleteSemaphore(&registerAgentConnectedSem);
409
	tptp_deleteSemaphore(&(agent->registerAgentConnectedSem));
398
	tptp_deleteSemaphore(&registerAgentCompletedSem);
410
	tptp_deleteSemaphore(&(agent->registerAgentCompletedSem));
411
	agent->registrationStatus = 0;
399
	return 0;
412
	return 0;
400
}
413
}
401
414
415
int BaseAgentImpl::getAgentRegistrationStatus()
416
{
417
    return (registrationStatus);
418
}
419
420
421
// registerAgent() establishes a private connection with the Agent Controller
422
// and creates a thread to get messages coming in from that connection. Does not
423
// return until the AC's agentRegistered response is received.
424
// returns 0 if successful
425
int BaseAgentImpl::registerAgent()
426
{
427
	registerFunc(this);
428
	return getAgentRegistrationStatus();
429
}
430
402
int BaseAgentImpl::deRegisterAgent()
431
int BaseAgentImpl::deRegisterAgent()
403
{
432
{
404
	char commandFormat[] = "<Cmd src=\"%d\" dest=\"%d\" ctxt=\"%d\"> <deregisterAgent iid=\"org.eclipse.tptp.agentManager\"><agentID>%d</agentID></deregisterAgent></Cmd>";
433
	char commandFormat[] = "<Cmd src=\"%d\" dest=\"%d\" ctxt=\"%d\"> <deregisterAgent iid=\"org.eclipse.tptp.agentManager\"><agentID>%d</agentID></deregisterAgent></Cmd>";

Return to bug 186080