Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions TAO/docs/tutorials/Quoter/RTCORBA/Stock_Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
// ACE headers
#include "ace/Task.h"

// TAO headrs
// #include "tao/orbconf.h"

// STL headers
#include <map>
#include <string>
Expand All @@ -25,7 +22,7 @@
* The parameter type may be any type that has a method called "updated_stocks" and
* accepts a std::vector of std::strings as an argument.
*/
template <typename CALLBACK>
template <typename CALLBACK_TYPE>
class Stock_Database : public ACE_Task_Base
{
public:
Expand All @@ -38,8 +35,7 @@ class Stock_Database : public ACE_Task_Base
/// @param file The name of a file to read initial stocks and values from.
Stock_Database (const char *file, u_int rate = 1);

typedef std::map <std::string,
unsigned int> Init_Map;
typedef std::map <std::string, unsigned int> Init_Map;

/// Constructor
/// @param stockmap A map containing stocks and initial values. An initial value
Expand All @@ -53,7 +49,7 @@ class Stock_Database : public ACE_Task_Base
* the () operator defined accepting a std::vector of strings as the argument.
* @returns A cookie to identify the registration
*/
Cookie register_callback (CALLBACK &obj);
Cookie register_callback (CALLBACK_TYPE &obj);

/**
* Removes a callback from the notification queue.
Expand Down Expand Up @@ -111,7 +107,7 @@ class Stock_Database : public ACE_Task_Base
siginfo_t * = 0,
ucontext_t * = 0);

typedef std::map <Cookie, CALLBACK *> Callback_Map;
typedef std::map <Cookie, CALLBACK_TYPE *> Callback_Map;

private:
/// The filname initialized from, if any.
Expand Down
76 changes: 38 additions & 38 deletions TAO/docs/tutorials/Quoter/RTCORBA/Stock_Database.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@

#include <fstream>
#include <vector>
template <typename CALLBACK>
template <typename CALLBACK_TYPE>
struct Map_Init
{
Map_Init (typename Stock_Database<CALLBACK>::Stock_Map &map)
Map_Init (typename Stock_Database<CALLBACK_TYPE>::Stock_Map &map)
: map_ (map)
{
}

void operator () (const typename Stock_Database<CALLBACK>::Init_Map::value_type &item)
void operator () (const typename Stock_Database<CALLBACK_TYPE>::Init_Map::value_type &item)
{
typename Stock_Database<CALLBACK>::StockInfo stock_info (item.first.c_str ());
typename Stock_Database<CALLBACK_TYPE>::StockInfo stock_info (item.first.c_str ());

// If the initial value is nonzero, use that - otherwise, use a number
// between 0 and 100
Expand All @@ -30,12 +30,12 @@ struct Map_Init
map_[item.first] = stock_info;
}

typename Stock_Database<CALLBACK>::Stock_Map &map_;
typename Stock_Database<CALLBACK_TYPE>::Stock_Map &map_;
};

// Stock_Database
template <typename CALLBACK>
Stock_Database<CALLBACK>::Stock_Database (u_int rate)
template <typename CALLBACK_TYPE>
Stock_Database<CALLBACK_TYPE>::Stock_Database (u_int rate)
: rate_ (rate),
active_ (false)
{
Expand All @@ -46,33 +46,33 @@ Stock_Database<CALLBACK>::Stock_Database (u_int rate)

std::for_each (map.begin (),
map.end (),
Map_Init<CALLBACK> (this->stock_map_));
Map_Init<CALLBACK_TYPE> (this->stock_map_));
}

template <typename CALLBACK>
Stock_Database<CALLBACK>::Stock_Database (const char *file, u_int rate)
template <typename CALLBACK_TYPE>
Stock_Database<CALLBACK_TYPE>::Stock_Database (const char *file, u_int rate)
: filename_ (file),
rate_ (rate),
active_ (false)
{
this->handle_signal (0, 0, 0);
}

template <typename CALLBACK>
Stock_Database<CALLBACK>::Stock_Database (const Init_Map &stockmap,
u_int rate)
template <typename CALLBACK_TYPE>
Stock_Database<CALLBACK_TYPE>::Stock_Database (const Init_Map &stockmap,
u_int rate)
: rate_ (rate),
active_ (false)
{
std::for_each (stockmap.begin (),
stockmap.end (),
Map_Init<CALLBACK> (this->stock_map_));
Map_Init<CALLBACK_TYPE> (this->stock_map_));
}

// get_stock_info
template <typename CALLBACK>
typename Stock_Database<CALLBACK>::StockInfo
Stock_Database<CALLBACK>::get_stock_info(const char *name)
template <typename CALLBACK_TYPE>
typename Stock_Database<CALLBACK_TYPE>::StockInfo
Stock_Database<CALLBACK_TYPE>::get_stock_info(const char *name)
{
ACE_READ_GUARD_RETURN (ACE_RW_Thread_Mutex,
guard,
Expand All @@ -93,9 +93,9 @@ Stock_Database<CALLBACK>::get_stock_info(const char *name)
return iter->second;
}

template <typename CALLBACK>
typename Stock_Database<CALLBACK>::Cookie
Stock_Database<CALLBACK>::register_callback (CALLBACK &obj)
template <typename CALLBACK_TYPE>
typename Stock_Database<CALLBACK_TYPE>::Cookie
Stock_Database<CALLBACK_TYPE>::register_callback (CALLBACK_TYPE &obj)
{
ACE_Utils::UUID uuid;
ACE_Utils::UUID_GENERATOR::instance ()->generate_UUID (uuid);
Expand All @@ -105,16 +105,16 @@ Stock_Database<CALLBACK>::register_callback (CALLBACK &obj)
return uuid.to_string ()->c_str ();
}

template <typename CALLBACK>
template <typename CALLBACK_TYPE>
void
Stock_Database<CALLBACK>::update_rate (u_int rate)
Stock_Database<CALLBACK_TYPE>::update_rate (u_int rate)
{
this->rate_ = rate;
}

template <typename CALLBACK>
template <typename CALLBACK_TYPE>
void
Stock_Database<CALLBACK>::start (void)
Stock_Database<CALLBACK_TYPE>::start ()
{
if (!this->active_)
{ // Double checked locking
Expand All @@ -129,9 +129,9 @@ Stock_Database<CALLBACK>::start (void)
}
}

template <typename CALLBACK>
template <typename CALLBACK_TYPE>
void
Stock_Database<CALLBACK>::stop (void)
Stock_Database<CALLBACK_TYPE>::stop ()
{
ACE_WRITE_GUARD (ACE_RW_Thread_Mutex,
guard,
Expand All @@ -140,11 +140,11 @@ Stock_Database<CALLBACK>::stop (void)
this->active_ = false;
}

template <typename CALLBACK>
template <typename CALLBACK_TYPE>
int
Stock_Database<CALLBACK>::handle_signal (int,
siginfo_t *,
ucontext_t *)
Stock_Database<CALLBACK_TYPE>::handle_signal (int,
siginfo_t *,
ucontext_t *)
{
ACE_WRITE_GUARD_RETURN (ACE_RW_Thread_Mutex,
guard,
Expand All @@ -156,7 +156,7 @@ Stock_Database<CALLBACK>::handle_signal (int,
std::string name;
u_int value = 0;

typename Stock_Database<CALLBACK>::Init_Map map;
typename Stock_Database<CALLBACK_TYPE>::Init_Map map;

while (input.good ())
{
Expand All @@ -169,16 +169,16 @@ Stock_Database<CALLBACK>::handle_signal (int,

std::for_each (map.begin (),
map.end (),
Map_Init<CALLBACK> (this->stock_map_));
Map_Init<CALLBACK_TYPE> (this->stock_map_));

return 0;
}


template <typename CALLBACK>
template <typename CALLBACK_TYPE>
struct Stock_Updater
{
void operator () (typename Stock_Database<CALLBACK>::Stock_Map::value_type &item)
void operator () (typename Stock_Database<CALLBACK_TYPE>::Stock_Map::value_type &item)
{
// Determine if the stock has changed.
if (ACE_OS::rand () % 2)
Expand All @@ -203,7 +203,7 @@ struct Stock_Updater
item.second.high_ = item.second.last_;
}

void operator () (typename Stock_Database<CALLBACK>::Callback_Map::value_type &item)
void operator () (typename Stock_Database<CALLBACK_TYPE>::Callback_Map::value_type &item)
{
(*item.second) (changed_);
}
Expand All @@ -212,17 +212,17 @@ private:
std::vector <std::string> changed_;
};

template <typename CALLBACK>
template <typename CALLBACK_TYPE>
int
Stock_Database<CALLBACK>::svc (void)
Stock_Database<CALLBACK_TYPE>::svc ()
{
ACE_DEBUG ((LM_DEBUG, "tock!\n"));

while (this->active_)
{
{
// Init our functor
Stock_Updater<CALLBACK> updater;
Stock_Updater<CALLBACK_TYPE> updater;

{ // Control the scope of our mutex to avoid deadlock.
ACE_WRITE_GUARD_RETURN (ACE_RW_Thread_Mutex,
Expand Down
Loading