summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/ImplRepo_Service/XML_Backing_Store.h
blob: ba2ee8f1baeb42ae3be9ea04ce91d6d3af1d1450 (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* -*- C++ -*- */

//=============================================================================
/**
*  @file XML_Backing_Store.h
*
*  $Id$
*
*  This class defines an implementation of the backing store as a single XML file.
*
*  @author Darrell Brunsch <brunsch@cs.wustl.edu>
*  @author Priyanka Gontla <gontla_p@ociweb.com>
*/
//=============================================================================

#ifndef XML_BACKING_STORE_H
#define XML_BACKING_STORE_H

#include "ace/config-lite.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "Locator_Repository.h"

#include <vector>

class ACE_Configuration;
class ACEXML_FileCharStream;
class ACEXML_DefaultHandler;

/**
* @class XML_Backing_Store
*
* @brief XML backing store interface containing all ImR persistent information
* in a single file
*
*/
class XML_Backing_Store : public Locator_Repository
{
public:
  typedef std::pair<ACE_CString, ACE_CString> NameValue;
  typedef std::vector<NameValue> NameValues;
  XML_Backing_Store(const Options& opts,
                    CORBA::ORB_ptr orb,
                    bool suppress_erase = false);

  virtual ~XML_Backing_Store();

  /// indicate the XML filename as the persistence mode for the repository
  virtual const ACE_TCHAR* repo_mode() const;

  /// create the Server_Info server object
  /// @param info the source Server_Info data
  /// @param server_started indicates if the server object
  ///        existed when data was persisted
  /// @param extra_params extra name value pairs that
  ///        were reported for the server
  virtual void load_server (Server_Info *info,
                            bool server_started,
                            const NameValues& extra_params);

  /// create the Activator_Info activator object
  /// @param activator_name the Activator_Info name
  /// @param token the Activator_Info token
  /// @param ior the Activator_Info ior
  /// @param extra_params extra name value pairs that
  ///        were reported for the activator
  virtual void load_activator (const ACE_CString& activator_name,
                               long token,
                               const ACE_CString& ior,
                               const NameValues& extra_params);
protected:
  /// perform XML backing store specific initialization
  /// (loads servers and activators from the backing store)
  virtual int init_repo(PortableServer::POA_ptr imr_poa);

  /// perform server persistent update
  virtual int persistent_update(const Server_Info_Ptr& info, bool add);

  /// perform activator persistent update
  virtual int persistent_update(const Activator_Info_Ptr& info, bool add);

  /// perform persistent remove
  virtual int persistent_remove(const ACE_CString& name, bool activator);

  /// load the contents of a file into the repo using a Locator_XMLHandler
  /// @param filename the filename to read the contents from
  /// @param open_file the already open FILE stream for the
  ///        filename
  int load(const ACE_TString& filename, FILE* open_file = 0);

  /// load the contents of a file into the repo using the provided
  /// ACEXML_DefaultHandler
  /// @param filename the filename to read the contents from
  /// @param xml_handler the ACEXML_DefaultHandler to use to parse
  ///        the file
  /// @param debug the current debug level
  /// @param open_file the already open FILE stream for the
  ///        filename
  static int load(const ACE_TString& filename,
                  ACEXML_DefaultHandler& xml_handler,
                  unsigned int debug,
                  FILE* open_file = 0);

  /// persist the server
  /// @param fp the FILE stream to persist the server contents to
  /// @param info the Server_Info to persist
  /// @param tag_prepend a character string to prepend at the start
  ///        of every xml line to maintain proper indentation
  /// @param name_values extra name value pairs to write as attributes
  void persist(FILE* fp,
               const Server_Info& info,
               const char* tag_prepend,
               const NameValues& name_values = NameValues());

  /// persist the activator
  /// @param fp the FILE stream to persist the activator contents to
  /// @param info the Server_Info to persist
  /// @param tag_prepend a character string to prepend at the start
  ///        of every xml line to maintain proper indentation
  /// @param name_values extra name value pairs to write as attributes
  void persist(FILE* fp,
               const Activator_Info& info,
               const char* tag_prepend,
               const NameValues& name_values = NameValues());

  /// create the Server_Info server object
  /// @param server_started indication from persistence indicating if the
  ///        server object was present
  /// @param si the server info in question
  void create_server(bool server_started, const Server_Info_Ptr& si);

protected:
  /// the filename indicated in the Options for the backing store
  const ACE_TString filename_;

private:
  /// persist all servers and activators
  int persist();
};

#endif /* XML_BACKING_STORE_H */