Giter VIP home page Giter VIP logo

Comments (5)

augcampos avatar augcampos commented on August 15, 2024

Hi there,

What do you mean "static compilation", because will be static linked on use?

  • check wiki examples, on section [build example] (Examples)
    g++ Test.cpp -o tt -lasteriskcpp

for the disable logging: Yes, please see the example (link)

  • you can set the level to LL_FATAL
    • LogHandler::getInstance()->setLevel(LL_TRACE); (Link)
  • or define DISABLE_LOG_HANDLER & DISABLE_LOG_TOTAL (link)

from asterisk-cpp.

mike-5345 avatar mike-5345 commented on August 15, 2024

Yes I would like to compile to an archive for static linking.

When I define DISABLE_LOG_TOTAL I get this error:
src/exceptions/ExceptionHandler.cpp: In static member function 'static void asteriskcpp::ExceptionHandler::signalHandler(int)': src/exceptions/ExceptionHandler.cpp:125:45: error: invalid operands of types 'const char [11]' and 'int' to binary 'operator<<' LOG_ERROR_DATA("Expected: " << SIGSEGV << ", got: " << signal << ", returning"); ^ src/exceptions/ExceptionHandler.cpp:125:17: error: 'LOG_ERROR_DATA' was not declared in this scope LOG_ERROR_DATA("Expected: " << SIGSEGV << ", got: " << signal << ", returning"); ^~~~~~~~~~~~~~ src/exceptions/ExceptionHandler.cpp:125:17: note: suggested alternative: 'LOG_ERROR_STR' LOG_ERROR_DATA("Expected: " << SIGSEGV << ", got: " << signal << ", returning"); ^~~~~~~~~~~~~~ LOG_ERROR_STR make: *** [Makefile:1500: libasteriskcpp_la-ExceptionHandler.lo] Error 1

Also, what is the proper way to attempt reconnection if it fails? Currently I am getting a segfault when I create and attempt to connect in a loop.

from asterisk-cpp.

augcampos avatar augcampos commented on August 15, 2024

Hi there,

I had no problem on compile and execute this test (after install via make):

#include <iostream>
#include <asteriskcpp/Manager.hpp>

#define DISABLE_LOG_HANDLER
#define DISABLE_LOG_TOTAL

using namespace asteriskcpp;

void eventCallback(const ManagerEvent& me) {
    std::cout << "TEST EVENT START: " << me.getEventName() << std::endl;
    if (me.getEventName() == "NewChannel") {
        std::cout << "E - " << me.toString() << std::endl;
    }
    std::cout << "TEST EVENT: " << me.toLog() << std::endl;
}

int main() {
    std::cout << asteriskcpp::getCurrentTimeStamp() << " START ASTERISK-CPP-TEST" << std::endl;
    LogHandler::getInstance()->setLevel(LL_FATAL);

    ManagerConnection mc;

    try {
        mc.addEventCallback(&eventCallback);

        if (mc.connect("192.168.1.10")) {

            if (mc.login("administrator", "secret")) {

                for (int i = 0; i < 1; i++) {
                    asteriskcpp::EventsAction ea("OFF");
                    mc.sendAction(&ea);
                    ea.setEventMask("ON");
                    mc.sendAction(&ea);
                    asteriskcpp::ManagerResponse* rpc;

                    asteriskcpp::AbsoluteTimeoutAction ata("SIP/1000", 30);
                    rpc = mc.syncSendAction(ata);
                    delete (rpc);

                    asteriskcpp::ListCommandsAction lca;
                    rpc = mc.syncSendAction(lca);
                    delete (rpc);

                    asteriskcpp::CommandAction coma("sip show peers");
                    asteriskcpp::CommandResponse* cr = (asteriskcpp::CommandResponse*) (mc.syncSendAction(coma));
                    std::cout << std::endl << "ZZZZZZ" << cr->toLog() << std::endl;
                    for (std::vector<std::string>::const_iterator it = cr->getResult().begin(); it != cr->getResult().end(); it++) {
                        std::cout << "[" << (*it) << "]" << std::endl;
                    }
                    delete (cr);
                }
                mc.logoff();
            }
            mc.disconnect();
        }
    } catch (Exception e) {
        std::cout << " ERROR :" << e.getMessage() << std::endl;
    }
    std::cout << asteriskcpp::getCurrentTimeStamp() << " END ASTERISK-CPP-TEST" << std::endl;
    exit(0);
}

from asterisk-cpp.

mike-5345 avatar mike-5345 commented on August 15, 2024

OK I followed your steps and it did work. Another question is, is there any case where it will log to stdout? Or does this prevent it from logging totally?

Also, what is the correct way to attempt a reconnect if one has failed?

And is there any way to compile to archive for static linking?

Thank you for your time

from asterisk-cpp.

augcampos avatar augcampos commented on August 15, 2024

is there any case where it will log to stdout? Or does this prevent it from sologging totally?

Is not supposed to do it, but could have missed some stdout(printf/cout), if I did open a issue so can be fixed :)

Also, what is the correct way to attempt a reconnect if one has failed?

Not at the lib level.
But the connect will return false and you can try again. Please see (code)

And is there any way to compile to archive for static linking?

At this time, No.
I try it, some time ago but I was getting to much trouble with the dependency libs.

from asterisk-cpp.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.