Skip to content

Commit a495f83

Browse files
committed
required changes
Signed-off-by: osamahammad21 <[email protected]>
1 parent f039976 commit a495f83

File tree

9 files changed

+99
-41
lines changed

9 files changed

+99
-41
lines changed

src/OpenRoad.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void OpenRoad::init(Tcl_Interp* tcl_interp,
162162
// Make components.
163163
utl::Progress::setBatchMode(batch_mode);
164164
logger_ = utl::makeLogger(log_filename, metrics_filename);
165-
callback_handler_ = new utl::CallBackHandler();
165+
callback_handler_ = new utl::CallBackHandler(logger_);
166166
db_->setLogger(logger_);
167167
sta_ = sta::makeDbSta();
168168
verilog_network_ = makeDbVerilogNetwork();

src/drt/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ cc_library(
8686
"src/AbstractGraphicsFactory.h",
8787
"src/DesignCallBack.cpp",
8888
"src/DesignCallBack.h",
89+
"src/PACallBack.h",
8990
"src/TritonRoute.cpp",
9091
"src/db/drObj/drAccessPattern.cpp",
9192
"src/db/drObj/drNet.cpp",

src/drt/src/TritonRoute.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ TritonRoute::TritonRoute()
5858
}
5959
}
6060

61-
TritonRoute::~TritonRoute()
62-
{
63-
callback_handler_->removeCallBack(pa_callback_.get());
64-
}
61+
TritonRoute::~TritonRoute() = default;
6562

