/* ----------------------------------------------------------------*/
void 
ErrorComponent::badMethod(CORBA::Short depth) 
{
        ACS_TRACE("::ErrorComponent::badMethod");
        if(depth>=1){
            try
                {
                        // We decrement the depth, because we are going to add one
                        // error here in any case.
                        buildErrorTrace(depth-1);
                }
                catch(ACSErrTypeCommon::GenericErrorExImpl &ex)
                {
                        ACSErrTypeCommon::GenericErrorExImpl ex2(ex, 
                                        __FILE__, __LINE__, 
                                        "ErrorComponent::badMethod");
                        ex2.setErrorDesc("Generated multi level exception");
                        throw ex2.getGenericErrorEx();
                }
                catch(...)
                {
                        ACSErrTypeCommon::UnexpectedExceptionExImpl ex2(__FILE__, __LINE__, 
                                        "ErrorComponent::badMethod");
                        throw ex2.getUnexpectedExceptionEx();
                }

                /*
                 * We should get here only if a depth<=1 was requested.
                 */
                ACSErrTypeCommon::GenericErrorExImpl ex(__FILE__, __LINE__, 
                                "ErrorComponent::badMethod");
                ex.setErrorDesc("An error trace with depth lower or equal to 1 was requested.");
                throw ex.getGenericErrorEx();
        }
}
/************
 * Utility method to build a deep ErrorTrace
 ************/
