text:
#define COBJMACROS

#include <stdio.h>
#include <windows.h>
#include <msi.h>
#include <msiquery.h>
#include <objidl.h>

#include "wine/test.h"

/*
 * The following are defined in Windows SDK's msidefs.h
 * but that file doesn't exist in the msvc6 header set.
 *
 * Some are already defined in PropIdl.h - undefine them
 */
#undef PID_DICTIONARY
#undef PID_CODEPAGE
#undef PID_SUBJECT
#undef PID_SECURITY

#define PID_DICTIONARY 0
#define PID_CODEPAGE 1
#define PID_TITLE 2
#define PID_SUBJECT 3
#define PID_AUTHOR 4
#define PID_KEYWORDS 5
#define PID_COMMENTS 6
#define PID_TEMPLATE 7
#define PID_LASTAUTHOR 8
#define PID_REVNUMBER 9
#define PID_EDITTINE 10
#define PID_LASTPRINTED 11
#define PID_CREATE_DTM 12
#define PID_LASTSAVE_DTM 13
#define PID_PAGECOUNT 14
#define PID_WORDCOUNT 15
#define PID_CHARCOUNT 16
#define PID_THUMBNAIL 17
#define PID_APPNAME 18
#define PID_SECURITY 19
#define PID_MSIVERSION PID_PAGECOUNT
#define PID_MSISOURCE PID_WORDCOUNT
#define PID_MSIRESTRICT PID_CHARCOUNT

static const char *msifile = "winetest-suminfo.msi";
static const WCHAR msifileW[] = {
    'w','i','n','e','t','e','s','t','-','s','u','m','i','n','f','o','.','m','s','i',0 };

