00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __OP_BundleList__
00020 #define __OP_BundleList__
00021
00022 #include "OP_API.h"
00023 #include <iostream.h>
00024 #include <UT/UT_PtrArray.h>
00025 #include <UT/UT_IntArray.h>
00026 #include <UT/UT_SymbolTable.h>
00027 #include <UT/UT_Notifier.h>
00028 #include "OP_Node.h"
00029
00030 class UT_String;
00031 class PRM_Name;
00032 class OP_Node;
00033 class OP_Network;
00034 class CMD_Args;
00035 class CMD_Manager;
00036 class OP_Bundle;
00037 class OP_Group;
00038 class OP_BundleFilter;
00039
00040
00041
00042 class OP_API OP_BundleListEvent
00043 {
00044 public:
00045
00046 enum OP_BundleListEventType
00047 {
00048 BUNDLE_ADDED,
00049 BUNDLE_DELETED
00050 };
00051
00052 OP_BundleListEvent( OP_BundleListEventType type, OP_Bundle &bundle )
00053 : myEventType( type ), myBundle( bundle ) {}
00054
00055
00056 OP_BundleListEventType myEventType;
00057 OP_Bundle &myBundle;
00058 };
00059
00060
00061
00062 class OP_API OP_BundleList
00063 {
00064 public:
00065 OP_BundleList();
00066 ~OP_BundleList();
00067
00068 void clear();
00069
00070 int entries() const { return myBundles.entries(); }
00071 OP_Bundle *getBundle(int i) { return myBundles(i); }
00072 OP_Bundle *getBundle(const char *name);
00073
00074 int internalEntries() const { return myInternal.entries(); }
00075 OP_Bundle *getInternalBundle(int i) { return myInternal(i); }
00076
00077 OP_Bundle *createBundle(const char *name, int internal=0);
00078 OP_Bundle *duplicateBundle(OP_Bundle * bundle);
00079 int destroyBundle(const char *name);
00080 int destroyBundle(int index);
00081
00082 char * findUniqueBundleName(const char *base = NULL);
00083 int renameBundle(const char *oldname, const char *newname);
00084
00085
00086
00087
00088 int getMemberships(const OP_Node *node,
00089 UT_PtrArray<OP_Bundle *> &memberships) const;
00090
00091
00092 const OP_BundleFilter *setBundleFilter(const char *bname,
00093 const char *fname);
00094 const OP_BundleFilter *lookupFilter(const char *name) const;
00095
00096
00097 void getFilters( UT_PtrArray<const OP_BundleFilter *> &list );
00098
00099
00100
00101 void bundleSetLock( OP_Bundle *bundle, bool lock );
00102 const OP_BundleFilter *bundleSetFilter(OP_Bundle* bundle,
00103 const char *fname);
00104 const OP_BundleFilter *bundleSetFilter(OP_Bundle* bundle,
00105 const OP_BundleFilter *filter);
00106 void bundleClear( OP_Bundle *bundle );
00107 int bundleAddOp( OP_Bundle *bundle, OP_Node* node );
00108 int bundleAddOps(OP_Bundle *bundle,
00109 const OP_NodeList &nodes );
00110 int bundleRemoveOp( OP_Bundle *bundle, OP_Node* node );
00111 int bundleRemoveOps(OP_Bundle *bundle,
00112 const OP_NodeList &nodes );
00113
00114
00115 void nodeAdded(OP_Node *node);
00116 void nodeDeleted(OP_Node *node);
00117 void nodeRenamed(OP_Node *node);
00118
00119
00120
00121 void refilterOp(OP_Node &node);
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 void bulkAddNodes(const OP_NodeList *nodes);
00132
00133 int getTouchTime() const { return myTouchTime; }
00134
00135
00136
00137
00138
00139
00140
00141
00142 OP_Bundle *getPattern(UT_String &prev_bundle,
00143 const OP_Network *creator,
00144 const OP_Node *relativeto,
00145 const char *pattern,
00146 const char *filter = 0,
00147 const char *label = 0,
00148 bool subnet_inclusion = true,
00149 bool addinterest=1);
00150 void deReferenceBundle(const UT_String &prev_bundle);
00151
00152 void sortBundles();
00153
00154
00155 void simplifyPattern( const OP_Node *root, UT_String &pattern );
00156
00157
00158
00159
00160
00161
00162 static void simplifyPatternSafely( const OP_Node *root, UT_String &pattern );
00163
00164 void cmdLs(CMD_Args &args);
00165 void cmdAdd(CMD_Args &args);
00166 void cmdRm(CMD_Args &args);
00167 void cmdOp(CMD_Args &args);
00168 void cmdName(CMD_Args &args);
00169 int saveToHip(ostream &os);
00170
00171 void buildBundleMenu(PRM_Name *menu, int max,
00172 const char *filter=0,
00173 int include_at_sign=1,
00174 int put_in_default_message=1);
00175
00176 static void installCommands(CMD_Manager *cmd);
00177 void notifyOpsOfGroupChange(OP_Group *group);
00178
00179
00180
00181 UT_NotifierImpl< OP_BundleListEvent& >
00182 &getEventNotifier() { return myEventNotifier; }
00183
00184 void dumpFilters(ostream &os);
00185
00186 private:
00187 void notifyBundleChange(const char *pattern);
00188 void notifyBundleDeletion(OP_Bundle *);
00189 void touch();
00190 bool getSortedPatternTokenNodes(
00191 const OP_Node *root,
00192 const char *pattern_token,
00193 OP_NodeList &nodes );
00194
00195 UT_PtrArray<OP_Bundle *> myBundles;
00196 UT_PtrArray<OP_Bundle *> myInternal;
00197 UT_SymbolTable myNames;
00198 int mySortDirty;
00199 int myTouchTime;
00200
00201 void nodeAddedRecurse(OP_Bundle *bundle,
00202 OP_Node *node);
00203 void nodeDeletedRecurse(OP_Bundle *bundle,
00204 OP_Node *node);
00205
00206
00207 UT_IntArray myPendingBulkAdded;
00208
00209
00210 UT_NotifierImpl<OP_BundleListEvent&> myEventNotifier;
00211 };
00212
00213
00214
00215 class op_NodeBundle;
00216 class OP_API OP_NodeBundleMemberships
00217 {
00218 public:
00219 OP_NodeBundleMemberships();
00220 OP_NodeBundleMemberships( OP_BundleList *bundle_list );
00221 ~OP_NodeBundleMemberships();
00222
00223
00224 void saveMemberships( OP_Node *node );
00225
00226
00227 void restoreMemberships( OP_Node *node );
00228
00229
00230 int64 getMemoryUsage() const;
00231
00232 int getNumBundles() const;
00233
00234 private:
00235 void saveChildMemberships( OP_Node *node, OP_Node *root );
00236
00237 private:
00238 UT_PtrArray<op_NodeBundle *> myNodeBundles;
00239 OP_BundleList * myBundleList;
00240 };
00241
00242 #endif