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 package uk.co.westhawk.snmp.beans;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 import uk.co.westhawk.snmp.stack.*;
52 import uk.co.westhawk.snmp.pdu.*;
53
54 import javax.swing.tree.*;
55 import java.awt.*;
56 import java.util.*;
57 import java.text.*;
58 import java.lang.*;
59 import java.io.*;
60 import java.beans.*;
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 public class DialogChannelStatusBean extends SNMPRunBean
115 implements Observer, TreeNode {
116 private static final String version_id = "@(#)$Id: DialogChannelStatusBean.java,v 1.18 2006/02/02 15:49:39 birgit Exp $ Copyright Westhawk Ltd";
117
118
119
120
121
122
123
124
125
126 public final static String dlgR4DeviceIndex = "1.3.6.1.4.1.3028.2.1.1.2.1.1.1";
127
128
129
130
131
132
133 public final static String dlgR4DeviceName = "1.3.6.1.4.1.3028.2.1.1.2.1.1.2";
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156 public final static String dlgR4DeviceType = "1.3.6.1.4.1.3028.2.1.1.2.1.1.3";
157
158
159
160
161
162
163 public final static String dlgR4DeviceOpenCount = "1.3.6.1.4.1.3028.2.1.1.2.1.1.5";
164
165
166
167
168
169 public final static String dlgR4VoiceChannelStatus = "1.3.6.1.4.1.3028.2.1.1.2.2.1.2";
170
171 private final static int NR_OID = 5;
172
173
174 public final static int unknown = 1;
175 public final static int voice = 2;
176 public final static int dti = 3;
177 public final static int isdn = 4;
178 public final static int msi = 5;
179
180
181 public final static int idle = 1;
182 public final static int playing = 2;
183 public final static int recording = 3;
184 public final static int gettingDigits = 5;
185 public final static int blocked = 16;
186
187 public final static int dialing = 4;
188 public final static int playTone = 6;
189 public final static int sendingFax = 8;
190 public final static int receivingFax = 9;
191 public final static int betweenFAXPages = 10;
192 public final static int hookState = 11;
193 public final static int winking = 12;
194 public final static int callProgess = 13;
195 public final static int gettingR2MF = 14;
196
197 public final static String vch_status[] = {
198 "",
199 "Channel not active",
200 "Playing Audio Data",
201 "Recording Audio Data",
202 "Dialing Digits",
203 "Collecting DTMF digits",
204 "Playing a tone",
205 "",
206 "Sending a FAX (VFX boards)",
207 "Receiving a FAX (VFX boards)",
208 "Between FAX pages (VFX boards)",
209 "Changing hook status to onhook or offhook",
210 "Performing a wink",
211 "Performing Call progress analysis",
212 "Retrieving R2MF digits",
213 "",
214 "Blocked"
215 };
216
217 private GetNextPdu_vec pdu;
218 private Hashtable channelIndexStatusHash;
219 private Hashtable channelHash;
220
221 private TreeNode parent;
222 private DefaultTreeModel treeModel;
223
224 private boolean isGetNextInFlight;
225 private Date lastUpdateDate = null;
226
227 private int deviceType = 0;
228 private String deviceName = "";
229 private int openCount = 0;
230 private int channelStatus = 0;
231
232
233
234
235 public DialogChannelStatusBean() {
236 channelIndexStatusHash = new Hashtable();
237 channelHash = new Hashtable();
238 }
239
240
241
242
243
244
245
246
247
248 public DialogChannelStatusBean(String h, int p) {
249 this(h, p, null);
250 }
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265 public DialogChannelStatusBean(String h, int p, String b) {
266 this();
267 setHost(h);
268 setPort(p);
269 setBindAddress(b);
270 }
271
272
273
274
275
276
277
278 public Date getLastUpdateDate() {
279 return lastUpdateDate;
280 }
281
282
283
284
285
286
287
288
289
290
291
292 public Enumeration getChannelIndexes() {
293 return channelIndexStatusHash.keys();
294 }
295
296
297
298
299 public synchronized int getChannelCount() {
300 return channelIndexStatusHash.size();
301 }
302
303
304
305
306
307
308
309
310 public String getChannelName(Integer index) {
311 String name = "";
312 Object obj = channelHash.get(index);
313 if (obj != null) {
314 ChannelStatus chSt = (ChannelStatus) obj;
315 name = chSt.getName();
316 }
317 return name;
318 }
319
320
321
322
323
324
325
326
327
328 public int getChannelStatus(Integer index) {
329 int status = 0;
330 Object obj = channelIndexStatusHash.get(index);
331 if (obj != null) {
332 status = ((Integer) obj).intValue();
333 }
334 return status;
335 }
336
337
338
339
340
341
342
343
344
345 public String getChannelStatusString(Integer index) {
346 int status = getChannelStatus(index);
347 String str = vch_status[status];
348 return str;
349 }
350
351
352
353
354 public Enumeration children() {
355 return channelHash.elements();
356 }
357
358
359
360
361
362 public int getChildCount() {
363 int sz = channelHash.size();
364 return sz;
365 }
366
367
368
369
370
371 public TreeNode getChildAt(int childIndex) {
372 TreeNode node = null;
373 if (childIndex < channelHash.size()) {
374 Enumeration e = channelHash.elements();
375 for (int i = 0; i <= childIndex; i++) {
376 node = (TreeNode) e.nextElement();
377 }
378 }
379 return node;
380 }
381
382
383
384
385
386
387 public int getIndex(TreeNode node) {
388 int ret = -1;
389 if (channelHash.contains(node)) {
390 boolean found = false;
391 Enumeration e = channelHash.elements();
392 while (e.hasMoreElements() && !found) {
393 TreeNode n = (TreeNode) e.nextElement();
394 found = (n == node);
395 ret++;
396 }
397 }
398 return ret;
399 }
400
401
402
403
404 public TreeNode getParent() {
405 return parent;
406 }
407
408
409
410
411 public boolean getAllowsChildren() {
412 return true;
413 }
414
415
416
417
418 public boolean isLeaf() {
419 return false;
420 }
421
422
423
424
425
426 public void action() {
427 if (isHostPortReachable()) {
428 lastUpdateDate = new Date();
429 isGetNextInFlight = false;
430 setRunning(true);
431 }
432 }
433
434
435
436
437
438
439
440
441 public void run() {
442 while (context != null && isRunning()) {
443 if (isGetNextInFlight == false) {
444
445 isGetNextInFlight = true;
446
447 pdu = new GetNextPdu_vec(context, NR_OID);
448 pdu.addObserver(this);
449
450 pdu.addOid(dlgR4DeviceIndex);
451 pdu.addOid(dlgR4DeviceName);
452 pdu.addOid(dlgR4DeviceType);
453 pdu.addOid(dlgR4DeviceOpenCount);
454 pdu.addOid(dlgR4VoiceChannelStatus);
455 try {
456 pdu.send();
457 } catch (PduException exc) {
458 System.out.println("PduException " + exc.getMessage());
459 } catch (IOException exc) {
460 System.out.println("IOException " + exc.getMessage());
461 }
462 }
463
464 try {
465 Thread.sleep(interval);
466 } catch (InterruptedException ix) {
467 ;
468 }
469 }
470 }
471
472
473
474
475
476
477 public void update(Observable obs, Object ov) {
478 boolean hasEnded = false;
479 int index;
480 varbind[] var;
481
482 pdu = (GetNextPdu_vec) obs;
483
484 if (pdu.isTimedOut() == false) {
485 if (pdu.getErrorStatus() == AsnObject.SNMP_ERR_NOERROR) {
486 var = (varbind[]) ov;
487 if (var[0].getOid().toString().startsWith(dlgR4DeviceIndex)) {
488 index = ((AsnInteger) var[0].getValue()).getValue();
489 deviceName = ((AsnOctets) var[1].getValue()).getValue();
490 deviceType = ((AsnInteger) var[2].getValue()).getValue();
491 openCount = ((AsnInteger) var[3].getValue()).getValue();
492 channelStatus = ((AsnInteger) var[4].getValue()).getValue();
493
494 if (deviceType == voice) {
495 Integer indexInt = new Integer(index);
496 if (openCount == 0) {
497 channelIndexStatusHash.remove(indexInt);
498 channelHash.remove(indexInt);
499 } else {
500 channelIndexStatusHash.put(indexInt,
501 new Integer(channelStatus));
502
503 ChannelStatus cStatus = (ChannelStatus) channelHash.get(indexInt);
504
505 if (cStatus == null) {
506 cStatus = new ChannelStatus(index, channelStatus,
507 deviceName, this);
508 channelHash.put(indexInt, cStatus);
509 } else {
510 cStatus.setStatus(channelStatus);
511 }
512 }
513 }
514
515
516 pdu = new GetNextPdu_vec(context, NR_OID);
517 pdu.addObserver(this);
518
519 pdu.addOid(var[0].getOid().toString());
520 pdu.addOid(var[1].getOid().toString());
521 pdu.addOid(var[2].getOid().toString());
522 pdu.addOid(var[3].getOid().toString());
523 pdu.addOid(var[4].getOid().toString());
524 try {
525 pdu.send();
526 } catch (PduException exc) {
527 System.out.println("PduException " + exc.getMessage());
528 } catch (IOException exc) {
529 System.out.println("IOException " + exc.getMessage());
530 }
531 } else {
532 hasEnded = true;
533 }
534 } else {
535 hasEnded = true;
536 }
537 } else {
538 channelIndexStatusHash.clear();
539 channelHash.clear();
540 hasEnded = true;
541 }
542
543 if (hasEnded) {
544
545 lastUpdateDate = new Date();
546 javax.swing.SwingUtilities.invokeLater(new TreeUpdate());
547 isGetNextInFlight = false;
548 }
549 }
550
551
552
553
554
555 public void setParent(TreeNode p) {
556 parent = p;
557 }
558
559
560
561
562
563 public void setDefaultTreeModel(DefaultTreeModel model) {
564 treeModel = model;
565 }
566
567
568
569
570
571
572
573 protected void fireTreeModelChanged() {
574 if (treeModel != null) {
575 treeModel.nodeStructureChanged(this);
576 }
577 }
578
579 class ChannelStatus extends Object implements TreeNode {
580 private TreeNode parent;
581 private int index, status;
582 private String name;
583
584 public ChannelStatus(int ind, int st, String nm, TreeNode par) {
585 index = ind;
586 status = st;
587 name = nm;
588 parent = par;
589 }
590
591 public int getIndex() {
592 return index;
593 }
594
595 public int getStatus() {
596 return status;
597 }
598
599 public void setStatus(int st) {
600 status = st;
601 }
602
603 public String getName() {
604 return name;
605 }
606
607 public String toString() {
608 return "" + index + " " + name + " " + vch_status[status];
609 }
610
611
612
613
614 public Enumeration children() {
615 return null;
616 }
617
618
619
620
621
622 public int getChildCount() {
623 return 0;
624 }
625
626
627
628
629
630 public TreeNode getChildAt(int childIndex) {
631 return null;
632 }
633
634
635
636
637
638
639 public int getIndex(TreeNode node) {
640 return -1;
641 }
642
643
644
645
646 public TreeNode getParent() {
647 return parent;
648 }
649
650
651
652
653 public boolean getAllowsChildren() {
654 return true;
655 }
656
657
658
659
660 public boolean isLeaf() {
661 return true;
662 }
663
664 }
665
666 class TreeUpdate implements Runnable {
667 public void run() {
668 fireTreeModelChanged();
669 firePropertyChange("modems", null, null);
670 }
671 }
672
673 }