Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / platform / DARWIN / AFSPreference / afsltd.m
1 //
2 // afsltd.m
3 // OpenAFS
4 //
5 // Created by Claudio Bisegni LNF-INFN on 26/04/08.
6 // Copyright 2008 Infn. All rights reserved.
7 //
8 #import "global.h"
9 #import "AFSPropertyManager.h"
10 #include <unistd.h>
11
12 BOOL useAklog = NO;
13 NSString *afsSysPath = nil;
14 AFSPropertyManager *propManager = nil;
15
16 void readPreferenceFile();
17 void makeAFSPropertyManager();
18 void callAKlog();
19
20 int main(int argc, char *argv[])
21 {
22
23 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
24
25 NSLog(@"Start AFS Preference Daemon");
26 // read the preference file
27 readPreferenceFile();
28
29 //check if base afs path is set
30 if(!afsSysPath) return 1;
31
32 //Sleep ten seconds
33 sleep(10);
34
35 //make the afs property manager and load all afs configuration
36 makeAFSPropertyManager();
37
38 //call aklog
39 callAKlog();
40 if(propManager) [propManager release];
41
42 [pool release];
43 return 0;
44 }
45
46 // -------------------------------------------------------------------------------
47 // readPreferenceFile:
48 // -------------------------------------------------------------------------------
49 void readPreferenceFile()
50 {
51 // read the preference for afs path
52 afsSysPath = (NSString*)CFPreferencesCopyAppValue((CFStringRef)PREFERENCE_AFS_SYS_PAT, (CFStringRef)kAfsCommanderID);
53
54
55 // read the preference for aklog use
56 NSNumber *useAklogPrefValue = (NSNumber*)CFPreferencesCopyAppValue((CFStringRef)PREFERENCE_USE_AKLOG, (CFStringRef)kAfsCommanderID);
57 useAklog = [useAklogPrefValue boolValue];
58
59 }
60
61 // -------------------------------------------------------------------------------
62 // makeAFSPropertyManager:
63 // -------------------------------------------------------------------------------
64 void makeAFSPropertyManager() {
65 if(propManager) {
66 [propManager release];
67 }
68 propManager = [[AFSPropertyManager alloc] initWithAfsPath:afsSysPath];
69 [propManager loadConfiguration];
70 }
71
72 // -------------------------------------------------------------------------------
73 // makeAFSPropertyManager:
74 // -------------------------------------------------------------------------------
75 void callAKlog() {
76 //call aklog for all selected cell, but first check if afs is up
77 if([propManager checkAfsStatus] && useAklog) {
78 [propManager getTokens:false
79 usr:nil
80 pwd:nil];
81
82 // send notification to
83 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kMExtraAFSStateChange];
84 }
85 }