public
Description: My OS X Thermometer client.
Clone URL: git://github.com/dustin/osx-thermometer.git
Search Repo:
osx-thermometer / LempSource.m
100644 82 lines (73 sloc) 1.642 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// LempSource.m
// Thermometer
//
// Created by Dustin Sallings on 2005/2/9.
// Copyright 2005 Dustin Sallings. All rights reserved.
//
 
#import "LempSource.h"
#import "LempClient.h"
 
@implementation LempSource
 
-(id)initWithURL:(NSURL *)u
{
  id rv=[super initWithURL:u];
  NSArray *names=[self initThermList];
  if(names == nil) {
    [rv release];
    rv=nil;
  } else {
    [self initThermsFromNames:names];
  }
  return(rv);
}
 
-(NSArray *)initThermList
{
  NSNumber *portNum=[url port];
  int port=8181;
  if(portNum != nil) {
    port=[portNum intValue];
  }
  LempClient *lc=[[LempClient alloc] initWithDelegate:self
    host:[url host] port:port];
  NSArray *rv=nil;
  if(lc == nil) {
    NSLog(@"lempClient failed to initialize");
  } else {
    rv=[lc therms];
    [NSThread detachNewThreadSelector:@selector(readLoop:)
      toTarget:lc withObject:nil];
  }
  return(rv);
}
 
-(void)lempReconnect
{
  NSArray *ta=[self initThermList];
  if(ta == nil) {
    NSLog(@"Failed to reconnect, retrying.");
    [NSTimer scheduledTimerWithTimeInterval:60
      target: self
      selector: @selector(lempReconnect)
      userInfo:nil repeats:NO];
  } else {
    NSLog(@"Reconnected");
  }
}
 
-(void)receiveUpdate:(TempReading *)reading;
{
  [self notifyReading:reading];
}
 
-(void)lempExiting:(LempClient *)lc
{
  /*
  NSString *s=[[NSString alloc] initWithFormat:
    @"lemp client failed at: %@, restarting", [[NSDate date] description]];
  [status setStringValue: s];
  [s release];
  */
  NSLog(@"lemp thread exiting, beginning restart sequence");
  [NSTimer scheduledTimerWithTimeInterval:15
    target: self
    selector: @selector(lempReconnect)
    userInfo:nil repeats:NO];
}
 
@end