1 #include "ace/OS_NS_unistd.h"
2 #include "ace/Log_Msg.h"
5 #include "Graphable_Element.h"
6 #include "Temperature_Grapher.h"
9 void Temperature_Grapher::monitor ()
13 this->update_graph ();
14 ACE_OS::sleep (this->opt_
.poll_interval ());
19 // Listing 2 code/ch21
20 void Temperature_Grapher::update_graph ()
22 Name_Binding_Ptr lastUpdate
23 (this->naming_context_
.fetch ("lastUpdate"));
25 if (!lastUpdate
.get ())
27 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("No data to graph\n")));
32 // Listing 3 code/ch21
33 Name_Binding_Ptr lastGraphed
34 (this->naming_context_
.fetch ("lastGraphed"));
36 if (lastGraphed
.get () &&
37 lastGraphed
->int_value () == lastUpdate
->int_value ())
39 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Data already graphed\n")));
44 // Listing 4 code/ch21
46 if (this->naming_context_
.list_name_entries
47 (set
, "history[") != 0)
50 ACE_TEXT ("There's nothing to graph\n")));
55 // Listing 5 code/ch21
56 Graphable_Element_List graphable
;
57 ACE_BINDING_ITERATOR
set_iterator (set
);
58 for (ACE_Name_Binding
*entry
= 0;
59 set_iterator
.next (entry
) != 0;
60 set_iterator
.advance ())
62 Name_Binding
binding (entry
);
63 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%s\t%s\t%s\n"),
68 Graphable_Element
*ge
= new Graphable_Element (entry
);
69 graphable
.push_back (*ge
);
73 // Listing 6 code/ch21
75 g
.graph (lastUpdate
->value (), graphable
);
76 this->naming_context_
.rebind ("lastGraphed",
77 lastUpdate
->int_value ());