dsrc isn't necessary for this repo
[client-tools.git] / src / external / 3rd / library / perforce / include / handler.h
blobfaa7210194a18a3b197f5f6bf997905cb2159225
1 /*
2 * Copyright 1995, 1996 Perforce Software. All rights reserved.
4 * This file is part of Perforce - the FAST SCM System.
5 */
7 /*
8 * handler.h - last chance handlers to keep track of loose objects
10 * Handlers provide a way of associating an object with a string so
11 * context can be retained across RPC dispatched function calls.
12 * This is used for file transfers, which are carried out in a series
13 * of RPC calls. The sender picks a handle name and then uses that
14 * consistenly during the transfer. The receiver uses the provided handle
15 * name to stash and retrieve the object the represents the open file.
17 * Handlers also provide a means of tracking across objects. If any
18 * object encounters an error, it can mark the handle so that a subsequent
19 * call to AnyErrors() can report so.
21 * Public classes:
23 * Handlers - a list of LastChance objects
24 * LastChance - a virtual base class that gets deleted with the
25 * handlers.
28 class LastChance;
30 struct Handler {
31 StrBuf name;
32 int anyErrors;
33 LastChance *lastChance;
34 } ;
36 class LastChance {
38 public:
39 LastChance()
41 handler = 0;
42 isError = 0;
45 virtual ~LastChance();
47 void Install( Handler *h )
49 handler = h;
50 handler->lastChance = this;
53 void SetError()
55 isError = 1;
58 void SetError( Error *e )
60 if( e->Test() ) isError = 1;
63 int IsError()
65 return isError;
68 private:
69 Handler *handler;
70 int isError;
72 } ;
74 const int maxHandlers = 3;
76 class Handlers {
78 public:
79 Handlers();
80 ~Handlers();
82 void Install( const StrPtr *name,
83 LastChance *lastChance,
84 Error *e );
86 LastChance * Get( const StrPtr *name, Error *e );
88 int AnyErrors( const StrPtr *nane );
90 private:
92 int numHandlers;
93 Handler table[maxHandlers];
94 Handler *Find( const StrPtr *handle, Error *e = 0 );
95 } ;