Commit e43f95c5 authored by Mohamed Ahmed's avatar Mohamed Ahmed

Firstly add of the events implementation

parent 0d4d7305
......@@ -51,8 +51,8 @@ add_message_files(
FILES
time.msg
srv_info.msg
# Message1.msg
# Message2.msg
subscription.msg
event_data.msg
)
## Generate services in the 'srv' folder
......
......@@ -14,8 +14,16 @@ bool APapp::TerminateApp_ = false;
static void signalHandler(int signum)
{
std::cout << "Signal handler called" << endl;
APapp::Terminate();
//std::cout << "Signal handler called" << endl;
}
static void signalHandlerInt(int signum)
{
std::cout << "Signal INT handler called" << endl;
APapp::Terminate();
}
APapp::APapp()
......@@ -36,7 +44,8 @@ void APapp::Initializing()
// signal handler
//cout << "signal handler registering" << endl;
std::signal(SIGTERM, signalHandler);
std::signal(SIGINT, signalHandlerInt);
//app initialize
InitializeApp();
......
string skeleton_id #service instance id
## string skeleton_id #service instance id
## string proxy_id #id of the proxy instance that subscribed on this event in case susbscribed.
string event_id #To identify among different events that're offered by this service
string state #Unsubscribed, Pending, or Subscribed
string policy #Update criteria, kLatestN or kNewestN
uint32 cache_size # size of local cashe that'll be used for this event.
\ No newline at end of file
uint32 maxSampleCount # maximum number of samples, which can be held for subscription.
\ No newline at end of file
#include "ara/com/timeservice_common.h"
#include "ara/core/future.h"
#include "ara/core/promise.h"
// ROS includes
#include <ros/ros.h>
#include "ros/this_node.h"
#include "ros/master.h"
#include "std_msgs/Int64.h"
#include "std_msgs/String.h"
#include "std_msgs/Bool.h"
#include "timeClient/time_srv.h"
#include "timeClient/srv_info.h"
#include "timeClient/subscription.h"
#include "timeClient/event_data.h"
namespace events
{
class BrakeEvent {
ros::NodeHandle rosHandler_;
ros::Publisher status_publisher;
ros::Subscriber data_subscriber;
ros::Subscriber status_subscriber;
/**
* \brief Shortcut for the events data type.
*/
using SampleType = timeService::RadarObjects;
SampleType radar;
std::string eventName;
std::string eventState;
std::vector<SampleType> samplesVector;
void eventStatus_callBack(const timeClient::subscription &msg);
void eventData_callBack(const timeClient::event_data &msg);
/**
* \brief The application expects the CM to subscribe the event.
*
* The Communication Management shall try to subscribe and resubscribe
* until \see Unsubscribe() is called explicitly.
* The error handling shall be kept within the Communication Management
.
*
* The function returns immediately. If the user wants to get notified,
* when subscription has succeeded, he needs to register a handler
* via \see SetSubscriptionStateChangeHandler(). This handler gets
* then called after subscription was successful.
*
* \param maxSampleCount maximum number of samples, which can be held.
*/
public:
BrakeEvent();
BrakeEvent(ros::NodeHandle& proxyNodeHandler);
/**
* \brief The application expects the CM to subscribe the event.
*
* The Communication Management shall try to subscribe and resubscribe
* until \see Unsubscribe() is called explicitly.
* The error handling shall be kept within the Communication Management
.
*
* The function returns immediately. If the user wants to get notified,
* when subscription has succeeded, he needs to register a handler
* via \see SetSubscriptionStateChangeHandler(). This handler gets
* then called after subscription was successful.
*
* \param maxSampleCount maximum number of samples, which can be held.
*/
void Subscribe(size_t maxSampleCount);
/**
* \brief Query current subscription state.
*
* \return Current state of the subscription.
*/
//ara::com::SubscriptionState GetSubscriptionState() const;
/**
* \brief Unsubscribe from the service.
*/
void Unsubscribe();
/**
* \brief Get the number of currently free/available sample slots.
*
* \return number from 0 - N (N = count given in call to Subscribe())
or an ErrorCode in case of number of currently held samples
*
already exceeds the max number given in Subscribe().
*
*/
//ara::core::Result<size_t> GetFreeSampleCount() const noexcept;
/**
* Setting a receive handler signals the Communication Management
* implementation to use event style mode.
* I.e. the registered handler gets called asynchronously by the
* Communication Management as soon as new event data arrives for
* that event. If user wants to have strict polling behavior,
* where you decide when to check for new data via GetNewSamples() he
* should NOT register a handler.
*
* Handler may be overwritten anytime during runtime.
*
* Provided Handler needs not to be re-entrant since the
* Communication Management implementation has to serialize calls
* to the handler: Handler gets called once by the MW, when new
* events arrived since the last call to GetNewSamples().
*
* When application calls GetNewSamples() again in the context of the
* receive handler, MW must - in case new events arrived in the
* meantime - defer next call to receive handler until after
* the previous call to receive handler has been completed.
*/
//void SetReceiveHandler(ara::com::EventReceiveHandler handler);
/**
* Remove handler set by SetReceiveHandler()
*/
//void UnsetReceiveHandler();
/**
* Setting a subscription state change handler, which shall get
* called by the Communication Management implementation as soon
* as the subscription state of this event has changed.
*
* Communication Management implementation will serialize calls
* to the registered handler. If multiple changes of the
* subscription state take place during the runtime of a
* previous call to a handler, the Communication Management
* aggregates all changes to one call with the last/effective
* state.
*
* Handler may be overwritten during runtime.
*/
//void SetSubscriptionStateChangeHandler(ara::com::SubscriptionStateChangeHandler handler);
/**
* \brief Get new data from the Communication Management
* buffers and provide it in callbacks to the given callable f.
*
* \pre BrakeEvent::Subscribe has been called before
* (and not be withdrawn by BrakeEvent::Unsubscribe)
*
* \param f
* \parblock
* callback, which shall be called with new sample.
*
* This callable has to fulfill signature
* void(ara::com::SamplePtr<SampleType const>)
* \parblockend
*
* \param maxNumberOfSamples
* \parblock
* upper bound of samples to be fetched from middleware buffers.
* Default value means "no restriction", i.e. all newly arrived samples
* are fetched as long as there are free sample slots.
* \parblockend
*
* \return Result, which contains the number of samples,
* which have been fetched and presented to user via calls to f or an
* ErrorCode in case of error (e.g. precondition not fullfilled)
*/
//template <typename F>
//ara::core::Result<size_t> GetNewSamples(F&& f, size_t maxNumberOfSamples = std::numeric_limits<size_t>::max());
};
}
\ No newline at end of file
......@@ -7,6 +7,7 @@
#include "ara/com/instance_identifier.h"
#include "ara/core/future.h"
#include "getTime.hpp"
#include "timeServiceEvent.hpp"
void callback(const timeClient::srv_info &msg);
......@@ -145,6 +146,7 @@ public:
static ara::com::FindServiceHandler<HandleType> proxyHandler; // possible disaster in case multiple objects in the same process
static std::vector<timeServiceProxy::HandleType> handlesVec;
methods::getTime getTime;
events::BrakeEvent BrakeEvent;
void callback(const timeClient::srv_info &msg);
......
......@@ -53,6 +53,7 @@ set(ADAPTIVEAUTOSARAPPLICATION_src
WatchappProxy.cpp
timeservice_proxy.cpp
getTime.cpp
timeServiceEvent.cpp
${APP_NAME}_activity.cpp
)
......
......@@ -29,5 +29,6 @@ ara::core::Future<timeService::getTimeOutput> getTime::operator()()
}catch(...){
std::cout<<"\n##############Bug\n###############\n";
}
}
......@@ -67,10 +67,6 @@ void Timeactivity::run()
{
std::cout << currentTime << " From service instance: " << INSTANCE_COLOR_40 << "40" << END_COLOR << std::endl;
}
else if(serviceInstances_ == 60)
{
std::cout << currentTime << " From service instance: " << INSTANCE_COLOR_40 << "60" << END_COLOR << std::endl;
}
}
else
......
#include "../inc/timeServiceEvent.hpp"
using namespace events;
BrakeEvent::BrakeEvent(ros::NodeHandle& proxyNodeHandler) :
rosHandler_(proxyNodeHandler)
{
BrakeEvent::eventName = typeid(*this).name();
std::cout<<"\n#############\n"<<BrakeEvent::eventName<<"\n##########\n";
BrakeEvent::eventState = "unsubscribed";
BrakeEvent::status_publisher = BrakeEvent::rosHandler_.advertise<timeClient::subscription>("timeService_events",10, true);
BrakeEvent::status_subscriber = BrakeEvent::rosHandler_.subscribe(BrakeEvent::eventName + "_status", 10, &BrakeEvent::eventStatus_callBack, this);
}
void BrakeEvent::eventStatus_callBack(const timeClient::subscription &msg)
{
std::cout<<"\n##################\n"<<msg<<"\n###########\n";
}
void BrakeEvent::eventData_callBack(const timeClient::event_data &msg)
{
}
void BrakeEvent::Subscribe(size_t maxSampleCount)
{
BrakeEvent::eventState = "pending";
BrakeEvent::data_subscriber = BrakeEvent::rosHandler_.subscribe(BrakeEvent::eventName + "_data", 10, &BrakeEvent::eventData_callBack, this);
timeClient::subscription msg;
msg.event_id = BrakeEvent::eventName;
msg.state = BrakeEvent::eventState;
BrakeEvent::status_publisher.publish(msg);
}
void BrakeEvent::Unsubscribe()
{
BrakeEvent::eventState = "unsubscribed";
BrakeEvent::data_subscriber.shutdown();
}
//ara::com::SubscriptionState BrakeEvent::GetSubscriptionState() const{}
//void BrakeEvent::SetReceiveHandler(ara::com::EventReceiveHandler handler){}
//void BrakeEvent::SetSubscriptionStateChangeHandler(ara::com::SubscriptionStateChangeHandler handler){}
//ara::core::Result<size_t> BrakeEvent::GetNewSamples(F&& f, size_t maxNumberOfSamples = std::numeric_limits<size_t>::max()){}
......@@ -21,7 +21,8 @@ timeServiceProxy::timeServiceProxy(HandleType &handle):
srv_ID("x" + std::to_string(handle.GetInstanceId().GetInstanceId())),
rosHandler_(ros::NodeHandle(srv_ID)),
proxyClient(rosHandler_.serviceClient<timeClient::time_srv>("timeService")),
getTime(rosHandler_, proxyClient)
getTime(rosHandler_, proxyClient),
BrakeEvent(rosHandler_)
{
std::cout<<"\nHello From Proxy Constructor\n"<<srv_ID<<std::endl;
}
......@@ -64,7 +65,7 @@ void callback(const timeClient::srv_info &msg)
{
std::string str = msg.srv_ns.substr(1);
timeServiceProxy::instanceID_ = std::stoi(str);
std::cout<<"\ncurrent_state: "<< msg.current_state<<std::endl;
//std::cout<<"\ncurrent_state: "<< msg.current_state;
//std::cout<<"\nprevious_state: "<< msg.previous_state;
if(msg.current_state == "on") //First time to see the serviceat this time
{
......@@ -83,7 +84,6 @@ void callback(const timeClient::srv_info &msg)
else if(msg.current_state == "off" && timeServiceProxy::handlesVec.size()>0) //Last time to see the service at this time
{
std::cout<<"\n##################\nThe state is: "<<msg.current_state<<"\n####################\n";
timeServiceProxy::HandleType handle;
handle.SetInstanceId(timeServiceProxy::instanceID_);
ara::com::FindServiceHandle f;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment