[BACK]Return to ClientInterest.c++ CVS log [TXT][DIR] Up to [Development] / fam / fam

Annotation of fam/fam/ClientInterest.c++, Revision 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 "ClientInterest.h"
        !            24:
        !            25: #include <assert.h>
        !            26: #include <errno.h>
        !            27:
        !            28: #include "Client.h"
        !            29: #include "Event.h"
        !            30: #include "FileSystem.h"
        !            31: #include "FileSystemTable.h"
        !            32:
        !            33: ClientInterest::ClientInterest(const char *name,
        !            34: 			       Client *c, Request r, const Cred& cr, Type type)
        !            35:     : Interest(name, myfilesystem = FileSystemTable::find(name, cr),
        !            36:                c->host(), VERIFY_EXPORTED),
        !            37:       myclient(c), request(r), mycred(cr), fs_request(0)
        !            38: {
        !            39:     ci_bits() = ACTIVE_STATE;
        !            40:     if (exported_to_host())
        !            41:     {
        !            42:         //  This is so horribly lame.  If this interest doesn't exist,
        !            43:         //  and someone somewhere set errno to EACCES, let's assume the
        !            44:         //  interest exists but this client doesn't have permission to
        !            45:         //  monitor it.  (The actual imon_express and lstat are done in
        !            46:         //  in the Interest constructor.)  This use of errno probably
        !            47:         //  makes it easy to become confused and suggest_insecure_compat
        !            48:         //  even when we shouldn't.
        !            49:         if ((!exists()) && (errno == EACCES) && (c != NULL))
        !            50:         {
        !            51:             c->suggest_insecure_compat(name);
        !            52:         }
        !            53:         post_event(exists() ? Event::Exists : Event::Deleted);
        !            54:         fs_request = myfilesystem->monitor(this, type);
        !            55:     }
        !            56:     else
        !            57:     {
        !            58:         post_event(Event::Deleted);
        !            59:     }
        !            60: }
        !            61:
        !            62: ClientInterest::~ClientInterest()
        !            63: {
        !            64:     myfilesystem->cancel(this, fs_request);
        !            65: }
        !            66:
        !            67: void
        !            68: ClientInterest::filesystem(FileSystem *fs)
        !            69: {
        !            70:     myfilesystem->cancel(this, fs_request);
        !            71:     myfilesystem = fs;
        !            72:     verify_exported_to_host();
        !            73:     if (exported_to_host())
        !            74:     {
        !            75:         fs_request = fs->monitor(this, type());
        !            76:         scan();
        !            77:     }
        !            78:     else if (fs_request != 0)
        !            79:     {
        !            80:         //  This Interest used to be on a filesystem which was mounted by
        !            81:         //  the client, but now is not?  Send a Deleted event.
        !            82:         post_event(Event::Deleted);
        !            83:         fs_request = 0;
        !            84:     }
        !            85: }
        !            86:
        !            87: void
        !            88: ClientInterest::findfilesystem()
        !            89: {
        !            90:     FileSystem *new_fs = FileSystemTable::find(name(), mycred);
        !            91:     if (new_fs != myfilesystem)
        !            92:     {
        !            93:         filesystem(new_fs);
        !            94:     }
        !            95: }
        !            96:
        !            97: //////////////////////////////////////////////////////////////////////////////
        !            98: //  Suspend/resume.
        !            99:
        !           100: bool
        !           101: ClientInterest::active() const
        !           102: {
        !           103:     return ci_bits() & ACTIVE_STATE;
        !           104: }
        !           105:
        !           106: void
        !           107: ClientInterest::suspend()
        !           108: {
        !           109:     if (active())
        !           110:     {   ci_bits() &= ~ACTIVE_STATE;
        !           111: 	myfilesystem->hl_suspend(fs_request);
        !           112:     }
        !           113: }
        !           114:
        !           115: void
        !           116: ClientInterest::resume()
        !           117: {
        !           118:     bool was_active = active();
        !           119:     ci_bits() |= ACTIVE_STATE;	// Set state before generating events.
        !           120:     do_scan();
        !           121:     if (!was_active)
        !           122: 	myfilesystem->hl_resume(fs_request);
        !           123: }
        !           124:
        !           125: void
        !           126: ClientInterest::post_event(const Event& event, const char *eventpath)
        !           127: {
        !           128:     assert(active());
        !           129:     if (!eventpath)
        !           130: 	eventpath = name();
        !           131:     myclient->post_event(event, request, eventpath);
        !           132: }
        !           133:
        !           134: Interest *
        !           135: ClientInterest::find_name(const char *)
        !           136: {
        !           137:     //  Ignore name.
        !           138:
        !           139:     return this;
        !           140: }
        !           141:
        !           142: bool
        !           143: ClientInterest::scan(Interest *ip)
        !           144: {
        !           145:     bool changed = false;
        !           146:     if (!ip)
        !           147: 	ip = this;
        !           148:     ip->mark_for_scan();
        !           149:     if (myclient->ready_for_events())
        !           150: 	changed = ip->do_scan();
        !           151:     else
        !           152: 	myclient->enqueue_for_scan(ip);
        !           153:     return changed;
        !           154: }
        !           155:
        !           156: void
        !           157: ClientInterest::unscan(Interest *ip)
        !           158: {
        !           159:     if (!ip)
        !           160: 	ip = this;
        !           161:     if (ip->needs_scan())
        !           162: 	myclient->dequeue_from_scan(ip);
        !           163: }
        !           164:
        !           165: bool
        !           166: ClientInterest::do_scan()
        !           167: {
        !           168:     bool changed = false;
        !           169:     if (needs_scan() && active()) {
        !           170:         become_user();
        !           171:         changed = Interest::do_scan();
        !           172:     }
        !           173:     return changed;
        !           174: }
        !           175:
        !           176: void
        !           177: ClientInterest::notify_created(Interest *ip)
        !           178: {
        !           179:     if (!ip)
        !           180: 	ip = this;
        !           181:     myfilesystem->ll_notify_created(ip);
        !           182: }
        !           183:
        !           184: void
        !           185: ClientInterest::notify_deleted(Interest *ip)
        !           186: {
        !           187:     if (!ip)
        !           188: 	ip = this;
        !           189:     myfilesystem->ll_notify_deleted(ip);
        !           190: }
        !           191:
        !           192: void
        !           193: ClientInterest::cancel()
        !           194: {
        !           195:     ci_bits() |= ACTIVE_STATE;
        !           196:     post_event(Event::Acknowledge);
        !           197:     unscan();
        !           198: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>