#include "stdafx.h"
#ifdef OLIVIA_COMPILA
#include "olv.h"
#include "olv_sock.h"

Colv_sock::Colv_sock(COlivia *olv)
{
	this->olv = olv;
	sprintf_s(ip,32,"0.0.0.0");
	puerto=19933;
}

Colv_sock::~Colv_sock(void)
{
}
//*************************************************************************************
BOOL Colv_sock::on_datos_recibidos( char *txt )
{
	int pr;
	char *ch = NULL;
	const int SZMSG = OLV_MAX_TAREA+OLV_MAX_MSG_PROCE+10;
	char msgtar[SZMSG];
	char *secto=NULL;
	BOOL ret=TRUE;

	if((strstr(txt,OliviaDef::GeneralDef::SockConf)) || (strstr(txt,OliviaDef::GeneralDef::SockConfPlan)) ||
		(strstr(txt,OliviaDef::GeneralDef::SockConfTodo)) && !olv->ya_config)
	{
		if(olv->pon_config(txt))
		{
			ch = strdup(OliviaDef::GeneralDef::SockConfOk);				
		}
		else
		{
			ch = strdup(OliviaDef::GeneralDef::SockConfNOk);	
		}
		if(!envia(ch))
		{
			ret= FALSE;
		}
	}	
	else if(strcmp(txt,OliviaDef::GeneralDef::SockProgr)==0)
	{
		pr=olv->dame_progre();
		if(!envia("%ld", pr))
		{
			ret= FALSE;
		}
	}
	else if(strcmp(txt,OliviaDef::GeneralDef::SockTarea)==0)
	{
		pr=olv->dame_tarea();
		strcpy_s(msgtar, SZMSG,olv->tareas_str[pr]);
		if(strlen(olv->msg_proce)>0)
			strcat_s(msgtar,olv->msg_proce);		
		///////////////////
		if(!envia("%s", msgtar ))
		{
			ret= FALSE;
		}
	}	
	else if(strcmp(txt,OliviaDef::GeneralDef::SockCanc)==0)
	{
		//Cancela...
		ch = strdup(OliviaDef::GeneralDef::SockCancOk);	
		if(!envia(ch))
			ret= FALSE;
		olv->cancela();
	}

	txt[0]=0;

	if(ch)
		free(ch);	
	if(secto)
		free(secto);

	return ret;
}
//*************************************************************************************
Cstr_socket_srv* Colv_sock::crea_cliente()
{
	Colv_sock *s;
	s= new Colv_sock(olv);
	return s;
}
//*************************************************************************************
#endif