Thu Apr 28 2011 17:13:53

Asterisk developer's documentation


clm.c File Reference

Usage of the SAForum AIS (Application Interface Specification) More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "ais.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "asterisk/cli.h"
#include "asterisk/logger.h"
Include dependency graph for clm.c:

Go to the source code of this file.

Functions

static char * ais_clm_show_members (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int ast_ais_clm_load_module (void)
int ast_ais_clm_unload_module (void)
 ASTERISK_FILE_VERSION (__FILE__,"$Revision: 271869 $")
static void clm_node_get_cb (SaInvocationT invocation, const SaClmClusterNodeT *cluster_node, SaAisErrorT error)
static void clm_track_cb (const SaClmClusterNotificationBufferT *notif_buffer, SaUint32T num_members, SaAisErrorT error)

Variables

static struct ast_cli_entry ais_cli []
static const SaClmCallbacksT clm_callbacks
SaClmHandleT clm_handle
static SaAisErrorT clm_init_res

Detailed Description

Usage of the SAForum AIS (Application Interface Specification)

Author:
Russell Bryant <russell@digium.com>

This file contains the code specific to the use of the CLM (Cluster Membership) Service.

Definition in file clm.c.


Function Documentation

static char* ais_clm_show_members ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 73 of file clm.c.

References ast_cli_args::argc, ast_cli_entry::args, ARRAY_LEN, ast_cli(), buf, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, clm_handle, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.

{
   int i;
   SaClmClusterNotificationBufferT buf;
   SaClmClusterNotificationT notif[64];
   SaAisErrorT ais_res;

   switch (cmd) {
   case CLI_INIT:
      e->command = "ais show clm members";
      e->usage =
         "Usage: ais show clm members\n"
         "       List members of the cluster using the CLM (Cluster Membership) service.\n";
      return NULL;

   case CLI_GENERATE:
      return NULL;   /* no completion */
   }

   if (a->argc != e->args)
      return CLI_SHOWUSAGE;

   buf.notification = notif;
   buf.numberOfItems = ARRAY_LEN(notif);

   ais_res = saClmClusterTrack(clm_handle, SA_TRACK_CURRENT, &buf);
   if (ais_res != SA_AIS_OK) {
      ast_cli(a->fd, "Error retrieving current cluster members.\n");
      return CLI_FAILURE;
   }

   ast_cli(a->fd, "\n"
               "=============================================================\n"
               "=== Cluster Members =========================================\n"
               "=============================================================\n"
               "===\n");

   for (i = 0; i < buf.numberOfItems; i++) {
      SaClmClusterNodeT *node = &buf.notification[i].clusterNode;

      ast_cli(a->fd, "=== ---------------------------------------------------------\n"
                     "=== Node Name: %s\n"
                     "=== ==> ID: 0x%x\n"
                     "=== ==> Address: %s\n"
                     "=== ==> Member: %s\n",
                     (char *) node->nodeName.value, (int) node->nodeId,
                     (char *) node->nodeAddress.value,
                     node->member ? "Yes" : "No");

      ast_cli(a->fd, "=== ---------------------------------------------------------\n"
                     "===\n");
   }

   ast_cli(a->fd, "=============================================================\n"
                  "\n");

   return CLI_SUCCESS;
}
int ast_ais_clm_load_module ( void  )

Definition at line 136 of file clm.c.

References ais_err2str(), ais_version, ARRAY_LEN, ast_cli_register_multiple(), ast_log(), clm_callbacks, clm_handle, clm_init_res, and LOG_ERROR.

Referenced by load_module().

{
   clm_init_res = saClmInitialize(&clm_handle, &clm_callbacks, &ais_version);
   if (clm_init_res != SA_AIS_OK) {
      ast_log(LOG_ERROR, "Could not initialize cluster membership service: %s\n",
         ais_err2str(clm_init_res));
      return -1;
   }

   ast_cli_register_multiple(ais_cli, ARRAY_LEN(ais_cli));

   return 0;
}
int ast_ais_clm_unload_module ( void  )

Definition at line 150 of file clm.c.

References ais_err2str(), ARRAY_LEN, ast_cli_unregister_multiple(), ast_log(), clm_handle, clm_init_res, and LOG_ERROR.

Referenced by load_module(), and unload_module().

{
   SaAisErrorT ais_res;

   if (clm_init_res != SA_AIS_OK) {
      return 0;
   }

   ast_cli_unregister_multiple(ais_cli, ARRAY_LEN(ais_cli));

   ais_res = saClmFinalize(clm_handle);
   if (ais_res != SA_AIS_OK) {
      ast_log(LOG_ERROR, "Problem stopping cluster membership service: %s\n",
         ais_err2str(ais_res));
      return -1;
   }

   return 0;
}
ASTERISK_FILE_VERSION ( __FILE__  ,
"$Revision: 271869 $"   
)
static void clm_node_get_cb ( SaInvocationT  invocation,
const SaClmClusterNodeT *  cluster_node,
SaAisErrorT  error 
) [static]

Definition at line 61 of file clm.c.

{

}
static void clm_track_cb ( const SaClmClusterNotificationBufferT *  notif_buffer,
SaUint32T  num_members,
SaAisErrorT  error 
) [static]

Definition at line 67 of file clm.c.

{

}

Variable Documentation

struct ast_cli_entry ais_cli[] [static]
Initial value:
 {
   AST_CLI_DEFINE(ais_clm_show_members, "List current members of the cluster"),
}

Definition at line 132 of file clm.c.

const SaClmCallbacksT clm_callbacks [static]
Initial value:
 {
   .saClmClusterNodeGetCallback = clm_node_get_cb,
   .saClmClusterTrackCallback   = clm_track_cb,
}

Definition at line 56 of file clm.c.

Referenced by ast_ais_clm_load_module().

SaAisErrorT clm_init_res [static]

Definition at line 49 of file clm.c.

Referenced by ast_ais_clm_load_module(), and ast_ais_clm_unload_module().