summaryrefslogtreecommitdiffstats
path: root/src/knutclient.h
blob: 6d490a75fae7de7811dfd573aee4d0b2f51bc464 (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/***************************************************************************
                          knutclient.h  -  description
                             -------------------
    begin                : Út srp 21 19:12:20 CEST 2001
    copyright            : (C) 2001 by Daniel Prynych
    email                : Daniel.Prynych@alo.cz
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KNUTCLIENT_H
#define KNUTCLIENT_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "knutmainwindow.h"
#include "knutvardata.h"
#include "knutupsdata.h"
#include "knutnet.h"
#include "knutdock.h"
#include "knutprefdlg.h"
#include "knutmessagemanager.h"

#include <kapplication.h>


#include <tqwidget.h>
#include <tqtimer.h>
#include <tqstringlist.h>
#include <tqmutex.h>

  const int countNextConnDelay = 10;
  const int nextConnDelay[] = {
  5, 5, 20, 30, 60, 60, 120, 300, 600, 900 };


class KNutClient : public TQObject, public KSessionManaged {
  Q_OBJECT
  TQ_OBJECT
  public:
    KNutClient(bool noDock = false, TQObject* tqparent=0,const char* name=0);
    ~KNutClient();

  private slots:
    void slotTimeout (void);

    void slotReconnectTimeout (void);

    void slotSetNewUPS (TQString name);

    void slotPreferenceUps(void);

    void slotSetConfig (unsigned int changeSetting);

    void slotPrintUPSVars(void);
    void slotInstComms(void);
    void slotRWVars(void);
    void slotChangeRWVars( TQString );

    void slotSaveConf (void);


    void slotExitApplication(void);


/**
 * 
 * Calls function for repainting of icon in dock.
 * Vola funkci pro prekresleni icony v doku.
 * 
 * @since  0.1
 **/
    void slotTryFirstConnection (int maxCount);



/**
 * This function is called when program repeats other connection;
 * Calls function for repainting of icon in dock.
 * Tata funkce je volana, kdyz program opakuje pokus o pripojeni.
 * Vola funkci pro prekresleni icony v doku.
 * 
 * @since  0.1
 **/
  void slotTryReepatFirstConnection (int number );


/**
 * Nastavi hodnoty po prvem pripojeni na UPS, zavola prekresleni docku a  nastartuje timer
 * Sets values after the first conection to UPS ,calls to tqrepaint of dock and starts timer
 * 
 * @since  0.2
 **/
    void slotFirstConnection (void);



/**
 * Zpracuje chybu spojeni
 * Executes error of connection
 * 
 * @since  0.1
 **/
    void slotErrorConnection (int error);


/**
 * Zpracuje ukonceni spojeni, pokud spojeni bylo ukonceno druhou stranou.
 * Executes end of connection, when connection was closed by the second side.
 * 
 * @since  0.1
 **/
    void slotConnectionClosed(void);


/**
 *
 *
 * @since  0.1
 **/
    void slotRefreshConnection(void);


    void closeMainWindow (void);
    void exitMainWindow (void);
    void slotActiveMainWindow (void);

    virtual bool commitData (TQSessionManager&);
    virtual bool saveState (TQSessionManager&);

  private:

/**
 * Prepares and show main window.
 * Pripravi a zobrazi hlavni okno.
 *
 * @since  0.1
 **/
    void makeMainWindow (void);

/**
 * Sets all variables to initial values.
 * Nastavi vsechny vsechny promenne na pocatecni hodnoty.
 *
 * @since  0.1
 **/
    void initVars (void);

    void loadConfiguration ( void );
    void saveConfiguration ( bool all = true );

    void upsActivate (void);
    void upsDeactivate (void);

    void setActiveUpsVars (bool mWindow = true);
    void setActiveXFerVars (bool activate);

    void getUpsData (void);

    void setActiveUpsInfo (TQString name);

    void addEventString (const TQString text, const TQString UPSAddress = TQString());

    void showStatusEvent(void);




/********* PRIVATE VARS****************/
    // hlavni informace o upsce
    // main informacion about UPS
    KNutVarData::upsInfoDef m_mainUpsInfo;

    // v teto strukture jsou ulozeny promene ktere nastavuji konfiguraci
    // in this structure are saveing values, which setting configuration
    KNutVarData::SettingDataDef settingData;

    KNutDock* m_myDock;

    KNutMainWindow* mainWindow;

    KNutUpsData* upsRecords;
    KNutVarData* analogRecords;

    TQTimer* m_upsTimer;
    TQTimer* m_reconnectTimer;

    TQStringList* m_listKNutEvent;

    bool m_panelsAreZeroing; //   indikuje zda je panel nulovany // use if analog panels is setting to zero
    //  kod posledni chyby spojeni zjistene v timeoutu
    //  nebere ohled zda byla chyba pri inicializaci
    int m_lastError;

    KNutMessageManager* m_myMessMan;

    // mutex for reconnect, only one reconnect at a time
    TQMutex m_reconnectMutex;
    TQMutex m_upsDeactivateMutex;

  };
#endif