# SoftBank Robotics documentation What's new in NAOqi 2.8?

# qi::ApplicationSession

`ApplicationSession` is an application with an embedded auto-connected `Session`.

## Summary

Global Classes

- class qi::ApplicationSession

  Functions (class qi::ApplicationSession)

  qi::ApplicationSession::listenUrl

  qi::ApplicationSession::run

  qi::ApplicationSession::standAlone

  qi::ApplicationSession::allListenUrl

  qi::ApplicationSession::config

  qi::ApplicationSession::~ApplicationSession

  qi::ApplicationSession::helpText

  qi::ApplicationSession::url

  qi::ApplicationSession::session

  qi::ApplicationSession::startSession

  qi::ApplicationSession::start

  qi::ApplicationSession::ApplicationSession

## Detailed Description

`ApplicationSession` is meant to be instantiated in the main function. It works pretty much like `Application` but embeds a Session in it. The session is connected when `start` is called (or when `run` is called if `start` is never called).

The session is automatically activated (in listening or connected mode) according to the arguments passed to the program.

`ApplicationSession` also parses arguments, see qi application arguments.

See also

This class follows the logic of `Application`.

### Usage Example

    #include <qi/applicationsession.hpp>

    int main(int argc, char* argv[])
    {
      qi::ApplicationSession app(argc, argv);

      app.start();

      qi::SessionPtr session = app.session();

      // do things with session->service() or session->registerService

      // if you want to keep the program running
      app.run();
    }

## Reference

### qi::ApplicationSession Class Reference

#### Introduction

`More...`

    #include <qi/applicationsession.hpp>

- Inherits: `noncopyable`, `qi::Application`

#### Enumerations

enum `Option`

  Name | Value | Brief
  --- | --- | ---
  `Option_None` | 0 | No option, this is the default behavior.
  `Option_NoAutoExit` | 1 | With this option the application won’t stop once the session is disconnected.

#### Public Functions

``ApplicationSession``(int& argc, char**& argv, int opt, const Url& defaultUrl)
``ApplicationSession``(const std::string& name, int& argc, char**& argv, int opt, const Url& defaultUrl)
``ApplicationSession``(int& argc, char**& argv, const Config& defaultConfig)
``~ApplicationSession``()
SessionPtr ``session``() const
const Config& ``config``() const
Url ``url``() const
Url ``listenUrl``() const
std::vector<Url> ``allListenUrl``() const
void ``start``()
void ``startSession``()
void ``run``()
bool ``standAlone``()
std::string ``helpText``() const

#### Detailed Description

ApplicationSession is an application with an embedded session. The constructor has to be the first method called of the class to initialize the class. Be careful with the scope of the object, once the destructor is called, the session is destroyed as well.

#### Function Documentation

`qi::ApplicationSession::``ApplicationSession`(int& argc, char**& argv, int opt = 0, const Url& defaultUrl = SessionConfig::defaultConnectUrl()

  Brief: Constructors of the class.

  Parameters: | argc – The number of arguments. argv – The array containing all the arguments given to the program. opt – Either ApplicationSession::Option_None or ApplicationSession::Option_NoAutoExit. The default behavior of ApplicationSession is to call stop() once the session gets disconnected. defaultUrl – The default url used if no qi-url was found in the command line arguments and no suitable QI_URL environment variable was defined.

  The session owned by the object can have two different modes: either standard or standalone.

  To make an application session standalone, you need to specify the “–qi-standalone” option on the command line arguments or set the option in the configuration passed at the application construction.

  A standard session must connect to a service directory, and therefore needs a URL to connect to. This URL is chosen from available values (the ones that have been specified) according to the following order: First the URL that was specified as “–qi-url <url>” in the command line arguments.Then the URL specified in the “QI_URL” environment variable.Finally the URL passed directly or as a member of the configuration to the constructor.

  A standalone session cannot connect to a service directory but must instead listen on some URLs. A standard session can also listen, but will only do if the “–qi-listen-url” is given in the command line arguments or if a service is registered on it. In both cases, the URLs to listen on are chosen from available values (the ones that have been specified) according to the following order: First the URLs that were specified as “–qi-listen-url <urls>” in the command line arguments.Then the URLs specified in the “QI_LISTEN_URL” environment variable.Then the URLs in the configuration passed to the constructor.Finally the hardcoded default listen URL.

  Both the “–qi-listen-url” command line argument and the “QI_LISTEN_URL” environment variable follow the same format “url1;url2;...”, allowing the user to specify multiple values.

`qi::ApplicationSession::``ApplicationSession`(const std::string& name, int& argc, char**& argv, int opt = 0, const Url& defaultUrl = SessionConfig::defaultConnectUrl()

`qi::ApplicationSession::``ApplicationSession`(int& argc, char**& argv, const Config& defaultConfig)

`qi::ApplicationSession::``~ApplicationSession`()

SessionPtr `qi::ApplicationSession::``session`()`const`

  Brief:

  Returns: | The embedded session used by ApplicationSession.

const Config& `qi::ApplicationSession::``config`()`const`

Url `qi::ApplicationSession::``url`()`const`

  Brief:

  Returns: | The URL used by ApplicationSession to connect to a service directory.

Url `qi::ApplicationSession::``listenUrl`()`const`

  Brief:

  Returns: | The first URL used by ApplicationSession to listen on.

std::vector<Url> `qi::ApplicationSession::``allListenUrl`()`const`

  Brief:

  Returns: | All the URLs used by ApplicationSession to listen on.

void `qi::ApplicationSession::``start`()

  Establishes the session’s connection and moreover starts listening if qi-listen-url was given. Deprecatedsince 2.5, use startSession instead

void `qi::ApplicationSession::``startSession`()

  Establishes the session’s connection and moreover starts listening if qi-listen-url was given.

void `qi::ApplicationSession::``run`()

  Runs the application and automatically calls start() if it hasn’t been done yet.

bool `qi::ApplicationSession::``standAlone`()

  Returns whether the ApplicationSession runs in standalone mode.

std::string `qi::ApplicationSession::``helpText`()`const`

  Brief:

  Returns: | A concatenation of the ApplicationSession’s help with the Application’s help texts.

Glossary Site map Index Support Contact Legal Notices