Annotation of fam/fam/MxClient.c++, Revision 1.1.1.1
1.1 trev 1: // Copyright (C) 1999 Silicon Graphics, Inc. All Rights Reserved.
2: //
3: // This program is free software; you can redistribute it and/or modify it
4: // under the terms of version 2 of the GNU General Public License as
5: // published by the Free Software Foundation.
6: //
7: // This program is distributed in the hope that it would be useful, but
8: // WITHOUT ANY WARRANTY; without even the implied warranty of
9: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, any
10: // license provided herein, whether implied or otherwise, is limited to
11: // this program in accordance with the express provisions of the GNU
12: // General Public License. Patent licenses, if any, provided herein do not
13: // apply to combinations of this program with other product or programs, or
14: // any other product whatsoever. This program is distributed without any
15: // warranty that the program is delivered free of the rightful claim of any
16: // third person by way of infringement or the like. See the GNU General
17: // Public License for more details.
18: //
19: // You should have received a copy of the GNU General Public License along
20: // with this program; if not, write the Free Software Foundation, Inc., 59
21: // Temple Place - Suite 330, Boston MA 02111-1307, USA.
22:
23: #include <stdlib.h>
24: #include "MxClient.h"
25:
26: #include <assert.h>
27:
28: #include "DirEntry.h"
29: #include "Directory.h"
30: #include "Event.h"
31: #include "File.h"
32: #include "Log.h"
33:
34: MxClient::MxClient(in_addr host)
35: : Client(NULL, host)
36: {
37: }
38:
39: MxClient::~MxClient()
40: {
41: while (requests.size())
42: {
43: Request r = requests.first();
44: delete interest(r); // Destroy all interests.
45: requests.remove(r);
46: }
47: }
48:
49: // MxClient::interest() maps a request number to a ClientInterest ptr.
50:
51: ClientInterest *
52: MxClient::interest(Request r)
53: {
54: ClientInterest *ip = requests.find(r);
55: if (!ip)
56: Log::error("%s invalid request number %d", name(), r);
57: return ip;
58: }
59:
60: bool
61: MxClient::check_new(Request request, const char *path)
62: {
63: if (path[0] != '/')
64: { Log::info("relative path \"%s\" rejected", path);
65: post_event(Event::Acknowledge, request, path);
66: return false;
67: }
68:
69: if (requests.find(request))
70: { Log::error("%s nonunique request number %d rejected", name(), request);
71: return false;
72: }
73:
74: return true;
75: }
76:
77: void
78: MxClient::monitor_file(Request request, const char *path, const Cred& cred)
79: {
80: if (check_new(request, path))
81: {
82: ClientInterest *ip = new File(path, this, request, cred);
83: requests.insert(request, ip);
84: }
85: }
86:
87: void
88: MxClient::monitor_dir(Request request, const char *path, const Cred& cred)
89: {
90: if (check_new(request, path))
91: {
92: ClientInterest *ip = new Directory(path, this, request, cred);
93: requests.insert(request, ip);
94: }
95: }
96:
97: void
98: MxClient::suspend(Request r)
99: {
100: ClientInterest *ip = interest(r);
101: if (ip)
102: ip->suspend();
103: }
104:
105: void
106: MxClient::resume(Request r)
107: {
108: ClientInterest *ip = interest(r);
109: if (ip)
110: ip->resume();
111: }
112:
113: void
114: MxClient::cancel(Request r)
115: {
116: ClientInterest *ip = interest(r);
117: if (ip) {
118: requests.remove(r);
119: ip->cancel();
120: delete ip;
121: }
122: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>