Skip to content

Commit

Permalink
finish up generic2
Browse files Browse the repository at this point in the history
  • Loading branch information
jeog committed May 3, 2016
1 parent 33965f8 commit c275945
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
25 changes: 13 additions & 12 deletions prov/generic2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ TOSDB_Generic::TOSDB_Generic(TOSDB_Generic&& gen)
:
_type_val( gen._type_val )
{
/* we are stealing the scalar value OR the string pointer */
/* we are stealing the scalar value OR the string pointer */
memcpy(this->_sub, gen._sub, SUB_SZ);
/* keep gen's carcas from screwing us if it had a string ptr */
memset(gen._sub, 0, SUB_SZ);
/* and change its type to keep it's destructor from a bad free */

/* leave the pointer but set _type_val to VOID to avoid bad free; ptr is an
implementation detail of the moved object that we can safely ignore */
gen._type_val = TYVAL_VOID;
}

Expand Down Expand Up @@ -79,20 +79,21 @@ TOSDB_Generic::operator=(const TOSDB_Generic& gen)
TOSDB_Generic&
TOSDB_Generic::operator=(TOSDB_Generic&& gen)
{
/* not sure if this is optimal or its better to branch(as above) and move
the string object in, allowing gen's destructor to delete
/* not sure if this is optimal or its better to branch(as above) and move
the string object in, allowing gen's destructor to delete
although, this way is a lot cleaner than 2 nested conditionals*/

although, this way is a lot cleaner than 2 nested conditionals*/
if(this->_type_val == TYVAL_STRING)
delete *(std::string**)this->_sub;

this->_type_val = gen._type_val;

/* we are stealing the scalar value OR the string pointer */
memcpy(this->_sub, gen._sub, SUB_SZ);
/* keep gen's carcas from screwing us if it had a string ptr */
memset(gen._sub, 0, SUB_SZ);
/* and change its type to keep it's destructor from doing the same */
/* we are stealing the scalar value OR the string pointer */
memcpy(this->_sub, gen._sub, SUB_SZ);

/* leave the pointer but set _type_val to VOID to avoid bad free; ptr is an
implementation detail of the moved object that we can safely ignore */
gen._type_val = TYVAL_VOID;

return *this;
Expand Down
11 changes: 6 additions & 5 deletions prov/generic2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ class TOSDB_Generic{
note: we don't hold a 'void' object per-se; when an object holding a string
is 'moved' we set the _type_val to TYVAL_VOID so the destructor knows
not to free the junk _sub then points at */

static const int TYVAL_VOID = 0;
static const int TYVAL_LONG = 1;
static const int TYVAL_LONG_LONG = 2;
static const int TYVAL_FLOAT = 3;
static const int TYVAL_DOUBLE = 4;
static const int TYVAL_STRING = 5;

static const int TYVAL_STRING = 5;

/* max string length we support is 255 chars */
/* max string length we support is 255 chars (why?) */
static const int STR_MAX = UCHAR_MAX - 1;

/* the (max) byte size of our internal representation */
static const int SUB_SZ = 8;

Expand Down Expand Up @@ -164,14 +165,14 @@ class TOSDB_Generic{
delete *(std::string**)(this->_sub);
}

inline bool
inline bool /* same type AND value */
operator==(const TOSDB_Generic& gen) const
{
return ( this->_type_val == gen._type_val )
&& ( this->as_string() == gen.as_string() );
}

inline bool
inline bool /* different type OR value */
operator!=(const TOSDB_Generic& gen) const
{
return !(this->operator==(gen));
Expand Down
38 changes: 23 additions & 15 deletions src/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ SendMsgWaitForResponse(long msg)
if(!master){
master = mstr_ptr_ty( new DynamicIPCMaster(TOSDB_COMM_CHANNEL) );
master->try_for_slave();
// ERROR CHECK
// ERROR CHECK
IPC_TIMED_WAIT( master->grab_pipe() <= 0,
"SendMsgWaitForResponse timed out",
-1 );
Expand Down Expand Up @@ -263,9 +263,14 @@ SpawnRestrictedProcess(int session = -1)
}else{
ret = true;
}
}
if(tkn_hndl) CloseHandle(tkn_hndl);
if(ctkn_hndl) CloseHandle(ctkn_hndl);
}

if(tkn_hndl)
CloseHandle(tkn_hndl);

if(ctkn_hndl)
CloseHandle(ctkn_hndl);

return ret;
}
};
Expand Down Expand Up @@ -318,9 +323,9 @@ ServiceMain(DWORD argc, LPSTR argv[])
WaitForSingleObject(engine_pinfo.hProcess, INFINITE);
}

/* !! IF WE GET HERE WE WILL SHUTDOWN !!*/
/* !! IF WE GET HERE WE WILL SHUTDOWN !! */
UpdateStatus(SERVICE_STOPPED, 0);
/* !! IF WE GET HERE WE WILL SHUTDOWN !!*/
/* !! IF WE GET HERE WE WILL SHUTDOWN !! */

TOSDB_Log("STATE","SERVICE_STOPPED");
}
Expand All @@ -332,7 +337,7 @@ ParseArgs(std::vector<std::string>& vec, std::string str)
std::string::size_type i = str.find_first_of(' ');

if( str.empty() ){ /* done */
return;
return;
}else if(i == std::string::npos){ /* only 1 str */
vec.push_back(str);
return;
Expand All @@ -355,7 +360,7 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLn, int nShowCmd)
SmartBuffer<CHAR> module_buf(MAX_PATH);
GetModuleFileName(NULL, module_buf.get(), MAX_PATH);

/* start logging */
/* start logging */
std::string logpath(TOSDB_LOG_PATH);
logpath.append(LOG_NAME);
StartLogging(logpath.c_str());
Expand Down Expand Up @@ -383,6 +388,7 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLn, int nShowCmd)
int admin_pos = 0;
int no_service_pos = 0;


/* look for --admin and/or --noservice args */
if(argc > 0 && args[0] == "--admin")
admin_pos = 1;
Expand All @@ -394,9 +400,10 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLn, int nShowCmd)
else if(argc > 1 && args[1] == "--noservice")
no_service_pos = 2;


switch(argc){ /* look for custom_session arg */
case 0:
break;
case 0:
break;
case 1:
if(admin_pos == 0 && no_service_pos == 0)
custom_session = std::stoi(args[0]);
Expand All @@ -412,15 +419,15 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLn, int nShowCmd)
if(admin_pos > 0 && no_service_pos > 0)
custom_session = std::stoi(args[2]);
break;
default:
std::string serr("invalid # of args: ");
default:
std::string serr("invalid # of args: ");
serr.append(std::to_string(argc));
TOSDB_LogH("STARTUP",serr.c_str());
return 1;
}
std::stringstream ss_args;
ss_args << "cmd_str: " << cmd_str << " argc: " << std::to_string(argc)

std::stringstream ss_args;
ss_args << "cmd_str: " << cmd_str << " argc: " << std::to_string(argc)
<< " custom_session: " << std::to_string(custom_session)
<< " admin_pos: " << std::to_string(admin_pos)
<< " no_service_pos: " << std::to_string(no_service_pos);
Expand All @@ -434,6 +441,7 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLn, int nShowCmd)
/* populate the engine command and if --noservice is passed jump right into
the engine via SpawnRestrictedProcess; otherwise Start the service which
will handle that for us */

if(no_service_pos > 0){
strcpy_s(engine_cmd,"--noservice");
is_service = false;
Expand Down

0 comments on commit c275945

Please sign in to comment.