gboolean afdal_session_login gchar *  usr,
gchar *  passwd,
gchar *  kernel_hostname,
gchar *  kernel_port,
AfDalNulFunc  usr_function,
gpointer  usr_data

Perform a login process against central server.

This function tries to login on the af-kernel located at kernel_hostname and kernel_port, using as login usr and password passwd.

When server's response arrives usr_function will be called with the given usr_data.

Every Af-Arch client must perform a login process and be accepted in order to invoke remote services in other Af-Arch server nodes.

Currently, Af-Arch servers doesn't need to perform a login request in other to talk with other servers. They actually can do request to other servers if the services invoked are public. In the case a server need to invoke remote services that aren't public, the server will also need to perform a login request (and of course, central server must allow him to execute services, check asplclm tool to know more about how to configure permissions to enable users to invoke services)

This function, as all function inside the Af-Arch framework which request you to provide a response handler function, will not block caller. This means the function will return inmediatly and once the response have arrived, the function provided, in this case usr_function, will be executed in a separeted automatically created thread.

Here is an example on how to make a login request. Keep in mind this API is for asynchronous request so the example needs to implement a blocking mechanism to wait remote server response. Of course, this will no be needed while programming interfaces because they already have a mainloop allways running.

#include <afdal.h>

gboolean my_login_process (AfDalNulData *data, gpointer usr_data) 
        GAsyncQueue * queue = usr_data;

        // check login status
        if (AFDAL_IS_OK (data)) {
                g_print ("Login process was successfull, status message: %s\n",
                         AFDAL_RESPONSE (data));
        }else {
                g_print ("Login process has failed, status message: %s\n",
                         AFDAL_RESPONSE (data));
        // free no longer needed data
        afdal_nul_free (data);

        // unblocking main thread
        g_async_queue_push (queue, GINT_TO_POINTER (TRUE));
        return TRUE;

gint main (gint argc, gchar ** argv) {
        gchar * static_user = "aspl";
        gchar * static_pass = "test";
        gchar * static_host = "titan.aspl";
        // it is considered as a standard to run af-kernel servers
        // on tcp port 55000
        gchar * static_port = "55000";
        // first of all, initialize Af-Arch
        afdal_init ();

        // Create an async queue to be able to wait. This is necessary
        // for this example to implement a blocking mechanism because
        // this function is asynchronous. 
        // This means that it will
        // return inmediatly allowing you to do other task while login
        // request is been performed.
        // Once the request response arrives, my_login_process function
        // will be executed from a different thread.
        GAsyncQueue * queue = g_async_queue_new ();

        // perform login request.
        if (!afdal_session_login (static_user, static_pass, 
                                  static_host, static_port, 
                                  my_login_process, queue)) {
                g_print ("Unable to make the login request, exiting..\n");
                return -1;
        g_print ("Making login request, waiting response..:\n");

        // keeps on waiting until response arrives
        g_async_queue_pop   (queue);
        g_async_queue_unref (queue);

        return 0;

You can also try to use synchronous login request but it is only recomended on the following situations:

  • You are going to programm a cilent interface for console mode which doesn't need threading. That's because synchronous login request will block the caller until the response is received.

  • You are going to program some kind of batch process in C or C# which only makes login, do some maintenance job and then logout.

  • You are going to programm a web page usign ASP.NET / XSP from Mono. On this case, asynchronous programming doesn't make sense. What it is needed is a blocking programming model.

In the rest of cases, it is assumed (and recomended) to avoid synchronous programming because the blocking issue. Most client interfaces aren't implemented using threads mechanism but some kind of loop based on the poll or select system call function. As a consecuence, to make blocking calls will freeze your client interface showing a really ugly hanged interface effect.

usr login user
passwd password associated
kernel_hostname hostname where af-kernel is running
kernel_port port where af-kernel is listening
usr_function function to be executed when the server response arrives.
usr_data user data passed to user_function.
TRUE if login request is sent or FALSE if not.