Skip to content

Commit

Permalink
Refactoring of the Client class source code
Browse files Browse the repository at this point in the history
  • Loading branch information
ellysh committed Mar 2, 2013
1 parent 4f95094 commit e3e00fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
39 changes: 17 additions & 22 deletions source/client/client.cpp
Expand Up @@ -24,21 +24,19 @@ Client::~Client()

void Client::WriteLong(const size_t index, const long value)
{
Package package;
package.index = index;
memcpy(&package.data, &value, PACKAGE_DATA_SIZE);

int rc = ioctl(dev_file_, IOCTL_SET_MSG, &package);

if ( rc != 0 )
Speaker::Instance()->PrintError(kSetCommandError);
WriteData(index, &value);
}

void Client::WriteDouble(const size_t index, const double value)
{
WriteData(index, &value);
}

void Client::WriteData(const size_t index, const void* value)
{
Package package;
package.index = index;
memcpy(&package.data, &value, PACKAGE_DATA_SIZE);
memcpy(&package.data, value, PACKAGE_DATA_SIZE);

int rc = ioctl(dev_file_, IOCTL_SET_MSG, &package);

Expand All @@ -48,21 +46,21 @@ void Client::WriteDouble(const size_t index, const double value)

long Client::ReadLong(const size_t index) const
{
Package package;
package.index = index;

int rc = ioctl(dev_file_, IOCTL_GET_MSG, &package);

if ( rc != 0 )
Speaker::Instance()->PrintError(kGetCommandError);

long result;
memcpy(&result, &package.data, PACKAGE_DATA_SIZE);
ReadData(index, &result);

return result;
}

double Client::ReadDouble(const size_t index) const
{
double result;
ReadData(index, &result);

return result;
}

void Client::ReadData(const size_t index, void* result) const
{
Package package;
package.index = index;
Expand All @@ -72,8 +70,5 @@ double Client::ReadDouble(const size_t index) const
if ( rc != 0 )
Speaker::Instance()->PrintError(kGetCommandError);

double result;
memcpy(&result, &package.data, PACKAGE_DATA_SIZE);

return result;
memcpy(result, &package.data, PACKAGE_DATA_SIZE);
}
3 changes: 3 additions & 0 deletions source/client/client.h
Expand Up @@ -23,6 +23,9 @@ class Client : protected Debug

private:
int dev_file_;

void WriteData(const size_t index, const void* value);
void ReadData(const size_t index, void* result) const;
};

}
Expand Down

0 comments on commit e3e00fb

Please sign in to comment.