API 0.9.5
Foundation/CPUserSessionManager.j
Go to the documentation of this file.
00001 /*
00002  * CPUserSessionManager.j
00003  * Foundation
00004  *
00005  * Created by Francisco Tolmasky.
00006  * Copyright 2008, 280 North, Inc.
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 
00024 CPUserSessionUndeterminedStatus = 0;
00025 CPUserSessionLoggedInStatus     = 1;
00026 CPUserSessionLoggedOutStatus    = 2;
00027 
00028 CPUserSessionManagerStatusDidChangeNotification         = @"CPUserSessionManagerStatusDidChangeNotification";
00029 CPUserSessionManagerUserIdentifierDidChangeNotification = @"CPUserSessionManagerUserIdentifierDidChangeNotification";
00030 
00031 var CPDefaultUserSessionManager = nil;
00032 
00033 @implementation CPUserSessionManager : CPObject
00034 {
00035     CPUserSessionStatus _status;
00036 
00037     CPString            _userIdentifier;
00038 }
00039 
00040 + (id)defaultManager
00041 {
00042     if (!CPDefaultUserSessionManager)
00043         CPDefaultUserSessionManager = [[CPUserSessionManager alloc] init];
00044 
00045     return CPDefaultUserSessionManager;
00046 }
00047 
00048 - (id)init
00049 {
00050     self = [super init];
00051 
00052     if (self)
00053         _status = CPUserSessionUndeterminedStatus;
00054 
00055     return self;
00056 }
00057 
00058 - (CPUserSessionStatus)status
00059 {
00060     return _status;
00061 }
00062 
00063 - (void)setStatus:(CPUserSessionStatus)aStatus
00064 {
00065     if (_status == aStatus)
00066         return;
00067 
00068     _status = aStatus;
00069 
00070     [[CPNotificationCenter defaultCenter]
00071         postNotificationName:CPUserSessionManagerStatusDidChangeNotification
00072                       object:self];
00073 
00074     if (_status != CPUserSessionLoggedInStatus)
00075         [self setUserIdentifier:nil];
00076 }
00077 
00078 - (CPString)userIdentifier
00079 {
00080     return _userIdentifier;
00081 }
00082 
00083 - (void)setUserIdentifier:(CPString)anIdentifier
00084 {
00085     if (_userIdentifier == anIdentifier)
00086         return;
00087 
00088     _userIdentifier = anIdentifier;
00089 
00090     [[CPNotificationCenter defaultCenter]
00091         postNotificationName:CPUserSessionManagerUserIdentifierDidChangeNotification
00092                       object:self];
00093 }
00094 
00095 @end
 All Classes Files Functions Variables Defines