//
// CamCategory.h
//
// Base class for Categories which use the cam service.
//
//
// Copyright (c) 1998, 2000 Silicon Graphics, Inc. All Rights Reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of version 2.1 of the GNU Lesser General Public
// License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it would be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// Further, this software is distributed without any warranty that it is
// free of the rightful claim of any third person regarding infringement
// or the like. Any license provided herein, whether implied or
// otherwise, applies only to this software file. Patent licenses, if
// any, provided herein do not apply to combinations of this program
// with other software, or any other product whatsoever.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
// USA.
//
// Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
// Mountain View, CA 94043, or http://www.sgi.com/
//
// For further information regarding this notice, see:
// http://oss.sgi.com/projects/GenInfo/NoticeExplan/
//
#ident "1.1"
#include <cam.h>
#include <sysadm/Category.h>
#include <sysadm/DictionaryOf.h>
#include <fsmgr/config.h>
// CAM_WAR is for "cam workaround". All code marked #ifdef CAM_WAR is
// hacking to get around bugs in libcam.
#define CAM_WAR
namespace fsmgr {
using namespace sysadm;
//
// "CAM_STATE" is the name of an Attribute synthesized for Resource
// and ResourceGroup categories that represents the state of an Item.
//
#define STATE_KEY "CAM_STATE"
//
// The following long longs are the possible values for the
// "CAM_STATE" Attribute.
//
// Resource, ResourceGroup
#define STATE_NULL (0LL)
#define STATE_UNKNOWN (1LL)
#define STATE_ONLINE_PENDING (2LL)
#define STATE_ONLINE (3LL)
#define STATE_OFFLINE_PENDING (4LL)
#define STATE_OFFLINE (5LL)
#define STATE_ERROR (6LL)
#define STATE_MAINTENANCE (7LL)
// Resource Group
#define STATE_ONLINE_READY (8LL)
//
// "CAM_STATUS" is the name of an Attribute synthesized for Cluster,
// Machine, Resource, and Resource Group categories, that represents
// the status of an Item. CAM_STATUS differs from CAM_STATE in that
// it takes on the STATUS_ERROR value when there is an error on a
// Resource or a ResourceGroup. This simplifies client code in the
// DetailView that wants to be able tell what kind of icon to display
// and whether or not to blink by looking at only one attribute.
//
#define STATUS_KEY "CAM_STATUS"
//
// The following strings are the possible values for the "CAM_STATUS"
// Attribute.
//
// Cluster, Machine, Resource, ResourceGroup
#define STATUS_UNKNOWN "UNKNOWN"
// Cluster and Machine
#define STATUS_INACTIVE "INACTIVE"
// Cluster
#define STATUS_ACTIVE "ACTIVE"
// Machine
#define STATUS_UP "UP"
#define STATUS_DOWN "DOWN"
// Resource, ResourceGroup
#define STATUS_ONLINE_PENDING "ONLINE_PENDING"
#define STATUS_ONLINE "ONLINE"
#define STATUS_OFFLINE_PENDING "OFFLINE_PENDING"
#define STATUS_OFFLINE "OFFLINE"
#define STATUS_ERROR "ERROR"
#define STATUS_MAINTENANCE "MAINTENANCE"
// Resource Group
#define STATUS_ONLINE_READY "ONLINE_READY"
// Filesystem
#define STATUS_MOUNTED "MOUNTED"
#define STATUS_UNMOUNTED "UNMOUNTED"
#define STATUS_MOUNT_READY "MOUNT_READY"
//
// CamCategory translates libcam notifications into Category
// notifications. Multiple libcam categories can be combined into a
// single Category. Attributes of libcam objects with the same
// selector will be set on the same Item.
//
class CamCategory : public Category {
public:
// Constructor for subclasses that only monitor one
// cam_category_t. Subclasses should pass the name of their
// Catetory as "selector" and the cam_category_t type of their
// Category as "category". Additional cam_category_t's can be
// added to addCategory().
//
// The cam_category_t passed to the constructor is distinguished
// from any categories passed to addCategory() in that in order
// for CamCategory to create an Item, an object in the
// distinguished cam_category_t must exist. In other words, if
// CamCategory gets an "add" notification about an object from the
// distinguished cam_category_t, it will create an Item and add
// it. If CamCategory gets an "add" notification from one of the
// other objects, it will not create an Item unless an Item from
// the distinguished cam_category_t already exists.
//
// Clients can therefore count on the presence of attributes from
// the distinguished categories, but should not assume that
// attributes from any of the other categories are there.
CamCategory(const String& selector, cam_category_t category);
// Destructor.
virtual ~CamCategory();
// Add a cam_category_t to be monitored to this CamCategory. This
// methods cannot be called after calling startMonitor().
void addCategory(cam_category_t category);
// Called when notification filter is first added. Start the
// connection with libcam.
virtual void startMonitor();
protected:
#ifdef CAM_WAR
virtual void addItem(const Item& item);
#endif
// Create an item corresponding to "obj".
virtual Item* createItemFromObject(const cam_object_t& obj);
// Create any attributes that need to be derived from the original object.
// This is called before calling Category::addItem and
// Category::changeItem.
virtual void modifyItemOnCamEvent(Item* item);
// Get the selector for "obj".
virtual String getSelectorFromObject(const cam_object_t& obj);
enum { MAX_CATEGORIES = 3 };
unsigned int _numCategories;
cam_category_t _categories[MAX_CATEGORIES];
DictionaryOf<Item>* _itemCache;
void copyAttrs(const Item* source, Item& dest);
private:
#ifdef CAM_WAR
bool checkCategory(cam_category_t category);
#endif
static void handleInput(void* clientData, int id, int fd);
void addOrChangeObject(const cam_object_t& obj);
void handleAdded(const cam_event_t& event);
void handleInventory(const cam_event_t& event);
void handleModify(const cam_event_t& event);
void handleRemove(const cam_event_t& event);
static void initTypeTable();
unsigned int _numInventories;
cam_handle_t _handle;
int _inputId;
static DictionaryOf<const Attribute::EType> _typeTable;
static DictionaryOf<String> _invisibleAttrs;
static const Attribute::EType STRING;
static const Attribute::EType LONG;
static const Attribute::EType BOOLEAN;
static const Attribute::EType DOUBLE;
};
} // namespace fsmgr