Пример #1
0
	void AddToOffset(std::size_t added_offset)
	{
		if ((write_offset_ + added_offset) > mapping_size_)
			ThrowInvalidArgument("The value specified to 'LogHandlerFileMMap::"
				"AddToOffset()' (" + AnyToString(added_offset) + ") when added "
				"to the current 'write_offset_' value (" +
				AnyToString(write_offset_) + ") is greater than the "
				"'mapped_size_' member (" + AnyToString(mapping_size_) + ").");

		write_offset_ += added_offset;
	}
Пример #2
0
//	////////////////////////////////////////////////////////////////////////////
TimeTM TimeTM::TimeLocal(const time_t in_time)
{
	if (in_time < static_cast<time_t>(0))
		ThrowInvalidArgument("Invalid 'time_t' encountered in invocation of "
			"method TimeTM::TimeLocal() (value = " + AnyToString(in_time) + ").");

	struct tm  out_time;
	struct tm *result_ptr;

#ifdef _Windows
	if ((result_ptr = localtime(&in_time)) == NULL)
		TimeT_To_TimeTM_ConvertError("TimeLocal", "localtime", in_time, NULL,
			result_ptr);
	out_time = *result_ptr;
#else
# if defined(__EXTENSIONS__) || defined(_REENTRANT) || defined(_POSIX_C_SOURCE)
	if (((result_ptr = localtime_r(&in_time, &out_time)) == NULL) ||
		(result_ptr != &out_time))
		TimeT_To_TimeTM_ConvertError("TimeLocal", "localtime_r", in_time,
			&out_time, result_ptr);
# else
	if ((result_ptr = localtime(&in_time)) == NULL)
		TimeT_To_TimeTM_ConvertError("TimeLocal", "localtime", in_time, NULL,
			result_ptr);
	out_time = *result_ptr;
# endif /* #if defined(__EXTENSIONS__ || _REENTRANT || _POSIX_C_SOURCE) */
#endif /* #ifdef _Windows */

	return(TimeTM(out_time));
}
Пример #3
0
//	////////////////////////////////////////////////////////////////////////////
TimeVal &TimeVal::AddMicroseconds(int usecs_to_add)
{
	int secs_to_add = usecs_to_add / 1000000;
	int new_usec    = tv_usec + (usecs_to_add % 1000000);

	if (new_usec >= 1000000) {
		secs_to_add += new_usec / 1000000;
		new_usec    %= 1000000;
	}
	else if (new_usec < 0) {
		secs_to_add += -1 + (new_usec / 1000000);
		new_usec     = 1000000 + (new_usec % 1000000);
	}

	if (secs_to_add) {
		try {
			AddSeconds(secs_to_add);
		}
		catch (const std::exception &except) {
			Rethrow(except, "Unable to add the requested number of microseconds "
				"(" + AnyToString(usecs_to_add) + "): " +
				std::string(except.what()));
		}
	}

	tv_usec = new_usec;

	return(*this);
}
Пример #4
0
//	////////////////////////////////////////////////////////////////////////////
void LogHandlerXFile::OpenFileImpl(const char *file_name)
{
	boost::shared_ptr<std::ofstream> tmp_file_ptr(
		new std::ofstream(file_name,
			(!(my_flags_ & DoNotAppend)) ?
			(std::ios_base::app | std::ios_base::ate) :
			(std::ios_base::app | std::ios_base::trunc)));

	if (tmp_file_ptr->fail())
		ThrowErrno("Open attempt failed.");

//	CODE NOTE: LogFileHandler buffering test code. To be removed.
std::streambuf *new_buffer_ptr =
	tmp_file_ptr->rdbuf()->pubsetbuf(TestFileBuffer, sizeof(TestFileBuffer));
if (new_buffer_ptr == NULL)
	ThrowErrno("Attempt to set the log file buffer size to " +
		AnyToString(sizeof(TestFileBuffer)) + " bytes failed.");

	{
		std::string               tmp_file_name(file_name);
		boost::mutex::scoped_lock my_lock(the_lock_);
		if ((out_file_ptr_ != NULL) && out_file_ptr_->is_open()) {
			out_file_ptr_->flush();
			out_file_ptr_->close();
			out_file_ptr_.reset();
		}
		out_file_ptr_.swap(tmp_file_ptr);
		out_file_name_.swap(tmp_file_name);
	}
}
Пример #5
0
//	////////////////////////////////////////////////////////////////////////////
void LogHandlerFileBase::OpenFile(const char *base_name, const char *dir_name,
	const MLB::Utility::TimeT &start_time)
{
	std::string file_name;

	if ((base_name == NULL) || (!(*base_name)))
		file_name = "LogFile.";
	else {
		file_name = base_name;
		if (base_name[strlen(base_name) - 1] != '.')
			file_name += '.';
	}

	std::string tmp_date_time(start_time.ToString());

	tmp_date_time[10]  = '.';
	tmp_date_time[13]  = '.';
	tmp_date_time[16]  = '.';
	file_name         += tmp_date_time + "." + GetHostNameCanonical() + "." +
		AnyToString(CurrentProcessId()) + ".log";

	boost::filesystem::path tmp_file(file_name, boost::filesystem::native);

	if ((dir_name != NULL) && *dir_name) {
		std::string tmp_dir_name;
		ResolveFilePathGeneral(dir_name, tmp_dir_name, "", true, true, false);
		boost::filesystem::path tmp_path(tmp_dir_name, boost::filesystem::native);
		boost::filesystem::path this_file;
		this_file        = tmp_path / tmp_file;
		file_name        = this_file.native_file_string();
	}
	else {
		if (!tmp_file.has_root_path())
			tmp_file = boost::filesystem::system_complete(tmp_file);
		file_name = tmp_file.native_file_string();
	}

	OpenFile(file_name);
}
Пример #6
0
//	////////////////////////////////////////////////////////////////////////////
void ParseFromString(const char *in_date, time_t &out_secs,
	long &out_fractional, long fractional_places)
{
	if (in_date == NULL)
		ThrowInvalidArgument("Specified date string pointer is 'NULL'.");

	try {
		size_t date_length = strlen(in_date);
		char   date_buffer[Length_TimeSpec + 9 + 1];
		if (date_length < 8)
			ThrowInvalidArgument("Unknown date format.");
		if (date_length == 8) {
			char *end_ptr;
			strtoul(in_date, &end_ptr, 10);
			if (end_ptr != (in_date + 8))
				ThrowInvalidArgument("Invalid undelimited date string --- "
					"only numeric characters are valid.");
			strcat(nstrcat(strcat(nstrcat(strcat(nstrcpy(date_buffer, in_date, 4),
				"-"), in_date + 4, 2), "-"), in_date + 6, 2),
				" 00:00:00.000000000");
			ParseFromString_Basic(date_buffer, out_secs, out_fractional,
				fractional_places);
		}
		else {
			if ((!isdigit(in_date[0])) || (!isdigit(in_date[1])) ||
				(!isdigit(in_date[2])) || (!isdigit(in_date[3])) ||
				(!isdigit(in_date[5])) || (!isdigit(in_date[6])) ||
				(!isdigit(in_date[8])) || (!isdigit(in_date[9])))
				ThrowInvalidArgument("Invalid delimited date string --- "
					"expected format for date portion is 'yyyy-mm-dd'.");
			if (((in_date[4] != '-') && (in_date[4] != '/')) ||
				 ((in_date[7] != '-') && (in_date[7] != '/')))
				ThrowInvalidArgument("Invalid delimited date string --- "
					"expected format for date portion is 'yyyy-mm-dd'.");
			if (date_length == 10) {
				strcat(strcpy(date_buffer, in_date), " 00:00:00.000000000");
				ParseFromString_Basic(date_buffer, out_secs, out_fractional,
					fractional_places);
			}
			else if (date_length <= Length_TimeSpec) {
				if (((date_length < 20) && (date_length != 13) &&
					(date_length != 16) && (date_length != 19)))
					ThrowInvalidArgument("Unknown date format.");
				if (((in_date[10] != ' ') && (in_date[10] != '.')) ||
					(!isdigit(in_date[11])) || (!isdigit(in_date[12])))
					ThrowInvalidArgument("Invalid delimited date/time string.");
				if (date_length == 13)
					ParseFromString_Basic(strcat(strcpy(date_buffer, in_date),
						":00:00.000000000"), out_secs, out_fractional,
						fractional_places);
				else {
					if (((in_date[13] != ':') && (in_date[13] != '.')) ||
						(!isdigit(in_date[14])) || (!isdigit(in_date[15])))
						ThrowInvalidArgument("Invalid delimited date/time string.");
					if (date_length == 16)
						ParseFromString_Basic(strcat(strcpy(date_buffer, in_date),
							":00.000000000"), out_secs, out_fractional,
							fractional_places);
					else {
						if (((in_date[16] != ':') && (in_date[16] != '.')) ||
							(!isdigit(in_date[17])) || (!isdigit(in_date[18])))
							ThrowInvalidArgument("Invalid delimited date/time string.");
						else if (date_length == 19)
							ParseFromString_Basic(strcat(strcpy(date_buffer, in_date),
								".000000000"), out_secs, out_fractional,
								fractional_places);
						else if (in_date[19] != '.')
							ThrowInvalidArgument("Invalid delimited date/time string.");
						else
							ParseFromString_Basic(nstrcat(strcpy(date_buffer, in_date),
								"000000000", Length_TimeSpec - date_length), out_secs,
								out_fractional, fractional_places);
					}
				}
			}
			else
				ThrowInvalidArgument("Date/time string length exceeds maximum "
					"permissible (" + AnyToString(Length_TimeSpec) +
					" characters).");
		}
	}
	catch (const std::exception &except) {
		Rethrow(except, "Unable to parse date/time string '" +
			std::string(in_date) + "': " + std::string(except.what()));
	}
}
Пример #7
0
CefRefPtr<CefV8Value> CefDictionaryValueToV8Value(
        CefRefPtr<CefDictionaryValue> dictValue,
        int nestingLevel) {
    if (!dictValue->IsValid()) {
        DebugLog("CefDictionaryValueToV8Value() FAILED: " \
                "CefDictionaryValue is invalid");
        return CefV8Value::CreateNull();
    }
    if (nestingLevel > 8) {
        DebugLog("CefDictionaryValueToV8Value(): WARNING: " \
            "max nesting level (8) exceeded");
        return CefV8Value::CreateNull();
    }
    std::vector<CefString> keys;
    if (!dictValue->GetKeys(keys)) {
        DebugLog("CefDictionaryValueToV8Value() FAILED: " \
            "dictValue->GetKeys() failed");
        return CefV8Value::CreateNull();
    }
    CefRefPtr<CefV8Value> ret = CefV8Value::CreateObject(NULL);
    CefRefPtr<CefBinaryValue> binaryValue;
    PythonCallback pyCallback;
    CefRefPtr<CefV8Handler> v8FunctionHandler;
    for (std::vector<CefString>::iterator it = keys.begin(); \
            it != keys.end(); ++it) {
        CefString key = *it;
        cef_value_type_t valueType = dictValue->GetType(key);
        bool success;
        std::string callbackName = "python_callback_";
        if (valueType == VTYPE_NULL) {
            success = ret->SetValue(key,
                    CefV8Value::CreateNull(),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else if (valueType == VTYPE_BOOL) {
            success = ret->SetValue(key,
                    CefV8Value::CreateBool(dictValue->GetBool(key)),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else if (valueType == VTYPE_INT) {
            success = ret->SetValue(key,
                    CefV8Value::CreateInt(dictValue->GetInt(key)),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else if (valueType == VTYPE_DOUBLE) {
            success = ret->SetValue(key,
                    CefV8Value::CreateDouble(dictValue->GetDouble(key)),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else if (valueType == VTYPE_STRING) {
            success = ret->SetValue(key,
                    CefV8Value::CreateString(dictValue->GetString(key)),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else if (valueType == VTYPE_BINARY) {
            binaryValue = dictValue->GetBinary(key);
            if (binaryValue->GetSize() == sizeof(pyCallback)) {
                binaryValue->GetData(&pyCallback, sizeof(pyCallback), 0);
                v8FunctionHandler = new V8FunctionHandler(
                        NULL, pyCallback.callbackId);
                // You must provide a function name to
                // CefV8Value::CreateFunction(), otherwise it fails.
                callbackName.append(AnyToString(pyCallback.callbackId));
                success = ret->SetValue(key,
                                CefV8Value::CreateFunction(
                                        callbackName, v8FunctionHandler),
                                V8_PROPERTY_ATTRIBUTE_NONE);
            } else {
                DebugLog("CefListValueToV8Value(): WARNING: " \
                        "unknown binary value, setting value to null");
                success = ret->SetValue(key,
                        CefV8Value::CreateNull(),
                        V8_PROPERTY_ATTRIBUTE_NONE);
            }
        } else if (valueType == VTYPE_DICTIONARY) {
            success = ret->SetValue(key,
                    CefDictionaryValueToV8Value(
                            dictValue->GetDictionary(key),
                            nestingLevel + 1),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else if (valueType == VTYPE_LIST) {
            success = ret->SetValue(key,
                    CefListValueToV8Value(
                            dictValue->GetList(key),
                            nestingLevel + 1),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        } else {
            DebugLog("CefDictionaryValueToV8Value(): WARNING: " \
                    "unknown type, setting value to null");
            success = ret->SetValue(key,
                    CefV8Value::CreateNull(),
                    V8_PROPERTY_ATTRIBUTE_NONE);
        }
        if (!success) {
            DebugLog("CefDictionaryValueToV8Value(): WARNING: " \
                    "ret->SetValue() failed");
        }
    }
    return ret;
}
Пример #8
0
CefRefPtr<CefV8Value> CefListValueToV8Value(
        CefRefPtr<CefListValue> listValue,
        int nestingLevel) {
    if (!listValue->IsValid()) {
        DebugLog("CefListValueToV8Value() FAILED: " \
                "CefDictionaryValue is invalid");
        return CefV8Value::CreateNull();
    }
    if (nestingLevel > 8) {
        DebugLog("CefListValueToV8Value(): WARNING: " \
            "max nesting level (8) exceeded");
        return CefV8Value::CreateNull();
    }
    int listSize = (int)listValue->GetSize();
    CefRefPtr<CefV8Value> ret = CefV8Value::CreateArray(listSize);
    CefRefPtr<CefBinaryValue> binaryValue;
    PythonCallback pyCallback;
    CefRefPtr<CefV8Handler> v8FunctionHandler;
    for (int key = 0; key < listSize; ++key) {
        cef_value_type_t valueType = listValue->GetType(key);
        bool success;
        std::string callbackName = "python_callback_";
        if (valueType == VTYPE_NULL) {
            success = ret->SetValue(key,
                    CefV8Value::CreateNull());
        } else if (valueType == VTYPE_BOOL) {
            success = ret->SetValue(key,
                    CefV8Value::CreateBool(listValue->GetBool(key)));
        } else if (valueType == VTYPE_INT) {
            success = ret->SetValue(key,
                    CefV8Value::CreateInt(listValue->GetInt(key)));
        } else if (valueType == VTYPE_DOUBLE) {
            success = ret->SetValue(key,
                    CefV8Value::CreateDouble(listValue->GetDouble(key)));
        } else if (valueType == VTYPE_STRING) {
            success = ret->SetValue(key,
                    CefV8Value::CreateString(listValue->GetString(key)));
        } else if (valueType == VTYPE_BINARY) {
            binaryValue = listValue->GetBinary(key);
            if (binaryValue->GetSize() == sizeof(pyCallback)) {
                binaryValue->GetData(&pyCallback, sizeof(pyCallback), 0);
                v8FunctionHandler = new V8FunctionHandler(
                        NULL, pyCallback.callbackId);
                // You must provide a function name to
                // CefV8Value::CreateFunction(), otherwise it fails.
                callbackName.append(AnyToString(pyCallback.callbackId));
                success = ret->SetValue(key,
                                CefV8Value::CreateFunction(
                                        callbackName, v8FunctionHandler));
            } else {
                DebugLog("CefListValueToV8Value(): WARNING: " \
                        "unknown binary value, setting value to null");
                success = ret->SetValue(key, CefV8Value::CreateNull());
            }
        } else if (valueType == VTYPE_DICTIONARY) {
            success = ret->SetValue(key,
                    CefDictionaryValueToV8Value(
                            listValue->GetDictionary(key),
                            nestingLevel + 1));
        } else if (valueType == VTYPE_LIST) {
            success = ret->SetValue(key,
                    CefListValueToV8Value(
                            listValue->GetList(key),
                            nestingLevel + 1));
        } else {
            DebugLog("CefListValueToV8Value(): WARNING: " \
                    "unknown type, setting value to null");
            success = ret->SetValue(key,
                    CefV8Value::CreateNull());
        }
        if (!success) {
            DebugLog("CefListValueToV8Value(): WARNING: " \
                    "ret->SetValue() failed");
        }
    }
    return ret;
}