Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / APG / Naming / Temperature_Grapher.cpp
blob2020981a6126a53f5b720ad33552e8e5f7f39310
1 #include "ace/OS_NS_unistd.h"
2 #include "ace/Log_Msg.h"
4 #include "Graph.h"
5 #include "Graphable_Element.h"
6 #include "Temperature_Grapher.h"
8 // Listing 1 code/ch21
9 void Temperature_Grapher::monitor ()
11 for (;;)
13 this->update_graph ();
14 ACE_OS::sleep (this->opt_.poll_interval ());
17 // Listing 1
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")));
28 return;
30 // Listing 2
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")));
40 return;
42 // Listing 3
44 // Listing 4 code/ch21
45 ACE_BINDING_SET set;
46 if (this->naming_context_.list_name_entries
47 (set, "history[") != 0)
49 ACE_DEBUG ((LM_INFO,
50 ACE_TEXT ("There's nothing to graph\n")));
51 return;
53 // Listing 4
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"),
64 binding.type (),
65 binding.name (),
66 binding.value ()));
68 Graphable_Element *ge = new Graphable_Element (entry);
69 graphable.push_back (*ge);
71 // Listing 5
73 // Listing 6 code/ch21
74 Graph g;
75 g.graph (lastUpdate->value (), graphable);
76 this->naming_context_.rebind ("lastGraphed",
77 lastUpdate->int_value ());
78 // Listing 6