예제 #1
0
파일: XCefInfo.cpp 프로젝트: Zion-007/XCef
static void _list_to_dict(
	CefRefPtr<CefListValue> &		src,
	CefRefPtr<CefDictionaryValue> & dest,
	CefDictionaryValue::KeyList &	keys
	)
{
	if (!src.get())
		return;
	if (!dest.get())
		dest = CefDictionaryValue::Create();

	bool has_keys = keys.size() == dest->GetSize();
	for (int i = 0, nsize = static_cast<int>(src->GetSize()); i < nsize; ++i)
	{
		std::string key = has_keys ? keys[i] : std::to_string(i);
		switch (src->GetType(i))
		{
		case VTYPE_NULL:
			dest->SetNull(key);
			break;
		case VTYPE_BOOL:
			dest->SetBool(key, src->GetBool(i));
			break;
		case VTYPE_INT:
			dest->SetInt(key, src->GetInt(i));
			break;
		case VTYPE_DOUBLE:
			dest->SetDouble(key, src->GetDouble(i));
			break;
		case VTYPE_STRING:
			dest->SetString(key, src->GetString(i));
			break;
		case VTYPE_BINARY:
			dest->SetBinary(key, src->GetBinary(i));
			break;
		case VTYPE_DICTIONARY:
			dest->SetDictionary(key, src->GetDictionary(i));
			break;
		case VTYPE_LIST:
			dest->SetList(key, src->GetList(i));
			break;
		default:
			assert(0);
			break;
		}
	}
}
예제 #2
0
파일: XCefInfo.cpp 프로젝트: Zion-007/XCef
// ¶ªÆúkey
static void _dict_to_list(CefRefPtr<CefDictionaryValue> & src, CefRefPtr<CefListValue> & dest)
{
	if (!src.get())
		return;
	if (!dest.get())
		dest = CefListValue::Create();

	CefDictionaryValue::KeyList keys;
	src->GetKeys(keys);

	int idx = 0;
	for (CefString & i : keys)
	{
		switch (src->GetType(i))
		{
		case VTYPE_NULL:
			dest->SetNull(idx);
			break;
		case VTYPE_BOOL:
			dest->SetBool(idx, src->GetBool(i));
			break;
		case VTYPE_INT:
			dest->SetInt(idx, src->GetInt(i));
			break;
		case VTYPE_DOUBLE:
			dest->SetDouble(idx, src->GetDouble(i));
			break;
		case VTYPE_STRING:
			dest->SetString(idx, src->GetString(i));
			break;
		case VTYPE_BINARY:
			dest->SetBinary(idx, src->GetBinary(i));
			break;
		case VTYPE_DICTIONARY:
			dest->SetDictionary(idx, src->GetDictionary(i));
			break;
		case VTYPE_LIST:
			dest->SetList(idx, src->GetList(i));
			break;
		default:
			assert(0);
			break;
		}
		++idx;
	}
}
예제 #3
0
bool ClientHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId source_process, CefRefPtr<CefProcessMessage> message)
{
	if (message->GetName().ToString() == "show_keyboard"){
		
		PostCallback(callback1(WhenKeyboard, true));

	}else if (message->GetName().ToString() == "hide_keyboard"){
		
		PostCallback(callback1(WhenKeyboard, false));
		
	}else{ 

		CefRefPtr<CefListValue> args = message->GetArgumentList();
		Upp::Vector<Upp::Value> par;
	
		for (unsigned i = 0; i < args->GetSize(); i++){
			CefValueType type = args->GetType(i);
			switch(type){
				
				case VTYPE_BOOL: 
					par.Add(args->GetBool(i));
					break;
				
				case VTYPE_DOUBLE:
					par.Add(args->GetDouble(i));
					break;
					
				case VTYPE_INT:
					par.Add(args->GetInt(i));
					break;
					
				case VTYPE_STRING:
					par.Add(args->GetString(i).ToString().c_str());
					break;
				
				default:
					par.Add("OnProcessMessageReceived: unsupported parameter type");
					break; 
			}
		}
		
		PostCallback(callback2(WhenMessage, message->GetName().ToString(), par));
	}
	return true;
}
void IPC_Container::GetObjectsFromIPC(
        CefRefPtr<CefProcessMessage> msg,
        std::vector<std::function<void(std::vector<int>, std::vector<double>, std::vector<std::string>, int64 frameID, int nodeID)> > singleObjectCreationFunctions
    )
{

    CefRefPtr<CefListValue> args = msg->GetArgumentList();
    int index = 0;

    int64 frameID = (int64) args->GetDouble(index++);

    // Amount of each different object type listed
    int types = args->GetInt(index++);
    //std::cout << "types: " << types << std::endl;

    std::vector<int> amount_type;
    for (int i = 0; i < types; i++)
    {
        amount_type.push_back(args->GetInt(index++));
        //std::cout << "type[" << i << "]: " << amount_type[i] << std::endl;
    }

    for (int i = 0; i < types; i++)
    {
        // Fill attributes to vectors
        std::vector<int> integers = {};
        std::vector<double> doubles = {};
        std::vector<std::string> strings = {};

        for (int j = 0; j < amount_type[i]; j++)
        {
            // Iteration for each attribute to be read
            for (int k = 0; k < (int)_scheme.size(); k++)
            {
                //DLOG(INFO) << "Object#" << j<< "/"<<amount_type[i]<<": Reading attribute #" << k << "("<< _scheme[k].GetName() << ") starting at IPC position #" << index;
                int schemeArraySize = _scheme[k].GetArraySize();
                if (schemeArraySize == 0)
                {
                    switch (_scheme[k].GetDatatype())
                    {
                        case Datatype::INTEGER:
                        {
                            integers.push_back(args->GetInt(index++));
                            break;
                        }
                        case Datatype::DOUBLE:
                        {
                            doubles.push_back(args->GetDouble(index++));
                            break;
                        }
                        case Datatype::STRING:
                        {
                            strings.push_back(args->GetString(index++));
                            break;
                        }
                    }
                }
                else if (schemeArraySize > 0)
                {
                    switch (_scheme[k].GetDatatype())
                    {
                        // TODO: Grouping of array elements with vector in vector?

                        case Datatype::INTEGER:
                        {
                            for (int l = 0; l < _scheme[k].GetArraySize(); l++)
                            {
                                integers.push_back(args->GetInt(index++));
                            }
                            break;
                        }
                        case Datatype::DOUBLE:
                        {

                            for (int l = 0; l < _scheme[k].GetArraySize(); l++)
                            {
                                doubles.push_back(args->GetDouble(index++));
                            }
                            break;
                        }
                        case Datatype::STRING:
                        {

                            for (int l = 0; l < _scheme[k].GetArraySize(); l++)
                            {
                                strings.push_back(args->GetString(index++));
                            }

                            break;
                        }
                    }
                }
                else // ERROR CASE
                {
                    // std::cout << "WARNING: Scheme array size < 0!" << std::endl;
                }
            }
            // Call function for specific object type with read data
            singleObjectCreationFunctions[i](integers, doubles, strings, frameID, j);

            // Clear all attribute values
            integers.clear();
            doubles.clear();
            strings.clear();
        }
    }
}
예제 #5
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;
}
예제 #6
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;
}
예제 #7
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
boost::python::dict CefDictionaryValueToPy( CefRefPtr<CefDictionaryValue> d )
{
	boost::python::dict result;

	CefDictionaryValue::KeyList keys;
	d->GetKeys( keys );

	for( size_t i = 0; i < keys.size(); i++ )
	{
		std::string k = keys[i].ToString();

		switch( d->GetType( keys[i] ) )
		{
			case VTYPE_INT:
			{
				result[k.c_str()] = d->GetInt( keys[i] );
				break;
			}
			case VTYPE_DOUBLE:
			{
				result[k.c_str()] = d->GetDouble( keys[i] );
				break;
			}
			case VTYPE_BOOL:
			{
				result[k.c_str()] = d->GetBool( keys[i] );
				break;
			}
			case VTYPE_STRING:
			{
				result[k.c_str()] = d->GetString( keys[i] ).ToString().c_str();
				break;
			}
			case VTYPE_BINARY:
			{
				WarsCefData_t warsCefData;
				CefRefPtr<CefBinaryValue> binaryData = d->GetBinary( keys[i] );
				binaryData->GetData( &warsCefData, sizeof( warsCefData ), 0 );
				if( warsCefData.type == WARSCEF_TYPE_JSOBJECT )
				{
					WarsCefJSObject_t warsCefJSObject;
					binaryData->GetData( &warsCefJSObject, sizeof( warsCefJSObject ), 0 );

					CefRefPtr<JSObject> jsResultObject = new JSObject( "", warsCefJSObject.uuid );
					result[k.c_str()] = boost::python::object( PyJSObject( jsResultObject ) );
				}
				else
				{
					result[k.c_str()] = boost::python::object();
				}
				break;
			}
			case VTYPE_DICTIONARY:
			{
				result[k.c_str()] = CefDictionaryValueToPy( d->GetDictionary( keys[i] ) );
				break;
			}
			case VTYPE_LIST:
			{
				result[k.c_str()] = CefValueListToPy( d->GetList( keys[i] ) );
				break;
			}
			default:
			{
				result[k.c_str()] = d->GetString( keys[i] ).ToString().c_str();
				break;
			}
		}
	}

	return result;
}
예제 #8
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
boost::python::list CefValueListToPy( CefRefPtr<CefListValue> l )
{
	boost::python::list result;
	for( size_t i = 0; i < l->GetSize(); i++ )
	{
		switch( l->GetType( i ) )
		{
			case VTYPE_INT:
			{
				result.append( l->GetInt( i ) );
				break;
			}
			case VTYPE_DOUBLE:
			{
				result.append( l->GetDouble( i ) );
				break;
			}
			case VTYPE_BOOL:
			{
				result.append( l->GetBool( i ) );
				break;
			}
			case VTYPE_STRING:
			{
				result.append( l->GetString( i ).ToString().c_str() );
				break;
			}
			case VTYPE_BINARY:
			{
				WarsCefData_t warsCefData;
				l->GetBinary( i )->GetData( &warsCefData, sizeof( warsCefData ), 0 );
				if( warsCefData.type == WARSCEF_TYPE_JSOBJECT )
				{
					WarsCefJSObject_t warsCefJSObject;
					l->GetBinary( i )->GetData( &warsCefJSObject, sizeof( warsCefJSObject ), 0 );

					CefRefPtr<JSObject> jsResultObject = new JSObject( "", warsCefJSObject.uuid );
					result.append( boost::python::object( PyJSObject( jsResultObject ) ) );
				}
				else
				{
					result.append( boost::python::object() );
				}
				break;
			}
			case VTYPE_DICTIONARY:
			{
				result.append( CefDictionaryValueToPy( l->GetDictionary( i ) ) );
				break;
			}
			case VTYPE_LIST:
			{
				result.append( CefValueListToPy( l->GetList( i ) ) );
				break;
			}
			default:
			{
				result.append( l->GetString( i ).ToString().c_str() );
				break;
			}
		}
	}
	return result;
}