POSIX driver: Proper use of std:: and uavcan::

This commit is contained in:
Pavel Kirienko
2015-08-20 05:42:17 +03:00
parent b4b6c9eff5
commit cf39ecf879
2 changed files with 21 additions and 14 deletions
@@ -75,7 +75,7 @@ protected:
friend FDCache; friend FDCache;
FDCacheItem* next_; FDCacheItem* next_;
time_t last_access_; std::time_t last_access_;
const int fd_; const int fd_;
const int oflags_; const int oflags_;
const char* const path_; const char* const path_;
@@ -101,6 +101,7 @@ protected:
~FDCacheItem() ~FDCacheItem()
{ {
using namespace std;
if (valid()) if (valid())
{ {
::free(const_cast<char*>(path_)); ::free(const_cast<char*>(path_));
@@ -117,13 +118,14 @@ protected:
return fd_; return fd_;
} }
time_t getAccess() const std::time_t getAccess() const
{ {
return last_access_; return last_access_;
} }
time_t acessed() std::time_t acessed()
{ {
using namespace std;
last_access_ = time(NULL); last_access_ = time(NULL);
return getAccess(); return getAccess();
} }
@@ -135,11 +137,13 @@ protected:
bool expired() const bool expired() const
{ {
using namespace std;
return 0 == last_access_ || (time(NULL) - last_access_) > MaxAgeSeconds; return 0 == last_access_ || (time(NULL) - last_access_) > MaxAgeSeconds;
} }
bool equals(const char* path, int oflags) const bool equals(const char* path, int oflags) const
{ {
using namespace std;
return oflags_ == oflags && 0 == ::strcmp(path, path_); return oflags_ == oflags && 0 == ::strcmp(path, path_);
} }
@@ -275,7 +279,6 @@ protected:
if (pi && !pi->valid()) if (pi && !pi->valid())
{ {
/* Allocation worked but clone or path failed */ /* Allocation worked but clone or path failed */
delete pi; delete pi;
pi = NULL; pi = NULL;
} }
@@ -286,7 +289,6 @@ protected:
* If allocation fails no harm just can not cache it * If allocation fails no harm just can not cache it
* return open fd * return open fd
*/ */
return fd; return fd;
} }
/* add new */ /* add new */
@@ -334,7 +336,7 @@ protected:
* Implementation of this method is required. * Implementation of this method is required.
* On success the method must return zero. * On success the method must return zero.
*/ */
virtual int16_t getInfo(const Path& path, uint64_t& out_size, EntryType& out_type) virtual uavcan::int16_t getInfo(const Path& path, uavcan::uint64_t& out_size, EntryType& out_type)
{ {
int rv = uavcan::protocol::file::Error::INVALID_VALUE; int rv = uavcan::protocol::file::Error::INVALID_VALUE;
@@ -376,12 +378,15 @@ protected:
* if the end of file is reached. * if the end of file is reached.
* On success the method must return zero. * On success the method must return zero.
*/ */
virtual int16_t read(const Path& path, const uint64_t offset, uint8_t* out_buffer, uint16_t& inout_size) virtual uavcan::int16_t read(const Path& path, const uavcan::uint64_t offset, uavcan::uint8_t* out_buffer,
uavcan::uint16_t& inout_size)
{ {
int rv = uavcan::protocol::file::Error::INVALID_VALUE; int rv = uavcan::protocol::file::Error::INVALID_VALUE;
if (path.size() > 0 && inout_size != 0) if (path.size() > 0 && inout_size != 0)
{ {
using namespace std;
FDCacheBase& cache = getFDCache(); FDCacheBase& cache = getFDCache();
int fd = cache.open(path.c_str(), O_RDONLY); int fd = cache.open(path.c_str(), O_RDONLY);
@@ -86,6 +86,8 @@ class FirmwareVersionChecker : public uavcan::IFirmwareVersionChecker
int copyIfNot(const char* srcpath, const char* destpath) int copyIfNot(const char* srcpath, const char* destpath)
{ {
using namespace std;
// Does the file exist // Does the file exist
int rv = 0; int rv = 0;
int dfd = open(destpath, O_RDONLY, 0); int dfd = open(destpath, O_RDONLY, 0);
@@ -158,13 +160,13 @@ class FirmwareVersionChecker : public uavcan::IFirmwareVersionChecker
struct AppDescriptor struct AppDescriptor
{ {
uint8_t signature[sizeof(uavcan::uint64_t)]; uavcan::uint8_t signature[sizeof(uavcan::uint64_t)];
uint64_t image_crc; uavcan::uint64_t image_crc;
uint32_t image_size; uavcan::uint32_t image_size;
uint32_t vcs_commit; uavcan::uint32_t vcs_commit;
uint8_t major_version; uavcan::uint8_t major_version;
uint8_t minor_version; uavcan::uint8_t minor_version;
uint8_t reserved[6]; uavcan::uint8_t reserved[6];
}; };
static int getFileInfo(const char* path, AppDescriptor& descriptor) static int getFileInfo(const char* path, AppDescriptor& descriptor)