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 @import <Foundation/CPObject.j> 00024 @import <Foundation/CPString.j> 00025 00026 00027 CPUserSessionUndeterminedStatus = 0; 00028 CPUserSessionLoggedInStatus = 1; 00029 CPUserSessionLoggedOutStatus = 2; 00030 00031 CPUserSessionManagerStatusDidChangeNotification = @"CPUserSessionManagerStatusDidChangeNotification"; 00032 CPUserSessionManagerUserIdentifierDidChangeNotification = @"CPUserSessionManagerUserIdentifierDidChangeNotification"; 00033 00034 var CPDefaultUserSessionManager = nil; 00035 00036 @implementation CPUserSessionManager : CPObject 00037 { 00038 CPUserSessionStatus _status; 00039 00040 CPString _userIdentifier; 00041 } 00042 00043 + (id)defaultManager 00044 { 00045 if (!CPDefaultUserSessionManager) 00046 CPDefaultUserSessionManager = [[CPUserSessionManager alloc] init]; 00047 00048 return CPDefaultUserSessionManager; 00049 } 00050 00051 - (id)init 00052 { 00053 self = [super init]; 00054 00055 if (self) 00056 _status = CPUserSessionUndeterminedStatus; 00057 00058 return self; 00059 } 00060 00061 - (CPUserSessionStatus)status 00062 { 00063 return _status; 00064 } 00065 00066 - (void)setStatus:(CPUserSessionStatus)aStatus 00067 { 00068 if (_status == aStatus) 00069 return; 00070 00071 _status = aStatus; 00072 00073 [[CPNotificationCenter defaultCenter] 00074 postNotificationName:CPUserSessionManagerStatusDidChangeNotification 00075 object:self]; 00076 00077 if (_status != CPUserSessionLoggedInStatus) 00078 [self setUserIdentifier:nil]; 00079 } 00080 00081 - (CPString)userIdentifier 00082 { 00083 return _userIdentifier; 00084 } 00085 00086 - (void)setUserIdentifier:(CPString)anIdentifier 00087 { 00088 if (_userIdentifier == anIdentifier) 00089 return; 00090 00091 _userIdentifier = anIdentifier; 00092 00093 [[CPNotificationCenter defaultCenter] 00094 postNotificationName:CPUserSessionManagerUserIdentifierDidChangeNotification 00095 object:self]; 00096 } 00097 00098 @end