text: /*
   * Note: this file originally auto-generated by mib2c using
   *  : mib2c.container.conf 17798 2009-10-27 06:44:54Z magfr $
   */
  
  #include <net-snmp/net-snmp-config.h>
  #include <net-snmp/net-snmp-includes.h>
  #include <net-snmp/agent/net-snmp-agent-includes.h>
  #include <net-snmp/agent/net-snmp-agent-includes.h>
  #include <net-snmp/agent/table_container.h>
  #include "cpqIdeAtaDiskTable.h"
  
  int SataDiskCondition;
  
  extern int netsnmp_arch_idedisk_container_load(netsnmp_container*);
  static void     _cache_free(netsnmp_cache * cache, void *magic);
  static int      _cache_load(netsnmp_cache * cache, void *vmagic);
  
  /** Initializes the cpqIdeAtaDiskTable module */
  void
  init_cpqIdeAtaDiskTable(void)
  {
      /*
       * here we initialize all the tables we're planning on supporting 
       */
      initialize_table_cpqIdeAtaDiskTable();
  }
  
  /** Initialize the cpqIdeAtaDiskTable table by defining its contents and how it's structured */
  void
  initialize_table_cpqIdeAtaDiskTable(void)
  {
      const oid       cpqIdeAtaDiskTable_oid[] =
          { 1, 3, 6, 1, 4, 1, 232, 14, 2, 4, 1 };
      const size_t    cpqIdeAtaDiskTable_oid_len =
          OID_LENGTH(cpqIdeAtaDiskTable_oid);
      netsnmp_handler_registration *reg = NULL;
      netsnmp_mib_handler *handler = NULL;
      netsnmp_container *container = NULL;
      netsnmp_table_registration_info *table_info = NULL;
      netsnmp_cache  *cache = NULL;
  
      int reg_tbl_ret = SNMPERR_SUCCESS;
  
      DEBUGMSGTL(("cpqIdeAtaDiskTable:init",
                  "initializing table cpqIdeAtaDiskTable\n"));
  
      reg =
          netsnmp_create_handler_registration("cpqIdeAtaDiskTable",
                                              cpqIdeAtaDiskTable_handler,
                                              cpqIdeAtaDiskTable_oid,
                                              cpqIdeAtaDiskTable_oid_len,
                                              HANDLER_CAN_RONLY);
      if (NULL == reg) {
          snmp_log(LOG_ERR,
                   "error creating handler registration for cpqIdeAtaDiskTable\n");
          goto bail;
      }
  
      container =
          netsnmp_container_find("cpqIdeAtaDiskTable:table_container");
      if (NULL == container) {
          snmp_log(LOG_ERR,
                   "error creating container for cpqIdeAtaDiskTable\n");
          goto bail;
      }
      container->container_name = strdup("cpqIdeAtaDiskTable  container");
  
      table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
      if (NULL == table_info) {
          snmp_log(LOG_ERR,
                   "error allocating table registration for cpqIdeAtaDiskTable\n");
          goto bail;
      }
      netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER,   /* index: cpqIdeAtaDiskControllerIndex */
                                       ASN_INTEGER,       /* index: cpqIdeAtaDiskIndex */
                                       0);
      table_info->min_column = COLUMN_CPQIDEATADISKCONTROLLERINDEX;
      table_info->max_column = COLUMN_CPQIDEATADISKTEMPERATURETHRESHOLD;
  
      /*************************************************
       *
       * inject container_table helper
       */
      handler = netsnmp_container_table_handler_get(table_info, container,
                                                    TABLE_CONTAINER_KEY_NETSNMP_INDEX);
      if (NULL == handler) {
          snmp_log(LOG_ERR,
                   "error allocating table registration for cpqIdeAtaDiskTable\n");
          goto bail;
      }
      if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
          snmp_log(LOG_ERR,
                   "error injecting container_table handler for cpqIdeAtaDiskTable\n");
          goto bail;
      }
      handler = NULL;             /* reg has it, will reuse below */
  
      /*************************************************
       *
       * inject cache helper
       */
      cache = netsnmp_cache_create(300,    /* timeout in seconds */
                                   _cache_load, _cache_free,
                                   cpqIdeAtaDiskTable_oid,
                                   cpqIdeAtaDiskTable_oid_len);
  
      if (NULL == cache) {
          snmp_log(LOG_ERR, "error creating cache for cpqIdeAtaDiskTable\n");
          goto bail;
      }
      cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;
      cache->magic = container;
  
      handler = netsnmp_cache_handler_get(cache);
      if (NULL == handler) {
          snmp_log(LOG_ERR,
                   "error creating cache handler for cpqIdeAtaDiskTable\n");
          goto bail;
      }
  
      if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
          snmp_log(LOG_ERR,
                   "error injecting cache handler for cpqIdeAtaDiskTable\n");
          goto bail;
      }
      handler = NULL;             /* reg has it */
  
      /*
       * register the table
       */
      reg_tbl_ret = netsnmp_register_table(reg, table_info);
      if (reg_tbl_ret != SNMPERR_SUCCESS ) {
          snmp_log(LOG_ERR,
                   "error registering table handler for cpqIdeAtaDiskTable\n");
          goto bail;
      }
  
      return;                     /* ok */
  
      /*
       * Some error occurred during registration. Clean up and bail.
       */
    bail:                        /* not ok */
  
      if (handler)
          netsnmp_handler_free(handler);
  
      if (cache)
          netsnmp_cache_free(cache);
  
      if (table_info)
          netsnmp_table_registration_info_free(table_info);
  
      if (container)
          CONTAINER_FREE(container);
  
      if (reg_tbl_ret == SNMPERR_SUCCESS)
          if (reg)
              netsnmp_handler_registration_free(reg);
  }
  
  /** Typical data structure for a row entry */
  /** create a new row in the table */
  cpqIdeAtaDiskTable_entry *
  cpqIdeAtaDiskTable_createEntry(netsnmp_container * container,
                                 oid cpqIdeAtaDiskControllerIndex,
                                 oid cpqIdeAtaDiskIndex)
  {
      cpqIdeAtaDiskTable_entry *entry;
  
      entry = SNMP_MALLOC_TYPEDEF(cpqIdeAtaDiskTable_entry);
      if (!entry)
          return NULL;
  
      entry->cpqIdeAtaDiskControllerIndex = cpqIdeAtaDiskControllerIndex;
      entry->cpqIdeAtaDiskIndex = cpqIdeAtaDiskIndex;
      entry->oid_index.len = 2;
      entry->oid_index.oids = (oid *) &entry->cpqIdeAtaDiskControllerIndex;
      return entry;
  }
  
  /** remove a row from the table */
  void
  cpqIdeAtaDiskTable_removeEntry(netsnmp_container * container,
                                 cpqIdeAtaDiskTable_entry * entry)
  {
  
      if (!entry)
          return;                 /* Nothing to remove */
      CONTAINER_REMOVE(container, entry);
      if (entry)
          SNMP_FREE(entry);       /* XXX - release any other internal resources */
  }
  
  /** remove a row from the table */
  void
  cpqIdeAtaDiskTable_freeEntry(cpqIdeAtaDiskTable_entry * entry)
  {
  
      if (!entry)
          return;                 /* Nothing to remove */
      SNMP_FREE(entry);           /* XXX - release any other internal resources */
  }
  
  /** handles requests for the cpqIdeAtaDiskTable table */
  int
  cpqIdeAtaDiskTable_handler(netsnmp_mib_handler *handler,
                             netsnmp_handler_registration *reginfo,
                             netsnmp_agent_request_info *reqinfo,
                             netsnmp_request_info *requests)
  {
  
      netsnmp_request_info *request;
      netsnmp_table_request_info *table_info;
      cpqIdeAtaDiskTable_entry *table_entry;
  
      DEBUGMSGTL(("cpqIdeAtaDiskTable:handler", "Processing request (%d)\n",
                  reqinfo->mode));
  
      switch (reqinfo->mode) {
          /*
           * Read-support (also covers GetNext requests)
           */
      case MODE_GET:
          for (request = requests; request; request = request->next) {
              if (request->processed)
                  continue;
              table_entry = (cpqIdeAtaDiskTable_entry *)
                  netsnmp_container_table_extract_context(request);
              table_info = netsnmp_extract_table_info(request);
              if ((NULL == table_entry) || (NULL == table_info)) {
                  snmp_log(LOG_ERR,
                           "could not extract table entry or info for cpqIdeAtaDiskTable\n");
                  snmp_set_var_typed_value(request->requestvb,
                                           SNMP_ERR_GENERR, NULL, 0);
                  continue;
              }
  
              switch (table_info->colnum) {
              case COLUMN_CPQIDEATADISKCONTROLLERINDEX:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskControllerIndex);
                  break;
              case COLUMN_CPQIDEATADISKINDEX:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskIndex);
                  break;
              case COLUMN_CPQIDEATADISKMODEL:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                           table_entry->cpqIdeAtaDiskModel,
                                           table_entry->
                                           cpqIdeAtaDiskModel_len);
                  break;
              case COLUMN_CPQIDEATADISKFWREV:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                           table_entry->cpqIdeAtaDiskFwRev,
                                           table_entry->
                                           cpqIdeAtaDiskFwRev_len);
                  break;
              case COLUMN_CPQIDEATADISKSERIALNUMBER:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                           table_entry->
                                           cpqIdeAtaDiskSerialNumber,
                                           table_entry->
                                           cpqIdeAtaDiskSerialNumber_len);
                  break;
              case COLUMN_CPQIDEATADISKSTATUS:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskStatus);
                  break;
              case COLUMN_CPQIDEATADISKCONDITION:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskCondition);
                  break;
              case COLUMN_CPQIDEATADISKCAPACITY:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskCapacity);
                  break;
              case COLUMN_CPQIDEATADISKSMARTENABLED:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskSmartEnabled);
                  break;
              case COLUMN_CPQIDEATADISKTRANSFERMODE:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskTransferMode);
                  break;
              case COLUMN_CPQIDEATADISKCHANNEL:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskChannel);
                  break;
              case COLUMN_CPQIDEATADISKNUMBER:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskNumber);
                  break;
              case COLUMN_CPQIDEATADISKLOGICALDRIVEMEMBER:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskLogicalDriveMember);
                  break;
              case COLUMN_CPQIDEATADISKISSPARE:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskIsSpare);
                  break;
              case COLUMN_CPQIDEATADISKOSNAME:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                           table_entry->cpqIdeAtaDiskOsName,
                                           table_entry->
                                           cpqIdeAtaDiskOsName_len);
                  break;
              case COLUMN_CPQIDEATADISKTYPE:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->cpqIdeAtaDiskType);
                  break;
              case COLUMN_CPQIDEATADISKSATAVERSION:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskSataVersion);
                  break;
              case COLUMN_CPQIDEATADISKMEDIATYPE:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskMediaType);
                  break;
              case COLUMN_CPQIDEATADISKSSDWEARSTATUS:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskSSDWearStatus);
                  break;
              case COLUMN_CPQIDEATADISKPOWERONHOURS:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                             table_entry->
                                             cpqIdeAtaDiskPowerOnHours);
                  break;
              case COLUMN_CPQIDEATADISKSSDPERCNTENDRNCEUSED:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_GAUGE,
                                             table_entry->
                                             cpqIdeAtaDiskSSDPercntEndrnceUsed);
                  break;
              case COLUMN_CPQIDEATADISKSSDESTTIMEREMAININGHOURS:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_COUNTER,
                                             table_entry->
                                             cpqIdeAtaDiskSSDEstTimeRemainingHours);
                  break;
              case COLUMN_CPQIDEATADISKCURRTEMPERATURE:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskCurrTemperature);
                  break;
              case COLUMN_CPQIDEATADISKTEMPERATURETHRESHOLD:
                  if (!table_entry) {
                      netsnmp_set_request_error(reqinfo, request,
                                                SNMP_NOSUCHINSTANCE);
                      continue;
                  }
                  snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                             table_entry->
                                             cpqIdeAtaDiskTemperatureThreshold);
                  break;
  
              default:
                  netsnmp_set_request_error(reqinfo, request,
                                            SNMP_NOSUCHOBJECT);
                  break;
              }
          }
          break;
  
      }
      return SNMP_ERR_NOERROR;
  }
  
  /**
   * @internal
   */
  static int
  _cache_load(netsnmp_cache * cache, void *vmagic)
  {
      netsnmp_container *container;
  
      DEBUGMSGTL(("internal:cpqIdeAtaDiskTable:_cache_load", "called\n"));
  
      if ((NULL == cache) || (NULL == cache->magic)) {
          snmp_log(LOG_ERR,
                   "invalid cache for cpqIdeAtaDiskTable_cache_load\n");
          return -1;
      }
      container = (netsnmp_container *) cache->magic;
  
      /** should only be called for an invalid or expired cache */
      netsnmp_assert((0 == cache->valid) || (1 == cache->expired));
  
      /*
       * load cache here (or call function to do it)
       */
  
      netsnmp_arch_idedisk_container_load(container);
      return 0;
  }                               /* _cache_load */
  
  /**
   * @Internal
   */
  /** remove a row from the table */
  static void
  cpqIdeAtaDiskTable_freeEntry_cb(cpqIdeAtaDiskTable_entry * entry,
                                  void *magic)
  {
  
      cpqIdeAtaDiskTable_freeEntry(entry);
  }
  
  /**
   * @internal
   */
  static void
  _cache_free(netsnmp_cache * cache, void *magic)
  {
      netsnmp_container *container;
  
      DEBUGMSGTL(("internal:cpqIdeAtaDiskTable:_cache_free", "called\n"));
  
      if ((NULL == cache) || (NULL == cache->magic)) {
          snmp_log(LOG_ERR,
                   "invalid cache in cpqIdeAtaDiskTable_cache_free\n");
          return;
      }
      container = (netsnmp_container *) cache->magic;
  
      /*
       * empty (but don't free) cache here
       */
      CONTAINER_CLEAR(container,
                      (netsnmp_container_obj_func *)
                      cpqIdeAtaDiskTable_freeEntry_cb, NULL);
  }                               /* _cache_free */
  