static void test_suminfo(void)
{
    MSIHANDLE hdb = 0, hsuminfo;
    UINT r, count, type;
    DWORD sz;
    INT val;
    FILETIME ft;
    char buf[0x10];

    DeleteFileA(msifile);

    /* just MsiOpenDatabase should not create a file */
    r = MsiOpenDatabaseW(msifileW, MSIDBOPEN_CREATE, &hdb);
    ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");

    r = MsiGetSummaryInformationA(hdb, NULL, 0, NULL);
    ok(r == ERROR_INVALID_PARAMETER, "MsiGetSummaryInformation wrong error\n");

    r = MsiGetSummaryInformationA(hdb, NULL, 0, &hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed %u\n", r);

    r = MsiCloseHandle(hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");

    r = MsiGetSummaryInformationA(0, "", 0, &hsuminfo);
    todo_wine
    ok(r == ERROR_INSTALL_PACKAGE_INVALID || r == ERROR_INSTALL_PACKAGE_OPEN_FAILED,
       "MsiGetSummaryInformation failed %u\n", r);

    r = MsiGetSummaryInformationA(hdb, "", 0, &hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed %u\n", r);

    r = MsiSummaryInfoGetPropertyCount(0, NULL);
    ok(r == ERROR_INVALID_HANDLE, "getpropcount failed\n");

    r = MsiSummaryInfoGetPropertyCount(hsuminfo, NULL);
    ok(r == ERROR_SUCCESS, "getpropcount failed\n");

    count = -1;
    r = MsiSummaryInfoGetPropertyCount(hsuminfo, &count);
    ok(r == ERROR_SUCCESS, "getpropcount failed\n");
    ok(count == 0, "count should be zero\n");

    r = MsiSummaryInfoGetPropertyA(hsuminfo, 0, NULL, NULL, NULL, 0, NULL);
    ok(r == ERROR_SUCCESS, "getpropcount failed\n");

    r = MsiSummaryInfoGetPropertyA(hsuminfo, -1, NULL, NULL, NULL, 0, NULL);
    ok(r == ERROR_UNKNOWN_PROPERTY, "MsiSummaryInfoGetProperty wrong error\n");

    r = MsiSummaryInfoGetPropertyA(hsuminfo, PID_SECURITY+1, NULL, NULL, NULL, 0, NULL);
    ok(r == ERROR_UNKNOWN_PROPERTY, "MsiSummaryInfoGetProperty wrong error\n");

    type = -1;
    r = MsiSummaryInfoGetPropertyA(hsuminfo, 0, &type, NULL, NULL, 0, NULL);
    ok(r == ERROR_SUCCESS, "getpropcount failed\n");
    ok(type == 0, "wrong type\n");

    type = -1;
    val = 1234;
    r = MsiSummaryInfoGetPropertyA(hsuminfo, 0, &type, &val, NULL, 0, NULL);
    ok(r == ERROR_SUCCESS, "getpropcount failed\n");
    ok(type == 0, "wrong type\n");
    ok(val == 1234, "wrong val\n");

    buf[0]='x';
    buf[1]=0;
    sz = 0x10;
    r = MsiSummaryInfoGetPropertyA(hsuminfo, PID_REVNUMBER, &type, &val, NULL, buf, &sz);
    ok(r == ERROR_SUCCESS, "getpropcount failed\n");
    ok(buf[0]=='x', "cleared buffer\n");
    ok(sz == 0x10, "count wasn't zero\n");
    ok(type == VT_EMPTY, "should be empty\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "Mike");
    ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_TITLE, VT_LPSTR, 1, NULL, "JungAh");
    ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_TITLE, VT_LPSTR, 1, &ft, "Mike");
    ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_CODEPAGE, VT_I2, 1, &ft, "JungAh");
    ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiCloseHandle(hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");

    /* try again with the update count set */
    r = MsiGetSummaryInformationA(hdb, NULL, 1, &hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, 0, VT_LPSTR, 1, NULL, NULL);
    ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_CODEPAGE, VT_LPSTR, 1, NULL, NULL);
    ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_TITLE, VT_I4, 0, NULL, "Mike");
    ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_AUTHOR, VT_I4, 0, NULL, "JungAh");
    ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_KEYWORDS, VT_I2, 0, NULL, "Mike");
    ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_COMMENTS, VT_FILETIME, 0, NULL, "JungAh");
    ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_TEMPLATE, VT_I2, 0, NULL, "Mike");
    ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_LASTAUTHOR, VT_LPSTR, 0, NULL, NULL);
    ok(r == ERROR_INVALID_PARAMETER, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_LASTSAVE_DTM, VT_FILETIME, 0, NULL, NULL);
    ok(r == ERROR_INVALID_PARAMETER, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_LASTAUTHOR, VT_LPWSTR, 0, NULL, "h\0i\0\0");
    ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_REVNUMBER, VT_I4, 0, NULL, "Jungah");
    ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_PAGECOUNT, VT_LPSTR, 1, NULL, NULL);
    ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "Mike");
    ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty failed\n");

    sz = 2;
    strcpy(buf,"x");
    r = MsiSummaryInfoGetPropertyA(hsuminfo, PID_TITLE, &type, NULL, NULL, buf, &sz );
    ok(r == ERROR_MORE_DATA, "MsiSummaryInfoSetProperty failed\n");
    ok(sz == 4, "count was wrong\n");
    ok(type == VT_LPSTR, "type was wrong\n");
    ok(!strcmp(buf,"M"), "buffer was wrong\n");

    sz = 4;
    strcpy(buf,"x");
    r = MsiSummaryInfoGetPropertyA(hsuminfo, PID_TITLE, &type, NULL, NULL, buf, &sz );
    ok(r == ERROR_MORE_DATA, "MsiSummaryInfoSetProperty failed\n");
    ok(sz == 4, "count was wrong\n");
    ok(type == VT_LPSTR, "type was wrong\n");
    ok(!strcmp(buf,"Mik"), "buffer was wrong\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "JungAh");
    ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty failed\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_CODEPAGE, VT_I2, 1, &ft, "Mike");
    ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiCloseHandle(hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");

    /* try again with a higher update count */
    r = MsiGetSummaryInformationA(hdb, NULL, 10, &hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "JungAh");
    ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty failed\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_CODEPAGE, VT_LPSTR, 1, NULL, NULL);
    ok(r == ERROR_DATATYPE_MISMATCH, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_CODEPAGE, VT_I2, 1, NULL, NULL);
    ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_CODEPAGE, VT_I2, 1, &ft, "Mike");
    ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_AUTHOR, VT_LPSTR, 1, &ft, "Mike");
    ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoPersist(hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiSummaryInfoPersist failed\n");

    MsiDatabaseCommit(hdb);

    r = MsiCloseHandle(hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");

    r = MsiCloseHandle(hdb);
    ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");

    /* filename, non-zero update count */
    r = MsiGetSummaryInformationA(0, msifile, 1, &hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed\n");

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_AUTHOR, VT_LPSTR, 1, &ft, "Mike");
    ok(r == ERROR_SUCCESS, "MsiSummaryInfoSetProperty wrong error\n");

    r = MsiSummaryInfoPersist(hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiSummaryInfoPersist failed %u\n", r);

    r = MsiCloseHandle(hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiCloseHandle failed %u\n", r);

    /* filename, zero update count */
    r = MsiGetSummaryInformationA(0, msifile, 0, &hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed %u\n", r);

    r = MsiSummaryInfoSetPropertyA(hsuminfo, PID_AUTHOR, VT_LPSTR, 1, &ft, "Mike");
    todo_wine ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty wrong error, %u\n", r);

    r = MsiSummaryInfoPersist(hsuminfo);
    ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoPersist wrong error %u\n", r);

    r = MsiCloseHandle(hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");

    r = DeleteFileA(msifile);
    ok(r, "DeleteFile failed\n");
}

static const WCHAR tb[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
static const WCHAR sd[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
static const WCHAR sp[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */

#define LOSE_CONST(x) ((LPSTR)(UINT_PTR)(x))

static void test_create_database_binary(void)
{
    static const CLSID CLSID_MsiDatabase =
        { 0xc1084, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46 } };
    static const CLSID IID_IPropertySetStorage =
        { 0x13a, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46 } };
    static const CLSID FMTID_SummaryInformation =
        { 0xf29f85e0, 0x4ff9, 0x1068, {0xab, 0x91, 0x08, 0x00, 0x2b, 0x27, 0xb3, 0xd9}};
    DWORD mode = STGM_CREATE | STGM_READWRITE | STGM_DIRECT | STGM_SHARE_EXCLUSIVE;
    IPropertySetStorage *pss = NULL;
    IPropertyStorage *ps = NULL;
    IStorage *stg = NULL;
    IStream *stm = NULL;
    HRESULT r;
    PROPSPEC propspec[10];
    PROPVARIANT propvar[10];
    USHORT data[2] = { 0, 0 };

    r = StgCreateDocfile( msifileW, mode, 0, &stg );
    ok( r == S_OK, "failed to create database\n");

    r = IStorage_SetClass( stg, &CLSID_MsiDatabase );
    ok( r == S_OK, "failed to set clsid\n");

    /* create the _StringData stream */
    r = IStorage_CreateStream( stg, sd, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm );
    ok( r == S_OK, "failed to create stream\n");

    IStream_Release( stm );

    /* create the _StringPool stream */
    r = IStorage_CreateStream( stg, sp, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm );
    ok( r == S_OK, "failed to create stream\n");

    r = IStream_Write( stm, data, sizeof data, NULL );
    ok( r == S_OK, "failed to write stream\n");

    IStream_Release( stm );

    /* create the _Tables stream */
    r = IStorage_CreateStream( stg, tb, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm );
    ok( r == S_OK, "failed to create stream\n");

    IStream_Release( stm );

    r = IStorage_QueryInterface( stg, &IID_IPropertySetStorage, (void**) &pss );
    ok( r == S_OK, "failed to set clsid\n");

    r = IPropertySetStorage_Create( pss, &FMTID_SummaryInformation, NULL, 0, mode, &ps );
    ok( r == S_OK, "failed to create property set\n");

    r = IPropertyStorage_SetClass( ps, &FMTID_SummaryInformation );
    ok( r == S_OK, "failed to set class\n");

    propspec[0].ulKind = PRSPEC_PROPID;
    U(propspec[0]).propid = PID_TITLE;
    propvar[0].vt = VT_LPSTR;
    U(propvar[0]).pszVal = LOSE_CONST("test title");

    propspec[1].ulKind = PRSPEC_PROPID;
    U(propspec[1]).propid = PID_SUBJECT;
    propvar[1].vt = VT_LPSTR;
    U(propvar[1]).pszVal = LOSE_CONST("msi suminfo / property storage test");

    propspec[2].ulKind = PRSPEC_PROPID;
    U(propspec[2]).propid = PID_AUTHOR;
    propvar[2].vt = VT_LPSTR;
    U(propvar[2]).pszVal = LOSE_CONST("mike_m");

    propspec[3].ulKind = PRSPEC_PROPID;
    U(propspec[3]).propid = PID_TEMPLATE;
    propvar[3].vt = VT_LPSTR;
    U(propvar[3]).pszVal = LOSE_CONST(";1033");  /* actually the string table's codepage */

    propspec[4].ulKind = PRSPEC_PROPID;
    U(propspec[4]).propid = PID_REVNUMBER;
    propvar[4].vt = VT_LPSTR;
    U(propvar[4]).pszVal = LOSE_CONST("{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");

    propspec[5].ulKind = PRSPEC_PROPID;
    U(propspec[5]).propid = PID_PAGECOUNT;
    propvar[5].vt = VT_I4;
    U(propvar[5]).lVal = 100;

    propspec[6].ulKind = PRSPEC_PROPID;
    U(propspec[6]).propid = PID_WORDCOUNT;
    propvar[6].vt = VT_I4;
    U(propvar[6]).lVal = 0;

    /* MSDN says that PID_LASTPRINTED should be a VT_FILETIME... */
    propspec[7].ulKind = PRSPEC_PROPID;
    U(propspec[7]).propid = PID_LASTPRINTED;
    propvar[7].vt = VT_LPSTR;
    U(propvar[7]).pszVal = LOSE_CONST("7/1/1999 5:17");

    r = IPropertyStorage_WriteMultiple( ps, 8, propspec, propvar, PID_FIRST_USABLE );
    ok( r == S_OK, "failed to write properties\n");

    IPropertyStorage_Commit( ps, STGC_DEFAULT );

    IPropertyStorage_Release( ps );
    IPropertySetStorage_Release( pss );

    IStorage_Commit( stg, STGC_DEFAULT );
    IStorage_Release( stg );
}

static void test_summary_binary(void)
{
    MSIHANDLE hdb = 0, hsuminfo = 0;
    UINT r, type, count;
    INT ival;
    DWORD sz;
    char sval[20];

    DeleteFileA( msifile );

    test_create_database_binary();

    ok(GetFileAttributesA(msifile) != INVALID_FILE_ATTRIBUTES, "file doesn't exist!\n");

    /* just MsiOpenDatabase should not create a file */
    r = MsiOpenDatabaseW(msifileW, MSIDBOPEN_READONLY, &hdb);
    ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");

    r = MsiGetSummaryInformationA(hdb, NULL, 0, &hsuminfo);
    ok(r == ERROR_SUCCESS, "MsiGetSummaryInformation failed\n");

    /*
     * Check what reading PID_LASTPRINTED does...
     * The string value is written to the msi file
     * but it appears that we're not allowed to read it back again.
     * We can still read its type though...?
     */
    sz = sizeof sval;
    sval[0] = 0;
    type = 0;
    r = MsiSummaryInfoGetPropertyA(hsuminfo, PID_LASTPRINTED, &type, NULL, NULL, sval, &sz);
    ok(r == ERROR_SUCCESS, "MsiSummaryInfoGetProperty failed\n");
    ok(!lstrcmpA(sval, "") || !lstrcmpA(sval, "7"),
        "Expected empty string or \"7\", got \"%s\"\n", sval);
    todo_wine {
    ok(type == VT_LPSTR, "Expected VT_LPSTR, got %d\n", type);
    ok(sz == 0 || sz == 1, "Expected 0 or 1, got %d\n", sz);
    }

    ival = -1;
    r = MsiSummaryInfoGetPropertyA(hsuminfo, PID_WORDCOUNT, &type, &ival, NULL, NULL, NULL);
    ok(r == ERROR_SUCCESS, "MsiSummaryInfoGetProperty failed\n");
    todo_wine ok( ival == 0, "value incorrect\n");

    /* looks like msi adds some of its own values in here */
    count = 0;
    r = MsiSummaryInfoGetPropertyCount( hsuminfo, &count );
    ok(r == ERROR_SUCCESS, "getpropcount failed\n");
    todo_wine ok(count == 10, "prop count incorrect\n");

    r = MsiSummaryInfoSetPropertyA( hsuminfo, PID_TITLE, VT_LPSTR, 0, NULL, "Mike" );
    ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoSetProperty failed %u\n", r);

    r = MsiSummaryInfoPersist( hsuminfo );
    ok(r == ERROR_FUNCTION_FAILED, "MsiSummaryInfoPersist failed %u\n", r);

    MsiCloseHandle( hsuminfo );
    MsiCloseHandle( hdb );

    DeleteFileA( msifile );
}

START_TEST(suminfo)
{
    test_suminfo();
    test_summary_binary();
}


text:
<?php

namespace DTS\eBaySDK\Trading\Types;

/**
 *
 * @property boolean $PurchaseReminderEmailPreferences
 */
class PurchaseReminderEmailPreferencesType extends \DTS\eBaySDK\Types\BaseType
{
    /**
     * @var array Properties belonging to objects of this class.
     */
    private static $propertyTypes = array(
        'PurchaseReminderEmailPreferences' => array(
            'type' => 'boolean',
            'unbound' => false,
            'attribute' => false,
            'elementName' => 'PurchaseReminderEmailPreferences'
        )
    );

    /**
     * @param array $values Optional properties and values to assign to the object.
     */
    public function __construct(array $values = array())
    {
        list($parentValues, $childValues) = self::getParentValues(self::$propertyTypes, $values);

        parent::__construct($parentValues);

        if (!array_key_exists(__CLASS__, self::$properties)) {
            self::$properties[__CLASS__] = array_merge(self::$properties[get_parent_class()], self::$propertyTypes);
        }

        if (!array_key_exists(__CLASS__, self::$xmlNamespaces)) {
            self::$xmlNamespaces[__CLASS__] = 'urn:ebay:apis:eBLBaseComponents';
        }

        $this->setValues(__CLASS__, $childValues);
    }
}

redpajama_set_name: RedPajamaGithub


text:
//====================================================================================================================//
// File:          qcan_socket_canpie_fd.cpp                                                                           //
// Description:   QCAN classes - CAN socket for CANpie FD                                                             //
//                                                                                //
// Copyright (C) MicroControl GmbH & Co. KG                                                                           //
// 53844 Troisdorf - Germany                                                                                //
// www.microcontrol.net                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the   //
// following conditions are met:                                                                                //
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions, the following   //
//    disclaimer and the referenced file 'LICENSE'.                                                                   //
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the       //
//    following disclaimer in the documentation and/or other materials provided with the distribution.                //
// 3. Neither the name of MicroControl nor the names of its contributors may be used to endorse or promote products   //
//    derived from this software without specific prior written permission.                                           //
//                                                                                //
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance     //
// with the License. You may obtain a copy of the License at                                                          //
//                                                                                //
//    http://www.apache.org/licenses/LICENSE-2.0                                                                      //
//                                                                                //
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed   //
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for  //
// the specific language governing permissions and limitations under the License.                                     //
//                                                                                //
//====================================================================================================================//

/*--------------------------------------------------------------------------------------------------------------------*\
** Include files                                                                                **
**                                                                                **
\*--------------------------------------------------------------------------------------------------------------------*/

#include "qcan_socket_canpie_fd.hpp"

#include <QtCore/QCoreApplication>
#include <QtCore/QTimer>

/*--------------------------------------------------------------------------------------------------------------------*\
** Definitions                                                                                **
**                                                                                **
\*--------------------------------------------------------------------------------------------------------------------*/

//---------------------------------------------------------------------------------------------------
/*!
** \def     CP_DRIVER_MAJOR
** \ingroup CP_VERSION
**
** Major version number of CANpie driver implementation.
*/
#define  CP_DRIVER_MAJOR          1

//---------------------------------------------------------------------------------------------------
/*!
** \def     CP_DRIVER_MINOR
** \ingroup CP_VERSION
**
** Minor version number of CANpie driver implementation.
*/
#define  CP_DRIVER_MINOR          4

#define  CP_USER_FLAG_RCV        ((uint32_t)(0x00000001))
#define  CP_USER_FLAG_TRM        ((uint32_t)(0x00000002))

enum DrvInfo_e {
   eDRV_INFO_OFF = 0,
   eDRV_INFO_INIT
};

/*--------------------------------------------------------------------------------------------------------------------*\
** Variables of module                                                                                **
**                                                                                **
\*--------------------------------------------------------------------------------------------------------------------*/

//------------------------------------------------------------------------------------------------------
//
static QCoreApplication *  pclApplicationS = 0L;

//------------------------------------------------------------------------------------------------------
//
static QCanSocketCpFD      aclCanSockListS[QCAN_NETWORK_MAX];

/*--------------------------------------------------------------------------------------------------------------------*\
** Function implementation                                                                                **
**                                                                                **
\*--------------------------------------------------------------------------------------------------------------------*/

//--------------------------------------------------------------------------------------------------------------------//
// CheckParam()                                                                                //
// check valid port, buffer number and driver state                                                                   //
//--------------------------------------------------------------------------------------------------------------------//
static CpStatus_tv CheckParam(const CpPort_ts * ptsPortV, const uint8_t ubBufferIdxV, const uint8_t ubReqStateV )
{
   CpStatus_tv tvStatusT = eCP_ERR_CHANNEL;

   //---------------------------------------------------------------------------------------------------
   // test CAN port
   //
   if (ptsPortV != (CpPort_ts *) 0L)
   {
      tvStatusT = eCP_ERR_INIT_MISSING;

      //-------------------------------------------------------------------------------------------
      // check for initialisation
      //
      if (ptsPortV->ubDrvInfo >= ubReqStateV)
      {
         tvStatusT = eCP_ERR_BUFFER;

         //-----------------------------------------------------------------------------------
         // check for valid buffer number
         //
         if (ubBufferIdxV < CP_BUFFER_MAX)
         {
            tvStatusT = eCP_ERR_NONE;
         }
      }
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreBitrate()                                                                                //
// Setup bit-rate of CAN controller                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreBitrate( CpPort_ts * ptsPortV, int32_t slNomBitRateV, int32_t slDatBitRateV)
{
   // QCanSocketCpFD *  pclSockT;
   CpStatus_tv       tvStatusT = eCP_ERR_CHANNEL;

   //---------------------------------------------------------------------------------------------------
   // debug information
   //
   qDebug() << "CpCoreBitrate() ............. :" << slNomBitRateV << slDatBitRateV;

   //---------------------------------------------------------------------------------------------------
   // get access to socket
   //
   if (ptsPortV != (CpPort_ts *) 0L)
   {
      if (ptsPortV->ubPhyIf < QCAN_NETWORK_MAX)
      {
         //----------------------------------------------------------------------------------------
         // This function does not modify the bitrate settings of the CANpie FD server, because
         // alter the bitrate settings might be denied by the server. So we just return here.
         //
         tvStatusT = eCP_ERR_NONE;
      }
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreBufferConfig()                                                                                //
// Configure CAN message buffer                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreBufferConfig( CpPort_ts * ptsPortV, uint8_t   ubBufferIdxV,
                                uint32_t  ulIdentifierV, uint32_t  ulAcceptMaskV,
                                uint8_t   ubFormatV, uint8_t   ubDirectionV)
{
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpStatus_tv       tvStatusT;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV and ubBufferIdxV
   //
   tvStatusT = CheckParam(ptsPortV, ubBufferIdxV, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {

      //-------------------------------------------------------------------------------------------
      // test message format and mask identifier
      //
      switch(ubFormatV & CP_MASK_MSG_FORMAT)
      {
         case CP_MSG_FORMAT_CBFF:
         case CP_MSG_FORMAT_FBFF:
            ulIdentifierV = ulIdentifierV & CP_MASK_STD_FRAME;
            ulAcceptMaskV = ulAcceptMaskV & CP_MASK_STD_FRAME;
            break;

         case CP_MSG_FORMAT_CEFF:
         case CP_MSG_FORMAT_FEFF:
            ulIdentifierV = ulIdentifierV & CP_MASK_EXT_FRAME;
            ulAcceptMaskV = ulAcceptMaskV & CP_MASK_EXT_FRAME;
            break;
      }

      //-------------------------------------------------------------------------------------------
      // copy to simulated CAN buffer
      //
      pclSockT->atsCanMsgP[ubBufferIdxV].ulIdentifier  = ulIdentifierV;
      pclSockT->atsCanMsgP[ubBufferIdxV].ubMsgCtrl     = ubFormatV;

      //-------------------------------------------------------------------------------------------
      // mark Tx/Rx message
      //
      if(ubDirectionV == eCP_BUFFER_DIR_TRM)
      {
         pclSockT->atsCanMsgP[ubBufferIdxV].ulMsgUser = CP_USER_FLAG_TRM;
      }
      else
      {
         pclSockT->atsCanMsgP[ubBufferIdxV].ulMsgUser = CP_USER_FLAG_RCV;
      }

      //-------------------------------------------------------------------------------------------
      // set acceptance mask to default value
      //
      pclSockT->atsAccMaskP[ubBufferIdxV] = ulAcceptMaskV;
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreBufferGetData()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreBufferGetData( CpPort_ts * ptsPortV, uint8_t   ubBufferIdxV,
                                 uint8_t * pubDestDataV, uint8_t   ubStartPosV, uint8_t   ubSizeV)
{
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpStatus_tv       tvStatusT;
   uint8_t           ubCntT;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV and ubBufferIdxV
   //
   tvStatusT = CheckParam(ptsPortV, ubBufferIdxV, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {

      //-------------------------------------------------------------------------------------------
      // test start position and size
      //
      if ( (ubStartPosV + ubSizeV) > CP_DATA_SIZE )
      {
         tvStatusT = eCP_ERR_PARAM;
      }
      else
      {
         //-----------------------------------------------------------------------------------
         // copy data from simulated CAN buffer
         //
         for(ubCntT = ubStartPosV; ubCntT < (ubStartPosV + ubSizeV); ubCntT++)
         {
            *pubDestDataV = CpMsgGetData(&(pclSockT->atsCanMsgP[ubBufferIdxV]), ubCntT);
            pubDestDataV++;
         }
      }
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreBufferGetDlc()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreBufferGetDlc(  CpPort_ts * ptsPortV, uint8_t ubBufferIdxV, uint8_t * pubDlcV)
{
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpStatus_tv       tvStatusT;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV and ubBufferIdxV
   //
   tvStatusT = CheckParam(ptsPortV, ubBufferIdxV, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {

      //-------------------------------------------------------------------------------------------
      // read DLC from simulated CAN buffer
      //
      *pubDlcV = pclSockT->atsCanMsgP[ubBufferIdxV].ubMsgDLC;
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreBufferRelease()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreBufferRelease( CpPort_ts * ptsPortV, uint8_t ubBufferIdxV)
{
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpStatus_tv       tvStatusT;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV and ubBufferIdxV
   //
   tvStatusT = CheckParam(ptsPortV, ubBufferIdxV, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {

      //-------------------------------------------------------------------------------------------
      // clear simulated CAN buffer
      //
      pclSockT->atsCanMsgP[ubBufferIdxV].ulIdentifier = 0;
      pclSockT->atsCanMsgP[ubBufferIdxV].ubMsgDLC     = 0;
      pclSockT->atsCanMsgP[ubBufferIdxV].ubMsgCtrl    = 0;

      CpCoreFifoRelease(ptsPortV, ubBufferIdxV);
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreBufferSend()                                                                                //
// send message out of the CAN controller                                                                             //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreBufferSend(CpPort_ts * ptsPortV, uint8_t ubBufferIdxV)
{
   QCanFrame         clFrameT;
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpStatus_tv       tvStatusT;
   CpTrmHandler_Fn   pfnTrmHandlerT;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV and ubBufferIdxV
   //
   tvStatusT = CheckParam(ptsPortV, ubBufferIdxV, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {
      //-------------------------------------------------------------------------------------------
      // write CAN frame
      //
      clFrameT = pclSockT->fromCpMsg(ubBufferIdxV);
      if(pclSockT->write(clFrameT) == false)
      {
         tvStatusT = eCP_ERR_TRM_FULL;
         qDebug() << "Failed to write message";
      }
      else
      {
         pclSockT->tsStatisticP.ulTrmMsgCount++;

         if (pclSockT->pfnTrmIntHandlerP != 0)
         {
            pfnTrmHandlerT = pclSockT->pfnTrmIntHandlerP;
            tvStatusT = (* pfnTrmHandlerT)(&(pclSockT->atsCanMsgP[ubBufferIdxV]), ubBufferIdxV);
         }
      }
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreBufferSetData()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreBufferSetData( CpPort_ts * ptsPortV, uint8_t ubBufferIdxV,  uint8_t * pubSrcDataV,
                                 uint8_t   ubStartPosV, uint8_t   ubSizeV)
{
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpStatus_tv       tvStatusT;
   uint8_t           ubCntT;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV and ubBufferIdxV
   //
   tvStatusT = CheckParam(ptsPortV, ubBufferIdxV, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {

      //-------------------------------------------------------------------------------------------
      // test start position and size
      //
      if ( (ubStartPosV + ubSizeV) > CP_DATA_SIZE )
      {
         tvStatusT = eCP_ERR_PARAM;
      }
      else
      {
         //-----------------------------------------------------------------------------------
         // copy data from simulated CAN buffer
         //
         for (ubCntT = ubStartPosV; ubCntT < (ubStartPosV + ubSizeV); ubCntT++)
         {
            CpMsgSetData(&(pclSockT->atsCanMsgP[ubBufferIdxV]), ubCntT, *pubSrcDataV);
            pubSrcDataV++;
         }
      }
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreBufferSetDlc()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreBufferSetDlc(  CpPort_ts * ptsPortV, uint8_t ubBufferIdxV, uint8_t ubDlcV)
{
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpStatus_tv       tvStatusT;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV and ubBufferIdxV
   //
   tvStatusT = CheckParam(ptsPortV, ubBufferIdxV, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {

      //-------------------------------------------------------------------------------------------
      // write DLC to simulated CAN buffer
      //
      pclSockT->atsCanMsgP[ubBufferIdxV].ubMsgDLC = ubDlcV;
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreCanMode()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreCanMode(CpPort_ts * ptsPortV, uint8_t ubModeV)
{
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpStatus_tv       tvStatusT = eCP_ERR_CHANNEL;

   //---------------------------------------------------------------------------------------------------
   // debug information
   //
   qDebug() << "CpCoreCanMode() ............. :" << ubModeV;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV
   //
   tvStatusT = CheckParam(ptsPortV, eCP_BUFFER_1, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {
      //-------------------------------------------------------------------------------------------
      // switch CAN controller into mode "ubModeV"
      //
      switch(ubModeV)
      {
         //-----------------------------------------------------------------------------------
         // Stop the CAN controller (passive on the bus)
         //
         case eCP_MODE_INIT:
            pclSockT->tsCanStateP.ubCanErrState  = eCP_STATE_INIT;
            tvStatusT = eCP_ERR_NONE;
            break;

         //-----------------------------------------------------------------------------------
         // Start the CAN controller (active on the bus)
         //
         case eCP_MODE_START:
            pclSockT->tsCanStateP.ubCanErrState  = eCP_STATE_BUS_ACTIVE;
            tvStatusT = eCP_ERR_NONE;
            break;

         //-----------------------------------------------------------------------------------
         // Start the CAN controller (Listen-Only)
         //
         case eCP_MODE_LISTEN_ONLY:
            pclSockT->tsCanStateP.ubCanErrState  = eCP_STATE_BUS_ACTIVE;
            tvStatusT = eCP_ERR_NONE;
            break;

         //-----------------------------------------------------------------------------------
         // Other modes are not supported
         //
         default:
            tvStatusT = eCP_ERR_NOT_SUPPORTED;
            break;
      }

   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreCanState()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreCanState(CpPort_ts * ptsPortV, CpState_ts * ptsStateV)
{
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpStatus_tv       tvStatusT = eCP_ERR_CHANNEL;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV
   //
   tvStatusT = CheckParam(ptsPortV, eCP_BUFFER_1, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {
      tvStatusT = eCP_ERR_PARAM;

      if ( ptsStateV != (CpState_ts *) 0L )
      {
         //----------------------------------------------------------------------------------------
         // copy current CAN state
         //
         ptsStateV->ubCanErrState = pclSockT->tsCanStateP.ubCanErrState;
         ptsStateV->ubCanErrType  = pclSockT->tsCanStateP.ubCanErrType;

         //----------------------------------------------------------------------------------------
         // copy current error counter
         //
         ptsStateV->ubCanRcvErrCnt = pclSockT->tsCanStateP.ubCanRcvErrCnt;
         ptsStateV->ubCanTrmErrCnt = pclSockT->tsCanStateP.ubCanTrmErrCnt;

         tvStatusT = eCP_ERR_NONE;
      }
   }

   return(tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreDriverInit()                                                                                //
// init CAN controller                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreDriverInit(uint8_t ubPhyIfV, CpPort_ts * ptsPortV, uint8_t ubConfigV)
{
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpStatus_tv       tvStatusT = eCP_ERR_GENERIC;

   //---------------------------------------------------------------------------------------------------
   // debug information
   //
   qDebug() << "CpCoreDriverInit() .......... :" << ubPhyIfV << ubConfigV;

   //---------------------------------------------------------------------------------------------------
   // Check if an instance of QCoreApplication is active. In case there is no QCoreApplication there
   // is no QEventLoop and we need a thread that polls data from the CANpie server.
   //
   if (pclApplicationS == 0L)
   {
      if (QCoreApplication::instance() == 0L)
      {
         int32_t slAppArgcT = 0;
         char ** szAppArgvT = NULL;
         pclApplicationS = new QCoreApplication(slAppArgcT, szAppArgvT);

         qDebug() << "QCanSocketCpFD() ............ : create new QCoreApplication";
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test parameter
   //
   if ((ubPhyIfV > QCAN_NETWORK_MAX) || (ubPhyIfV == eCAN_CHANNEL_NONE))
   {
      tvStatusT = eCP_ERR_CHANNEL;
   }
   else
   {
      //-------------------------------------------------------------------------------------------
      // Get access to socket and check if it is already connected
      //
      pclSockT = &aclCanSockListS[ubPhyIfV - 1];
      if (pclSockT->isConnected() == false)
      {
         pclSockT->connectNetwork((CAN_Channel_e) ubPhyIfV);

         //-----------------------------------------------------------------------------------
         // Wait here until the connection is established
         //
         QTimer clConnectionTimerT;
         clConnectionTimerT.setSingleShot(true);
         clConnectionTimerT.start(100);
         bool btConnectionEstablishedT = false;
         while ( (btConnectionEstablishedT == false) && (clConnectionTimerT.isActive()) )
         {
            QCoreApplication::instance()->processEvents();
            btConnectionEstablishedT = pclSockT->isConnected();
         }
      }

      //-------------------------------------------------------------------------------------------
      // initialise members if socket is conneted
      //
      if (pclSockT->isConnected())
      {
         //-----------------------------------------------------------------------------------
         // connect the readyRead() signal with the slot for message reception
         //
         pclSockT->connect(pclSockT, &QCanSocketCpFD::readyRead, pclSockT, &QCanSocketCpFD::onSocketReceive);

         //-----------------------------------------------------------------------------------
         // no FIFOs attached to message buffers
         //
         for (uint8_t ubBufferCntT = 0; ubBufferCntT < CP_BUFFER_MAX; ubBufferCntT++)
         {
            pclSockT->aptsCanFifoP[ubBufferCntT] = Q_NULLPTR;
         }

         //---------------------------------------------------------------------------
         // store physical channel information
         //
         ptsPortV->ubPhyIf   = ubPhyIfV;
         ptsPortV->ubDrvInfo = eDRV_INFO_INIT;

         //---------------------------------------------------------------------------
         // clear CAN state
         //
         pclSockT->tsCanStateP.ubCanErrState  = eCP_STATE_INIT;
         pclSockT->tsCanStateP.ubCanErrType   = eCP_ERR_TYPE_NONE;
         pclSockT->tsCanStateP.ubCanRcvErrCnt = 0;
         pclSockT->tsCanStateP.ubCanTrmErrCnt = 0;

         //---------------------------------------------------------------------------
         // clear statistic information
         //
         pclSockT->tsStatisticP.ulErrMsgCount = 0;
         pclSockT->tsStatisticP.ulRcvMsgCount = 0;
         pclSockT->tsStatisticP.ulTrmMsgCount = 0;

         tvStatusT = eCP_ERR_NONE;

      }
      else
      {
         tvStatusT = eCP_ERR_INIT_FAIL;
      }
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreDriverRelease()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreDriverRelease(CpPort_ts * ptsPortV)
{
   CpStatus_tv       tvStatusT;
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;

   //---------------------------------------------------------------------------------------------------
   // debug information
   //
   qDebug() << "CpCoreDriverRelease() ....... :" << (ptsPortV->ubPhyIf);

   //---------------------------------------------------------------------------------------------------
   // release ready read connection
   //
   pclSockT->disconnect(pclSockT, &QCanSocketCpFD::readyRead, pclSockT, &QCanSocketCpFD::onSocketReceive);

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV
   //
   tvStatusT = CheckParam(ptsPortV, eCP_BUFFER_1, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   CpCoreCanMode(ptsPortV, eCP_MODE_INIT);

   //---------------------------------------------------------------------------------------------------
   // Disconnect the socket
   //
   if (pclSockT != (QCanSocketCpFD *) 0L)
   {
      pclSockT->disconnectNetwork();
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreFifoConfig()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreFifoConfig(CpPort_ts * ptsPortV, uint8_t ubBufferIdxV, CpFifo_ts * ptsFifoV)
{
   CpStatus_tv       tvStatusT;
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;

   qDebug() << "CpCoreFifoConfig()........... :" << ubBufferIdxV;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV and ubBufferIdxV
   //
   tvStatusT = CheckParam(ptsPortV, ubBufferIdxV, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {

      pclSockT->aptsCanFifoP[ubBufferIdxV] = ptsFifoV;
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreFifoRead()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreFifoRead(CpPort_ts * ptsPortV, uint8_t ubBufferIdxV, CpCanMsg_ts * ptsCanMsgV, uint32_t * pulMsgCntV)
{
   CpStatus_tv       tvStatusT;
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpFifo_ts *       ptsFifoT;
   CpCanMsg_ts *     ptsFifoMsgT;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV and ubBufferIdxV
   //
   tvStatusT = CheckParam(ptsPortV, ubBufferIdxV, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {
      ptsFifoT = pclSockT->aptsCanFifoP[ubBufferIdxV];

      if (ptsFifoT == Q_NULLPTR)
      {
         tvStatusT = eCP_ERR_FIFO_PARAM;
      }
      else
      {
         if(CpFifoIsEmpty(ptsFifoT) == 1)
         {
            //--------------------------------------------------------------------------------
            // FIFO is empty, no data has been copied
            //
            *pulMsgCntV = 0;
            tvStatusT = eCP_ERR_FIFO_EMPTY;
         }
         else
         {
            ptsFifoMsgT = CpFifoDataOutPtr(ptsFifoT);
            memcpy(ptsCanMsgV, ptsFifoMsgT, sizeof(CpCanMsg_ts));
            CpFifoIncOut(ptsFifoT);
            *pulMsgCntV = 1;
            tvStatusT = eCP_ERR_NONE;
         }
      }
   }
   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreFifoRelease()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreFifoRelease(CpPort_ts * ptsPortV, uint8_t ubBufferIdxV)
{
   CpStatus_tv       tvStatusT;
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV and ubBufferIdxV
   //
   tvStatusT = CheckParam(ptsPortV, ubBufferIdxV, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {
      pclSockT->aptsCanFifoP[ubBufferIdxV] = Q_NULLPTR;
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreFifoWrite()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreFifoWrite(CpPort_ts * ptsPortV, uint8_t ubBufferIdxV, CpCanMsg_ts * ptsCanMsgV, uint32_t * pulMsgCntV)
{
   QCanFrame         clFrameT;
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpStatus_tv       tvStatusT;
   uint32_t          ulMsgCntT;
   CpTrmHandler_Fn   pfnTrmHandlerT;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV and ubBufferIdxV
   //
   tvStatusT = CheckParam(ptsPortV, ubBufferIdxV, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {

      //-------------------------------------------------------------------------------------------
      // write CAN frame
      //
      for (ulMsgCntT = 0; ulMsgCntT < *pulMsgCntV; ulMsgCntT++)
      {
         clFrameT = pclSockT->fromCpMsg(ptsCanMsgV);
         if(pclSockT->write(clFrameT) == false)
         {
            tvStatusT = eCP_ERR_TRM_FULL;
            break;
         }

         if (pclSockT->pfnTrmIntHandlerP != 0)
         {
            pfnTrmHandlerT = pclSockT->pfnTrmIntHandlerP;
            tvStatusT = (* pfnTrmHandlerT)(ptsCanMsgV, ubBufferIdxV);
         }

         ptsCanMsgV++;
      }
      *pulMsgCntV = ulMsgCntT;   // store number of messages written

      pclSockT->tsStatisticP.ulTrmMsgCount += ulMsgCntT;
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreHDI()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreHDI(CpPort_ts *ptsPortV, CpHdi_ts *ptsHdiV)
{
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpStatus_tv       tvStatusT = eCP_ERR_CHANNEL;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV
   //
   tvStatusT = CheckParam(ptsPortV, eCP_BUFFER_1, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if ( pclSockT != (QCanSocketCpFD *) 0L )
   {
      if (ptsHdiV != (CpHdi_ts *) 0L)
      {
         ptsHdiV->ubVersionMajor   = CP_VERSION_MAJOR;
         ptsHdiV->ubVersionMinor   = CP_VERSION_MINOR;
         ptsHdiV->ubCanFeatures    = 3;
         ptsHdiV->ubDriverFeatures = 0;
         ptsHdiV->ubDriverMajor    = CP_DRIVER_MAJOR;
         ptsHdiV->ubDriverMinor    = CP_DRIVER_MINOR;
         ptsHdiV->ubBufferMax      = CP_BUFFER_MAX;
         ptsHdiV->slNomBitRate     = pclSockT->slNomBitRateP;
         ptsHdiV->slDatBitRate     = pclSockT->slDatBitRateP;

         tvStatusT = eCP_ERR_NONE;
      }
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreIntFunctions()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreIntFunctions( CpPort_ts * ptsPortV,
                        uint8_t (* pfnRcvHandler)(CpCanMsg_ts *, uint8_t),
                        uint8_t (* pfnTrmHandler)(CpCanMsg_ts *, uint8_t),
                        uint8_t (* pfnErrHandler)(CpState_ts *) )
{
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;
   CpStatus_tv       tvStatusT = eCP_ERR_CHANNEL;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV
   //
   tvStatusT = CheckParam(ptsPortV, eCP_BUFFER_1, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if (pclSockT != (QCanSocketCpFD *) 0L)
   {
      //---------------------------------------------------------------------------
      // store the new callbacks
      //
      pclSockT->pfnRcvIntHandlerP = pfnRcvHandler;
      pclSockT->pfnTrmIntHandlerP = pfnTrmHandler;
      pclSockT->pfnErrIntHandlerP = pfnErrHandler;

      tvStatusT = eCP_ERR_NONE;
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpCoreStatistic()                                                                                //
// return statistical information                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpCoreStatistic(CpPort_ts * ptsPortV, CpStatistic_ts * ptsStatsV)
{
   CpStatus_tv       tvStatusT = eCP_ERR_CHANNEL;
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;

   //---------------------------------------------------------------------------------------------------
   // test parameter ptsPortV
   //
   tvStatusT = CheckParam(ptsPortV, eCP_BUFFER_1, eDRV_INFO_INIT);

   //---------------------------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   if (tvStatusT == eCP_ERR_NONE)
   {
      if ( ((ptsPortV->ubPhyIf) > eCP_CHANNEL_NONE) && ((ptsPortV->ubPhyIf) <= QCAN_NETWORK_MAX) )
      {
         pclSockT  = &aclCanSockListS[(ptsPortV->ubPhyIf) - 1];
      }
   }

   //---------------------------------------------------------------------------------------------------
   // test if previous operations failed before we proceed
   //
   if (pclSockT != (QCanSocketCpFD *) 0L)
   {
      tvStatusT = eCP_ERR_PARAM;
      if (ptsStatsV != (CpStatistic_ts *) 0L)
      {
         ptsStatsV->ulErrMsgCount = pclSockT->tsStatisticP.ulErrMsgCount;
         ptsStatsV->ulRcvMsgCount = pclSockT->tsStatisticP.ulRcvMsgCount;
         ptsStatsV->ulTrmMsgCount = pclSockT->tsStatisticP.ulTrmMsgCount;
         tvStatusT = eCP_ERR_NONE;
      }
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpSocketConnectSlots()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpSocketConnectSlots(uint8_t ubPhyIfV, QObject * pclDestObjectV,
                                 const char * pubSockConnectV, const char * pubSockDisconnectV,
                                 const char * pubSockErrorV)
{
   QCanSocketCpFD *  pclSockT = (QCanSocketCpFD *) 0L;

   //---------------------------------------------------------------------------------------------------
   // debug information
   //
   qDebug() << "CpSocketConnectSlots() ...... : " << pclDestObjectV;

   //---------------------------------------------------------------------------------------------------
   // test parameter
   //
   if ((ubPhyIfV > QCAN_NETWORK_MAX) || (ubPhyIfV == eCAN_CHANNEL_NONE))
   {
      return(eCP_ERR_CHANNEL);
   }

   //-----------------------------------------------------------------------------------
   // get pointer to CANpie socket class
   //
   pclSockT  = &aclCanSockListS[ubPhyIfV - 1];

   if(pubSockConnectV != Q_NULLPTR)
   {
      QObject::connect( pclSockT, SIGNAL(connected()),
                        pclDestObjectV, pubSockConnectV);
   }

   if(pubSockDisconnectV != Q_NULLPTR)
   {
      QObject::connect( pclSockT, SIGNAL(disconnected()),
                        pclDestObjectV, pubSockDisconnectV);
   }

   if(pubSockErrorV != Q_NULLPTR)
   {
      QObject::connect( pclSockT,
                        SIGNAL(error(QAbstractSocket::SocketError)),
                        pclDestObjectV, pubSockErrorV);
   }
   return (eCP_ERR_NONE);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpSocketInstance()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
QCanSocket * CpSocketInstance(uint8_t ubPhyIfV)
{
   QCanSocket *  pclSockT = (QCanSocket *) 0L;

   //---------------------------------------------------------------------------------------------------
   // test parameter
   //
   if ((ubPhyIfV < QCAN_NETWORK_MAX) && (ubPhyIfV > eCAN_CHANNEL_NONE))
   {
      pclSockT = (QCanSocket *) &aclCanSockListS[ubPhyIfV - 1];
   }

   return (pclSockT);
}

//--------------------------------------------------------------------------------------------------------------------//
// CpSocketProcessEvents()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
void CpSocketProcessEvents()
{
   if (pclApplicationS != 0L)
   {
      pclApplicationS->processEvents();
   }
}

//--------------------------------------------------------------------------------------------------------------------//
// CpSocketSetHostAddress()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpStatus_tv CpSocketSetHostAddress(uint8_t ubPhyIfV, QHostAddress clHostAddressV)
{
   QCanSocketCpFD *   pclSockT;
   CpStatus_tv        tvStatusT = eCP_ERR_CHANNEL;

   //---------------------------------------------------------------------------------------------------
   // test parameter
   //
   if ( (ubPhyIfV > eCAN_CHANNEL_NONE) && (ubPhyIfV <= QCAN_NETWORK_MAX) )
   {

      //-------------------------------------------------------------------------------------------
      // get pointer to CANpie socket class
      //
      pclSockT  = &aclCanSockListS[ubPhyIfV - 1];

      pclSockT->setHostAddress(clHostAddressV);
      tvStatusT = eCP_ERR_NONE;
   }

   return (tvStatusT);
}

//--------------------------------------------------------------------------------------------------------------------//
// QCanSocketCpFD::QCanSocketCpFD()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
QCanSocketCpFD::QCanSocketCpFD()
{
   //---------------------------------------------------------------------------------------------------
   // debug information
   //
   qDebug() << "QCanSocketCpFD() ............ : create object";

   //---------------------------------------------------------------------------------------------------
   // clear members
   //
   pfnErrIntHandlerP  = 0;
   pfnRcvIntHandlerP  = 0;
   pfnTrmIntHandlerP  = 0;

   slNomBitRateP      = eCAN_BITRATE_NONE;
   slDatBitRateP      = eCAN_BITRATE_NONE;

}

//--------------------------------------------------------------------------------------------------------------------//
// QCanSocketCpFD::~QCanSocketCpFD()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
QCanSocketCpFD::~QCanSocketCpFD()
{
   //---------------------------------------------------------------------------------------------------
   // debug information
   //
   qDebug() << "~QCanSocketCpFD() ........... : delete object";

}

//--------------------------------------------------------------------------------------------------------------------//
// QCanSocketCpFD::fromCanFrame()                                                                                //
// message conversion                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
CpCanMsg_ts QCanSocketCpFD::fromCanFrame(QCanFrame & clCanFrameR)
{
   CpCanMsg_ts    tsCanMsgT;
   uint8_t        ubDataCntT;

   switch(clCanFrameR.frameFormat())
   {
      case QCanFrame::eFORMAT_CAN_STD:
         CpMsgInit(&tsCanMsgT, CP_MSG_FORMAT_CBFF);
         break;

      case QCanFrame::eFORMAT_CAN_EXT:
         CpMsgInit(&tsCanMsgT, CP_MSG_FORMAT_CEFF);
         break;

      case QCanFrame::eFORMAT_FD_STD:
         CpMsgInit(&tsCanMsgT, CP_MSG_FORMAT_FBFF);
         break;

      case QCanFrame::eFORMAT_FD_EXT:
         CpMsgInit(&tsCanMsgT, CP_MSG_FORMAT_FEFF);
         break;
   }

   CpMsgSetIdentifier(&tsCanMsgT, clCanFrameR.identifier());
   CpMsgSetDlc(&tsCanMsgT, clCanFrameR.dlc());

   for (ubDataCntT = 0; ubDataCntT < CP_DATA_SIZE; ubDataCntT++)
   {
      CpMsgSetData(&tsCanMsgT, ubDataCntT, clCanFrameR.data(ubDataCntT));
   }
   return(tsCanMsgT);
}

//--------------------------------------------------------------------------------------------------------------------//
// QCanSocketCpFD::fromCpMsg()                                                                                //
// message conversion                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
QCanFrame QCanSocketCpFD::fromCpMsg(CpCanMsg_ts * ptsCanMsgV)
{
   QCanFrame      clCanFrameT;
   uint8_t        ubDataCntT;

   if (CpMsgIsFdFrame(ptsCanMsgV))
   {
      if (CpMsgIsExtended(ptsCanMsgV))
      {
         clCanFrameT.setFrameFormat(QCanFrame::eFORMAT_FD_EXT);
      }
      else
      {
         clCanFrameT.setFrameFormat(QCanFrame::eFORMAT_FD_STD);
      }
   }
   else
   {
      if (CpMsgIsExtended(ptsCanMsgV))
      {
         clCanFrameT.setFrameFormat(QCanFrame::eFORMAT_CAN_EXT);
      }
      else
      {
         clCanFrameT.setFrameFormat(QCanFrame::eFORMAT_CAN_STD);
      }
   }
   clCanFrameT.setIdentifier(CpMsgGetIdentifier(ptsCanMsgV));
   clCanFrameT.setDlc(CpMsgGetDlc(ptsCanMsgV));

   for (ubDataCntT = 0; ubDataCntT < clCanFrameT.dataSize(); ubDataCntT++)
   {
      clCanFrameT.setData(ubDataCntT, CpMsgGetData(ptsCanMsgV, ubDataCntT));
   }

   return (clCanFrameT);
}

//--------------------------------------------------------------------------------------------------------------------//
// QCanSocketCpFD::fromCpMsg()                                                                                //
// message conversion                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
QCanFrame QCanSocketCpFD::fromCpMsg(uint8_t ubMsgBufferV)
{
   QCanFrame      clCanFrameT;
   CpCanMsg_ts *  ptsCanMsgT;
   uint8_t        ubDataCntT;

   ptsCanMsgT = &(atsCanMsgP[ubMsgBufferV]);

   if(CpMsgIsFdFrame(ptsCanMsgT))
   {
      if(CpMsgIsExtended(ptsCanMsgT))
      {
         clCanFrameT.setFrameFormat(QCanFrame::eFORMAT_FD_EXT);
      }
      else
      {
         clCanFrameT.setFrameFormat(QCanFrame::eFORMAT_FD_STD);
      }
   }
   else
   {
      if(CpMsgIsExtended(ptsCanMsgT))
      {
         clCanFrameT.setFrameFormat(QCanFrame::eFORMAT_CAN_EXT);
      }
      else
      {
         clCanFrameT.setFrameFormat(QCanFrame::eFORMAT_CAN_STD);
      }
   }
   clCanFrameT.setIdentifier(CpMsgGetIdentifier(ptsCanMsgT));
   clCanFrameT.setDlc(CpMsgGetDlc(ptsCanMsgT));

   for(ubDataCntT = 0; ubDataCntT < clCanFrameT.dataSize(); ubDataCntT++)
   {
      clCanFrameT.setData(ubDataCntT, CpMsgGetData(ptsCanMsgT, ubDataCntT));
   }

   return(clCanFrameT);
}

//--------------------------------------------------------------------------------------------------------------------//
// QCanSocketCpFD::handleCanFrame()                                                                                //
//                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
void QCanSocketCpFD::handleCanFrame(QCanFrame & clCanFrameR)
{
   CpCanMsg_ts    tsCanMsgT;
   CpCanMsg_ts *  ptsCanBufT;
   CpFifo_ts *    ptsFifoT;
   uint32_t       ulAccMaskT;
   uint8_t        ubBufferIdxT;

   tsCanMsgT = fromCanFrame(clCanFrameR);

   //---------------------------------------------------------------------------------------------------
   // run through all possible message buffer
   //
   for (ubBufferIdxT = 0; ubBufferIdxT < CP_BUFFER_MAX; ubBufferIdxT++)
   {
      //-------------------------------------------------------------------------------------------
      // setup pointer to CAN message buffer
      //
      ptsCanBufT = &(this->atsCanMsgP[ubBufferIdxT]);

      //-------------------------------------------------------------------------------------------
      // get acceptance mask
      //
      ulAccMaskT = this->atsAccMaskP[ubBufferIdxT];

      //-------------------------------------------------------------------------------------------
      // test direction flag
      //
      if ( ((ptsCanBufT->ulMsgUser) & CP_USER_FLAG_RCV) == 0) continue;

      //-------------------------------------------------------------------------------------------
      // distinguish frame types
      //
      if (CpMsgIsExtended(ptsCanBufT) == CpMsgIsExtended(&tsCanMsgT))
      {
         //-----------------------------------------------------------------------------------
         // check for identifier
         //
         if( (CpMsgGetIdentifier(ptsCanBufT) & ulAccMaskT) == (CpMsgGetIdentifier(&tsCanMsgT) & ulAccMaskT) )
         {
            //---------------------------------------------------------------------------
            // copy to buffer
            //
            ptsCanBufT->ulIdentifier   = tsCanMsgT.ulIdentifier;
            ptsCanBufT->ubMsgDLC       = tsCanMsgT.ubMsgDLC;
            ptsCanBufT->ubMsgCtrl      = tsCanMsgT.ubMsgCtrl;
            memcpy(&(ptsCanBufT->tuMsgData.aubByte[0]), &(tsCanMsgT.tuMsgData.aubByte[0]), CP_DATA_SIZE );

            //---------------------------------------------------------------------------
            // test for receive callback handler
            //
            if (this->aptsCanFifoP[ubBufferIdxT] == 0L)
            {
               //-------------------------------------------------------------------
               // no FIFO available
               //
               if (this->pfnRcvIntHandlerP != 0)
               {
                  (* this->pfnRcvIntHandlerP)(ptsCanBufT, ubBufferIdxT);
               }
            }
            else
            {
               ptsFifoT = this->aptsCanFifoP[ubBufferIdxT];
               if (CpFifoIsFull(ptsFifoT) == 0)
               {
                  ptsCanBufT = CpFifoDataInPtr(ptsFifoT);
                  memcpy(ptsCanBufT, &tsCanMsgT, sizeof(CpCanMsg_ts));
                  CpFifoIncIn(ptsFifoT);
               }
            }

            //---------------------------------------------------------------------------
            // Update statistic
            //
            tsStatisticP.ulRcvMsgCount++;

            //---------------------------------------------------------------------------
            // Quit loop because there was an identifier match
            //
            break;
         }
      }
   }
}

//--------------------------------------------------------------------------------------------------------------------//
// QCanSocketCpFD::onSocketReceive()                                                                                //
// receive CAN message                                                                                //
//--------------------------------------------------------------------------------------------------------------------//
void QCanSocketCpFD::onSocketReceive()
{
   QCanFrame         clCanFrameT;
   uint32_t          ulFrameCntT;
   uint32_t          ulFrameMaxT;

   //---------------------------------------------------------------------------------------------------
   // Check how many frames are available
   //
   ulFrameMaxT = framesAvailable();

   //---------------------------------------------------------------------------------------------------
   // Read CAN frames and handle them
   //
   for (ulFrameCntT = 0; ulFrameCntT < ulFrameMaxT; ulFrameCntT++)
   {
      if (this->read(clCanFrameT) == true)
      {
         handleCanFrame(clCanFrameT);
      }
   }
}


text: This is a invalid module.


text:
<?php

    // First we execute our common code to connection to the database and start the session
    require("common.php");

    // At the top of the page we check to see whether the user is logged in or not
    if(empty($_SESSION['user']))
    {
        // Remember that this die statement is absolutely critical.  Without it,
        // people can view your members-only content without logging in.
        die("Please login first!");
    }

    // Everything below this point in the file is secured by the login system

    // We can retrieve a list of members from the database using a SELECT query.
    // In this case we do not have a WHERE clause because we want to select all
    // of the rows from the database table.
    $query = "
        SELECT
            id,
            username,
            data
        FROM users
    ";

    try
    {
        // These two statements run the query against your database table.
        $stmt = $db->prepare($query);
        $stmt->execute();
    }
    catch(PDOException $ex)
    {
        // Note: On a production website, you should not output $ex->getMessage().
        // It may provide an attacker with helpful information about your code.
        die("Failed to run query: " . $ex->getMessage());
    }

    // Finally, we can retrieve all of the found rows into an array using fetchAll
    $rows = $stmt->fetchAll();

    foreach($rows as $row){
        if($row["username"] == $_SESSION["user"]["username"]){
            echo($row["data"]);
        }
    }
    ?>


text:
// Copyright 2016 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.build.lib.bazel.repository.skylark;

import static com.google.devtools.build.lib.packages.Attribute.attr;
import static com.google.devtools.build.lib.syntax.SkylarkType.castMap;
import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
import static com.google.devtools.build.lib.syntax.Type.STRING;
import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;

import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
import com.google.devtools.build.lib.packages.AttributeValueSource;
import com.google.devtools.build.lib.packages.Package.NameConflictException;
import com.google.devtools.build.lib.packages.PackageFactory;
import com.google.devtools.build.lib.packages.PackageFactory.PackageContext;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
import com.google.devtools.build.lib.packages.RuleFactory.InvalidRuleException;
import com.google.devtools.build.lib.rules.SkylarkAttr.Descriptor;
import com.google.devtools.build.lib.skylarkinterface.Param;
import com.google.devtools.build.lib.skylarkinterface.SkylarkSignature;
import com.google.devtools.build.lib.syntax.BaseFunction;
import com.google.devtools.build.lib.syntax.BuiltinFunction;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.FuncallExpression;
import com.google.devtools.build.lib.syntax.FunctionSignature;
import com.google.devtools.build.lib.syntax.Runtime;
import com.google.devtools.build.lib.syntax.SkylarkDict;
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.syntax.SkylarkSignatureProcessor;
import java.util.Map;

/**
 * The Skylark module containing the definition of {@code repository_rule} function to define a
 * skylark remote repository.
 */
public class SkylarkRepositoryModule {

  @SkylarkSignature(
    name = "repository_rule",
    doc =
        "Creates a new repository rule. Store it in a global value, so that it can be loaded and "
            + "called from the WORKSPACE file.",
    returnType = BaseFunction.class,
    parameters = {
      @Param(
        name = "implementation",
        type = BaseFunction.class,
        doc =
            "the function implementing this rule, has to have exactly one parameter: "
                + "repository_ctx. The function "
                + "is called during loading phase for each instance of the rule."
      ),
      @Param(
        name = "attrs",
        type = SkylarkDict.class,
        noneable = true,
        defaultValue = "None",
        doc =
            "dictionary to declare all the attributes of the rule. It maps from an attribute "
                + "name to an attribute object (see attr "
                + "module). Attributes starting with _ are private, and can be "
                + "used to add an implicit dependency on a label to a file (a repository "
                + "rule cannot depend on a generated artifact). The attribute "
                + "name is implicitly added and must not be specified.",
        named = true,
        positional = false
      ),
      @Param(
        name = "local",
        type = Boolean.class,
        defaultValue = "False",
        doc =
            "Indicate that this rule fetches everything from the local system and should be "
                + "reevaluated at every fetch.",
        named = true,
        positional = false
      ),
      @Param(
        name = "environ",
        type = SkylarkList.class,
        generic1 = String.class,
        defaultValue = "[]",
        doc =
            "Provides a list of environment variable that this repository rule depends on. If"
                + " an environment variable in that list change, the repository will be refetched.",
        named = true,
        positional = false
      )
    },
    useAst = true,
    useEnvironment = true
  )
  private static final BuiltinFunction repositoryRule =
      new BuiltinFunction("repository_rule") {
        @SuppressWarnings({"rawtypes", "unused"})
        // an Attribute.Builder instead of a Attribute.Builder<?> but it's OK.
        public BaseFunction invoke(
            BaseFunction implementation,
            Object attrs,
            Boolean local,
            SkylarkList<String> environ,
            FuncallExpression ast,
            com.google.devtools.build.lib.syntax.Environment funcallEnv)
            throws EvalException {
          funcallEnv.checkLoadingOrWorkspacePhase("repository_rule", ast.getLocation());
          // We'll set the name later, pass the empty string for now.
          Builder builder = new Builder("", RuleClassType.WORKSPACE, true);

          builder.addOrOverrideAttribute(attr("$local", BOOLEAN).defaultValue(local).build());
          builder.addOrOverrideAttribute(attr("$environ", STRING_LIST)
              .defaultValue(environ).build());
          BaseRuleClasses.nameAttribute(builder);
          BaseRuleClasses.commonCoreAndSkylarkAttributes(builder);
          builder.add(attr("expect_failure", STRING));
          if (attrs != Runtime.NONE) {
            for (Map.Entry<String, Descriptor> attr :
                castMap(attrs, String.class, Descriptor.class, "attrs").entrySet()) {
              Descriptor attrDescriptor = attr.getValue();
              AttributeValueSource source = attrDescriptor.getValueSource();
              String attrName = source.convertToNativeName(attr.getKey(), ast.getLocation());
              builder.addOrOverrideAttribute(attrDescriptor.build(attrName));
            }
          }
          builder.setConfiguredTargetFunction(implementation);
          builder.setRuleDefinitionEnvironment(funcallEnv);
          builder.setWorkspaceOnly();
          return new RepositoryRuleFunction(builder);
        }
      };

  private static final class RepositoryRuleFunction extends BaseFunction {
    private final Builder builder;

    public RepositoryRuleFunction(Builder builder) {
      super("repository_rule", FunctionSignature.KWARGS);
      this.builder = builder;
    }

    @Override
    public Object call(
        Object[] args, FuncallExpression ast, com.google.devtools.build.lib.syntax.Environment env)
        throws EvalException, InterruptedException {
      String ruleClassName = ast.getFunction().getName();
      try {
        RuleClass ruleClass = builder.build(ruleClassName);
        PackageContext context = PackageFactory.getContext(env, ast);
        @SuppressWarnings("unchecked")
        Map<String, Object> attributeValues = (Map<String, Object>) args[0];
        return context
            .getBuilder()
            .externalPackageData()
            .createAndAddRepositoryRule(
                context.getBuilder(), ruleClass, null, attributeValues, ast);
      } catch (InvalidRuleException | NameConflictException | LabelSyntaxException e) {
        throw new EvalException(ast.getLocation(), e.getMessage());
      }
    }
  }

  static {
    SkylarkSignatureProcessor.configureSkylarkFunctions(SkylarkRepositoryModule.class);
  }
}


text:
function [SInfo,isVersioned]=getfileinfo(fullFileName)
% GETFILEINFO generates a structure with svn file methadata including
% revision, last modification date etc.
%
% Input:
%   regular:
%       fullFileName: char[1,] - full file name
%
% Output:
%   SInfo: struct[1,1] - resulting file info
%   isVersioned: logical[1,1] - indicates whether the specified file is
%       versioned
%
% Example:
%
% SInfo=mxberry.dev.scm.subversion.getfileinfo('C:\MySVNWorkingCopy\myfile.m')
%
%        returns
%
% SInfo=
%
%                    path: 'C:\MySVNWorkingCopy\myfile.m'
%                    name: 'myfile.m'
%     workingCopyRootPath: 'MySVNWorkingCopy'
%                     uRL: [1x81 char]
%          repositoryRoot: 'https://mysvnserveraddress.com'
%          repositoryUUID: 'ad8adf1d-3c4f-4f16-b4fd-ec115ca36637'
%                revision: '53'
%                nodeKind: 'file'
%                schedule: 'normal'
%       lastChangedAuthor: 'dane'
%          lastChangedRev: '53'
%         lastChangedDate: [1x44 char]
%         textLastUpdated: [1x44 char]
%                checksum: 'd53792175d11aedff70c799ab925297ea55820bb'
%
% $Author: Peter Gagarinov, PhD <pgagarinov@gmail.com>,
% $Copyright: 2015-2016 Peter Gagarinov, PhD
%             2015 Moscow State University,
%            Faculty of Computational Mathematics and Computer Science,
%            System Analysis Department$
%
import mxberry.dev.scm.subversion.svncall;
import mxberry.dev.scm.subversion.getrevisionbypath;
rev=getrevisionbypath(fullFileName);
if strcmp(rev,'unversioned')
    SInfo=struct();
    isVersioned=false;
else
    isVersioned=true;
    propNameValueList=svncall(sprintf('info "%s@"',fullFileName));

    %
    propNameValueCList=cellfun(@(x)strsplit(x,': '),...
        propNameValueList(1:end-1),...
        'UniformOutput',false);
    propNameValueCMat=vertcat(propNameValueCList{:});
    propNameValueCMat(:,1)=cellfun(@formFieldName,propNameValueCMat(:,1),...
        'UniformOutput',false);
    %
    propNameValueCMat=transpose(propNameValueCMat);
    %
    SInfo=struct(propNameValueCMat{:});
end
end
function fieldName=formFieldName(inputStr)
fieldName=strrep(inputStr,' ','');
fieldName(1)=lower(fieldName(1));
end


text:
package com.markmwaura.weatherapp.Utils.pulltozoom;

import android.content.res.TypedArray;
import android.view.View;

public interface IPullToZoom<T extends View> {
    /**
     * Get the Wrapped Zoom View. Anything returned here has already been
     * added to the content view.
     *
     * @return The View which is currently wrapped
     */
    View getZoomView();

    View getHeaderView();

    /**
     * Get the Wrapped root View.
     *
     * @return The View which is currently wrapped
     */
    T getPullRootView();

    /**
     * Whether Pull-to-Refresh is enabled
     *
     * @return enabled
     */
    boolean isPullToZoomEnabled();

    /**
     * Returns whether the Widget is currently in the Zooming state
     *
     * @return true if the Widget is currently zooming
     */
    boolean isZooming();

    /**
     * Returns whether the Widget is currently in the Zooming anim type
     *
     * @return true if the anim is parallax
     */
    boolean isParallax();

    boolean isHideHeader();

    void handleStyledAttributes(TypedArray a);
}


text:
<tr *ngIf="_firstRowOffset < labelMinRequiredCells" aria-hidden="true">
  {{label}}

    {{_firstRowOffset >= labelMinRequiredCells ? label : ''}}

      {{item.displayValue}}