示例#1
0
		TokenType Compiler::GetPhase2TokenType(std::string tokenvalue)
		{
			/* Number */
			if (isdigit(tokenvalue[0]) || tokenvalue[0] == '-' || tokenvalue[0] == '+')
			{
				if (Util::Type::IsOfType<Int>(tokenvalue))
					return TokenType::Number;
				else
					throw GenericError("Invalid number " + tokenvalue);
			}
			/* Directive */
			else if (DirectiveHelper::IsDirectiveSign(tokenvalue[0]))
			{
				if (DirectiveHelper::IsDirective(tokenvalue.substr(1)))
					return DirectiveHelper::GetDirectiveType(tokenvalue.substr(1));
				else
					throw GenericError("Invalid directive " + tokenvalue);
			}
			/* Label Definition */
			else if (SyntaxHelper::IsLabelDef(tokenvalue))
				return TokenType::LabelDef;
			/* Check for opcode */
			else if (OpcodeInfo::Exists(tokenvalue))
				return TokenType::Opcode;

			return TokenType::NotAssigned;
		}
示例#2
0
	void Context::Run()
	{
		if (!loaded)
			throw GenericError("No loaded program");

		running = true;
		//bool dbg = false;
		while (running)
		{
			//if (dbg) std::cout << "EXEC\n";
			Byte opc = Fetch();
			//if (dbg) std::cout << "FETCH " << OpcodeInfo::Get(opc).name << "(" << (int)opc << ")" << std::endl;
			Value *v = nullptr;
			if (OpcodeInfo::Get(opc).hasoperand)
			{
				//if (dbg) std::cout << "  HAS OPR ";
				v = GetOperand();
				//if (dbg) std::cout << *v << std::endl;
			}
			//if (dbg) std::cout << "CALL\n";
			OpcodeInfo::Get(opc).handler(*this, (Opcode::ID)opc, v);
			//if (dbg) std::cout << "REL\n";
			if (v != nullptr)
				delete v;
			//if (dbg) std::cout << "END\n";
		}
	}
