20 #ifndef PDB_COMMUN_TEMPLATES_C
21 #define PDB_COMMUN_TEMPLATES_C
24 #include "BuiltInObjectTypeIDs.h"
28 #include <netinet/in.h>
37 #include <sys/socket.h>
38 #include <sys/types.h>
41 #include <netinet/in.h>
46 template <
class ObjType>
50 int16_t recType = getTypeID<ObjType>();
52 std::cout <<
"Fatal Error: BAD! Trying to send a handle to a non-Object type.\n";
53 logToMe->error(
"Fatal Error: BAD! Trying to send a handle to a non-Object type.\n");
56 if (
doTheWrite(((
char*)&recType), ((
char*)&recType) +
sizeof(int16_t))) {
57 errMsg =
"PDBCommunicator: not able to send the object type";
59 logToMe->error(strerror(errno));
60 std::cout << errMsg << strerror(errno) << std::endl;
67 if (record ==
nullptr) {
72 if (record ==
nullptr) {
75 std::cout <<
"Fatal Error: BAD! Trying to get a record for an object not created by "
76 "this thread's allocator.\n";
78 "Fatal Error: BAD! Trying to get a record for an object not created by this "
79 "thread's allocator.\n");
86 if (
doTheWrite((
char*)record, ((
char*)record) + record->numBytes())) {
87 PDB_COUT <<
"recType=" << recType << std::endl;
88 errMsg =
"PDBCommunicator: not able to send the object size";
89 std::cout << errMsg << std::endl;
90 std::cout << strerror(errno) << std::endl;
92 logToMe->error(strerror(errno));
102 PDB_COUT <<
"Sent object with typeName=" << getTypeName<ObjType>() <<
", recType=" << recType
103 <<
" and socketFD=" <<
socketFD << std::endl;
104 logToMe->info(std::string(
"Sent object with typeName=") + getTypeName<ObjType>() +
105 std::string(
", recType=") + std::to_string(recType) +
106 std::string(
" and socketFD=") + std::to_string(
socketFD));
118 char* mem = (
char*)data;
121 errMsg =
"Could not read the next object coming over the wire";
131 int16_t recType = NoMsg_TYPEID;
132 if (
doTheWrite(((
char*)&recType), ((
char*)&recType) +
sizeof(int16_t))) {
133 errMsg =
"PDBCommunicator: not able to send the object type";
135 logToMe->error(strerror(errno));
140 if (
doTheWrite(((
char*)&sizeOfBytes), ((
char*)&sizeOfBytes) +
sizeof(
size_t))) {
141 errMsg =
"PDBCommunicator: not able to send the object size";
143 logToMe->error(strerror(errno));
148 if (
doTheWrite(((
char*)data), ((
char*)data) + sizeOfBytes)) {
149 errMsg =
"PDBCommunicator: not able to send the bytes";
151 logToMe->error(strerror(errno));
159 template <
class ObjType>
162 std::string& errMsg) {
167 logToMe->debug(std::string(
"run getSizeOfNextObject() and get type=") +
168 std::to_string(
nextTypeID) + std::string(
" and size=") +
171 logToMe->debug(std::string(
"get size info directly with type=") +
172 std::to_string(
nextTypeID) + std::string(
" and size=") +
178 errMsg =
"Could not read the the object size";
179 std::cout <<
"PDBCommunicator: can not get message size, the connection is possibly closed "
183 "PDBCommunicator: can not get message size, the connection is possibly closed by the "
190 char* mem = (
char*)readToHere;
193 mem +=
sizeof(size_t);
197 errMsg =
"Could not read the next object coming over the wire";
205 logToMe->trace(
"PDBCommunicator: read the object with no problem.");
206 logToMe->trace(
"PDBCommunicator: root offset is " +
213 template <
class ObjType>
219 logToMe->debug(std::string(
"run getSizeOfNextObject() and get type=") +
220 std::to_string(
nextTypeID) + std::string(
" and size=") +
223 logToMe->debug(std::string(
"get size info directly with type=") +
224 std::to_string(
nextTypeID) + std::string(
" and size=") +
229 errMsg =
"Could not read the object size";
230 std::cout <<
"PDBCommunicator: can not get message size, the connection is possibly closed "
234 "PDBCommunicator: can not get message size, the connection is possibly closed by the "
240 if (mem ==
nullptr) {
243 PDB_COUT <<
"memory is failed to allocate for getNextObject()" << std::endl;
250 logToMe->trace(
"PDBCommunicator: about to do the deep copy.");
254 logToMe->trace(
"PDBCommunicator: completed the deep copy.");
bool doTheWrite(char *start, char *end)
size_t getSizeOfNextObject()
Handle< TargetType > deepCopyToCurrentAllocationBlock(Handle< TargetType > ©Me)
bool doTheRead(char *dataIn)
bool sendObject(Handle< ObjType > &sendMe, std::string &errMsg)
bool sendBytes(void *data, size_t size, std::string &errMsg)
Handle< ObjType > getNextObject(void *readToHere, bool &success, std::string &errMsg)
bool receiveBytes(void *data, std::string &errMsg)
Record< ObjType > * getRecord(Handle< ObjType > &forMe)
#define DEFAULT_PAGE_SIZE