diff options
author | bala <bala@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-07-09 21:35:07 +0000 |
---|---|---|
committer | bala <bala@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-07-09 21:35:07 +0000 |
commit | 16fe18e427896886277c68c7caa896e0405cccda (patch) | |
tree | 3150c78994edde3b26eb7313957de32aef4d8654 /TAO/examples/Persistent_Grid/Grid_i.cpp | |
parent | b9c14f5d8fa1d82a25db96d65620a3c277774a5f (diff) | |
download | ATCD-16fe18e427896886277c68c7caa896e0405cccda.tar.gz |
Changed according to Dr.Schmidt's suggestions
Diffstat (limited to 'TAO/examples/Persistent_Grid/Grid_i.cpp')
-rw-r--r-- | TAO/examples/Persistent_Grid/Grid_i.cpp | 79 |
1 files changed, 51 insertions, 28 deletions
diff --git a/TAO/examples/Persistent_Grid/Grid_i.cpp b/TAO/examples/Persistent_Grid/Grid_i.cpp index 9599a421a25..a192b8a4d8a 100644 --- a/TAO/examples/Persistent_Grid/Grid_i.cpp +++ b/TAO/examples/Persistent_Grid/Grid_i.cpp @@ -17,8 +17,7 @@ Grid_i::Grid_i (void) Grid_i::Grid_i (CORBA::Short x, CORBA::Short y, - Grid_Factory_i::pool_t *mem_pool, - CORBA::Environment &ACE_TRY_ENV) + pool_t *mem_pool) : width_ (x), height_ (y) { @@ -28,22 +27,26 @@ Grid_i::Grid_i (CORBA::Short x, if (mem_pool->find ("Array", (void *&) array_) == -1) { // Allocate memory for the matrix. - array_ = (CORBA::Long **) mem_pool->malloc (y * sizeof (CORBA::Long *)); + ACE_ALLOCATOR (array_, + ACE_static_cast (CORBA::Long **, + mem_pool->malloc (y * sizeof (CORBA::Long *)))); + //array_ = (CORBA::Long **) mem_pool->malloc (y * sizeof (CORBA::Long *)); if (array_ != 0) { for (int ctr = 0; ctr < y; ctr++) { - array_[ctr] = (CORBA::Long *)mem_pool->malloc (x * - sizeof (CORBA::Long)); - if (array_[ctr] == 0) - ACE_THROW (CORBA::NO_MEMORY ()); + ACE_ALLOCATOR (array_[ctr], + ACE_static_cast (CORBA::Long *, + mem_pool->malloc (x * + sizeof (CORBA::Long )))); + + //array_[ctr] = (CORBA::Long *)mem_pool->malloc (x * + // sizeof (CORBA::Long)); } mem_pool->bind ("Array", array_); } - else - ACE_THROW (CORBA::NO_MEMORY ()); } } @@ -61,6 +64,8 @@ Grid_i::set (CORBA::Short x, CORBA::Short y, CORBA::Long value, CORBA::Environment &ACE_TRY_ENV) + ACE_THROW_SPEC ((CORBA::SystemException, + Grid::RANGE_ERROR)) { if (x < 0 || y < 0 @@ -77,6 +82,8 @@ CORBA::Long Grid_i::get (CORBA::Short x, CORBA::Short y, CORBA::Environment &ACE_TRY_ENV) + ACE_THROW_SPEC ((CORBA::SystemException, + Grid::RANGE_ERROR)) { if (x < 0 || y < 0 @@ -90,13 +97,15 @@ Grid_i::get (CORBA::Short x, // Access methods. CORBA::Short -Grid_i::width (CORBA::Environment &A) +Grid_i::width (CORBA::Environment &) + ACE_THROW_SPEC ((CORBA::SystemException)) { return this->width_; } CORBA::Short Grid_i::height (CORBA::Environment &) + ACE_THROW_SPEC ((CORBA::SystemException)) { return this->height_; } @@ -104,6 +113,7 @@ Grid_i::height (CORBA::Environment &) void Grid_i::width (CORBA::Short x, CORBA::Environment &) + ACE_THROW_SPEC ((CORBA::SystemException)) { this->width_ = x; } @@ -111,28 +121,33 @@ Grid_i::width (CORBA::Short x, void Grid_i::height (CORBA::Short y, CORBA::Environment &) + ACE_THROW_SPEC ((CORBA::SystemException)) { this->height_ = y; } // Destroy the grid - void -Grid_i::destroy (CORBA::Environment &) +Grid_i::destroy (CORBA::Environment & ) + ACE_THROW_SPEC ((CORBA::SystemException)) { // Delete the array. - for (int i = 0; i < height_; i++) - delete [] array_[i]; + this->pool_t_->free (array_[i]); - delete [] array_; + // delete [] array_; + this->pool_t_->free (array_); ACE_DEBUG ((LM_DEBUG, " (%P|%t) %s\n", "Grid has been destroyed")); } - +void +Grid_i::set_pool (pool_t *pool) +{ + this->pool_t_ = pool; +} // Constructor Grid_Factory_i::Grid_Factory_i (void) @@ -165,9 +180,8 @@ Grid_ptr Grid_Factory_i::make_grid (CORBA::Short width, CORBA::Short height, CORBA::Environment &ACE_TRY_ENV) + ACE_THROW_SPEC ((CORBA::SystemException)) { - Grid_i *grid_ptr = 0; - ACE_DEBUG ((LM_DEBUG, " (%P|%t) Making a new Grid\n")); @@ -180,18 +194,25 @@ Grid_Factory_i::make_grid (CORBA::Short width, height = Grid_Factory::DEFAULT_HEIGHT; // Get a memory pool - pool_t_ = new pool_t (pool_name_); - + ACE_NEW_THROW_EX (pool_t_, + pool_t (pool_name_), + CORBA::NO_MEMORY ()); + + // pool_t_ = new pool_t (pool_name_); + // This attempts to create a new Grid_i and throws an exception and // returns a null value if it fails - ACE_NEW_THROW_EX (grid_ptr, - Grid_i (width, - height, - pool_t_, - ACE_TRY_ENV), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (Grid::_nil ()); - + int prev_no = errno; + Grid_i *grid_ptr = new Grid_i (width, + height, + pool_t_); + if (errno == ENOMEM) + ACE_THROW_RETURN (CORBA::NO_MEMORY (), 0); + + errno = prev_no; + + grid_ptr->set_pool (pool_t_); + // Register the Grid pointer. return grid_ptr->_this (ACE_TRY_ENV); } @@ -207,6 +228,7 @@ Grid_Factory_i::orb (CORBA::ORB_ptr o) // Shutdown. void Grid_Factory_i::shutdown (CORBA::Environment &) + ACE_THROW_SPEC ((CORBA::SystemException)) { ACE_DEBUG ((LM_DEBUG, " (%P|%t) %s\n", @@ -218,6 +240,7 @@ Grid_Factory_i::shutdown (CORBA::Environment &) void Grid_Factory_i::cleanup (CORBA::Environment &) + ACE_THROW_SPEC ((CORBA::SystemException)) { const char *name = "Array"; |