SemaphoreSetDistribuido::SemaphoreSetDistribuido(std::vector<unsigned short> & numeros_de_semaforo,
	const std::string & directorio_de_trabajo, const std::string & nombre_app, const std::string & nombre_grupo,
	char id, int cantidad_sems, bool create)
	: nombre_recurso(nombre_grupo), cantidad_de_semaforos(cantidad_sems)
{
	std::string prefijo_archivo;
	prefijo_archivo = std::string(directorio_de_trabajo).append(PREFIJO_RECURSO).append(nombre_grupo);
	char numero [5];
	unsigned short valor;

	if (cantidad_de_semaforos > 125) {
		throw GenericError("Cannot allocate %d semaphores, max 125", cantidad_de_semaforos);
	}

	std::vector<unsigned short> valores(2 * cantidad_de_semaforos, 0);

	create_if_not_exists(std::string(prefijo_archivo).append(POSTFIJO_LCK).c_str());

	if (create) {
		control = ControlTokens::get_instance(directorio_de_trabajo, true);
		semaforos = new SemaphoreSet(valores, std::string(prefijo_archivo).append(POSTFIJO_LCK).c_str(), id, 0664);
	} else {
		control = ControlTokens::get_instance(directorio_de_trabajo);
		semaforos = new SemaphoreSet(std::string(prefijo_archivo).append(POSTFIJO_LCK).c_str(), id, 0);
	}
	for (size_t i = 0 ; i < numeros_de_semaforo.size() ; i++) {

		valor = numeros_de_semaforo [i];
		sprintf(numero, "%d", valor);

		lanzar_comunicacion(directorio_de_trabajo, nombre_app,
			std::string(directorio_de_trabajo).append(PATH_LOCAL_BROKER_LIST_FILE).c_str(),
			std::string(nombre_grupo).append(numero), id, 0, valor);
	}
}
void SemaphoreSetDistribuido::lanzar_comunicacion(const std::string & directorio_de_trabajo,
	const std::string & nombre_aplicacion, const std::string & local_brokers_file, const std::string & nombre_grupo,
	char id, size_t tamanio_memoria, int numero_semaforo)
{
	char current_working_dir [FILENAME_MAX];
	char launch_dir [FILENAME_MAX];

	//ignore_signals();

	snprintf(directorio, FILENAME_MAX, "%s", directorio_de_trabajo.c_str());
	snprintf(nombre_app, MAX_NOMBRE_RECURSO, "%s", nombre_aplicacion.c_str());
	snprintf(brokers_file, FILENAME_MAX, "%s", local_brokers_file.c_str());
	snprintf(grupo, MAX_NOMBRE_RECURSO, "%s", nombre_grupo.c_str());
	snprintf(id_ipc, 4, "%d", id);
	snprintf(num_sem, 6, "%d", numero_semaforo);
	snprintf(cant_sems, 6, "%d", cantidad_de_semaforos);

#ifdef __x86_64__
	snprintf(tamanio_mem, sizeof(tamanio_mem), "%lu", tamanio_memoria);
#else
	snprintf(tamanio_mem, sizeof(tamanio_mem), "%u", tamanio_memoria);
#endif

	if (!getcwd(current_working_dir, sizeof(current_working_dir)))
		throw GenericError("Unable to get current working dir");
	current_working_dir [sizeof(current_working_dir) - 1] = '\0';

	locate_dir(launch_dir, current_working_dir, (char *)"clientes");

	relativize_dir(directorio, directorio_de_trabajo.c_str(), launch_dir, current_working_dir);
	relativize_dir(brokers_file, local_brokers_file.c_str(), launch_dir, current_working_dir);

	//ignore_childs();

	if (chdir(launch_dir) != 0) {
		throw GenericError("Cannot change working dir to %s", launch_dir);
	}

	handlers.push_back(new Process("local_broker_comm", args_local_broker_comm));

	if (chdir(current_working_dir) != 0) {
		throw GenericError("Cannot change working dir to %s", current_working_dir);
	}

}
示例#5
0
int
main (int argc, char **argv)
{  
try {

   if(argc<2) {
      throw GenericError("Faltan parametros para torre_de_control_svc: ./torre_de_control_svc config_file_abs_path");
   }
    
   std::string wkdir = ApiConfiguracion::get_torre_wkdir(argv[1]);
   crear_archivos_lck_torre(wkdir.c_str());

   torre_de_control = new TorreDeControlSvc(wkdir.c_str());
   api_torre = new ApiTorreDeControlSvc(wkdir.c_str(), argv[1]);

	register SVCXPRT *transp;

	pmap_unset (TORREDECONTROLPROG, TORREDECONTROLVERS);

	transp = svcudp_create(RPC_ANYSOCK);
	if (transp == NULL) {
		fprintf (stderr, "%s", "cannot create udp service.");
		exit(1);
	}
	if (!svc_register(transp, TORREDECONTROLPROG, TORREDECONTROLVERS, torredecontrolprog_1, IPPROTO_UDP)) {
		fprintf (stderr, "%s", "unable to register (TORREDECONTROLPROG, TORREDECONTROLVERS, udp).");
		exit(1);
	}

	transp = svctcp_create(RPC_ANYSOCK, 0, 0);
	if (transp == NULL) {
		fprintf (stderr, "%s", "cannot create tcp service.");
		exit(1);
	}
	if (!svc_register(transp, TORREDECONTROLPROG, TORREDECONTROLVERS, torredecontrolprog_1, IPPROTO_TCP)) {
		fprintf (stderr, "%s", "unable to register (TORREDECONTROLPROG, TORREDECONTROLVERS, tcp).");
		exit(1);
	}

	svc_run ();
	fprintf (stderr, "%s", "svc_run returned");
   return(0);
	// exit (1);
	/* NOTREACHED */

 } catch (const std::exception &e) {
	Log::crit("%s", e.what());
}
catch (...) {
	Log::crit("Critical error. Unknow exception at the end of the 'main' function.");
}

}
int ApiControlEquipajes::get_zona(int num_vuelo) {

	int* num_zona = get_zona_1(&num_vuelo, clnt_torre_de_control);

	if (num_zona != NULL) {
		Log::info("ApiControlEquipajes obtuve resultado del rpc server: zona del vuelo %d es %d", num_vuelo, (*num_zona));
	} else {
		throw GenericError("ApiControlEquipajes: Error al llamar al métdoo remoto desasignar _vuelo_1 sobre el rpc server");
	}

	return (*num_zona);

}
int main(int argc, char** argv) {
   try {
      std::string config_file( (argc>1)?argv[1]:DEFAULT_CONFIG_FILE );


      dictionary * ini = NULL;

      if ( (ini=iniparser_load(config_file.c_str())) == NULL ) {
         Log::crit("cannot parse the config file: %s\n", config_file.c_str());
         throw GenericError("cannot parse the config file %s", config_file.c_str());
      }

      int use_ipc = iniparser_getboolean(ini, "INTERMEDIATE_BROKER:use_ipc", -1);

      if(use_ipc) {
         Log::notice("No se lanzan los message_broker, use_ipc=true en archivo de configuracion %s", config_file.c_str());
         return 0;
      }

      Log::notice("Launch message_broker_server, read configuration from %s", config_file.c_str());

      strcpy(working_dir, iniparser_getstring(ini, "INTERMEDIATE_BROKER:working_dir", NULL));
      strcpy(port, iniparser_getstring(ini, "INTERMEDIATE_BROKER:port", NULL));
      strcpy(log_path, iniparser_getstring(ini, "INTERMEDIATE_BROKER:log_path", NULL));
      strcpy(persist_path, iniparser_getstring(ini, "INTERMEDIATE_BROKER:persist_path", NULL));

      Process process_server("./../local_broker/message_broker_server", args_message_broker);
      sleep(1);
      ApiComunicacionAeropuerto api_comm( ApiConfiguracion::get_wkdir(config_file.c_str()).c_str(), config_file.c_str(), true);


      Log::notice("Done, waiting for a SIGINT or a SIGTERM signal.");
      wait_signal();

      Log::notice("Signal recieved. Shutdown...");
      process_server.send_signal(SIGTERM);
      process_server.send_signal(SIGKILL);


   } catch (const std::exception &e) {
      Log::crit("%s", e.what());
   }
   catch (...) {
      Log::crit("Critical error. Unknow exception at the end of the 'main' function.");
   }

   return 0;
}
示例#8
0
		std::string Compiler::FixStringEscapeChars(std::string str)
		{
			std::string newstr;
			for (Length i = 0; i < str.length(); i++)
			{
				if (str[i] == '\\' && SyntaxHelper::IsEscapeCharacter(str[i + 1]))
				{
					i++;
					switch (SyntaxHelper::GetEscapeCharType(str[i]))
					{
						case SyntaxHelper::EscapeCharType::Backslash:
							newstr += '\\';
							break;
						case SyntaxHelper::EscapeCharType::Backspace:
							newstr += '\b';
							break;
						case SyntaxHelper::EscapeCharType::Formfeed:
							newstr += '\f';
							break;
						case SyntaxHelper::EscapeCharType::Newline:
							newstr += '\n';
							break;
						case SyntaxHelper::EscapeCharType::Null:
							newstr += '\0';
							break;
						case SyntaxHelper::EscapeCharType::Return:
							newstr += '\r';
							break;
						case SyntaxHelper::EscapeCharType::SingleQoute:
							newstr += '\'';
							break;
						case SyntaxHelper::EscapeCharType::Tab:
							newstr += '\t';
							break;
						case SyntaxHelper::EscapeCharType::Vtab:
							newstr += '\v';
							break;
						default:
							throw GenericError("Some weird character in escape encoder has been found .-.");
					}
				}
				else
					newstr += str[i];
			}
			return newstr;
		}
