lisha.ahuja 0 Newbie Poster

Hi Friends,

I am an java programmer and trying the code change in C++ now,Kindly guide me for the below issue I am facing,

The code which I need to modify is

Original code:-

/*
**--------------------------------------------------------------------------------------------
** Description		: This class starts the event listener threads for BRANCH
** Functionality	: It performs the following operations
**                        1. Accepts appAation properties from A_Enquiry program
**                        2. Checks for location (BRANCH)
**                        3. Starts the listener for corresponding location
**--------------------------------------------------------------------------------------------
*/

#include <A_Enquiry_Adapter.h>
#include <A_Branch_DataEventListener.h>


A_Enquiry_Adapter::A_Enquiry_Adapter(MAppProperties* pMAppProperties)
		:MApp(pMAppProperties) {}

//A_Enquiry_Adapter::A_Enquiry_Adapter(MAppProperties* pMAppProperties, MMessageBundle mb)
//		:MApp(pMAppProperties)
//{
//	m_mb = mb;
//}

A_Enquiry_Adapter::~A_Enquiry_Adapter()
{
}

void
A_Enquiry_Adapter::onInitialization() throw (MException)
{
	try
	{
		this->getTrace()->trace(MAPP_INFO_ROLE, "Enquiry Adapter started successfully");
		m_pMPublisher = MPublisher::downCast(getComponentByName("pub"));

		if (m_pMPublisher == 0) {
			this->getTrace()->trace(MAPP_ERROR_ROLE, "Publisher object not found in the repository file");
			throw MException( "onInitialization: Publisher not auto-created: pub");
		}

		A_Adapter_Utils lau;
		string loc = lau.getEnv("X_LOCATION");
		loc = lau.getUpper((char*)loc.c_str());
		lau.checkLocation(loc);

  		if (loc == "BRANCH")
		{
			m_pMSubscriber = MSubscriber::downCast(getComponentByName("sub_BR"));
			//get the subject of the sub "A.BCODE.*.ENQ.REQ" and replace the second
			//part using the getenv(X_BRANCH_CODE) and set this subject to
			//subscriber

			if (m_pMSubscriber == 0)
			{
				this->getTrace()->trace(MAPP_ERROR_ROLE, "Subscriber object not found in the repository file");
				throw MException( "onInitialization: Subscriber not auto-created: sub");
			}

			//Make the subscriber to accept both RV and AE formats
			Mboolean bValidate = Mfalse;
			m_pMSubscriber->validateMessage(bValidate);
			//m_pMSubscriber->addListener(new A_Branch_DataEventListener(m_pMPublisher, m_mb, this));
			m_pMSubscriber->addListener(new A_Branch_DataEventListener(m_pMPublisher, this));
			this->getTrace()->trace(MAPP_INFO_ROLE, "Branch Adapter. Listening for messages from Branch and MAN");
		}
		

		MList<MRvDispatcher *> *m_pDispatchers;
		m_pDispatchers = new MList<MRvDispatcher *>();
		MRvSession *pSession = MRvSession::downCast(getComponentByName("RV"));
		if (pSession)
		{
		        //Get the # of threds to be spawned
	                int threads = atoi(lau.getEnv("X_ENQ_THREADS").c_str());
			for(int i = 0; i <= threads; i++)
			{
				// this->getTrace()->trace(MAPP_INFO_ROLE, "THREAD STARTED INSIDE DISPATCHER FOR LOOP");
				MRvDispatcher *pDispatcher = new MRvDispatcher(this, pSession);
				m_pDispatchers->push_back(pDispatcher);
				//delete (pDispatcher);
			}
		}
	}
	catch (MException me)
	{
		throw me;
	}
	catch (A_Exceptions le)
	{
		char str1[10];
		int i = le.getLineno();
		sprintf(str1,"%d",i);
		string str = le.getDesc()+" at file "+le.getFilename()+" at line "+ str1;

		MString exception = (const char*) str.c_str();
		throw MException(exception);
	}

}

void
A_Enquiry_Adapter::onTermination() throw (MException)
{
	this->getTrace()->trace(MAPP_DEBUG_ROLE, "onTermination() is called");
}

---------------------------------------------------------------------------------------------------------------------------------------
I tried to change the code in the below manner:-
------------------------------------------------------------------------------------------------------
Change code section:-
---------------------------------------------------------------------------------------------------

MList<MRvDispatcher *> *m_pDispatchers;
          m_pDispatchers = new MList<MRvDispatcher *>();
          MRvSession *pSession = MRvSession::downCast(getComponentByName("RV"));
          if (pSession)
          {
		 //Get the # of threds to be spawned
			int threads = atoi(lau.getEnv("X_Y_ENQ_THREADS").c_str());
			for(int i=0; i<=threads;i++)
				{
					String session=”RV”+i;
					MRvSession *pSession[i] = MRvSession::downCast(getComponentByName(session));
					MRvDispatcher *pDispatcher = new MRvDispatcher(this, pSession[i]);
					m_pDispatchers->push_back(pDispatcher);
				}

-------------------------------------------------------------------------------------------------------------------
The issue with the change code is:-

-The program is basically for creating threads,support group is saying that the change code snippet will listen for same subject message and the requirement is to listen for messages with different subject name.
-I tried to change the code but it gives me the compilation error as follows,

Adapter.cpp: In member function āvirtual void Adapter::onInitialization()ā:
Adapter.cpp:113: error: āStringā was not declared in this scope
Adapter.cpp:113: error: expected `;' before āsessionā
Adapter.cpp:114: error: āsessionā was not declared in this scope
Adapter.cpp:114: error: variable-sized object āpSessionā may not be initialized