first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / octopi / library / tentacles / simple_entity_registry.h
1 #ifndef SIMPLE_CLIENT_REGISTRY_CLASS
2 #define SIMPLE_CLIENT_REGISTRY_CLASS
3
4 /*****************************************************************************\
5 *                                                                             *
6 *  Name   : simple_entity_registry                                            *
7 *  Author : Chris Koeritz                                                     *
8 *                                                                             *
9 *******************************************************************************
10 * Copyright (c) 2002-$now By Author.  This program is free software; you can  *
11 * redistribute it and/or modify it under the terms of the GNU General Public  *
12 * License as published by the Free Software Foundation; either version 2 of   *
13 * the License or (at your option) any later version.  This is online at:      *
14 *     http://www.fsf.org/copyleft/gpl.html                                    *
15 * Please send any updates to: fred@gruntose.com                               *
16 \*****************************************************************************/
17
18 #include "entity_registry.h"
19
20 namespace octopi {
21
22 // forward.
23 class octopus_entity;
24 class recognized_entity;
25 class recognized_entity_list;
26
27 //! Provides a basic implementation of an entity_registry for octopus.
28 /*!
29   Requests to add an entity are always permitted; the registration is a
30   formality that allows us to establish a record for the entity.
31   This base class just implements authorized() by invoking locate_entity()
32   to check if the entity exists.  Thus, using it as a security model really
33   just requires calling add_entity() whenever a new entity is seen.
34   A different security model can be implemented in a derived class by over-
35   riding the authorized() method and making it perform an application-
36   specific security check.
37 */
38
39 class simple_entity_registry : public entity_registry
40 {
41 public:
42   simple_entity_registry();
43   virtual ~simple_entity_registry();
44
45   virtual bool authorized(const octopus_entity &entity);
46     //!< returns true if the "entity" is a registered and authorized entity.
47
48   virtual bool locate_entity(const octopus_entity &entity,
49           timely::time_stamp &last_active, basis::byte_array &verification);
50     //!< retrieves the "security_record" for the "entity" if it exists.
51     /*!< true is returned on success. */
52
53   virtual bool add_entity(const octopus_entity &entity,
54           const basis::byte_array &verification);
55     //!< adds the "entity" to the list of authorized users.
56     /*!< note that this will still succeed if the entity is already present,
57     allowing it to serve as an entity refresh method.  if the "verification"
58     has any length, it will be stored in the record for the "entity". */
59
60   virtual bool refresh_entity(const octopus_entity &entity);
61     //!< this should be used to refresh the entity's health record.
62     /*!< it indicates that this entity is still functioning and should not be
63     removed due to inactivity. */
64
65   virtual bool zap_entity(const octopus_entity &entity);
66     //!< removes an "entity" if the entity can be found.
67     /*!< true is returned if that "entity" existed. */
68
69   virtual basis::astring text_form();
70     //!< shows the contents of the registry.
71
72 private:
73   basis::mutex *_secure_lock;  //!< the synchronizer for our tentacle list.
74   recognized_entity_list *_entities;  //!< list of recognized entities.
75 };
76
77 } //namespace.
78
79 #endif
80