/*****************************************************************************
* Copyright (c) 1990-98 Digi International Inc., All Rights Reserved
* 
* This software contains proprietary and confidential information of Digi
* International Inc.  By accepting transfer of this copy, Recipient agrees
* to retain this software in confidence, to prevent disclosure to others,
* and to make no use of this software other than that for which it was
* delivered.  This is an unpublished copyrighted work of Digi International
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
* prohibited.
* 
* Restricted Rights Legend
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7031 or
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -
* Restricted Rights at 48 CFR 52.227-19, as applicable.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
*
*****************************************************************************/


// ConfigObject.h: interface for the CConfigObject class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_CONFIGOBJECT_H__5B80F912_D2E7_11D1_BAB3_00805F9E3135__INCLUDED_)
#define AFX_CONFIGOBJECT_H__5B80F912_D2E7_11D1_BAB3_00805F9E3135__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000


#include "ConfigWizSheet.h"
#include "ConfigWizPage.h"
#include "TreeNode.h"


class FW_EXPORTED_CLASS CConfigObject : public CObject
{
	DECLARE_DYNAMIC(CConfigObject)

public:

	virtual ~CConfigObject();

   HINSTANCE GetDllHandle(void) const { return m_hDll; }
   void SetDllHandle(HINSTANCE const hDll) { m_hDll = hDll; }

   CConfigObject * GetParent(void) const { return m_pParent; }

   CString GetIdentity(void) const { return m_strIdentity; }

   CString GetDisplayName(void) const { return m_strDisplayName; }

   HKEY GetOpenConfigKey(void) const { return m_hKey; }

   enum
   {
      UNKNOWN = -1,
      ADAPTER,
      LINE,
      PROTOCOL,
      SERVICE,
      PORT,
	  ROUTER,
   };

   int GetType(void) const { return m_eType; }

   enum
   {
      NOABILITIES    = 0x0000,
      DOPROPERTIES   = 0x0001,
      ADDCHILD       = 0x0002,
      DELETECHILD    = 0x0004,
   };

   int GetAbility(void) const { return m_eAbility; }

   INT_PTR GetChildCount(void) const { return m_apChildren.GetSize(); }
   CConfigObject * GetChild(int const nChild);

   struct SEnumDescendentsCriteria
   {
      CString strIdToMatch;

      SEnumDescendentsCriteria(CString const & strId = TEXT("")) { strIdToMatch = strId; iCurrentDescendent = -1; aDescendents.RemoveAll(); }

      // private
      int iCurrentDescendent;
      CTypedPtrArray<CObArray, CConfigObject*> aDescendents;

   };
   CConfigObject * EnumDescendents(SEnumDescendentsCriteria & Criteria);

   //
   // Overridables
   virtual BOOL AddChild(void) = 0;
   virtual BOOL DeleteChild(CConfigObject const * const pChild);

   virtual BOOL SetParameters(void);
   virtual BOOL RemoveParameters(BOOL fRemoveKey = FALSE);
   virtual BOOL CopyParameters(CConfigObject const * const pFrom);

   virtual BOOL BuildConfigDataRegPath(CString & strRegPath);

   virtual BOOL AddWizardPages(CConfigWizSheet * const pSheet) = 0;
   virtual BOOL RemoveWizardPages(CConfigWizSheet * const pSheet);
   virtual BOOL NextWizardPage(int const nState) = 0;

   virtual BOOL BuildDisplayTree(CTreeNode * const pNode);
   virtual CString GetInformationText(void);
   virtual BOOL DoProperties(void) = 0;

   virtual void ParentUpdate(void) {}

   virtual void ObjectToTrash(void) {}
   virtual void ObjectFromTrash(void) {}

   virtual INT_PTR GetConfiguredPorts(void);

protected:
   // operations
   void SetAbility(int const eAbility) { m_eAbility = eAbility; }
   void SetIdentity(CString const & strIdentity) { m_strIdentity = strIdentity; }
   void SetDisplayName(CString const & strDisplayName) { m_strDisplayName = strDisplayName; }
   void SetType(int const eType) { m_eType = eType; }
   // attributes
   //
   // Standard registry goo
   HKEY m_hKeyRoot;
   CString m_strRegPath;
   HKEY m_hKey;

   //
   // Allow instantiations of derived classes only
	CConfigObject(HKEY const hKeyRoot, CString const & strRegPath, CConfigObject const * const pParent);

   //
   // Children
   CTypedPtrArray<CObArray, CConfigObject*> m_apChildren;
   CTypedPtrArray<CObArray, CConfigObject*> m_apTrash;

   BOOL EmptyTrash(void);

private:
   //
   // Parent
   CConfigObject * m_pParent;

   //
   // Who am I?
   CString m_strIdentity;

   //
   // What do they call me?
   CString m_strDisplayName;

   //
   // What am I?
   int m_eType;

   //
   // What can I do?
   int m_eAbility;

   //
   // Where am I?
	HINSTANCE m_hDll;

   BOOL FindAllMatchingDescendents(SEnumDescendentsCriteria & Criteria);
};

#endif // !defined(AFX_CONFIGOBJECT_H__5B80F912_D2E7_11D1_BAB3_00805F9E3135__INCLUDED_)