void
ErrorComponent::buildErrorTrace(unsigned short depth) 
{
    ACS_TRACE("::ErrorComponent::buildErrorTrace");

    /*
     * If depth is 1, we are at the bottom and 
     * we just have to throw an exception.
     * Going up the recursive chain this will be
     * atteched to all other exceptions
     */
    if(depth == 1)
	{
	ACSErrTypeCommon::GenericErrorExImpl ex(__FILE__, __LINE__, 
						"ErrorComponent::buildErrorTrace");
	ex.setErrorDesc("Bottom of error trace");
	throw ex;
	}
	    
    /*
     * If depth > 1, make a recursive call.
     * We will have to get back an exception with a trace with
     * a depth shorter by 1 element.
     */
    if(depth > 1)
	{
	try
	    {
	    buildErrorTrace(depth-1);
	    }
	catch(ACSErrTypeCommon::GenericErrorExImpl &ex)
	    {
	    ACSErrTypeCommon::GenericErrorExImpl ex2(ex, 
						     __FILE__, __LINE__, 
						     "ErrorComponent::errorTrace");

	    ex2.setErrorDesc("Generated multi level exception level");
	    throw ex2;
	    }
	catch(...) // This should never happen!!!!
	    {
	    ACSErrTypeCommon::UnexpectedExceptionExImpl ex2(__FILE__, __LINE__, 
							    "ErrorComponent::errorTrace");
	    throw ex2.getUnexpectedExceptionEx();
	    }
	}
    /*
     * We should get here only if depth <= 0,
     * I.e. if there is not exception to throw.
     */
    return;
}
TEST(AsyncSocketException, SimpleTest) {
  AsyncSocketException ex1(
      AsyncSocketException::AsyncSocketExceptionType::NOT_OPEN,
      "test exception 1");

  EXPECT_EQ(
      AsyncSocketException::AsyncSocketExceptionType::NOT_OPEN, ex1.getType());
  EXPECT_EQ(0, ex1.getErrno());
  EXPECT_EQ(
      "AsyncSocketException: test exception 1, type = Socket not open",
      std::string(ex1.what()));

  AsyncSocketException ex2(
      AsyncSocketException::AsyncSocketExceptionType::BAD_ARGS,
      "test exception 2",
      111 /*ECONNREFUSED*/);

  EXPECT_EQ(
      AsyncSocketException::AsyncSocketExceptionType::BAD_ARGS, ex2.getType());
  EXPECT_EQ(111, ex2.getErrno());
  EXPECT_EQ(
      "AsyncSocketException: test exception 2, type = Invalid arguments, "
      "errno = 111 (Connection refused)",
      std::string(ex2.what()));
}
Ejemplo n.º 4
0
int main(){
	int menu;
	do {
		printf("\n\nEscolha 1 exercicio de 1 - 10, entre 0 para sair: \n--> ");
		scanf("%d", &menu);
		switch(menu){
			case 1: {
				ex1();
				break;
			}
			case 2: {
				ex2();
				break;
			}
			case 3: {
				int mat[5][5];
				matrixFill(5, 5, mat);
				printf("A media dos elementos abaixo da diagonal principal e %d.", (float)mediaAr(5, 5, mat));
				break;
			}
			case 4: {
				ex4();
				break;
			}
			case 5: {
				ex5();
				break;
			}
			case 6: {
				ex6();
				break;
			}
			case 7: {
				ex7();
				break;
			}
			case 8: {
				ex8();
				break;
			}
			case 9: {
				ex9();
				break;
			}
			case 10: {
				ex10();
				break;
			}
			default: {
				printf("Opcao invalida.\n");
				break;
			}
		}
	} while (menu != 0);
	return 0;
}
Ejemplo n.º 5
0
int ex1(struct parser* p)
{
    int alt_count=1;
    int label_1 = label_count++;

    printf("                              ; alternation %d\n", alt_count);
    ex2(p);

    while (lstring(p, "/")) {
        alt_count++;
        printf("                              ; alternation %d\n", alt_count);

        out3("BT", label_1);

        if (!ex2(p)) break;
    }
    generate_label(label_1);

    return 1;
}
Ejemplo n.º 6
0
void ex()
{
	printf("Введите номер задания (1 или 2 или q для выхода):\n");
	char c;
	scanf("\n%c",&c);
	switch (c)
	{
		case '1': ex1();break;
		case '2': ex2();break;
		case 'q': return;break;
		default : break;
	}
}
void  ErrorComponent::exceptionFromCompletion(CORBA::Short depth) 
{
        ACS_TRACE("ErrorComponent::exceptionFromCompletion");
        if(depth==1){
                ACSErrTypeCommon::GenericErrorExImpl ex2(
                                __FILE__, __LINE__,
                                "ErrorComponent::exceptionFromCompletion");
                ex2.setErrorDesc("Exception with trace of depth 1 (not generated from a completion)");
                throw ex2.getGenericErrorEx();
        }    


        CompletionImpl *comp = createCompletion(depth>0?depth-1:0);
        ACS_DEBUG("ErrorComponent::exceptionFromCompletion","first step");
        // if comp does not conatin error (=is error free) we just return 
        // otherwise we create a new exception which takes the error trace from a completion comp.     
        if (!comp->isErrorFree())
        {
               ACS_DEBUG("ErrorComponent::exceptionFromCompletion","second step");

                // The constructor takes care for the memory manamgent 
                // for the passed completion or exception.
                // If a completion or an exception is passed as pointer the constructor assumes that
                // completion was created on the heap and thus it deletes it afterwards,
                // so it MUST NOT be deleted by the user !
                // If a completion or an exception is passed as an object (or reference to it) 
                // the constructor assumes that the it was created on the stack 
                // and thus it does not delete it.
                //
                // NOTE: do not pass a pointer of a completion or an exception 
                // which was created on the stack !! In this case just send the completion object.
                ACSErrTypeCommon::GenericErrorExImpl ex2(comp, 
                                __FILE__, __LINE__, 
                                "ErrorComponent::exceptionFromCompletion");
                ex2.setErrorDesc("Exception generated by adding an error trace from a completion");
                throw ex2.getGenericErrorEx();
        }//if
}
Ejemplo n.º 8
0
int main()
{
    try
    {
        ex1();
        ex2();
        ex3();
        ex4();
        ex5();
    }
    catch(SQLException& e)
    {
        std::cerr << e.message() << std::endl;
    }

    return 0;
}
Ejemplo n.º 9
0
int main(int argc, char **argv) {
	
	print("LISTA DE EXERCICIOS DE FDA - 02");
	ex1();
	ex2();
	ex3();
	ex4();
	ex5();
	ex6();
	ex7();
	ex8();
	ex9();
	ex10();
	ex11();
	ex12();
	ex13();
	
	return 0;
}
Ejemplo n.º 10
0
int main(int argc, char **argv)
{
  if (argc < 2 || strcmp("-h", (const char *)argv[1]) == 0 || strcmp("--help", (const char *)argv[1]) == 0) {
    print_usage();
    return 1;
  }

  if (strcmp("ex1", (const char *)argv[1]) == 0)
    ex1();
  else if (strcmp("ex2", (const char *)argv[1]) == 0)
    ex2();
  else if (strcmp("ex3", (const char *)argv[1]) == 0)
    ex3();
  else if (strcmp("ex4", (const char *)argv[1]) == 0)
    ex4();
  else
    print_usage();

  return 0;
}
Ejemplo n.º 11
0
int main(int argc, char* argv[]) {
    int ex = getExerciseNumber(argc, argv);
    switch (ex){
        case 1 :
            ex1();
            return 0;
        case 2:
            ex2();
            return 0;
        case 3:
            ex3();
            return 0;
        case 4:
            ex4();
            return 0;
        default:
            printf("\n The exercise does not exist!\n");
            printf("You specified exercise: %d", ex);
            return 0;
    }
}
Ejemplo n.º 12
0
int select_method(char * metodo, char * parametros, char * parametros2, char * parametros3) {
    int cod_error = 0;
    load_file(parametros);

    if(strcmp(metodo, "ex2") == 0) {
        cod_error = ex2();
    } else if(strcmp(metodo, "ex3") == 0) {
        cod_error = ex3();
    } else if(strcmp(metodo, "ex4") == 0) {
        cod_error = ex4(parametros2);
    } else if(strcmp(metodo, "ex5") == 0) {
        cod_error = ex6(parametros2);
    } else if(strcmp(metodo, "ex7") == 0) {
        cod_error = ex7(parametros2, parametros3);
    } else if(strcmp(metodo, "ex8") == 0) {
        cod_error = ex8(parametros2);
    } else if(strcmp(metodo, "ex10") == 0) {
        cod_error = ex10(parametros2);
    }
    return 1;
}
Ejemplo n.º 13
0
void XBPyThread::stop()
{
  CSingleLock lock(m_pExecuter->m_critSection);
  if(m_stopping)
    return;

  m_stopping = true;

  if (m_threadState)
  {
    PyEval_AcquireLock();
    PyThreadState* old = PyThreadState_Swap((PyThreadState*)m_threadState);

    //tell xbmc.Monitor to call onAbortRequested()
    if (addon)
      g_pythonParser.OnAbortRequested(addon->ID());

    PyObject *m;
    m = PyImport_AddModule((char*)"xbmc");
    if(!m || PyObject_SetAttrString(m, (char*)"abortRequested", PyBool_FromLong(1)))
      CLog::Log(LOGERROR, "XBPyThread::stop - failed to set abortRequested");

    PyThreadState_Swap(old);
    old = NULL;
    PyEval_ReleaseLock();

    XbmcThreads::EndTime timeout(PYTHON_SCRIPT_TIMEOUT);
    while (!stoppedEvent.WaitMSec(15))
    {
      if (timeout.IsTimePast())
      {
        CLog::Log(LOGERROR, "XBPyThread::stop - script didn't stop in %d seconds - let's kill it", PYTHON_SCRIPT_TIMEOUT / 1000);
        break;
      }
      // We can't empty-spin in the main thread and expect scripts to be able to
      // dismantle themselves. Python dialogs aren't normal XBMC dialogs, they rely
      // on TMSG_GUI_PYTHON_DIALOG messages, so pump the message loop.
      if (g_application.IsCurrentThread())
      {
        CSingleExit ex(g_graphicsContext);
        CApplicationMessenger::Get().ProcessMessages();
      }
    }
    // Useful for add-on performance metrics
    if (!timeout.IsTimePast())
      CLog::Log(LOGDEBUG, "XBPyThread::stop - script termination took %dms", PYTHON_SCRIPT_TIMEOUT - timeout.MillisLeft());
    
    //everything which didn't exit by now gets killed
    {
      // grabbing the PyLock while holding the XBPython m_critSection is asking for a deadlock
      CSingleExit ex2(m_pExecuter->m_critSection);
      PyEval_AcquireLock();
    }

    // since we released the XBPython m_critSection it's possible that the state is cleaned up 
    // so we need to recheck for m_threadState == NULL
    if (m_threadState)
    {
      old = PyThreadState_Swap((PyThreadState*)m_threadState);    
      for(PyThreadState* state = ((PyThreadState*)m_threadState)->interp->tstate_head; state; state = state->next)
      {
        // Raise a SystemExit exception in python threads
        Py_XDECREF(state->async_exc);
        state->async_exc = PyExc_SystemExit;
        Py_XINCREF(state->async_exc);
      }

      // If a dialog entered its doModal(), we need to wake it to see the exception
      g_pythonParser.PulseGlobalEvent();

    }

    if (old != NULL)
      PyThreadState_Swap(old);

    lock.Leave();
    PyEval_ReleaseLock();
  }
}
Ejemplo n.º 14
0
//-----------------------------------------------------------------------------
void 
ArchiveSupplier::send_event(CORBA::Short priority,
			    ACS::Time timeStamp,
			    const std::string& component,
			    const std::string& property,
			    CORBA::Any value,
			    const std::string& container)
    
