File: FileManager.h

package info (click to toggle)
trafficserver 9.2.5%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 53,008 kB
  • sloc: cpp: 345,484; ansic: 31,134; python: 24,200; sh: 7,271; makefile: 3,045; perl: 2,261; java: 277; pascal: 119; sql: 94; xml: 2
file content (101 lines) | stat: -rw-r--r-- 3,564 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/** @file

  Interface for class to manage configuration updates

  @section license License

  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */

#pragma once

#include "tscore/ink_mutex.h"
#include "tscore/List.h"

#include <unordered_map>

class ExpandingArray;
class ConfigManager;

typedef void (*FileCallbackFunc)(char *, char *);

struct callbackListable {
public:
  FileCallbackFunc func;
  LINK(callbackListable, link);
};

enum lockAction_t {
  ACQUIRE_LOCK,
  RELEASE_LOCK,
};

//  class FileManager
//
//  public functions:
//
//  addFile(char*, char *, bool, configFileInfo*) - adds a new config file to be
//       managed.  A ConfigManager object is created for the file.
//       if the file_info ptr is not NULL, a WebFileEdit object
//       is also created
//
//  getRollbckObj(char* , ConfigManagerPtr**) - sets *rbPtr to ConfigManager
//       object bound to fileName.  Returns true if there is
//       a binding and false otherwise
//
//  getWFEObj(char*, WebFileEdit**)  - sets *wfePtr to WebFileEdit
//       object bound to fileName.  Returns true if there is
//       a binding and false otherwise
//
//  registerCallback(FileCallbackFunc) - registers a callback function
//       which will get called every time a managed file changes.  The
//       callback function should NOT use the calling thread to
//       access any ConfigManager objects or block for a long time
//
//  fileChanged(const char* fileName, const char *configName) - called by ConfigManager objects
//       when their contents change.  Triggers callbacks to FileCallbackFuncs
//
//  isConfigStale() - returns whether the in-memory files might be stale
//       compared to what is on disk.
//
//  rereadConfig() - Checks all managed files to see if they have been
//       updated
//  addConfigFileGroup(char* data_str, int data_size) - update config file group infos
class FileManager
{
public:
  FileManager();
  ~FileManager();
  void addFile(const char *fileName, const char *configName, bool root_access_needed, bool isRequired,
               ConfigManager *parentConfig = nullptr);
  bool getConfigObj(const char *fileName, ConfigManager **rbPtr);
  void registerCallback(FileCallbackFunc func);
  void fileChanged(const char *fileName, const char *configName);
  void rereadConfig();
  bool isConfigStale();
  void configFileChild(const char *parent, const char *child);

private:
  ink_mutex accessLock; // Protects bindings hashtable
  ink_mutex cbListLock; // Protects the CallBack List
  DLL<callbackListable> cblist;
  std::unordered_map<std::string_view, ConfigManager *> bindings;
  void addFileHelper(const char *fileName, const char *configName, bool root_access_needed, bool isRequired,
                     ConfigManager *parentConfig);
};

void initializeRegistry(); // implemented in AddConfigFilesHere.cc