1 /* 2 * net.h 3 * 4 * Public header file for the net client driver. 5 */ 6 7 /* 8 * Copyright (C) 2000-2006 Kern Sibbald 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of version 2 of the GNU General 12 * Public License as published by the Free Software Foundation. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public 20 * License along with this program; if not, write to the Free 21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 * MA 02110-1335, USA. 23 */ 24 25 #ifndef _NET_H 26 #define _NET_H 27 28 #define BIGBUF 4096 29 30 class NetUpsDriver: public UpsDriver 31 { 32 public: 33 NetUpsDriver(UPSINFO *ups); ~NetUpsDriver()34 virtual ~NetUpsDriver() {} 35 Factory(UPSINFO * ups)36 static UpsDriver *Factory(UPSINFO *ups) 37 { return new NetUpsDriver(ups); } 38 39 virtual bool get_capabilities(); 40 virtual bool read_volatile_data(); 41 virtual bool read_static_data(); 42 virtual bool check_state(); 43 virtual bool Open(); 44 virtual bool Close(); 45 virtual bool entry_point(int command, void *data); 46 47 private: 48 49 bool getupsvar(const char *request, char *answer, int anslen); 50 bool poll_ups(); 51 bool fill_status_buffer(); 52 bool get_ups_status_flag(int fill); 53 54 static SelfTestResult decode_testresult(char* str); 55 static LastXferCause decode_lastxfer(char *str); 56 57 struct CmdTrans { 58 const char *request; 59 const char *upskeyword; 60 int nfields; 61 }; 62 static const CmdTrans cmdtrans[]; 63 64 char _device[MAXSTRING]; 65 char *_hostname; 66 int _port; 67 sock_t _sockfd; 68 bool _got_caps; 69 bool _got_static_data; 70 time_t _last_fill_time; 71 char _statbuf[BIGBUF]; 72 int _statlen; 73 time_t _tlog; 74 bool _comm_err; 75 int _comm_loss; 76 }; 77 78 #endif /* _NET_H */ 79