Files CCore/inc/net/PTPSupportBase.h CCore/src/net/PTPSupportBase.cpp
Files CCore/inc/net/PTPSupport.h CCore/src/net/PTPSupport.cpp
PTP Support is a PTP service with 6 functions. The service id is 1. Function ids are 1-6.
const ServiceIdType ServiceId = 1 ; const FunctionIdType FunctionId_Len = 1 ; const FunctionIdType FunctionId_Seed = 2 ; const FunctionIdType FunctionId_Session = 3 ; const FunctionIdType FunctionId_Echo = 4 ; const FunctionIdType FunctionId_ErrorDesc = 5 ; const FunctionIdType FunctionId_Exist = 6 ;
Function Len has the following input/output:
struct LenInput { LenType to_server_info_len; LenType to_client_info_len; }; struct LenOutput { LenType to_server_info_len; LenType to_client_info_len; };
This function is used to cap input/output packet lengths. Client sends its limits to the server. Limits should not exceed MaxInfoLen (1440). Server downs these limits to its own limits and sends back to the client. These values can be used further to calculate different data limits in other PTP service/functions.
Function Seed has the following input/output:
struct SeedInput { }; struct SeedOutput { uint64 seed1; uint64 seed2; };
The return value is a random 128-bit value. It can be used for random seeding.
Function Session has the empty input/output:
struct SessionInput { }; struct SessionOutput { };
This function is used to inform the server, that this particular client starts a new session and all remaining state information from the past should be discarded, if any. It is recommended, that PTP client-server interaction starts with Len and Session functions.
Function Echo has the following input/output:
struct EchoInput { uint32 delay_msec; uint8 len; uint8 data[len]; }; struct EchoOutput { uint8 len; uint8 data[len]; };
This function echoes the input data after the given delay in milliseconds. The maximum delay value is 1000*60*60 (1 hour).
Function ErrorDesc has the following input/output:
struct ErrorDescInput { ServiceIdType service_id; FunctionIdType function_id; ErrorIdType error; }; struct ErrorDescOutput { uint8 len; uint8 str[len]; };
This function returns a text description of the particular error code. The input contains a service/function ids and the error code. The output is a text (byte) string, up to 255 byte length.
Function Exist has the following input/output:
struct ExistInput { ServiceIdType service_id; FunctionIdType function_id; }; struct ExistOutput { ServiceIdType service_id; FunctionIdType function_id; ErrorIdType error; };
This function can be used to check if the given service/function id combination is implemented by the server. Output contains the copy of the input and the error code. The error code is NoError or NoFunction.
The file txt/cpp/PTPSupport.txt.cpp contains this service definition.
PTPSupportBase.h defines these entities withing namespace PTPSupport.
Support functions can be performed using the ClientDevice class. There are several helper classes for this. They are located withing the namespace PTP.
Each class constructor take the pointer to the ClientDevice object and the reference to the PacketSet<uint8> object. The packet set is used to take a transaction packet.
The method perform() or perform_guarded() performs the transaction. It is a blocking call. The first argument is a timeout, both MSec and TimeScope argument types are allowed. perform() returns a boolean value to indicate a success, perform_guarded() throws an exception in case of error. If the operation successfully finished, the result can be obtained by the correspondent get() methods.
class Support_Exist : NoCopy
{
....
public:
Support_Exist(ClientDevice *client,PacketSet<uint8> &pset);
template <class TimeoutType>
bool perform(TimeoutType timeout,ServiceIdType service_id,FunctionIdType function_id);
enum ResultType
{
NotExist,
Exist,
Unknown
};
friend const char * GetTextDesc(ResultType result);
ResultType getResult();
};
perform() takes the ServiceId and FunctionId as arguments.
getResult() returns the result as an enum value. If the operation is failed, the Unknown is returned.
class Support_ErrorDesc : NoCopy
{
....
public:
Support_ErrorDesc(ClientDevice *client,PacketSet<uint8> &pset);
template <class TimeoutType>
bool perform(TimeoutType timeout,ServiceIdType service_id,FunctionIdType function_id,ErrorIdType error_id);
StrLen getDesc() const;
};
perform() takes the ServiceId, FunctionId and ErrorIdType as arguments.
getDesc() returns the StrLen error description from the internal buffer. If the operation is failed, "Unknown error" is returned.
class Support_Seed : NoCopy
{
....
public:
Support_Seed(ClientDevice *client,PacketSet<uint8> &pset);
template <class TimeoutType>
bool perform(TimeoutType timeout);
template <class TimeoutType>
void perform_guarded(TimeoutType timeout);
uint64 getSeed1() const;
uint64 getSeed2() const;
};
getSeed1() and getSeed2() is the seed. Zero is returned in case of error.
class Support_Echo : NoCopy
{
....
public:
Support_Echo(ClientDevice *client,PacketSet<uint8> &pset);
template <class TimeoutType,class Fill>
bool perform(TimeoutType timeout,uint32 delay_msec,Fill &fill);
template <class TimeoutType,class Fill>
void perform_guarded(TimeoutType timeout,uint32 delay_msec,Fill &fill);
PtrLen<const uint8> getEcho() const;
};
perform() takes the delay and the reference to the Fill class as arguments. This class is responsible for the echo data creation. It must implement the following interface:
class Fill { public: ulen getLen(); void fill(PtrLen<uint8> buf); };
getEcho() returns the echoed data from the internal buffer. The empty range is returned in case of error.