VirtualInstrumentManager.cc 3.03 KB
/*
 * VirtualInstrumentManager.cc
 *
 *  Created on: Jan 17, 2013
 *      Author: f.casimir
 */

#include "VirtualInstrumentManager.hh"
#include "VirtualInstrument.hh"
#include "Properties.hh"

namespace AMDA {
	namespace DDServerInterface {

		VirtualInstrumentManager::VirtualInstrumentManager() {
			AMDA::helpers::Properties lProperties("app.properties");
                        _userHost = lProperties["app.user.host"];			
                        _userName = lProperties["app.user.name"];   
		}

		VirtualInstrumentManager::~VirtualInstrumentManager() {
		}

		VirtualInstrumentSPtr VirtualInstrumentManager::getVirtualInstrument(const std::string& pVirtualInstrumentName) {
			VirtualInstrumentSPtr lResult;
			auto lIt = _virtualInstrumentMap.find(pVirtualInstrumentName);
			if (lIt == _virtualInstrumentMap.end()) {
				lResult = VirtualInstrumentSPtr(new VirtualInstrument(*this,pVirtualInstrumentName));
				_virtualInstrumentMap[pVirtualInstrumentName]=lResult;
			} else {
				lResult = lIt->second.lock();
				if ( ! lResult) {
					_virtualInstrumentMap.erase(lIt);
					lResult = VirtualInstrumentSPtr(new VirtualInstrument(*this,pVirtualInstrumentName));
					_virtualInstrumentMap[pVirtualInstrumentName]=lResult;
				}
			}
			return lResult;
		}

		const char* VirtualInstrumentManager::getUserHost() {
			return _userHost.c_str();
		}
		
		const char* VirtualInstrumentManager::getUserName() {
			return _userName.c_str();
		}

		int VirtualInstrumentManager::ddErrorToAmdaError(int ddError) {
			if (ddError >= 0)
				return 0;
			switch (ddError) {
				case NOCONNECTION:
					return AMDA_ERROR_NOCONNECTION;
				case TOOMANYREQ:
					return AMDA_ERROR_TOOMANYREQ;
				case REQSENDERR:
					return AMDA_ERROR_REQSENDERR;
				case REPLYRECERR:
					return AMDA_ERROR_REPLYRECERR;
				case NOID:
					return AMDA_ERROR_NOID;
				case NOREFFILE:
					return AMDA_ERROR_NOREFFILE;
				case NOTIMESFILE:
					return AMDA_ERROR_NOTIMESFILE;
				case NOINFOFILE:
					return AMDA_ERROR_NOINFOFILE;
				case NOVAR:
					return AMDA_ERROR_NOVAR;
				case OUTOFTIME:
					return AMDA_ERROR_OUTOFTIME;
				case CACHERR:
					return AMDA_ERROR_CACHERR;
				case CACHTOOREC:
					return AMDA_ERROR_CACHTOOREC;
				case WAITEXTCALL:
					return AMDA_ERROR_WAITEXTCALL;
				case TRYAGAIN:
					return AMDA_ERROR_TRYAGAIN;
				case NODATAATTIME:
					return AMDA_ERROR_NODATAATTIME;
				case GAPISSMALL:
					return AMDA_ERROR_GAPISSMALL;
				case CTIMEISSHIFTED:
					return AMDA_ERROR_CTIMEISSHIFTED;
				case DATAFILEERR:
					return AMDA_ERROR_DATAFILEERR;
				case ENVIRERROR:
					return AMDA_ERROR_ENVIRERROR;
				case NOPOINTER:
					return AMDA_ERROR_NOPOINTER;
				case INTSERERR:
					return AMDA_ERROR_INTSERERR;
				case TIMEINEMPTY:
					return AMDA_ERROR_TIMEINEMPTY;
				case NOEXEC:
					return AMDA_ERROR_NOEXEC;
				case NOPERMISSION:
					return AMDA_ERROR_OPERMISSION;
				case NOHOST:
					return AMDA_ERROR_NOHOST;
				case NOUSERSFILE:
					return AMDA_ERROR_NNOUSERSFILE;
			}
			return AMDA_ERROR_UNKNOWN;
		}
	} /* namespace DDServerInterface */
} /* namespace AMDA */