{
    //would save space to make this a member variable but there could
    //be problems with multi-threaded apps
    CosNotification::StructuredEvent archiving_event;
    populateHeader(archiving_event);

    //the eventName consists of container named concatenated with the
    //component and property names, delimited by ':'s.
    const char *separator = ":";
    ACE_CString eventName = container.c_str();
    eventName += separator; 
    eventName += component.c_str();
    eventName += separator;
    eventName += property.c_str();
    //std::string eventName = container + ":" + component + ":" + property;
    
    //save a CORBA any by placing the container/component/property names in the event_name
    archiving_event.header.fixed_header.event_name = CORBA::string_dup(eventName.c_str());

    //there are only two elements within filterable_data: the time_stamp and the value
    archiving_event.filterable_data.length(2);
    archiving_event.filterable_data[0].name = CORBA::string_dup("time_stamp");
    archiving_event.filterable_data[0].value <<= timeStamp;
    archiving_event.filterable_data[1].name = CORBA::string_dup("value");
    archiving_event.filterable_data[1].value = value;
    
    //delegate to another method which will actually send the event
	 try{
		 this->publishEvent(archiving_event);
	 }
	 catch(ACSErrTypeCORBA::CORBAReferenceNilExImpl& ex1)
	 {
		 acsncErrType::PublishEventFailureExImpl
			 ex2 (__FILE__, __LINE__, "ArchiveSupplier::send_event");
		 ex2.setEventName("archiving_event");
		 ex2.setChannelName(channelName_mp);
		 throw ex2;
	 }
	 catch(ACSErrTypeCORBA::NarrowFailedExImpl& ex1)
	 {
		 acsncErrType::PublishEventFailureExImpl
			 ex2 (__FILE__, __LINE__, "ArchiveSupplier::send_event");
		 ex2.setEventName("archiving_event");
		 ex2.setChannelName(channelName_mp);
		 throw ex2;
	 }
	 catch(ACSErrTypeCORBA::FailedToResolveServiceExImpl& ex1)
	 {
		 acsncErrType::PublishEventFailureExImpl
			 ex2 (__FILE__, __LINE__, "ArchiveSupplier::send_event");
		 ex2.setEventName("archiving_event");
		 ex2.setChannelName(channelName_mp);
		 throw ex2;
	 }
}
Ejemplo n.º 15
0
int main (){
	int menu, exit = 0;
	setlocale(LC_ALL, "");
	while(!exit){
		printf("\t \n \n Escolha um exercicio:");
		printf("\t \t \n 1.Calcula maior elemento da matriz e divide os elementos por ele");
		printf("\t \t \n 2.Realiza trocas com a matriz 10x10");
		printf("\t \t \n 3.Retorna media aritimetica dos elementos abaixo da diagonal principal");
		printf("\t \t \n 4.Recebe matriz e mostra elementos cujo a soma da linha com coluna e impar");
		printf("\t \t \n 5.Verifica se uma matriz A e a transposta de uma matriz B");
		printf("\t \t \n 6.Verifica se uma matriz e simetrica");
		printf("\t \t \n 7.Gera matrizes simetricas");
		printf("\t \t \n 8.Encontrar elemento minimax de matriz");
		printf("\t \t \n 9.Recebe matriz de caracteres e procura por string");
		printf("\t \t \n 10.Verifica se a matriz e inca");
		printf("\t \t \n0.Sair");
		printf("\n \t Opcao >> ");
		scanf("%d", &menu);
		switch(menu){
			case 1:{
				ex1();
				break;
			}
			case 2:{
				ex2();
				break;
			}
			case 3:{
				ex3();
				break;
			}
			case 4:{
				ex4();
				break;
			}
			case 5:{
				ex5();
				break;
			}
			case 6:{
				ex6();
				break;
			}
			case 7:{
				ex7();
				break;
			}
			case 8:{
				ex8();
				break;
			}
			case 9:{
				ex9();
				break;
			}
			case 10:{
				ex10();
				break;
			}
			case 0:{
				exit = 1;
				break;
			}
			default:{
				printf("\t\t\t\nOpcao Invalida.\n\n\n");
				break;
			}
		}
	}
}
Ejemplo n.º 16
0
void RestApi::Handle(HttpOutput& httpOutput, const std::string& uri, const std::string& method, const std::string& body)
{
    if (method == "GET")
    {
        bool foundHandler = false;
        for (GetHandlersType::iterator it = GetHandlers.begin(); it != GetHandlers.end(); ++it)
        {
            boost::regex ex(it->first);
            if (boost::regex_match(uri, ex))
            {
                RestApiOutput restApiOutput(httpOutput);
                RestApiGetCall restApiGetCall(restApiOutput, *this);

                const int subs[] = {1};  // we just want to see group 1
                boost::sregex_token_iterator i(uri.begin(), uri.end(), ex, subs);
                std::string id = *i;

                restApiGetCall.SetResourceID(id);

                it->second(restApiGetCall);
                foundHandler = true;
                break;
            }
        }
        if (!foundHandler)
        {
            httpOutput.SendBody("Handler not found\n");
            return;
        }
    }
    else if (method == "POST")
    {
        bool foundHandler = false;
        for (PostHandlersType::iterator it = PostHandlers.begin(); it != PostHandlers.end(); ++it)
        {
            boost::regex ex(it->first);
            if (boost::regex_match(uri, ex))
            {
                RestApiOutput restApiOutput(httpOutput);
                RestApiPostCall restApiPostCall(restApiOutput, *this, body);

                const int subs[] = {1};  // we just want to see group 1
                boost::regex ex2(it->first);
                boost::sregex_token_iterator i(uri.begin(), uri.end(), ex2, subs);
                std::string id = *i;

                restApiPostCall.SetResourceID(id);

                it->second(restApiPostCall);
                foundHandler = true;
                break;
            }
        }
        if (!foundHandler)
        {
            httpOutput.SendBody("Handler not found");
            return;
        }
    }
    else
    {
        httpOutput.SendBody("Not implemented");
        return;
    }
}
Ejemplo n.º 17
0
int main(){
	ex2();
	return 0;
}
Ejemplo n.º 18
0
LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
    POINT coord;
    static segment *s;
    static cerc *c;

    switch (message)                  /* handle the messages */
    {

        case WM_CREATE:
            addMenu(hWnd);
            // Generez doua puncte, un segment si un cerc
        break;
        case WM_COMMAND:
            wmId    = LOWORD(wParam);
            wmEvent = HIWORD(wParam);
            // Parse the menu selections:
            switch (wmId) {
                case IDM_EXERCITIU_1:
                    current = 1;
                    ex1(hWnd);
                    break;
                case IDM_EXERCITIU_2:
                    current = 2;
                    ex2(hWnd);
                    break;
                case IDM_EXERCITIU_3:
                    current = 3;
                    clicks = 0;
                    L.clear();
                    InvalidateRect (hWnd, NULL, TRUE);
                    UpdateWindow (hWnd);
                    break;
                case IDM_EOL:
                    clicks = 0;
                    break;
                case IDM_CLEAR:
                    current = 0;
                    L.clear();
                    InvalidateRect (hWnd, NULL, TRUE);
                    UpdateWindow (hWnd);
                    break;
                case IDM_EXIT:
                    DestroyWindow(hWnd);
                    break;
                default:
                    current = 0;
                    return DefWindowProc(hWnd, message, wParam, lParam);
            }
		break;
        case WM_LBUTTONDOWN:

            if(current == 3)    {

                GetCursorPos(&coord);
                // Preiau coord. cursorului f. de coltul zonei client
                ScreenToClient(hWnd, (LPPOINT) &coord);


                if( clicks == 0 )   {

                    s = new segment();

                    s->setX(coord.x);
                    s->setY(coord.y);

                }   else {

                    s->setDx(coord.x - s->getX());
                    s->setDy(coord.y - s->getY());
                    s->setColor(color);
                    L.push_back(s);
                    InvalidateRect (hWnd, NULL, TRUE);
                    UpdateWindow (hWnd);
                    s = new segment();
                    s->setX(coord.x);
                    s->setY(coord.y);
                }
                clicks++;

            } else if(current == 4) {

                GetCursorPos(&coord);
                // Preiau coord. cursorului f. de coltul zonei client
                ScreenToClient(hWnd, (LPPOINT) &coord);


                if( clicks == 0 )   {

                    c = new cerc();

                    c->setX(coord.x);
                    c->setY(coord.y);

                    clicks++;

                }   else {


                    int dx = (coord.x - c->getX());
                    int dy = (coord.y - c->getY());
                    c->setR(sqrt(dx*dx + dy*dy));
                    c->setColor(color);
                    L.push_back(c);
                    InvalidateRect (hWnd, NULL, TRUE);
                    UpdateWindow (hWnd);
                    clicks = 0;
                }

            }

            break;
        case WM_KEYDOWN:
            switch (wParam) {

                case VK_END:
                    clicks = 0;
                break;

                case 'r': case 'R':
                    color = RGB(255, 0, 0); // Desenez cu rosu
                break;

                case 'g': case 'G':
                    color = RGB(0, 255, 0); // Desenez cu verde
                break;

                case 'b': case 'B':
                    color = RGB(0, 0, 255); // Desenez cu albastru
                break;

                case 's': case 'S':
                    current = 3;
                    clicks = 0;
                break;

                case 'c': case 'C':
                    current = 4;
                    clicks = 0;
                break;

            }
        break;
        case WM_PAINT:  {
            hdc = BeginPaint(hWnd, &ps);
            std::list<punct*>::iterator it;
                for (it=L.begin(); it!=L.end(); ++it){
                    (*it)->draw(hdc);
                }
            EndPaint(hWnd, &ps);
            UpdateWindow(hWnd);
        }
		break;
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hWnd, message, wParam, lParam);
    }

    return 0;
}