示例#9
0
int Debugger::FormatError(char *buffer, size_t maxLength)
{
    if (!ErrorExists())
        return -1;

    assert(m_Top >= 0 && m_Top < (int)m_pCalls.size());

    Tracer *pTracer = m_pCalls[m_Top];
    int error = pTracer->m_Error;
    const char *gen_err = GenericError(error);
    int size = 0;
    //trace_info_t *pTrace = pTracer->GetEnd();
    //cell cip = _CipAsVa(m_pAmx->cip);
    //cell *p_cip = NULL;
    //int amx_err = AMX_ERR_NONE;

    size += UTIL_Format(buffer, maxLength, "Run time error %d: %s ", error, gen_err);
    buffer += size;
    maxLength -= size;

    if (error == AMX_ERR_NATIVE || error == AMX_ERR_INVNATIVE)
    {
        char native_name[sNAMEMAX+1];
        int num = 0;
        /*//go two instructions back
        cip -= (sizeof(cell) * 2);
        int instr = _GetOpcodeFromCip(cip, p_cip);
        if (instr == OP_SYSREQ_C)
        {
        	num = (int)*p_cip;
        }*/
        //New code only requires this...
        num = (int)(_INT_PTR)m_pAmx->usertags[UT_NATIVE];
        /*amx_err = */amx_GetNative(m_pAmx, num, native_name);
        /*if (num)
        	amx_err = amx_GetNative(m_pAmx, (int)*p_cip, native_name);
        else
        	amx_err = AMX_ERR_NOTFOUND;*/
        //if (!amx_err)
        size += UTIL_Format(buffer, maxLength, "(native \"%s\")", native_name);
    }

    return size;
}
示例#10
0
		void Compiler::Phase3()
		{
			TokenListNode *cn = m_tl.head;
			while (cn != nullptr)
			{
				if (TokenHelper::IsOpcodeOrDirective(cn->value->type))
				{
					switch (cn->value->type)
					{
						case TokenType::Opcode:
							if (OpcodeInfo::Get(cn->value->value).hasoperand)
							{
								if (cn->next != nullptr && !TokenHelper::IsOperand(cn->next->value->type))
									throw TokenError(cn->next->value, m_name, "Expected valid operand");

								if (cn->next != nullptr)
									cn = cn->next;
							}
							break;
						default:
							throw TokenError(cn->value, m_name, "Invalid token type");
					}
				}
				else if (cn->value->type == TokenType::LabelDef) ; // just ignore it
				else
					throw TokenError(cn->value, m_name, "Invalid token type");

				if (cn != nullptr)
					cn = cn->next;
			}

			/* Check for invalid exports */
			for (std::string &exported : m_tl.exports)
			{
				bool found = false;
				for (const auto &l : m_tl.labels)
					if (std::get<0>(l) == exported)
						found = true;
				if (!found)
					throw GenericError("Undefined label " + exported);
			}

			/* Check for duplicate exports */
			int d_count = 0;
			for (std::string &e : m_tl.exports)
			{
				for (std::string &e2 : m_tl.exports)
					if (e2 == e && ++d_count > 1)
						throw GenericError("Duplicate export " + e2);
				d_count = 0;
			}

			/* Check for duplicate labels */
			d_count = 0;
			for (const auto &l : m_tl.labels)
			{
				for (const auto &l2 : m_tl.labels)
					if (std::get<0>(l) == std::get<0>(l2) && ++d_count > 1)
						throw TokenError(std::get<1>(l2)->value, m_name, "Duplicate label " + std::get<0>(l));
				d_count = 0;
			}
		}
示例#11
0
void Debugger::FmtGenericMsg(AMX *amx, int error, char buffer[], size_t maxLength)
{
    const char *filename = "";
    char native[sNAMEMAX+1];

    CList<CScript,AMX*>::iterator a = g_loadedscripts.find(amx);
    if (a)
        filename = (*a).getName();
    size_t len = strlen(filename);
    for (size_t i=len-1; i<len; i--)
    {
        if ((filename[i] == '/' || filename[i] == '\\') && i != len - 1)
        {
            filename = &(filename[i+1]);
            break;
        }
    }

    if (error == AMX_ERR_EXIT)
    {
        UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") - %s", error, filename, GenericError(AMX_ERR_EXIT));
    } else if (error == AMX_ERR_NATIVE) {
        amx_GetNative(amx, reinterpret_cast<long>(amx->usertags[UT_NATIVE]), native);
        UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") (native \"%s\") - debug not enabled!", error, filename, native);
    } else {
        UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") - debug not enabled!", error, filename);
    }
}