Browse Source

uORBDevices: astyle

sbg
Ban Siesta 10 years ago committed by Lorenz Meier
parent
commit
fee8449de3
  1. 903
      src/modules/uORB/uORBDevices_nuttx.cpp
  2. 323
      src/modules/uORB/uORBDevices_nuttx.hpp
  3. 946
      src/modules/uORB/uORBDevices_posix.cpp
  4. 202
      src/modules/uORB/uORBDevices_posix.hpp

903
src/modules/uORB/uORBDevices_nuttx.cpp

File diff suppressed because it is too large Load Diff

323
src/modules/uORB/uORBDevices_nuttx.hpp

@ -43,8 +43,8 @@
namespace uORB namespace uORB
{ {
class DeviceNode; class DeviceNode;
class DeviceMaster; class DeviceMaster;
} }
/** /**
@ -53,166 +53,167 @@ namespace uORB
class uORB::DeviceNode : public device::CDev class uORB::DeviceNode : public device::CDev
{ {
public: public:
/** /**
* Constructor * Constructor
*/ */
DeviceNode DeviceNode
( (
const struct orb_metadata *meta, const struct orb_metadata *meta,
const char *name, const char *name,
const char *path, const char *path,
int priority int priority
); );
/** /**
* Destructor * Destructor
*/ */
~DeviceNode(); ~DeviceNode();
/** /**
* Method to create a subscriber instance and return the struct * Method to create a subscriber instance and return the struct
* pointing to the subscriber as a file pointer. * pointing to the subscriber as a file pointer.
*/ */
virtual int open(struct file *filp); virtual int open(struct file *filp);
/** /**
* Method to close a subscriber for this topic. * Method to close a subscriber for this topic.
*/ */
virtual int close(struct file *filp); virtual int close(struct file *filp);
/** /**
* reads data from a subscriber node to the buffer provided. * reads data from a subscriber node to the buffer provided.
* @param filp * @param filp
* The subscriber from which the data needs to be read from. * The subscriber from which the data needs to be read from.
* @param buffer * @param buffer
* The buffer into which the data is read into. * The buffer into which the data is read into.
* @param buflen * @param buflen
* the length of the buffer * the length of the buffer
* @return * @return
* ssize_t the number of bytes read. * ssize_t the number of bytes read.
*/ */
virtual ssize_t read(struct file *filp, char *buffer, size_t buflen); virtual ssize_t read(struct file *filp, char *buffer, size_t buflen);
/** /**
* writes the published data to the internal buffer to be read by * writes the published data to the internal buffer to be read by
* subscribers later. * subscribers later.
* @param filp * @param filp
* the subscriber; this is not used. * the subscriber; this is not used.
* @param buffer * @param buffer
* The buffer for the input data * The buffer for the input data
* @param buflen * @param buflen
* the length of the buffer. * the length of the buffer.
* @return ssize_t * @return ssize_t
* The number of bytes that are written * The number of bytes that are written
*/ */
virtual ssize_t write(struct file *filp, const char *buffer, size_t buflen); virtual ssize_t write(struct file *filp, const char *buffer, size_t buflen);
/** /**
* IOCTL control for the subscriber. * IOCTL control for the subscriber.
*/ */
virtual int ioctl(struct file *filp, int cmd, unsigned long arg); virtual int ioctl(struct file *filp, int cmd, unsigned long arg);
/** /**
* Method to publish a data to this node. * Method to publish a data to this node.
*/ */
static ssize_t publish static ssize_t publish
( (
const orb_metadata *meta, const orb_metadata *meta,
orb_advert_t handle, orb_advert_t handle,
const void *data const void *data
); );
/** /**
* processes a request for add subscription from remote * processes a request for add subscription from remote
* @param rateInHz * @param rateInHz
* Specifies the desired rate for the message. * Specifies the desired rate for the message.
* @return * @return
* 0 = success * 0 = success
* otherwise failure. * otherwise failure.
*/ */
int16_t process_add_subscription( int32_t rateInHz ); int16_t process_add_subscription(int32_t rateInHz);
/** /**
* processes a request to remove a subscription from remote. * processes a request to remove a subscription from remote.
*/ */
int16_t process_remove_subscription(); int16_t process_remove_subscription();
/** /**
* processed the received data message from remote. * processed the received data message from remote.
*/ */
int16_t process_received_message( int32_t length, uint8_t* data ); int16_t process_received_message(int32_t length, uint8_t *data);
/** /**
* Add the subscriber to the node's list of subscriber. If there is * Add the subscriber to the node's list of subscriber. If there is
* remote proxy to which this subscription needs to be sent, it will * remote proxy to which this subscription needs to be sent, it will
* done via uORBCommunicator::IChannel interface. * done via uORBCommunicator::IChannel interface.
* @param sd * @param sd
* the subscriber to be added. * the subscriber to be added.
*/ */
void add_internal_subscriber(); void add_internal_subscriber();
/** /**
* Removes the subscriber from the list. Also notifies the remote * Removes the subscriber from the list. Also notifies the remote
* if there a uORBCommunicator::IChannel instance. * if there a uORBCommunicator::IChannel instance.
* @param sd * @param sd
* the Subscriber to be removed. * the Subscriber to be removed.
*/ */
void remove_internal_subscriber(); void remove_internal_subscriber();
protected: protected:
virtual pollevent_t poll_state(struct file *filp); virtual pollevent_t poll_state(struct file *filp);
virtual void poll_notify_one(struct pollfd *fds, pollevent_t events); virtual void poll_notify_one(struct pollfd *fds, pollevent_t events);
private: private:
struct SubscriberData { struct SubscriberData {
unsigned generation; /**< last generation the subscriber has seen */ unsigned generation; /**< last generation the subscriber has seen */
unsigned update_interval; /**< if nonzero minimum interval between updates */ unsigned update_interval; /**< if nonzero minimum interval between updates */
struct hrt_call update_call; /**< deferred wakeup call if update_period is nonzero */ struct hrt_call update_call; /**< deferred wakeup call if update_period is nonzero */
void *poll_priv; /**< saved copy of fds->f_priv while poll is active */ void *poll_priv; /**< saved copy of fds->f_priv while poll is active */
bool update_reported; /**< true if we have reported the update via poll/check */ bool update_reported; /**< true if we have reported the update via poll/check */
int priority; /**< priority of publisher */ int priority; /**< priority of publisher */
}; };
const struct orb_metadata *_meta; /**< object metadata information */ const struct orb_metadata *_meta; /**< object metadata information */
uint8_t *_data; /**< allocated object buffer */ uint8_t *_data; /**< allocated object buffer */
hrt_abstime _last_update; /**< time the object was last updated */ hrt_abstime _last_update; /**< time the object was last updated */
volatile unsigned _generation; /**< object generation count */ volatile unsigned _generation; /**< object generation count */
pid_t _publisher; /**< if nonzero, current publisher */ pid_t _publisher; /**< if nonzero, current publisher */
const int _priority; /**< priority of topic */ const int _priority; /**< priority of topic */
private: // private class methods. private: // private class methods.
SubscriberData *filp_to_sd(struct file *filp) { SubscriberData *filp_to_sd(struct file *filp)
SubscriberData *sd = (SubscriberData *)(filp->f_priv); {
return sd; SubscriberData *sd = (SubscriberData *)(filp->f_priv);
} return sd;
}
bool _IsRemoteSubscriberPresent;
int32_t _subscriber_count; bool _IsRemoteSubscriberPresent;
int32_t _subscriber_count;
/**
* Perform a deferred update for a rate-limited subscriber. /**
*/ * Perform a deferred update for a rate-limited subscriber.
void update_deferred(); */
void update_deferred();
/**
* Bridge from hrt_call to update_deferred /**
* * Bridge from hrt_call to update_deferred
* void *arg ORBDevNode pointer for which the deferred update is performed. *
*/ * void *arg ORBDevNode pointer for which the deferred update is performed.
static void update_deferred_trampoline(void *arg); */
static void update_deferred_trampoline(void *arg);
/**
* Check whether a topic appears updated to a subscriber. /**
* * Check whether a topic appears updated to a subscriber.
* @param sd The subscriber for whom to check. *
* @return True if the topic should appear updated to the subscriber * @param sd The subscriber for whom to check.
*/ * @return True if the topic should appear updated to the subscriber
bool appears_updated(SubscriberData *sd); */
bool appears_updated(SubscriberData *sd);
// disable copy and assignment operators
DeviceNode( const DeviceNode& ); // disable copy and assignment operators
DeviceNode& operator=( const DeviceNode& ); DeviceNode(const DeviceNode &);
DeviceNode &operator=(const DeviceNode &);
}; };
/** /**
@ -224,14 +225,14 @@ private: // private class methods.
class uORB::DeviceMaster : public device::CDev class uORB::DeviceMaster : public device::CDev
{ {
public: public:
DeviceMaster(Flavor f); DeviceMaster(Flavor f);
virtual ~DeviceMaster(); virtual ~DeviceMaster();
static uORB::DeviceNode* GetDeviceNode( const char * node_name ); static uORB::DeviceNode *GetDeviceNode(const char *node_name);
virtual int ioctl(struct file *filp, int cmd, unsigned long arg); virtual int ioctl(struct file *filp, int cmd, unsigned long arg);
private: private:
Flavor _flavor; Flavor _flavor;
static ORBMap _node_map; static ORBMap _node_map;
}; };

946
src/modules/uORB/uORBDevices_posix.cpp

File diff suppressed because it is too large Load Diff

202
src/modules/uORB/uORBDevices_posix.hpp

@ -41,110 +41,110 @@
namespace uORB namespace uORB
{ {
class DeviceNode; class DeviceNode;
class DeviceMaster; class DeviceMaster;
} }
class uORB::DeviceNode : public device::VDev class uORB::DeviceNode : public device::VDev
{ {
public: public:
DeviceNode(const struct orb_metadata *meta, const char *name, const char *path, int priority); DeviceNode(const struct orb_metadata *meta, const char *name, const char *path, int priority);
~DeviceNode(); ~DeviceNode();
virtual int open(device::file_t *filp); virtual int open(device::file_t *filp);
virtual int close(device::file_t *filp); virtual int close(device::file_t *filp);
virtual ssize_t read(device::file_t *filp, char *buffer, size_t buflen); virtual ssize_t read(device::file_t *filp, char *buffer, size_t buflen);
virtual ssize_t write(device::file_t *filp, const char *buffer, size_t buflen); virtual ssize_t write(device::file_t *filp, const char *buffer, size_t buflen);
virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg); virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg);
static ssize_t publish(const orb_metadata *meta, orb_advert_t handle, const void *data ); static ssize_t publish(const orb_metadata *meta, orb_advert_t handle, const void *data);
/** /**
* processes a request for add subscription from remote * processes a request for add subscription from remote
* @param rateInHz * @param rateInHz
* Specifies the desired rate for the message. * Specifies the desired rate for the message.
* @return * @return
* 0 = success * 0 = success
* otherwise failure. * otherwise failure.
*/ */
int16_t process_add_subscription( int32_t rateInHz ); int16_t process_add_subscription(int32_t rateInHz);
/** /**
* processes a request to remove a subscription from remote. * processes a request to remove a subscription from remote.
*/ */
int16_t process_remove_subscription(); int16_t process_remove_subscription();
/** /**
* processed the received data message from remote. * processed the received data message from remote.
*/ */
int16_t process_received_message( int32_t length, uint8_t* data ); int16_t process_received_message(int32_t length, uint8_t *data);
/** /**
* Add the subscriber to the node's list of subscriber. If there is * Add the subscriber to the node's list of subscriber. If there is
* remote proxy to which this subscription needs to be sent, it will * remote proxy to which this subscription needs to be sent, it will
* done via uORBCommunicator::IChannel interface. * done via uORBCommunicator::IChannel interface.
* @param sd * @param sd
* the subscriber to be added. * the subscriber to be added.
*/ */
void add_internal_subscriber(); void add_internal_subscriber();
/** /**
* Removes the subscriber from the list. Also notifies the remote * Removes the subscriber from the list. Also notifies the remote
* if there a uORBCommunicator::IChannel instance. * if there a uORBCommunicator::IChannel instance.
* @param sd * @param sd
* the Subscriber to be removed. * the Subscriber to be removed.
*/ */
void remove_internal_subscriber(); void remove_internal_subscriber();
protected: protected:
virtual pollevent_t poll_state(device::file_t *filp); virtual pollevent_t poll_state(device::file_t *filp);
virtual void poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events); virtual void poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events);
private: private:
struct SubscriberData { struct SubscriberData {
unsigned generation; /**< last generation the subscriber has seen */ unsigned generation; /**< last generation the subscriber has seen */
unsigned update_interval; /**< if nonzero minimum interval between updates */ unsigned update_interval; /**< if nonzero minimum interval between updates */
struct hrt_call update_call; /**< deferred wakeup call if update_period is nonzero */ struct hrt_call update_call; /**< deferred wakeup call if update_period is nonzero */
void *poll_priv; /**< saved copy of fds->f_priv while poll is active */ void *poll_priv; /**< saved copy of fds->f_priv while poll is active */
bool update_reported; /**< true if we have reported the update via poll/check */ bool update_reported; /**< true if we have reported the update via poll/check */
int priority; /**< priority of publisher */ int priority; /**< priority of publisher */
}; };
const struct orb_metadata *_meta; /**< object metadata information */ const struct orb_metadata *_meta; /**< object metadata information */
uint8_t *_data; /**< allocated object buffer */ uint8_t *_data; /**< allocated object buffer */
hrt_abstime _last_update; /**< time the object was last updated */ hrt_abstime _last_update; /**< time the object was last updated */
volatile unsigned _generation; /**< object generation count */ volatile unsigned _generation; /**< object generation count */
unsigned long _publisher; /**< if nonzero, current publisher */ unsigned long _publisher; /**< if nonzero, current publisher */
const int _priority; /**< priority of topic */ const int _priority; /**< priority of topic */
SubscriberData *filp_to_sd(device::file_t *filp); SubscriberData *filp_to_sd(device::file_t *filp);
int32_t _subscriber_count; int32_t _subscriber_count;
/** /**
* Perform a deferred update for a rate-limited subscriber. * Perform a deferred update for a rate-limited subscriber.
*/ */
void update_deferred(); void update_deferred();
/** /**
* Bridge from hrt_call to update_deferred * Bridge from hrt_call to update_deferred
* *
* void *arg ORBDevNode pointer for which the deferred update is performed. * void *arg ORBDevNode pointer for which the deferred update is performed.
*/ */
static void update_deferred_trampoline(void *arg); static void update_deferred_trampoline(void *arg);
/** /**
* Check whether a topic appears updated to a subscriber. * Check whether a topic appears updated to a subscriber.
* *
* @param sd The subscriber for whom to check. * @param sd The subscriber for whom to check.
* @return True if the topic should appear updated to the subscriber * @return True if the topic should appear updated to the subscriber
*/ */
bool appears_updated(SubscriberData *sd); bool appears_updated(SubscriberData *sd);
// disable copy and assignment operators // disable copy and assignment operators
DeviceNode( const DeviceNode& ); DeviceNode(const DeviceNode &);
DeviceNode& operator=( const DeviceNode& ); DeviceNode &operator=(const DeviceNode &);
}; };
/** /**
@ -156,15 +156,15 @@ private:
class uORB::DeviceMaster : public device::VDev class uORB::DeviceMaster : public device::VDev
{ {
public: public:
DeviceMaster(Flavor f); DeviceMaster(Flavor f);
~DeviceMaster(); ~DeviceMaster();
static uORB::DeviceNode* GetDeviceNode( const char *node_name ); static uORB::DeviceNode *GetDeviceNode(const char *node_name);
virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg); virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg);
private: private:
Flavor _flavor; Flavor _flavor;
static std::map<std::string, uORB::DeviceNode*> _node_map; static std::map<std::string, uORB::DeviceNode *> _node_map;
}; };
#endif /* _uORBDeviceNode_posix.hpp */ #endif /* _uORBDeviceNode_posix.hpp */

Loading…
Cancel
Save