6663
void TritonRoute::setDebugDR(bool on)
6764
{
@@ -545,7 +542,7 @@ void TritonRoute::init(
545542
design_ = std::make_unique<frDesign>(logger_, router_cfg_.get());
546543
dist->addCallBack(new RoutingCallBack(this, dist, logger));
547544
graphics_factory_ = std::move(graphics_factory);
548-
callback_handler_->addCallBack(pa_callback_.get());
545+
pa_callback_->setOwner(callback_handler);
549546
}
550547

551548
bool TritonRoute::initGuide()

src/utl/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ package(
1515
cc_library(
1616
name = "utl",
1717
srcs = [
18+
"src/CallBack.cpp",
19+
"src/CallBackHandler.cpp",
1820
"src/CFileUtils.cpp",
1921
"src/CommandLineProgress.cpp",
2022
"src/CommandLineProgress.h",
@@ -30,6 +32,8 @@ cc_library(
3032
"src/timer.cpp",
3133
],
3234
hdrs = [
35+
"include/utl/CallBack.h",
36+
"include/utl/CallBackHandler.h",
3337
"include/utl/CFileUtils.h",
3438
"include/utl/Logger.h",
3539
"include/utl/Metrics.h",
@@ -85,6 +89,8 @@ cc_library(
8589
":tcl",
8690
],
8791
hdrs = [
92+
"include/utl/CallBack.h",
93+
"include/utl/CallBackHandler.h",
8894
"include/utl/CFileUtils.h",
8995
"include/utl/Logger.h",
9096
"include/utl/MakeLogger.h",

src/utl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ endif()
3737

3838
add_library(utl_lib
3939
src/CallBackHandler.cpp
40+
src/CallBack.cpp
4041
src/Metrics.cpp
4142
src/CFileUtils.cpp
4243
src/ScopedTemporaryFile.cpp

src/utl/include/utl/CallBack.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,34 @@
44
#pragma once
55

66
namespace utl {
7+
class CallBackHandler;
78

8-
/// @brief Base class for callbacks to enable inter-module communication.
9-
///
10-
/// This class provides a standardized interface for modules to communicate
11-
/// with each other through callback mechanisms. Derived classes should
12-
/// implement specific callback methods as needed.
13-
///
9+
/**
10+
* @brief Base class for callbacks to enable inter-module communication.
11+
*
12+
* This class provides a standardized interface for modules to communicate
13+
* with each other through callback mechanisms. Derived classes should
14+
* implement specific callback methods as needed.
15+
*/
1416
class CallBack
1517
{
1618
public:
17-
virtual ~CallBack() = default;
19+
virtual ~CallBack();
1820

19-
/// @brief Called when pin access needs to be updated.
20-
///
21-
/// This callback is triggered when modules detect that access points need to
22-
/// be recalculated or updated.
23-
virtual void onPinAccessUpdateRequired() {};
21+
/**
22+
* @brief Called when pin access needs to be updated.
23+
*
24+
* This callback is triggered when modules detect that access points need to
25+
* be recalculated or updated.
26+
*/
27+
virtual void onPinAccessUpdateRequired() {}
28+
29+
void setOwner(CallBackHandler* owner);
30+
CallBackHandler* getOwner() const { return owner_; }
31+
void removeOwner();
32+
33+
private:
34+
CallBackHandler* owner_{nullptr};
2435
};
2536

2637
} // namespace utl

src/utl/include/utl/CallBackHandler.h

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,44 @@
55

66
#include <set>
77

8-
#include "utl/CallBack.h"
9-
108
namespace utl {
11-
12-
/// @brief Handler class for managing callback registration and triggering.
13-
///
14-
/// This class provides a centralized mechanism for modules to register
15-
/// callbacks and trigger them when specific events occur.
9+
class Logger;
10+
class CallBack;
11+
12+
/**
13+
* @brief Handler class for managing callback registration and triggering.
14+
*
15+
* This class provides a centralized mechanism for modules to register
16+
* callbacks and trigger them when specific events occur.
17+
*/
1618
class CallBackHandler
1719
{
1820
public:
19-
CallBackHandler() = default;
21+
CallBackHandler(utl::Logger* logger);
2022
~CallBackHandler() = default;
2123

22-
/// @brief Register a callback for event notifications.
23-
///
24-
/// @param callback Pointer to the callback object to register
24+
/**
25+
* @brief Register a callback for event notifications.
26+
*
27+
* @param callback Pointer to the callback object to register
28+
*/
2529
void addCallBack(CallBack* callback);
2630

27-
/// @brief Unregister a callback from event notifications.
28-
///
29-
/// @param callback Pointer to the callback object to unregister
31+
/**
32+
* @brief Unregister a callback from event notifications.
33+
*
34+
* @param callback Pointer to the callback object to unregister
35+
*/
3036
void removeCallBack(CallBack* callback);
3137

32-
/// @brief Trigger the onPinAccessUpdateRequired callback for all registered
33-
/// callbacks.
34-
///
35-
/// This method iterates through all registered callbacks and calls their
36-
/// onPinAccessUpdateRequired method.
38+
/**
39+
* @brief Trigger the onPinAccessUpdateRequired callback for all registered
40+
* callbacks.
41+
*/
3742
void triggerOnPinAccessUpdateRequired();
3843

3944
private:
40-
/// @brief Set of registered callbacks.
45+
utl::Logger* logger_;
4146
std::set<CallBack*> callbacks_;
4247
};
4348

src/utl/src/CallBack.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
// Copyright (c) 2025-2025, The OpenROAD Authors
3+
4+
#include "utl/CallBack.h"
5+
6+
#include "utl/CallBackHandler.h"
7+
8+
namespace utl {
9+
10+
CallBack::~CallBack()
11+
{
12+
removeOwner();
13+
}
14+
15+
void CallBack::setOwner(CallBackHandler* owner)
16+
{
17+
owner_ = owner;
18+
owner_->addCallBack(this);
19+
}
20+
21+
void CallBack::removeOwner()
22+
{
23+
if (owner_) {
24+
owner_->removeCallBack(this);
25+
owner_ = nullptr;
26+
}
27+
}
28+
29+
} // namespace utl

src/utl/src/CallBackHandler.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33

44
#include "utl/CallBackHandler.h"
55

6+
#include "utl/CallBack.h"
7+
#include "utl/Logger.h"
8+
69
namespace utl {
710

11+
CallBackHandler::CallBackHandler(utl::Logger* logger) : logger_(logger)
12+
{
13+
}
14+
815
void CallBackHandler::addCallBack(CallBack* callback)
916
{
17+
if (callback == nullptr) {
18+
logger_->error(utl::UTL, 200, "Registering null callback is not allowed");
19+
}
1020
callbacks_.insert(callback);
1121
}
1222

@@ -18,9 +28,7 @@ void CallBackHandler::removeCallBack(CallBack* callback)
1828
void CallBackHandler::triggerOnPinAccessUpdateRequired()
1929
{
2030
for (CallBack* callback : callbacks_) {
21-
if (callback != nullptr) {
22-
callback->onPinAccessUpdateRequired();
23-
}
31+
callback->onPinAccessUpdateRequired();
2432
}
2533
}
2634

0 commit comments

Comments
 (0)