hexsha stringlengths 40 40 | size int64 5 1.05M | ext stringclasses 588
values | lang stringclasses 305
values | max_stars_repo_path stringlengths 3 363 | max_stars_repo_name stringlengths 5 118 | max_stars_repo_head_hexsha stringlengths 40 40 | max_stars_repo_licenses listlengths 1 10 | max_stars_count float64 1 191k ⌀ | max_stars_repo_stars_event_min_datetime stringdate 2015-01-01 00:00:35 2022-03-31 23:43:49 ⌀ | max_stars_repo_stars_event_max_datetime stringdate 2015-01-01 12:37:38 2022-03-31 23:59:52 ⌀ | max_issues_repo_path stringlengths 3 363 | max_issues_repo_name stringlengths 5 118 | max_issues_repo_head_hexsha stringlengths 40 40 | max_issues_repo_licenses listlengths 1 10 | max_issues_count float64 1 134k ⌀ | max_issues_repo_issues_event_min_datetime stringlengths 24 24 ⌀ | max_issues_repo_issues_event_max_datetime stringlengths 24 24 ⌀ | max_forks_repo_path stringlengths 3 363 | max_forks_repo_name stringlengths 5 135 | max_forks_repo_head_hexsha stringlengths 40 40 | max_forks_repo_licenses listlengths 1 10 | max_forks_count float64 1 105k ⌀ | max_forks_repo_forks_event_min_datetime stringdate 2015-01-01 00:01:02 2022-03-31 23:27:27 ⌀ | max_forks_repo_forks_event_max_datetime stringdate 2015-01-03 08:55:07 2022-03-31 23:59:24 ⌀ | content stringlengths 5 1.05M | avg_line_length float64 1.13 1.04M | max_line_length int64 1 1.05M | alphanum_fraction float64 0 1 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
27b5946e666dbbba9ed782932699266678e5c6d4 | 3,932 | c | C | main.c | xixitalk/binCompare | 86cf54cdca8df03237dcfc23d100f22bbb4a17a4 | [
"Apache-2.0"
] | 2 | 2017-11-02T07:56:07.000Z | 2021-08-19T04:41:25.000Z | main.c | xixitalk/binCompare | 86cf54cdca8df03237dcfc23d100f22bbb4a17a4 | [
"Apache-2.0"
] | null | null | null | main.c | xixitalk/binCompare | 86cf54cdca8df03237dcfc23d100f22bbb4a17a4 | [
"Apache-2.0"
] | null | null | null | #include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define ONCE_SIZE 48
#define FILE1_START 0
#define FILE1_END 1
#define FILE2_END 2
#define FILE_END 3
#define TYPE_32 4
#define TYPE_16 2
#define TYPE_8 1
static unsigned int print_len = TYPE_8;
static unsigned int start_addr = 0;
static unsigned int cmp_lenght = 0;
static void usage(char *app)
{
printf("%s file1 file2 [type] [start addr] [lenght]\n", app);
printf("type:1 2 4 for char short int mode,default 1\n");
}
static void print_hex(const char *buf, int type)
{
unsigned int *p32 = NULL;
unsigned short *p16 = NULL;
unsigned char *p8 = NULL;
int j = 0;
for(j = 0; j < 16; j += type)
{
switch(type)
{
case TYPE_8:
p8 = (unsigned char *) & (buf[j]);
printf("%02x ", *p8);
break;
case TYPE_16:
p16 = (unsigned short *) & (buf[j]);
printf("%04x ", *p16);
break;
case TYPE_32:
default:
p32 = (unsigned int *) & (buf[j]);
printf("%08x ", *p32);
break;
}
}
}
static void print_char(const char *buf, int type)
{
char *pchar = NULL;
int j = 0, m = 0;
for(j = 0; j < 16; j += type)
{
for(m = type - 1; m >= 0; m--)
{
pchar = (char *) & (buf[j + m]);
if(isprint(*pchar))
{
printf("%c ", *pchar);
//exit(0); /*for test*/
}
else
{
printf("%c ", ' ');
}
}
printf(" ");
}
}
static void print_data(int addr, const char *buf1, const char *buf2)
{
int i = 0;
unsigned int *pitem = NULL;
char *pchar = NULL;
for(i = 0; i < ONCE_SIZE; i += 16)
{
printf("0x%08x ", addr + i);
print_hex(buf1 + i, print_len);
printf(" ");
print_hex(buf2 + i, print_len);
printf("\n");
printf(" ");
print_char(buf1 + i, print_len);
printf(" ");
print_char(buf2 + i, print_len);
printf("\n");
}
}
static void file_compare(const char *file1, const char *file2)
{
FILE *fd1 = NULL;
FILE *fd2 = NULL;
char buf1[128], buf2[128];
int loopflag = 0;
unsigned addr = 0;
unsigned int len1 = 0, len2 = 0;
fd1 = fopen(file1, "rb");
if(NULL == fd1)
{
perror(file1);
exit(-1);
}
fd2 = fopen(file2, "rb");
if(NULL == fd2)
{
perror(file2);
exit(-1);
}
if(start_addr > 0)
addr = start_addr;
if(0 != fseek(fd1, addr, SEEK_SET))
{
printf("%s fseek 0x08x error%", file1, addr);
exit(-1);
}
if(0 != fseek(fd2, addr, SEEK_SET))
{
printf("%s fseek 0x08x error%", file2, addr);
exit(-1);
}
while(!loopflag)
{
memset(buf1, 0, 128);
memset(buf2, 0, 128);
len1 = fread(buf1, 1, ONCE_SIZE, fd1);
len2 = fread(buf2, 1, ONCE_SIZE, fd2);
if(len1 < ONCE_SIZE || len2 < ONCE_SIZE)
loopflag = FILE_END;
if(len2 > len1)
loopflag = FILE1_END;
if(len2 < len1)
loopflag = FILE2_END;
if(memcmp(buf1, buf2, ONCE_SIZE))
{
print_data(addr, buf1, buf2);
}
else
{
printf("0x%08x same\n", addr);
}
switch(loopflag)
{
case FILE1_END:
printf("file %s is shorter than %s\n", file1, file2);
break;
case FILE2_END:
printf("file %s is larger than %s\n", file1, file2);
break;
case FILE_END:
printf("file %s same size with %s\n", file1, file2);
break;
}
addr += ONCE_SIZE;
if(cmp_lenght > 0)
{
if(addr > (start_addr + cmp_lenght))
break;
}
}
fclose(fd1);
fclose(fd2);
}
int main(int argc, char *argv[])
{
if(argc < 3)
{
usage(argv[0]);
exit(-1);
}
if(argc > 3)
{
print_len = atoi(argv[3]);
if(print_len != TYPE_8 && print_len != TYPE_16 && print_len != TYPE_32)
{
printf("type error\n");
exit(-1);
}
}
if(argc > 5)
{
start_addr = strtoul(argv[4], NULL, 0);
cmp_lenght = strtoul(argv[5], NULL, 0);
}
file_compare(argv[1], argv[2]);
return 0;
}
| 17.553571 | 74 | 0.540692 |
dfbbb3e07acf60743c0de94191bb1d2a6b165624 | 728 | h | C | mcu/imx7/src/app_ecspi.h | binp-automation/psc | 8884bc10b6ff6ed2f7b8f0ef16c14309dc8f0b85 | [
"MIT"
] | null | null | null | mcu/imx7/src/app_ecspi.h | binp-automation/psc | 8884bc10b6ff6ed2f7b8f0ef16c14309dc8f0b85 | [
"MIT"
] | null | null | null | mcu/imx7/src/app_ecspi.h | binp-automation/psc | 8884bc10b6ff6ed2f7b8f0ef16c14309dc8f0b85 | [
"MIT"
] | null | null | null | #pragma once
#include <stdint.h>
void APP_ECSPI_HardwareInit();
/*!
* @brief Configure SPI subsystem.
*
* @param baud_rate SPI baudrate.
* @return Status, 0 - success, 1 - timed out.
*/
uint8_t APP_ECSPI_Init(uint32_t baud_rate);
/*!
* @brief Transfer data over SPI synchronously.
*
* @param txBuffer Data to transmit.
* @param rxBuffer Where data to be placed when received.
* @param transferSize Time to wait for send to complete in milliseconds, 0 to wait forever.
* @param timeout Time to wait for send to complete in milliseconds, 0 to wait forever.
* @return Operation status, zero on success.
*/
uint8_t APP_ECSPI_Transfer(uint8_t* txBuffer, uint8_t* rxBuffer, uint32_t transferSize, uint32_t timeout);
| 28 | 106 | 0.740385 |
248f7e441ad4fbfb2210c68d4511de28ff8bcd2f | 595 | h | C | log.h | slowforce/jsmnexample | d96acbb2e2962e01027be75db98363624fc44648 | [
"MIT"
] | 64 | 2015-02-05T20:29:26.000Z | 2021-12-06T04:38:08.000Z | log.h | slowforce/jsmnexample | d96acbb2e2962e01027be75db98363624fc44648 | [
"MIT"
] | 5 | 2015-06-13T08:57:13.000Z | 2019-01-15T09:01:13.000Z | log.h | slowforce/jsmnexample | d96acbb2e2962e01027be75db98363624fc44648 | [
"MIT"
] | 27 | 2015-01-18T15:12:35.000Z | 2022-01-06T03:32:33.000Z | #pragma once
#include <string.h>
#include <errno.h>
#define STR(x) #x
#define STRINGIFY(x) STR(x)
#define LINESTR STRINGIFY(__LINE__)
#define log_assert(x) if (!(x)) log_die("%s: assertion failed: " #x \
" (" __FILE__ ", line " LINESTR \
")", __func__)
#define log_null(x) log_assert(x != NULL)
#define log_debug(msg, ...) log_info("%s: " msg, __func__, ##__VA_ARGS__)
#define log_syserr(msg) log_die("%s: %s: %s", __func__, msg, strerror(errno))
void log_die(char *msg, ...);
void log_info(char *msg, ...);
| 27.045455 | 77 | 0.568067 |
a41b20644f85bc3a5f4540b7e9ae12e56bc042f1 | 1,057 | h | C | main/DS3231.h | Kartikkman/WatchDog | 59f1e62572197a05486f6e9bd3dd5554a55b03c8 | [
"Apache-2.0"
] | 1 | 2020-04-11T09:55:49.000Z | 2020-04-11T09:55:49.000Z | main/DS3231.h | Kartikkman/WatchDog | 59f1e62572197a05486f6e9bd3dd5554a55b03c8 | [
"Apache-2.0"
] | 1 | 2018-04-28T10:40:45.000Z | 2018-04-28T10:40:45.000Z | main/DS3231.h | Kartikkman/WatchDog | 59f1e62572197a05486f6e9bd3dd5554a55b03c8 | [
"Apache-2.0"
] | null | null | null |
#ifndef __DS3231_H__
#define __DS3231_H__
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <stdio.h>
#include "esp_log.h"
#include"driver/uart.h"
#include"esp_err.h"
#include"string.h"
#include"driver/i2c.h"
#define SLAVE_ADDR 104 // Address of DS3231 ( Real Time Clock )
char * bcd_char(uint8_t *arr,int length_arr); // Function which converts the BCD no into the Character Array ( Used after receiving Time from RTC -- For Example : BCD NO : 2,3 to ASCII Code of '2','3')
uint8_t *convert_bcd(uint8_t *arr); // Function which converts the BCD no into Integer ( For Example : BCD NO : 2,3 to 23 )
char * DS3231_get_time(); // Function which obtains the time from DS3231 ( Calls the raw I2C functions & receives the Data )
void DS3231_update_time(uint8_t *addr_register_write,uint8_t *data_register_write); // Function to Update the Time stores inside the RTC ( DS3231 ) ( Calls the raw I2C functions & sends the Data which needs to be written )
#endif | 44.041667 | 223 | 0.690634 |
a49136e29f66c799b876140f5be2de9aac5ca12d | 712 | h | C | lab_07_01/inc/io.h | Untouchabl3Pineapple/iu7-c | c1d47eab5cf3c816aa3aaa1c3d4d9a042b1747fa | [
"MIT"
] | 2 | 2021-01-10T00:44:16.000Z | 2022-03-10T16:59:27.000Z | lab_07_01/inc/io.h | Untouchabl3Pineapple/iu7-c | c1d47eab5cf3c816aa3aaa1c3d4d9a042b1747fa | [
"MIT"
] | null | null | null | lab_07_01/inc/io.h | Untouchabl3Pineapple/iu7-c | c1d47eab5cf3c816aa3aaa1c3d4d9a042b1747fa | [
"MIT"
] | 1 | 2021-09-03T17:01:47.000Z | 2021-09-03T17:01:47.000Z | #ifndef IO_H
#define IO_H
#include "../inc/macrologger.h"
#include <stdio.h>
#define OK 0
#define ARGS_ERROR 1
#define FILE_OPEN_ERROR 2
#define INPUT_FILE_NAME_SIZE 20
#define OUTPUT_FILE_NAME_SIZE 20
#define FILTR_SIZE 20
#define ARGS_LOWER_LIMIT 3
#define ARGS_UPPER_LIMIT 4
int parse_args(const int agrc, const char **argv, int *const args_number, \
char *const in_file_name, char *const out_file_name, char *const filtr);
int scan_file_len(FILE *const f, int *const file_len);
void fill_array(FILE *const f, int *const array);
//void print_array(const int *pb_filtr_array, const int *pe_filtr_array);
void fill_file(FILE *const f, const int *pb_filtr_array, const int *pe_filtr_array);
#endif // IO_H
| 27.384615 | 84 | 0.775281 |
cc7fc7da82b98fb3dd29deebcc102bab7c122454 | 141 | c | C | test/u_read.c | rdentato/umf | 5246d80ee2754380635167205f5e9999a1e27702 | [
"MIT"
] | null | null | null | test/u_read.c | rdentato/umf | 5246d80ee2754380635167205f5e9999a1e27702 | [
"MIT"
] | null | null | null | test/u_read.c | rdentato/umf | 5246d80ee2754380635167205f5e9999a1e27702 | [
"MIT"
] | null | null | null |
#include "umf.h"
int main(int argc, char *argv[])
{
if (argc > 1) {
mf_read(argv[1],NULL,NULL,NULL,NULL,NULL);
}
return 0;
}
| 9.4 | 46 | 0.560284 |
015bb8e9161060ef6a6bbcd29f939f01041eff72 | 247 | h | C | src/color.h | matheusmv/snake-game | 5edc7bcd933e1029c5b00f50693b0de8c7156462 | [
"MIT"
] | null | null | null | src/color.h | matheusmv/snake-game | 5edc7bcd933e1029c5b00f50693b0de8c7156462 | [
"MIT"
] | null | null | null | src/color.h | matheusmv/snake-game | 5edc7bcd933e1029c5b00f50693b0de8c7156462 | [
"MIT"
] | null | null | null | #ifndef _COLOR_H
#define _COLOR_H
#include "common_libs.h"
typedef enum color { GRAY, GREEN, BLACK, RED } Color;
typedef struct colorRGBA {
Color code;
uint8_t R, G, B, A;
} ColorRGBA;
ColorRGBA get_color(Color color);
#endif
| 15.4375 | 53 | 0.684211 |
6211072988f8cd0d0b47d4015cb39fa0df74ff4c | 2,050 | c | C | server/src/interact.c | TaylorP/Raspboot | 75be279343de301c239a6425ca377157c3aa31e6 | [
"MIT"
] | 7 | 2017-06-28T15:05:54.000Z | 2020-11-26T19:55:53.000Z | server/src/interact.c | TaylorP/Raspboot | 75be279343de301c239a6425ca377157c3aa31e6 | [
"MIT"
] | null | null | null | server/src/interact.c | TaylorP/Raspboot | 75be279343de301c239a6425ca377157c3aa31e6 | [
"MIT"
] | null | null | null | #include <common/command.h>
#include <common/mode.h>
#include "interact.h"
#include "uart.h"
S32 raspbootInteractMode(U32* address, U32* mode)
{
U8 input = raspbootUartGet();
if (input == MODE_INTERACT)
{
return PROCESS_INTERACT_SUCCESS;
}
else if (input == MODE_TRANSFER)
{
*mode = input;
return PROCESS_INTERACT_SUCCESS;
}
else if (input == MODE_ABORT)
{
*mode = input;
return PROCESS_INTERACT_ERROR;
}
if (input == COMMAND_INTERACT_GO)
{
U32 addr = 0;
U32 i;
for (i = 0; i < 4; i++)
{
addr = addr << 8;
addr |= raspbootUartGet();
}
*address = addr;
return PROCESS_INTERACT_EXECUTE;
}
else if (input == COMMAND_INTERACT_GET)
{
U8 count = raspbootUartGet();
U32 addr = 0;
U32 i;
for (i = 0; i < 4; i++)
{
addr = addr << 8;
addr |= raspbootUartGet();
}
U8* mem = (U8*)(addr);
for (i = 0; i < count; i++, mem++)
{
raspbootUartPut(*mem);
}
return PROCESS_INTERACT_SUCCESS;
}
else if (input == COMMAND_INTERACT_SET)
{
U32 addr = 0;
U32 value = raspbootUartGet();
U32 i;
for (i = 0; i < 4; i++)
{
addr = addr << 8;
addr |= raspbootUartGet();
}
U8* mem = (U8*)(addr);
*mem = value;
return PROCESS_INTERACT_SUCCESS;
}
else if (input == COMMAND_INTERACT_SET_W)
{
U32 addr = 0;
U32 value = 0;
U32 i;
for (i = 0; i < 4; i++)
{
value = value << 8;
value |= raspbootUartGet();
}
for (i = 0; i < 4; i++)
{
addr = addr << 8;
addr |= raspbootUartGet();
}
U32* mem = (U32*)(addr);
*mem = value;
return PROCESS_INTERACT_SUCCESS;
}
return PROCESS_INTERACT_ERROR;
} | 19.902913 | 49 | 0.462927 |
0639dd71496c362e3f85600c8c14403dde1aeb5b | 2,737 | c | C | public/freetds-1.00.23/src/odbc/unittests/connect2.c | thepriyakadam/hrms | af7f44ac10691850487e2c412a666694680a0672 | [
"Unlicense"
] | null | null | null | public/freetds-1.00.23/src/odbc/unittests/connect2.c | thepriyakadam/hrms | af7f44ac10691850487e2c412a666694680a0672 | [
"Unlicense"
] | null | null | null | public/freetds-1.00.23/src/odbc/unittests/connect2.c | thepriyakadam/hrms | af7f44ac10691850487e2c412a666694680a0672 | [
"Unlicense"
] | null | null | null | #include "common.h"
/*
* Test setting current "catalog" before and after connection using
* either SQLConnect and SQLDriverConnect
*/
static int failed = 0;
static void init_connect(void);
static void
init_connect(void)
{
CHKAllocEnv(&odbc_env, "S");
CHKAllocConnect(&odbc_conn, "S");
}
static void
normal_connect(void)
{
CHKConnect(T(odbc_server), SQL_NTS, T(odbc_user), SQL_NTS, T(odbc_password), SQL_NTS, "SI");
}
static void
driver_connect(const char *conn_str)
{
SQLTCHAR tmp[1024];
SQLSMALLINT len;
CHKDriverConnect(NULL, T(conn_str), SQL_NTS, tmp, ODBC_VECTOR_SIZE(tmp), &len, SQL_DRIVER_NOPROMPT, "SI");
}
static void
check_dbname(const char *dbname)
{
SQLINTEGER len;
SQLTCHAR out[512];
char sql[1024];
len = sizeof(out);
CHKGetConnectAttr(SQL_ATTR_CURRENT_CATALOG, (SQLPOINTER) out, sizeof(out), &len, "SI");
if (strcmp(C(out), dbname) != 0) {
fprintf(stderr, "Current database (%s) is not %s\n", C(out), dbname);
failed = 1;
}
sprintf(sql, "IF DB_NAME() <> '%s' SELECT 1", dbname);
CHKAllocStmt(&odbc_stmt, "S");
odbc_check_no_row(sql);
SQLFreeStmt(odbc_stmt, SQL_DROP);
odbc_stmt = SQL_NULL_HSTMT;
}
static void
set_dbname(const char *dbname)
{
CHKSetConnectAttr(SQL_ATTR_CURRENT_CATALOG, (SQLPOINTER) T(dbname), strlen(dbname)*sizeof(SQLTCHAR), "SI");
}
int
main(int argc, char *argv[])
{
char tmp[1024];
if (odbc_read_login_info())
exit(1);
/* try setting db name before connect */
printf("SQLConnect before 1..\n");
init_connect();
set_dbname("master");
normal_connect();
check_dbname("master");
/* check change after connection */
printf("SQLConnect after..\n");
set_dbname("tempdb");
check_dbname("tempdb");
printf("SQLConnect after not existing..\n");
strcpy(tmp, "IDontExist");
CHKSetConnectAttr(SQL_ATTR_CURRENT_CATALOG, (SQLPOINTER) tmp, strlen(tmp), "E");
check_dbname("tempdb");
odbc_disconnect();
/* try setting db name before connect */
printf("SQLConnect before 2..\n");
init_connect();
set_dbname("tempdb");
normal_connect();
check_dbname("tempdb");
odbc_disconnect();
/* try connect string with using DSN */
printf("SQLDriverConnect before 1..\n");
sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;DATABASE=%s;", odbc_server, odbc_user, odbc_password, odbc_database);
init_connect();
set_dbname("master");
driver_connect(tmp);
check_dbname(odbc_database);
odbc_disconnect();
/* try connect string with using DSN */
printf("SQLDriverConnect before 2..\n");
sprintf(tmp, "DSN=%s;UID=%s;PWD=%s;", odbc_server, odbc_user, odbc_password);
init_connect();
set_dbname("tempdb");
driver_connect(tmp);
check_dbname("tempdb");
odbc_disconnect();
if (failed) {
printf("Some tests failed\n");
return 1;
}
printf("Done.\n");
return 0;
}
| 22.252033 | 108 | 0.707709 |
94bf3759971bb1cdb5b236313232c2322e38436d | 2,695 | c | C | thermal_hal/thermal-8998.c | nojick/android_hardware_device_ido_treble | f8085a4e6b32a08b4df877c4008e3f47a2b6800b | [
"FTL"
] | 1 | 2022-02-21T18:40:49.000Z | 2022-02-21T18:40:49.000Z | thermal/thermal-8998.c | Aoihara/tree_xiaomi_land | 25aa757217d075bbeb7f45c42018cf38c4d41798 | [
"Apache-2.0"
] | null | null | null | thermal/thermal-8998.c | Aoihara/tree_xiaomi_land | 25aa757217d075bbeb7f45c42018cf38c4d41798 | [
"Apache-2.0"
] | null | null | null | /*
* Copyright (c) 2017-2018 The Linux Foundation. All rights reserved.
* Not a contribution
* Copyright (C) 2016 The Android Open Source Project
*
* 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.
*/
#define LOG_TAG "ThermalHAL-8998"
#include <utils/Log.h>
#include <hardware/hardware.h>
#include <hardware/thermal.h>
#include "thermal_common.h"
static char *cpu_sensors_8998[] =
{
"tsens_tz_sensor1",
"tsens_tz_sensor2",
"tsens_tz_sensor3",
"tsens_tz_sensor4",
"tsens_tz_sensor7",
"tsens_tz_sensor8",
"tsens_tz_sensor9",
"tsens_tz_sensor10",
};
static char *misc_sensors_8998[] =
{
"tsens_tz_sensor12",
"battery",
"quiet_therm"
};
static struct target_therm_cfg sensor_cfg_8998[] = {
{
.type = DEVICE_TEMPERATURE_CPU,
.sensor_list = cpu_sensors_8998,
.sens_cnt = ARRAY_SIZE(cpu_sensors_8998),
.mult = 0.1,
.throt_thresh = 60,
.shutdwn_thresh = 115,
},
{
.type = DEVICE_TEMPERATURE_GPU,
.sensor_list = &misc_sensors_8998[0],
.sens_cnt = 1,
.mult = 0.1,
.label = "GPU",
},
{
.type = DEVICE_TEMPERATURE_BATTERY,
.sensor_list = &misc_sensors_8998[1],
.sens_cnt = 1,
.mult = 0.001,
.shutdwn_thresh = 60,
.label = "battery",
},
{
.type = DEVICE_TEMPERATURE_SKIN,
.sensor_list = &misc_sensors_8998[2],
.sens_cnt = 1,
.mult = 1.0,
.throt_thresh = 44,
.shutdwn_thresh = 70,
.vr_thresh = 58,
.label = "skin",
}
};
ssize_t get_temperatures(thermal_module_t *module, temperature_t *list, size_t size) {
ALOGD("Entering %s",__func__);
static int thermal_sens_size;
if (!thermal_sens_size) {
thermal_sens_size = thermal_zone_init(sensor_cfg_8998,
ARRAY_SIZE(sensor_cfg_8998));
if (thermal_sens_size <= 0) {
ALOGE("thermal sensor initialization is failed\n");
thermal_sens_size = 0;
return 0;
}
}
if (list == NULL)
return thermal_sens_size;
return get_temperature_for_all(list, size);
}
| 26.683168 | 86 | 0.628571 |
9e90b4b81ef5c35b930f0e1569acba43ca43008c | 3,630 | h | C | src/include/foreign/foreign.h | bradfordb-vmware/gpdb | 5cc23bd1df4133aaa7a80174f5b0950933a83cc2 | [
"PostgreSQL",
"Apache-2.0"
] | 4 | 2017-11-28T08:12:58.000Z | 2020-10-28T04:15:52.000Z | src/include/foreign/foreign.h | bradfordb-vmware/gpdb | 5cc23bd1df4133aaa7a80174f5b0950933a83cc2 | [
"PostgreSQL",
"Apache-2.0"
] | 9 | 2016-06-08T05:36:15.000Z | 2016-06-24T04:30:10.000Z | src/include/foreign/foreign.h | bradfordb-vmware/gpdb | 5cc23bd1df4133aaa7a80174f5b0950933a83cc2 | [
"PostgreSQL",
"Apache-2.0"
] | 6 | 2018-11-16T23:50:54.000Z | 2021-11-08T02:13:41.000Z | /*-------------------------------------------------------------------------
*
* foreign.h
* support for foreign-data wrappers, servers and user mappings.
*
*
* Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
*
* src/include/foreign/foreign.h
*
*-------------------------------------------------------------------------
*/
#ifndef FOREIGN_H
#define FOREIGN_H
#include "nodes/parsenodes.h"
/* Helper for obtaining username for user mapping */
#define MappingUserName(userid) \
(OidIsValid(userid) ? GetUserNameFromId(userid, false) : "public")
/*
* Generic option types for validation.
* NB! These are treated as flags, so use only powers of two here.
*/
typedef enum
{
ServerOpt = 1, /* options applicable to SERVER */
UserMappingOpt = 2, /* options for USER MAPPING */
FdwOpt = 4 /* options for FOREIGN DATA WRAPPER */
} GenericOptionFlags;
typedef struct ForeignDataWrapper
{
Oid fdwid; /* FDW Oid */
Oid owner; /* FDW owner user Oid */
char *fdwname; /* Name of the FDW */
Oid fdwhandler; /* Oid of handler function, or 0 */
Oid fdwvalidator; /* Oid of validator function, or 0 */
List *options; /* fdwoptions as DefElem list */
char exec_location; /* execute on MASTER, ANY or ALL SEGMENTS, Greenplum MPP specific */
} ForeignDataWrapper;
typedef struct ForeignServer
{
Oid serverid; /* server Oid */
Oid fdwid; /* foreign-data wrapper */
Oid owner; /* server owner user Oid */
char *servername; /* name of the server */
char *servertype; /* server type, optional */
char *serverversion; /* server version, optional */
List *options; /* srvoptions as DefElem list */
char exec_location; /* execute on MASTER, ANY or ALL SEGMENTS, Greenplum MPP specific */
} ForeignServer;
typedef struct UserMapping
{
Oid umid; /* Oid of user mapping */
Oid userid; /* local user Oid */
Oid serverid; /* server Oid */
List *options; /* useoptions as DefElem list */
} UserMapping;
typedef struct ForeignTable
{
Oid relid; /* relation Oid */
Oid serverid; /* server Oid */
List *options; /* ftoptions as DefElem list */
char exec_location; /* execute on COORDINATOR, ANY or ALL SEGMENTS, Greenplum MPP specific */
} ForeignTable;
/* Flags for GetForeignServerExtended */
#define FSV_MISSING_OK 0x01
/* Flags for GetForeignDataWrapperExtended */
#define FDW_MISSING_OK 0x01
extern char SeparateOutMppExecute(List **options);
extern ForeignServer *GetForeignServer(Oid serverid);
extern ForeignServer *GetForeignServerExtended(Oid serverid,
bits16 flags);
extern ForeignServer *GetForeignServerByName(const char *name, bool missing_ok);
extern UserMapping *GetUserMapping(Oid userid, Oid serverid);
extern ForeignDataWrapper *GetForeignDataWrapper(Oid fdwid);
extern ForeignDataWrapper *GetForeignDataWrapperExtended(Oid fdwid,
bits16 flags);
extern ForeignDataWrapper *GetForeignDataWrapperByName(const char *name,
bool missing_ok);
extern ForeignTable *GetForeignTable(Oid relid);
extern bool rel_is_external_table(Oid relid);
extern List *GetForeignColumnOptions(Oid relid, AttrNumber attnum);
extern Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok);
extern Oid get_foreign_server_oid(const char *servername, bool missing_ok);
/* ----------------
* compiler constants for ForeignTable's exec_location
* ----------------
*/
#define FTEXECLOCATION_ANY 'a'
#define FTEXECLOCATION_COORDINATOR 'c'
#define FTEXECLOCATION_ALL_SEGMENTS 's'
#define FTEXECLOCATION_NOT_DEFINED 'n'
#endif /* FOREIGN_H */
| 32.702703 | 96 | 0.684573 |
962bb32caa83e7dfb4df799f966089fd958e334e | 3,586 | c | C | gnu-efi/lib/runtime/rtstr.c | mbearup/shim | c9d168f66b6a78a4423e7e0d39d92a3b99728940 | [
"BSD-2-Clause"
] | null | null | null | gnu-efi/lib/runtime/rtstr.c | mbearup/shim | c9d168f66b6a78a4423e7e0d39d92a3b99728940 | [
"BSD-2-Clause"
] | null | null | null | gnu-efi/lib/runtime/rtstr.c | mbearup/shim | c9d168f66b6a78a4423e7e0d39d92a3b99728940 | [
"BSD-2-Clause"
] | null | null | null | /*++
Copyright (c) 1998 Intel Corporation
Module Name:
str.c
Abstract:
String runtime functions
Revision History
--*/
#include "lib.h"
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrCmp)
#endif
INTN
RUNTIMEFUNCTION
RtStrCmp (
IN CONST CHAR16 *s1p,
IN CONST CHAR16 *s2p
)
// compare strings
{
CONST UINT16 *s1 = (CONST UINT16 *)s1p;
CONST UINT16 *s2 = (CONST UINT16 *)s2p;
while (*s1) {
if (*s1 != *s2) {
break;
}
s1 += 1;
s2 += 1;
}
return *s1 - *s2;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrCpy)
#endif
VOID
RUNTIMEFUNCTION
RtStrCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
)
// copy strings
{
while (*Src) {
*(Dest++) = *(Src++);
}
*Dest = 0;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrnCpy)
#endif
VOID
RUNTIMEFUNCTION
RtStrnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
// copy strings
{
UINTN Size = RtStrnLen(Src, Len);
if (Size != Len)
RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0');
RtCopyMem(Dest, Src, Size * sizeof(CHAR16));
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStpCpy)
#endif
CHAR16 *
RUNTIMEFUNCTION
RtStpCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
)
// copy strings
{
while (*Src) {
*(Dest++) = *(Src++);
}
*Dest = 0;
return Dest;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStpnCpy)
#endif
CHAR16 *
RUNTIMEFUNCTION
RtStpnCpy (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
// copy strings
{
UINTN Size = RtStrnLen(Src, Len);
if (Size != Len)
RtSetMem(Dest + Size, (Len - Size) * sizeof(CHAR16), '\0');
RtCopyMem(Dest, Src, Size * sizeof(CHAR16));
return Dest + Size;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrCat)
#endif
VOID
RUNTIMEFUNCTION
RtStrCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src
)
{
RtStrCpy(Dest+RtStrLen(Dest), Src);
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrnCat)
#endif
VOID
RUNTIMEFUNCTION
RtStrnCat (
IN CHAR16 *Dest,
IN CONST CHAR16 *Src,
IN UINTN Len
)
{
UINTN DestSize, Size;
DestSize = RtStrLen(Dest);
Size = RtStrnLen(Src, Len);
RtCopyMem(Dest + DestSize, Src, Size * sizeof(CHAR16));
Dest[DestSize + Size] = '\0';
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrLen)
#endif
UINTN
RUNTIMEFUNCTION
RtStrLen (
IN CONST CHAR16 *s1
)
// string length
{
UINTN len;
for (len=0; *s1; s1+=1, len+=1) ;
return len;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrnLen)
#endif
UINTN
RUNTIMEFUNCTION
RtStrnLen (
IN CONST CHAR16 *s1,
IN UINTN Len
)
// string length
{
UINTN i;
for (i = 0; *s1 && i < Len; i++)
s1++;
return i;
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtStrSize)
#endif
UINTN
RUNTIMEFUNCTION
RtStrSize (
IN CONST CHAR16 *s1
)
// string size
{
UINTN len;
for (len=0; *s1; s1+=1, len+=1) ;
return (len + 1) * sizeof(CHAR16);
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtBCDtoDecimal)
#endif
UINT8
RUNTIMEFUNCTION
RtBCDtoDecimal(
IN UINT8 BcdValue
)
{
UINTN High, Low;
High = BcdValue >> 4;
Low = BcdValue - (High << 4);
return ((UINT8)(Low + (High * 10)));
}
#ifndef __GNUC__
#pragma RUNTIME_CODE(RtDecimaltoBCD)
#endif
UINT8
RUNTIMEFUNCTION
RtDecimaltoBCD (
IN UINT8 DecValue
)
{
UINTN High, Low;
High = DecValue / 10;
Low = DecValue - (High * 10);
return ((UINT8)(Low + (High << 4)));
}
| 15.259574 | 67 | 0.595929 |
961226a51ef9757a4933d4bda83389b2cae0dc21 | 6,904 | c | C | src/dwarf/Gfind_unwind_table.c | MeetLima/libunwind | 22b6a6fae1946926540d013a01f8a1e10ba5b735 | [
"MIT"
] | 1 | 2020-07-01T07:08:49.000Z | 2020-07-01T07:08:49.000Z | src/dwarf/Gfind_unwind_table.c | MeetLima/libunwind | 22b6a6fae1946926540d013a01f8a1e10ba5b735 | [
"MIT"
] | null | null | null | src/dwarf/Gfind_unwind_table.c | MeetLima/libunwind | 22b6a6fae1946926540d013a01f8a1e10ba5b735 | [
"MIT"
] | 1 | 2020-07-02T11:50:44.000Z | 2020-07-02T11:50:44.000Z | /* libunwind - a platform-independent unwind library
Copyright (C) 2003-2004 Hewlett-Packard Co
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
This file is part of libunwind.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <elf.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include "libunwind_i.h"
#include "dwarf-eh.h"
#include "dwarf_i.h"
int
dwarf_find_unwind_table (struct elf_dyn_info *edi, unw_addr_space_t as,
char *path, unw_word_t segbase, unw_word_t mapoff,
unw_word_t ip)
{
Elf_W(Phdr) *phdr, *ptxt = NULL, *peh_hdr = NULL, *pdyn = NULL;
unw_word_t addr, eh_frame_start, fde_count, load_base;
unw_word_t max_load_addr = 0;
unw_word_t start_ip = (unw_word_t) -1;
unw_word_t end_ip = 0;
struct dwarf_eh_frame_hdr *hdr;
unw_proc_info_t pi;
unw_accessors_t *a;
Elf_W(Ehdr) *ehdr;
#if UNW_TARGET_ARM
const Elf_W(Phdr) *parm_exidx = NULL;
#endif
int i, ret, found = 0;
/* XXX: Much of this code is Linux/LSB-specific. */
if (!elf_w(valid_object) (&edi->ei))
return -UNW_ENOINFO;
ehdr = edi->ei.image;
phdr = (Elf_W(Phdr) *) ((char *) edi->ei.image + ehdr->e_phoff);
for (i = 0; i < ehdr->e_phnum; ++i)
{
switch (phdr[i].p_type)
{
case PT_LOAD:
if (phdr[i].p_vaddr < start_ip)
start_ip = phdr[i].p_vaddr;
if (phdr[i].p_vaddr + phdr[i].p_memsz > end_ip)
end_ip = phdr[i].p_vaddr + phdr[i].p_memsz;
if (phdr[i].p_offset == mapoff)
ptxt = phdr + i;
if ((uintptr_t) edi->ei.image + phdr->p_filesz > max_load_addr)
max_load_addr = (uintptr_t) edi->ei.image + phdr->p_filesz;
break;
case PT_GNU_EH_FRAME:
peh_hdr = phdr + i;
break;
case PT_DYNAMIC:
pdyn = phdr + i;
break;
#if UNW_TARGET_ARM
case PT_ARM_EXIDX:
parm_exidx = phdr + i;
break;
#endif
default:
break;
}
}
if (!ptxt)
return 0;
load_base = segbase - ptxt->p_vaddr;
start_ip += load_base;
end_ip += load_base;
if (peh_hdr)
{
if (pdyn)
{
/* For dynamicly linked executables and shared libraries,
DT_PLTGOT is the value that data-relative addresses are
relative to for that object. We call this the "gp". */
Elf_W(Dyn) *dyn = (Elf_W(Dyn) *)(pdyn->p_offset
+ (char *) edi->ei.image);
for (; dyn->d_tag != DT_NULL; ++dyn)
if (dyn->d_tag == DT_PLTGOT)
{
/* Assume that _DYNAMIC is writable and GLIBC has
relocated it (true for x86 at least). */
edi->di_cache.gp = dyn->d_un.d_ptr;
break;
}
}
else
/* Otherwise this is a static executable with no _DYNAMIC. Assume
that data-relative addresses are relative to 0, i.e.,
absolute. */
edi->di_cache.gp = 0;
hdr = (struct dwarf_eh_frame_hdr *) (peh_hdr->p_offset
+ (char *) edi->ei.image);
if (hdr->version != DW_EH_VERSION)
{
Debug (1, "table `%s' has unexpected version %d\n",
path, hdr->version);
return -UNW_ENOINFO;
}
a = unw_get_accessors (unw_local_addr_space);
addr = (unw_word_t) (hdr + 1);
/* Fill in a dummy proc_info structure. We just need to fill in
enough to ensure that dwarf_read_encoded_pointer() can do it's
job. Since we don't have a procedure-context at this point, all
we have to do is fill in the global-pointer. */
memset (&pi, 0, sizeof (pi));
pi.gp = edi->di_cache.gp;
/* (Optionally) read eh_frame_ptr: */
if ((ret = dwarf_read_encoded_pointer (unw_local_addr_space, a,
&addr, hdr->eh_frame_ptr_enc, &pi,
&eh_frame_start, NULL)) < 0)
return -UNW_ENOINFO;
/* (Optionally) read fde_count: */
if ((ret = dwarf_read_encoded_pointer (unw_local_addr_space, a,
&addr, hdr->fde_count_enc, &pi,
&fde_count, NULL)) < 0)
return -UNW_ENOINFO;
if (hdr->table_enc != (DW_EH_PE_datarel | DW_EH_PE_sdata4))
{
#if 1
abort ();
#else
unw_word_t eh_frame_end;
/* If there is no search table or it has an unsupported
encoding, fall back on linear search. */
if (hdr->table_enc == DW_EH_PE_omit)
Debug (4, "EH lacks search table; doing linear search\n");
else
Debug (4, "EH table has encoding 0x%x; doing linear search\n",
hdr->table_enc);
eh_frame_end = max_load_addr; /* XXX can we do better? */
if (hdr->fde_count_enc == DW_EH_PE_omit)
fde_count = ~0UL;
if (hdr->eh_frame_ptr_enc == DW_EH_PE_omit)
abort ();
return linear_search (unw_local_addr_space, ip,
eh_frame_start, eh_frame_end, fde_count,
pi, need_unwind_info, NULL);
#endif
}
edi->di_cache.start_ip = start_ip;
edi->di_cache.end_ip = end_ip;
edi->di_cache.format = UNW_INFO_FORMAT_REMOTE_TABLE;
edi->di_cache.u.rti.name_ptr = 0;
/* two 32-bit values (ip_offset/fde_offset) per table-entry: */
edi->di_cache.u.rti.table_len = (fde_count * 8) / sizeof (unw_word_t);
edi->di_cache.u.rti.table_data = ((load_base + peh_hdr->p_vaddr)
+ (addr - (unw_word_t) edi->ei.image
- peh_hdr->p_offset));
/* For the binary-search table in the eh_frame_hdr, data-relative
means relative to the start of that section... */
edi->di_cache.u.rti.segbase = ((load_base + peh_hdr->p_vaddr)
+ ((unw_word_t) hdr - (unw_word_t) edi->ei.image
- peh_hdr->p_offset));
found = 1;
}
#if UNW_TARGET_ARM
if (parm_exidx)
{
edi->di_arm.format = UNW_INFO_FORMAT_ARM_EXIDX;
edi->di_arm.start_ip = start_ip;
edi->di_arm.end_ip = end_ip;
edi->di_arm.u.rti.name_ptr = (unw_word_t) path;
edi->di_arm.u.rti.table_data = load_base + parm_exidx->p_vaddr;
edi->di_arm.u.rti.table_len = parm_exidx->p_memsz;
found = 1;
}
#endif
#ifdef CONFIG_DEBUG_FRAME
/* Try .debug_frame. */
found = dwarf_find_debug_frame (found, &edi->di_debug, ip, load_base, path,
start_ip, end_ip);
#endif
return found;
}
| 30.148472 | 77 | 0.667439 |
cf2d243c5463512872f803d176ead8b3e5a2d05c | 181 | h | C | src/camlsnark_c/libsnark-caml/depends/libsnark-supercop/include/randombytes.h | Pratyush/snarky | 4776e98ba72d4c8706c689fd747462ef87db8799 | [
"MIT"
] | 34 | 2019-07-03T23:26:39.000Z | 2020-08-01T21:05:56.000Z | src/camlsnark_c/libsnark-caml/depends/libsnark-supercop/include/randombytes.h | Pratyush/snarky | 4776e98ba72d4c8706c689fd747462ef87db8799 | [
"MIT"
] | null | null | null | src/camlsnark_c/libsnark-caml/depends/libsnark-supercop/include/randombytes.h | Pratyush/snarky | 4776e98ba72d4c8706c689fd747462ef87db8799 | [
"MIT"
] | 16 | 2019-07-03T23:32:30.000Z | 2020-05-14T10:17:11.000Z | #ifndef randombytes_h
#define randombytes_h
#ifdef __cplusplus
extern "C" {
#endif
extern void randombytes(unsigned char *,unsigned long long);
#ifdef __cplusplus
}
#endif
#endif
| 13.923077 | 60 | 0.779006 |
a910380a9e11dae6214a388e6948065905f898e2 | 2,965 | c | C | client/src/logic/login_window/mx_signin_handler.c | NadinOk/chat | 64c8408725bd2533c99770cfeec211c605c4ab62 | [
"MIT"
] | null | null | null | client/src/logic/login_window/mx_signin_handler.c | NadinOk/chat | 64c8408725bd2533c99770cfeec211c605c4ab62 | [
"MIT"
] | null | null | null | client/src/logic/login_window/mx_signin_handler.c | NadinOk/chat | 64c8408725bd2533c99770cfeec211c605c4ab62 | [
"MIT"
] | null | null | null | //
// Created by Karina Barinova on 12.11.2020.
//
#include <client.h>
#define GET (void *)-1
t_info *signin_info(t_info *in) {
static t_info *info = 0;
if (info == 0)
info = mx_info_new();
if (in == GET)
return info;
info = in;
return info;
}
static bool mx_check_valid(char *login, char *password) {
if (login[0] == '\0' || password[0] == '\0')
return false;
return true;
}
static void mx_do_login(t_info *info) {
info = signin_info(GET);
const char *login = gtk_entry_get_text(
GTK_ENTRY(info->widgets->s_signin->username_entry));
const char *password = gtk_entry_get_text(
GTK_ENTRY(info->widgets->s_signin->password_entry));
if (mx_check_valid((char *)login, (char *)password)) {
info->user_info->login = (char *)login;
info->user_info->password = (char *)password;
info->token = mx_run_login(&info->user_info->user_id,
info->user_info->login, info->user_info->password, info->ip, info->port);
if (info->token) {
info->user_info->logged = true;
gtk_main_quit();
}
}
if (!login || !*login) {
gtk_widget_grab_focus(info->widgets->s_signin->username_entry);
gtk_label_set_text(GTK_LABEL(info->widgets->s_signin->status_label),
"Invalid login");
gtk_widget_set_name(info->widgets->s_signin->status_label,
"status_label");
return;
}
else if (!password || !*password) {
gtk_widget_grab_focus(info->widgets->s_signin->password_entry);
gtk_label_set_text(GTK_LABEL(info->widgets->s_signin->status_label),
"Invalid password");
gtk_widget_set_name(info->widgets->s_signin->status_label,
"status_label");
return;
}
else if (!info->token){
gtk_widget_grab_focus(info->widgets->s_signin->username_entry);
gtk_label_set_text(GTK_LABEL(info->widgets->s_signin->status_label),
"Invalid login or password");
gtk_widget_set_name(info->widgets->s_signin->status_label,
"status_label");
return;
}
}
static void mx_go_register(t_info *info) {
info = signin_info(GET);
info->user_info->regist = true;
mx_register_clear_input(info->widgets->s_register);
mx_change_window(info, MX_REGISTER_WINDOW);
info->user_info->regist = false;
}
void mx_signin_handler(t_info *info) {
signin_info(info);
t_signin *window = info->widgets->s_signin;
g_signal_connect(GTK_WIDGET(window->login_window), "destroy",
(GCallback)gtk_main_quit, NULL);
g_signal_connect(GTK_WIDGET(window->login_button), "clicked",
(GCallback)mx_do_login, info);
g_signal_connect(GTK_WIDGET(window->register_button), "clicked",
(GCallback)mx_go_register, info);
}
| 33.693182 | 82 | 0.61113 |
34404b25b3abf23faf4d559ebb84adac08d97290 | 63,980 | c | C | snapgear_linux/user/ntp/ntpq/ntpq.c | impedimentToProgress/UCI-BlueChip | 53e5d48b79079eaf60d42f7cb65bb795743d19fc | [
"MIT"
] | null | null | null | snapgear_linux/user/ntp/ntpq/ntpq.c | impedimentToProgress/UCI-BlueChip | 53e5d48b79079eaf60d42f7cb65bb795743d19fc | [
"MIT"
] | null | null | null | snapgear_linux/user/ntp/ntpq/ntpq.c | impedimentToProgress/UCI-BlueChip | 53e5d48b79079eaf60d42f7cb65bb795743d19fc | [
"MIT"
] | 3 | 2016-06-13T13:20:56.000Z | 2019-12-05T02:31:23.000Z | /*
* ntpq - query an NTP server using mode 6 commands
*/
#include <stdio.h>
#include "ntpq.h"
#include "ntp_unixtime.h"
#include "ntp_calendar.h"
#include "ntp_io.h"
#include "ntp_select.h"
#include "ntp_stdlib.h"
#include <ctype.h>
#include <signal.h>
#include <setjmp.h>
#include <netdb.h>
#ifdef SYS_WINNT
# include <io.h>
#else
#define closesocket close
#endif /* SYS_WINNT */
#ifdef HAVE_LIBREADLINE
# include <readline/readline.h>
# include <readline/history.h>
#endif /* HAVE_LIBREADLINE */
#ifdef SYS_VXWORKS
/* vxWorks needs mode flag -casey*/
#define open(name, flags) open(name, flags, 0777)
#define SERVER_PORT_NUM 123
#endif
/*
* Because we potentially understand a lot of commands we will run
* interactive if connected to a terminal.
*/
int interactive = 0; /* set to 1 when we should prompt */
const char *prompt = "ntpq> "; /* prompt to ask him about */
/*
* Keyid used for authenticated requests. Obtained on the fly.
*/
u_long info_auth_keyid = NTP_MAXKEY;
/*
* Type of key md5 or des
*/
#define KEY_TYPE_DES 3
#define KEY_TYPE_MD5 4
static int info_auth_keytype = KEY_TYPE_MD5; /* MD5 */
u_long current_time; /* needed by authkeys; not used */
/*
* Flag which indicates we should always send authenticated requests
*/
int always_auth = 0;
/*
* Flag which indicates raw mode output.
*/
int rawmode = 0;
/*
* Packet version number we use
*/
u_char pktversion = NTP_OLDVERSION + 1;
/*
* Don't jump if no set jmp.
*/
volatile int jump = 0;
/*
* Format values
*/
#define PADDING 0
#define TS 1 /* time stamp */
#define FL 2 /* l_fp type value */
#define FU 3 /* u_fp type value */
#define FS 4 /* s_fp type value */
#define UI 5 /* unsigned integer value */
#define SI 6 /* signed integer value */
#define HA 7 /* host address */
#define NA 8 /* network address */
#define ST 9 /* string value */
#define RF 10 /* refid (sometimes string, sometimes not) */
#define LP 11 /* leap (print in binary) */
#define OC 12 /* integer, print in octal */
#define MD 13 /* mode */
#define AR 14 /* array of times */
#define FX 15 /* test flags */
#define EOV 255 /* end of table */
/*
* System variable values. The array can be indexed by
* the variable index to find the textual name.
*/
struct ctl_var sys_var[] = {
{ 0, PADDING, "" }, /* 0 */
{ CS_LEAP, LP, "leap" }, /* 1 */
{ CS_STRATUM, UI, "stratum" }, /* 2 */
{ CS_PRECISION, SI, "precision" }, /* 3 */
{ CS_ROOTDELAY, FS, "rootdelay" }, /* 4 */
{ CS_ROOTDISPERSION, FU, "rootdispersion" }, /* 5 */
{ CS_REFID, RF, "refid" }, /* 6 */
{ CS_REFTIME, TS, "reftime" }, /* 7 */
{ CS_POLL, UI, "poll" }, /* 8 */
{ CS_PEERID, UI, "peer" }, /* 9 */
{ CS_STATE, UI, "state" }, /* 10 */
{ CS_OFFSET, FL, "offset" }, /* 11 */
{ CS_DRIFT, FS, "frequency" }, /* 12 */
{ CS_JITTER, FU, "jitter" }, /* 13 */
{ CS_CLOCK, TS, "clock" }, /* 14 */
{ CS_PROCESSOR, ST, "processor" }, /* 15 */
{ CS_SYSTEM, ST, "system" }, /* 16 */
{ CS_VERSION, ST, "version" }, /* 17 */
{ CS_STABIL, FS, "stability" }, /* 18 */
{ CS_VARLIST, ST, "sys_var_list" }, /* 19 */
{ 0, EOV, "" }
};
/*
* Peer variable list
*/
struct ctl_var peer_var[] = {
{ 0, PADDING, "" }, /* 0 */
{ CP_CONFIG, UI, "config" }, /* 1 */
{ CP_AUTHENABLE, UI, "authenable" }, /* 2 */
{ CP_AUTHENTIC, UI, "authentic" }, /* 3 */
{ CP_SRCADR, HA, "srcadr" }, /* 4 */
{ CP_SRCPORT, UI, "srcport" }, /* 5 */
{ CP_DSTADR, NA, "dstadr" }, /* 6 */
{ CP_DSTPORT, UI, "dstport" }, /* 7 */
{ CP_LEAP, LP, "leap" }, /* 8 */
{ CP_HMODE, MD, "hmode" }, /* 9 */
{ CP_STRATUM, UI, "stratum" }, /* 10 */
{ CP_PPOLL, UI, "ppoll" }, /* 11 */
{ CP_HPOLL, UI, "hpoll" }, /* 12 */
{ CP_PRECISION, SI, "precision" }, /* 13 */
{ CP_ROOTDELAY, FS, "rootdelay" }, /* 14 */
{ CP_ROOTDISPERSION, FU, "rootdispersion" }, /* 15 */
{ CP_REFID, RF, "refid" }, /* 16 */
{ CP_REFTIME, TS, "reftime" }, /* 17 */
{ CP_ORG, TS, "org" }, /* 18 */
{ CP_REC, TS, "rec" }, /* 19 */
{ CP_XMT, TS, "xmt" }, /* 20 */
{ CP_REACH, OC, "reach" }, /* 21 */
{ CP_VALID, UI, "valid" }, /* 22 */
{ CP_TIMER, UI, "timer" }, /* 23 */
{ CP_DELAY, FS, "delay" }, /* 24 */
{ CP_OFFSET, FL, "offset" }, /* 25 */
{ CP_JITTER, FU, "jitter" }, /* 26 */
{ CP_DISPERSION, FU, "dispersion" }, /* 27 */
{ CP_KEYID, UI, "keyid" }, /* 28 */
{ CP_FILTDELAY, AR, "filtdelay" }, /* 29 */
{ CP_FILTOFFSET, AR, "filtoffset" }, /* 30 */
{ CP_PMODE, ST, "pmode" }, /* 31 */
{ CP_RECEIVED, UI, "received" }, /* 32 */
{ CP_SENT, UI, "sent" }, /* 33 */
{ CP_FILTERROR, AR, "filtdisp" }, /* 34 */
{ CP_FLASH, FX, "flash" }, /* 35 */
{ CP_TTL, UI, "ttl" }, /* 36 */
{ CP_TTLMAX, UI, "ttlmax" }, /* 37 */
/*
* These are duplicate entries so that we can
* process deviant version of the ntp protocol.
*/
{ CP_SRCADR, HA, "peeraddr" }, /* 4 */
{ CP_SRCPORT, UI, "peerport" }, /* 5 */
{ CP_PPOLL, UI, "peerpoll" }, /* 11 */
{ CP_HPOLL, UI, "hostpoll" }, /* 12 */
{ CP_FILTERROR, AR, "filterror" }, /* 34 */
{ 0, EOV, "" }
};
/*
* Clock variable list
*/
struct ctl_var clock_var[] = {
{ 0, PADDING, "" }, /* 0 */
{ CC_TYPE, UI, "type" }, /* 1 */
{ CC_TIMECODE, ST, "timecode" }, /* 2 */
{ CC_POLL, UI, "poll" }, /* 3 */
{ CC_NOREPLY, UI, "noreply" }, /* 4 */
{ CC_BADFORMAT, UI, "badformat" }, /* 5 */
{ CC_BADDATA, UI, "baddata" }, /* 6 */
{ CC_FUDGETIME1, FL, "fudgetime1" }, /* 7 */
{ CC_FUDGETIME2, FL, "fudgetime2" }, /* 8 */
{ CC_FUDGEVAL1, UI, "stratum" }, /* 9 */
{ CC_FUDGEVAL2, RF, "refid" }, /* 10 */
{ CC_FLAGS, UI, "flags" }, /* 11 */
{ CC_DEVICE, ST, "device" }, /* 12 */
{ 0, EOV, "" }
};
/*
* flasher bits
*/
static const char *tstflagnames[] = {
"dup_pkt", /* TEST1 */
"bogus_pkt", /* TEST2 */
"proto_unsync", /* TEST3 */
"no_access", /* TEST4 */
"bad_auth", /* TEST5 */
"peer_unsync", /* TEST6 */
"peer_stratum", /* TEST7 */
"root_bounds", /* TEST8 */
"peer_bounds", /* TEST9 */
"bad_autokey", /* TEST10 */
"not_proventic" /* TEST11*/
};
int ntpqmain P((int, char **));
/*
* Built in command handler declarations
*/
static int openhost P((const char *));
static int sendpkt P((char *, int));
static int getresponse P((int, int, u_short *, int *, char **, int));
static int sendrequest P((int, int, int, int, char *));
static char * tstflags P((u_long));
static void getcmds P((void));
static RETSIGTYPE abortcmd P((int));
static void docmd P((const char *));
static void tokenize P((const char *, char **, int *));
static int findcmd P((char *, struct xcmd *, struct xcmd *, struct xcmd **));
static int getarg P((char *, int, arg_v *));
static int rtdatetolfp P((char *, l_fp *));
static int decodearr P((char *, int *, l_fp *));
static void help P((struct parse *, FILE *));
#ifdef QSORT_USES_VOID_P
static int helpsort P((const void *, const void *));
#else
static int helpsort P((char **, char **));
#endif
static void printusage P((struct xcmd *, FILE *));
static void timeout P((struct parse *, FILE *));
static void auth_delay P((struct parse *, FILE *));
static void host P((struct parse *, FILE *));
static void ntp_poll P((struct parse *, FILE *));
static void keyid P((struct parse *, FILE *));
static void keytype P((struct parse *, FILE *));
static void passwd P((struct parse *, FILE *));
static void hostnames P((struct parse *, FILE *));
static void setdebug P((struct parse *, FILE *));
static void quit P((struct parse *, FILE *));
static void version P((struct parse *, FILE *));
static void raw P((struct parse *, FILE *));
static void cooked P((struct parse *, FILE *));
static void authenticate P((struct parse *, FILE *));
static void ntpversion P((struct parse *, FILE *));
static void warning P((const char *, const char *, const char *));
static void error P((const char *, const char *, const char *));
static u_long getkeyid P((const char *));
static void atoascii P((int, char *, char *));
static void makeascii P((int, char *, FILE *));
static void rawprint P((int, int, char *, int, FILE *));
static void startoutput P((void));
static void output P((FILE *, char *, char *));
static void endoutput P((FILE *));
static void outputarr P((FILE *, char *, int, l_fp *));
static void cookedprint P((int, int, char *, int, FILE *));
#ifdef QSORT_USES_VOID_P
static int assoccmp P((const void *, const void *));
#else
static int assoccmp P((struct association *, struct association *));
#endif /* sgi || bsdi */
/*
* Built-in commands we understand
*/
struct xcmd builtins[] = {
{ "?", help, { OPT|STR, NO, NO, NO },
{ "command", "", "", "" },
"tell the use and syntax of commands" },
{ "help", help, { OPT|STR, NO, NO, NO },
{ "command", "", "", "" },
"tell the use and syntax of commands" },
{ "timeout", timeout, { OPT|UINT, NO, NO, NO },
{ "msec", "", "", "" },
"set the primary receive time out" },
{ "delay", auth_delay, { OPT|INT, NO, NO, NO },
{ "msec", "", "", "" },
"set the delay added to encryption time stamps" },
{ "host", host, { OPT|STR, NO, NO, NO },
{ "hostname", "", "", "" },
"specify the host whose NTP server we talk to" },
{ "poll", ntp_poll, { OPT|UINT, OPT|STR, NO, NO },
{ "n", "verbose", "", "" },
"poll an NTP server in client mode `n' times" },
{ "passwd", passwd, { NO, NO, NO, NO },
{ "", "", "", "" },
"specify a password to use for authenticated requests"},
{ "hostnames", hostnames, { OPT|STR, NO, NO, NO },
{ "yes|no", "", "", "" },
"specify whether hostnames or net numbers are printed"},
{ "debug", setdebug, { OPT|STR, NO, NO, NO },
{ "no|more|less", "", "", "" },
"set/change debugging level" },
{ "quit", quit, { NO, NO, NO, NO },
{ "", "", "", "" },
"exit ntpq" },
{ "exit", quit, { NO, NO, NO, NO },
{ "", "", "", "" },
"exit ntpq" },
{ "keyid", keyid, { OPT|UINT, NO, NO, NO },
{ "key#", "", "", "" },
"set keyid to use for authenticated requests" },
{ "version", version, { NO, NO, NO, NO },
{ "", "", "", "" },
"print version number" },
{ "raw", raw, { NO, NO, NO, NO },
{ "", "", "", "" },
"do raw mode variable output" },
{ "cooked", cooked, { NO, NO, NO, NO },
{ "", "", "", "" },
"do cooked mode variable output" },
{ "authenticate", authenticate, { OPT|STR, NO, NO, NO },
{ "yes|no", "", "", "" },
"always authenticate requests to this server" },
{ "ntpversion", ntpversion, { OPT|UINT, NO, NO, NO },
{ "version number", "", "", "" },
"set the NTP version number to use for requests" },
{ "keytype", keytype, { OPT|STR, NO, NO, NO },
{ "key type (md5|des)", "", "", "" },
"set key type to use for authenticated requests (des|md5)" },
{ 0, 0, { NO, NO, NO, NO },
{ "", "", "", "" }, "" }
};
/*
* Default values we use.
*/
#define DEFTIMEOUT (5) /* 5 second time out */
#define DEFSTIMEOUT (2) /* 2 second time out after first */
#define DEFDELAY 0x51EB852 /* 20 milliseconds, l_fp fraction */
#define DEFHOST "127.0.0.1" /* default host name */
#define LENHOSTNAME 256 /* host name is 256 characters long */
#define MAXCMDS 100 /* maximum commands on cmd line */
#define MAXHOSTS 200 /* maximum hosts on cmd line */
#define MAXLINE 512 /* maximum line length */
#define MAXTOKENS (1+MAXARGS+2) /* maximum number of usable tokens */
#define MAXVARLEN 256 /* maximum length of a variable name */
#define MAXVALLEN 400 /* maximum length of a variable value */
#define MAXOUTLINE 72 /* maximum length of an output line */
/*
* Some variables used and manipulated locally
*/
struct timeval tvout = { DEFTIMEOUT, 0 }; /* time out for reads */
struct timeval tvsout = { DEFSTIMEOUT, 0 }; /* secondary time out */
l_fp delay_time; /* delay time */
char currenthost[LENHOSTNAME]; /* current host name */
struct sockaddr_in hostaddr = { 0 }; /* host address */
int showhostnames = 1; /* show host names by default */
int sockfd; /* fd socket is opened on */
int havehost = 0; /* set to 1 when host open */
struct servent *server_entry = NULL; /* server entry for ntp */
#ifdef SYS_WINNT
WORD wVersionRequested;
WSADATA wsaData;
DWORD NumberOfBytesWritten;
HANDLE TimerThreadHandle = NULL; /* 1998/06/03 - Used in ntplib/machines.c */
void timer(void) { ; }; /* 1998/06/03 - Used in ntplib/machines.c */
#endif /* SYS_WINNT */
/*
* Sequence number used for requests. It is incremented before
* it is used.
*/
u_short sequence;
/*
* Holds data returned from queries. Declare buffer long to be sure of
* alignment.
*/
#define MAXFRAGS 24 /* maximum number of fragments */
#define DATASIZE (MAXFRAGS*480) /* maximum amount of data */
long pktdata[DATASIZE/sizeof(long)];
/*
* Holds association data for use with the &n operator.
*/
struct association assoc_cache[MAXASSOC];
int numassoc = 0; /* number of cached associations */
/*
* For commands typed on the command line (with the -c option)
*/
int numcmds = 0;
const char *ccmds[MAXCMDS];
#define ADDCMD(cp) if (numcmds < MAXCMDS) ccmds[numcmds++] = (cp)
/*
* When multiple hosts are specified.
*/
int numhosts = 0;
const char *chosts[MAXHOSTS];
#define ADDHOST(cp) if (numhosts < MAXHOSTS) chosts[numhosts++] = (cp)
/*
* Error codes for internal use
*/
#define ERR_UNSPEC 256
#define ERR_INCOMPLETE 257
#define ERR_TIMEOUT 258
#define ERR_TOOMUCH 259
/*
* Macro definitions we use
*/
#define ISSPACE(c) ((c) == ' ' || (c) == '\t')
#define ISEOL(c) ((c) == '\n' || (c) == '\r' || (c) == '\0')
#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
/*
* Jump buffer for longjumping back to the command level
*/
jmp_buf interrupt_buf;
/*
* Points at file being currently printed into
*/
FILE *current_output;
/*
* Command table imported from ntpdc_ops.c
*/
extern struct xcmd opcmds[];
char *progname;
volatile int debug;
#ifdef NO_MAIN_ALLOWED
CALL(ntpq,"ntpq",ntpqmain);
void clear_globals(void)
{
extern int ntp_optind;
extern char *ntp_optarg;
showhostnames = 0; /* don'tshow host names by default */
ntp_optind = 0;
ntp_optarg = 0;
server_entry = NULL; /* server entry for ntp */
havehost = 0; /* set to 1 when host open */
numassoc = 0; /* number of cached associations */
numcmds = 0;
numhosts = 0;
}
#endif
/*
* main - parse arguments and handle options
*/
#ifndef NO_MAIN_ALLOWED
int
main(
int argc,
char *argv[]
)
{
return ntpqmain(argc, argv);
}
#endif
int
ntpqmain(
int argc,
char *argv[]
)
{
int c;
int errflg = 0;
extern int ntp_optind;
extern char *ntp_optarg;
#ifdef NO_MAIN_ALLOWED
clear_globals();
taskPrioritySet(taskIdSelf(), 100 );
#endif
delay_time.l_ui = 0;
delay_time.l_uf = DEFDELAY;
progname = argv[0];
while ((c = ntp_getopt(argc, argv, "c:dinp")) != EOF)
switch (c) {
case 'c':
ADDCMD(ntp_optarg);
break;
case 'd':
++debug;
break;
case 'i':
interactive = 1;
break;
case 'n':
showhostnames = 0;
break;
case 'p':
ADDCMD("peers");
break;
default:
errflg++;
break;
}
if (errflg) {
(void) fprintf(stderr,
"usage: %s [-dinp] [-c cmd] host ...\n",
progname);
exit(2);
}
if (ntp_optind == argc) {
ADDHOST(DEFHOST);
} else {
for (; ntp_optind < argc; ntp_optind++)
ADDHOST(argv[ntp_optind]);
}
if (numcmds == 0 && interactive == 0
&& isatty(fileno(stdin)) && isatty(fileno(stderr))) {
interactive = 1;
}
#ifndef SYS_WINNT /* Under NT cannot handle SIGINT, WIN32 spawns a handler */
if (interactive)
(void) signal_no_reset(SIGINT, abortcmd);
#endif /* SYS_WINNT */
#ifdef SYS_WINNT
wVersionRequested = MAKEWORD(1,1);
if (WSAStartup(wVersionRequested, &wsaData)) {
fprintf(stderr, "No useable winsock.dll");
exit(1);
}
#endif /* SYS_WINNT */
if (numcmds == 0) {
(void) openhost(chosts[0]);
getcmds();
} else {
int ihost;
int icmd;
for (ihost = 0; ihost < numhosts; ihost++) {
if (openhost(chosts[ihost]))
for (icmd = 0; icmd < numcmds; icmd++)
docmd(ccmds[icmd]);
}
}
#ifdef SYS_WINNT
WSACleanup();
#endif /* SYS_WINNT */
return 0;
}
/*
* openhost - open a socket to a host
*/
static int
openhost(
const char *hname
)
{
u_int32 netnum;
char temphost[LENHOSTNAME];
if (server_entry == NULL) {
server_entry = getservbyname("ntp", "udp");
if (server_entry == NULL) {
#ifdef VMS /* UCX getservbyname() doesn't work [yet], but we do know better */
server_entry = (struct servent *)
malloc(sizeof(struct servent));
server_entry->s_port = htons(NTP_PORT);
#else
(void) fprintf(stderr, "%s: ntp/udp: unknown service\n",
progname);
exit(1);
#endif /* VMS & UCX */
}
if (debug > 2)
printf("Got ntp/udp service entry\n");
}
if (!getnetnum(hname, &netnum, temphost))
return 0;
if (debug > 2)
printf("Opening host %s\n", temphost);
if (havehost == 1) {
if (debug > 2)
printf("Closing old host %s\n", currenthost);
(void) closesocket(sockfd);
havehost = 0;
}
(void) strcpy(currenthost, temphost);
hostaddr.sin_family = AF_INET;
#ifndef SYS_VXWORKS
hostaddr.sin_port = server_entry->s_port;
#else
hostaddr.sin_port = htons(SERVER_PORT_NUM);
#endif
hostaddr.sin_addr.s_addr = netnum;
#ifdef SYS_WINNT
{
int optionValue = SO_SYNCHRONOUS_NONALERT;
int err;
err = setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&optionValue, sizeof(optionValue));
if (err != NO_ERROR) {
(void) fprintf(stderr, "cannot open nonoverlapped sockets\n");
exit(1);
}
}
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd == INVALID_SOCKET) {
error("socket", "", "");
exit(-1);
}
#else
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd == -1)
error("socket", "", "");
#endif /* SYS_WINNT */
#ifdef NEED_RCVBUF_SLOP
# ifdef SO_RCVBUF
{ int rbufsize = DATASIZE + 2048; /* 2K for slop */
if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF,
&rbufsize, sizeof(int)) == -1)
error("setsockopt", "", "");
}
# endif
#endif
if (connect(sockfd, (struct sockaddr *)&hostaddr,
sizeof(hostaddr)) == -1)
error("connect", "", "");
havehost = 1;
return 1;
}
/* XXX ELIMINATE sendpkt similar in ntpq.c, ntpdc.c, ntp_io.c, ntptrace.c */
/*
* sendpkt - send a packet to the remote host
*/
static int
sendpkt(
char *xdata,
int xdatalen
)
{
if (debug >= 3)
printf("Sending %d octets\n", xdatalen);
if (send(sockfd, xdata, (size_t)xdatalen, 0) == -1) {
warning("write to %s failed", currenthost, "");
return -1;
}
if (debug >= 4) {
int first = 8;
printf("Packet data:\n");
while (xdatalen-- > 0) {
if (first-- == 0) {
printf("\n");
first = 7;
}
printf(" %02x", *xdata++ & 0xff);
}
printf("\n");
}
return 0;
}
/*
* getresponse - get a (series of) response packet(s) and return the data
*/
static int
getresponse(
int opcode,
int associd,
u_short *rstatus,
int *rsize,
char **rdata,
int timeo
)
{
struct ntp_control rpkt;
struct timeval tvo;
u_short offsets[MAXFRAGS+1];
u_short counts[MAXFRAGS+1];
u_short offset;
u_short count;
int numfrags;
int seenlastfrag;
fd_set fds;
int n;
/*
* This is pretty tricky. We may get between 1 and MAXFRAG packets
* back in response to the request. We peel the data out of
* each packet and collect it in one long block. When the last
* packet in the sequence is received we'll know how much data we
* should have had. Note we use one long time out, should reconsider.
*/
*rsize = 0;
if (rstatus)
*rstatus = 0;
*rdata = (char *)pktdata;
numfrags = 0;
seenlastfrag = 0;
FD_ZERO(&fds);
again:
if (numfrags == 0)
tvo = tvout;
else
tvo = tvsout;
FD_SET(sockfd, &fds);
n = select(sockfd+1, &fds, (fd_set *)0, (fd_set *)0, &tvo);
#if 0
if (debug >= 1)
printf("select() returns %d\n", n);
#endif
if (n == -1) {
warning("select fails", "", "");
return -1;
}
if (n == 0) {
/*
* Timed out. Return what we have
*/
if (numfrags == 0) {
if (timeo)
(void) fprintf(stderr,
"%s: timed out, nothing received\n",
currenthost);
return ERR_TIMEOUT;
} else {
if (timeo)
(void) fprintf(stderr,
"%s: timed out with incomplete data\n",
currenthost);
if (debug) {
printf("Received fragments:\n");
for (n = 0; n < numfrags; n++)
printf("%4d %d\n", offsets[n],
counts[n]);
if (seenlastfrag)
printf("last fragment received\n");
else
printf("last fragment not received\n");
}
return ERR_INCOMPLETE;
}
}
n = recv(sockfd, (char *)&rpkt, sizeof(rpkt), 0);
if (n == -1) {
warning("read", "", "");
return -1;
}
if (debug >= 4) {
int len = n, first = 8;
char *data = (char *)&rpkt;
printf("Packet data:\n");
while (len-- > 0) {
if (first-- == 0) {
printf("\n");
first = 7;
}
printf(" %02x", *data++ & 0xff);
}
printf("\n");
}
/*
* Check for format errors. Bug proofing.
*/
if (n < CTL_HEADER_LEN) {
if (debug)
printf("Short (%d byte) packet received\n", n);
goto again;
}
if (PKT_VERSION(rpkt.li_vn_mode) > NTP_VERSION
|| PKT_VERSION(rpkt.li_vn_mode) < NTP_OLDVERSION) {
if (debug)
printf("Packet received with version %d\n",
PKT_VERSION(rpkt.li_vn_mode));
goto again;
}
if (PKT_MODE(rpkt.li_vn_mode) != MODE_CONTROL) {
if (debug)
printf("Packet received with mode %d\n",
PKT_MODE(rpkt.li_vn_mode));
goto again;
}
if (!CTL_ISRESPONSE(rpkt.r_m_e_op)) {
if (debug)
printf("Received request packet, wanted response\n");
goto again;
}
/*
* Check opcode and sequence number for a match.
* Could be old data getting to us.
*/
if (ntohs(rpkt.sequence) != sequence) {
if (debug)
printf(
"Received sequnce number %d, wanted %d\n",
ntohs(rpkt.sequence), sequence);
goto again;
}
if (CTL_OP(rpkt.r_m_e_op) != opcode) {
if (debug)
printf(
"Received opcode %d, wanted %d (sequence number okay)\n",
CTL_OP(rpkt.r_m_e_op), opcode);
goto again;
}
/*
* Check the error code. If non-zero, return it.
*/
if (CTL_ISERROR(rpkt.r_m_e_op)) {
int errcode;
errcode = (ntohs(rpkt.status) >> 8) & 0xff;
if (debug && CTL_ISMORE(rpkt.r_m_e_op)) {
printf("Error code %d received on not-final packet\n",
errcode);
}
if (errcode == CERR_UNSPEC)
return ERR_UNSPEC;
return errcode;
}
/*
* Check the association ID to make sure it matches what
* we sent.
*/
if (ntohs(rpkt.associd) != associd) {
if (debug)
printf("Association ID %d doesn't match expected %d\n",
ntohs(rpkt.associd), associd);
/*
* Hack for silly fuzzballs which, at the time of writing,
* return an assID of sys.peer when queried for system variables.
*/
#ifdef notdef
goto again;
#endif
}
/*
* Collect offset and count. Make sure they make sense.
*/
offset = ntohs(rpkt.offset);
count = ntohs(rpkt.count);
if (debug >= 3) {
int shouldbesize;
u_long key;
u_long *lpkt;
int maclen;
/*
* Usually we ignore authentication, but for debugging purposes
* we watch it here.
*/
shouldbesize = CTL_HEADER_LEN + count;
/* round to 8 octet boundary */
shouldbesize = (shouldbesize + 7) & ~7;
if (n & 0x3) {
printf("Packet not padded, size = %d\n", n);
} if ((maclen = n - shouldbesize) >= MIN_MAC_LEN) {
printf(
"Packet shows signs of authentication (total %d, data %d, mac %d)\n",
n, shouldbesize, maclen);
lpkt = (u_long *)&rpkt;
printf("%08lx %08lx %08lx %08lx %08lx %08lx\n",
(u_long)ntohl(lpkt[(n - maclen)/sizeof(u_long) - 3]),
(u_long)ntohl(lpkt[(n - maclen)/sizeof(u_long) - 2]),
(u_long)ntohl(lpkt[(n - maclen)/sizeof(u_long) - 1]),
(u_long)ntohl(lpkt[(n - maclen)/sizeof(u_long)]),
(u_long)ntohl(lpkt[(n - maclen)/sizeof(u_long) + 1]),
(u_long)ntohl(lpkt[(n - maclen)/sizeof(u_long) + 2]));
key = ntohl(lpkt[(n - maclen) / sizeof(u_long)]);
printf("Authenticated with keyid %lu\n", (u_long)key);
if (key != 0 && key != info_auth_keyid) {
printf("We don't know that key\n");
} else {
if (authdecrypt(key, (u_int32 *)&rpkt,
n - maclen, maclen)) {
printf("Auth okay!\n");
} else {
printf("Auth failed!\n");
}
}
}
}
if (debug >= 2)
printf("Got packet, size = %d\n", n);
if (count > (u_short)(n-CTL_HEADER_LEN)) {
if (debug)
printf(
"Received count of %d octets, data in packet is %d\n",
count, n-CTL_HEADER_LEN);
goto again;
}
if (count == 0 && CTL_ISMORE(rpkt.r_m_e_op)) {
if (debug)
printf("Received count of 0 in non-final fragment\n");
goto again;
}
if (offset + count > sizeof(pktdata)) {
if (debug)
printf("Offset %d, count %d, too big for buffer\n",
offset, count);
return ERR_TOOMUCH;
}
if (seenlastfrag && !CTL_ISMORE(rpkt.r_m_e_op)) {
if (debug)
printf("Received second last fragment packet\n");
goto again;
}
/*
* So far, so good. Record this fragment, making sure it doesn't
* overlap anything.
*/
if (debug >= 2)
printf("Packet okay\n");;
if (numfrags == MAXFRAGS) {
if (debug)
printf("Number of fragments exceeds maximum\n");
return ERR_TOOMUCH;
}
for (n = 0; n < numfrags; n++) {
if (offset == offsets[n])
goto again; /* duplicate */
if (offset < offsets[n])
break;
}
if ((u_short)(n > 0 && offsets[n-1] + counts[n-1]) > offset)
goto overlap;
if (n < numfrags && (u_short)(offset + count) > offsets[n])
goto overlap;
{
register int i;
for (i = numfrags; i > n; i--) {
offsets[i] = offsets[i-1];
counts[i] = counts[i-1];
}
}
offsets[n] = offset;
counts[n] = count;
numfrags++;
/*
* Got that stuffed in right. Figure out if this was the last.
* Record status info out of the last packet.
*/
if (!CTL_ISMORE(rpkt.r_m_e_op)) {
seenlastfrag = 1;
if (rstatus != 0)
*rstatus = ntohs(rpkt.status);
}
/*
* Copy the data into the data buffer.
*/
memmove((char *)pktdata + offset, (char *)rpkt.data, count);
/*
* If we've seen the last fragment, look for holes in the sequence.
* If there aren't any, we're done.
*/
if (seenlastfrag && offsets[0] == 0) {
for (n = 1; n < numfrags; n++) {
if (offsets[n-1] + counts[n-1] != offsets[n])
break;
}
if (n == numfrags) {
*rsize = offsets[numfrags-1] + counts[numfrags-1];
return 0;
}
}
goto again;
overlap:
/*
* Print debugging message about overlapping fragments
*/
if (debug)
printf("Overlapping fragments returned in response\n");
goto again;
}
/*
* sendrequest - format and send a request packet
*/
static int
sendrequest(
int opcode,
int associd,
int auth,
int qsize,
char *qdata
)
{
struct ntp_control qpkt;
int pktsize;
/*
* Check to make sure the data will fit in one packet
*/
if (qsize > CTL_MAX_DATA_LEN) {
(void) fprintf(stderr,
"***Internal error! qsize (%d) too large\n",
qsize);
return 1;
}
/*
* Fill in the packet
*/
qpkt.li_vn_mode = PKT_LI_VN_MODE(0, pktversion, MODE_CONTROL);
qpkt.r_m_e_op = (u_char)opcode & CTL_OP_MASK;
qpkt.sequence = htons(sequence);
qpkt.status = 0;
qpkt.associd = htons((u_short)associd);
qpkt.offset = 0;
qpkt.count = htons((u_short)qsize);
/*
* If we have data, copy it in and pad it out to a 64
* bit boundary.
*/
if (qsize > 0) {
memmove((char *)qpkt.data, qdata, (unsigned)qsize);
pktsize = qsize + CTL_HEADER_LEN;
while (pktsize & (sizeof(u_long) - 1)) {
qpkt.data[qsize++] = 0;
pktsize++;
}
} else {
pktsize = CTL_HEADER_LEN;
}
/*
* If it isn't authenticated we can just send it. Otherwise
* we're going to have to think about it a little.
*/
if (!auth && !always_auth) {
return sendpkt((char *)&qpkt, pktsize);
} else {
const char *pass = "\0";
int maclen = 0;
u_long my_keyid;
/*
* Pad out packet to a multiple of 8 octets to be sure
* receiver can handle it.
*/
while (pktsize & 7) {
qpkt.data[qsize++] = 0;
pktsize++;
}
/*
* Get the keyid and the password if we don't have one.
*/
if (info_auth_keyid == 0) {
maclen = getkeyid("Keyid: ");
if (maclen == 0) {
(void) fprintf(stderr,
"Invalid key identifier\n");
return 1;
}
}
if (!authistrusted(info_auth_keyid)) {
pass = getpass((info_auth_keytype == KEY_TYPE_DES)
? "DES Password: " : "MD5 Password: ");
if (*pass == '\0') {
(void) fprintf(stderr,
"Invalid password\n");
return (1);
}
}
info_auth_keyid = maclen;
authusekey(info_auth_keyid, info_auth_keytype, (const u_char *)pass);
authtrust(info_auth_keyid, 1);
/*
* Stick the keyid in the packet where
* cp currently points. Cp should be aligned
* properly. Then do the encryptions.
*/
my_keyid = htonl(info_auth_keyid);
memcpy(&qpkt.data[qsize], &my_keyid, sizeof my_keyid);
maclen = authencrypt(info_auth_keyid, (u_int32 *)&qpkt,
pktsize);
if (maclen == 0) {
(void) fprintf(stderr, "Key not found\n");
return (1);
}
return sendpkt((char *)&qpkt, pktsize + maclen);
}
/*NOTREACHED*/
}
/*
* doquery - send a request and process the response
*/
int
doquery(
int opcode,
int associd,
int auth,
int qsize,
char *qdata,
u_short *rstatus,
int *rsize,
char **rdata
)
{
int res;
int done;
/*
* Check to make sure host is open
*/
if (!havehost) {
(void) fprintf(stderr, "***No host open, use `host' command\n");
return -1;
}
done = 0;
sequence++;
again:
/*
* send a request
*/
res = sendrequest(opcode, associd, auth, qsize, qdata);
if (res != 0)
return res;
/*
* Get the response. If we got a standard error, print a message
*/
res = getresponse(opcode, associd, rstatus, rsize, rdata, done);
if (res > 0) {
if (!done && (res == ERR_TIMEOUT || res == ERR_INCOMPLETE)) {
if (res == ERR_INCOMPLETE) {
/*
* better bump the sequence so we don't
* get confused about differing fragments.
*/
sequence++;
}
done = 1;
goto again;
}
switch(res) {
case CERR_BADFMT:
(void) fprintf(stderr,
"***Server reports a bad format request packet\n");
break;
case CERR_PERMISSION:
(void) fprintf(stderr,
"***Server disallowed request (authentication?)\n");
break;
case CERR_BADOP:
(void) fprintf(stderr,
"***Server reports a bad opcode in request\n");
break;
case CERR_BADASSOC:
(void) fprintf(stderr,
"***Association ID %d unknown to server\n",associd);
break;
case CERR_UNKNOWNVAR:
(void) fprintf(stderr,
"***A request variable unknown to the server\n");
break;
case CERR_BADVALUE:
(void) fprintf(stderr,
"***Server indicates a request variable was bad\n");
break;
case ERR_UNSPEC:
(void) fprintf(stderr,
"***Server returned an unspecified error\n");
break;
case ERR_TIMEOUT:
(void) fprintf(stderr, "***Request timed out\n");
break;
case ERR_INCOMPLETE:
(void) fprintf(stderr,
"***Response from server was incomplete\n");
break;
case ERR_TOOMUCH:
(void) fprintf(stderr,
"***Buffer size exceeded for returned data\n");
break;
default:
(void) fprintf(stderr,
"***Server returns unknown error code %d\n", res);
break;
}
}
return res;
}
/*
* getcmds - read commands from the standard input and execute them
*/
static void
getcmds(void)
{
#ifdef HAVE_LIBREADLINE
char *line;
for (;;) {
if ((line = readline(interactive?prompt:"")) == NULL) return;
if (*line) add_history(line);
docmd(line);
free(line);
}
#else /* not HAVE_LIBREADLINE */
char line[MAXLINE];
for (;;) {
if (interactive) {
#ifdef VMS /* work around a problem with mixing stdout & stderr */
fputs("",stdout);
#endif
(void) fputs(prompt, stderr);
(void) fflush(stderr);
}
if (fgets(line, sizeof line, stdin) == NULL)
return;
docmd(line);
}
#endif /* not HAVE_LIBREADLINE */
}
/*
* abortcmd - catch interrupts and abort the current command
*/
static RETSIGTYPE
abortcmd(
int sig
)
{
if (current_output == stdout)
(void) fflush(stdout);
putc('\n', stderr);
(void) fflush(stderr);
if (jump) longjmp(interrupt_buf, 1);
}
/*
* docmd - decode the command line and execute a command
*/
static void
docmd(
const char *cmdline
)
{
char *tokens[1+MAXARGS+2];
struct parse pcmd;
int ntok;
static int i;
struct xcmd *xcmd;
/*
* Tokenize the command line. If nothing on it, return.
*/
tokenize(cmdline, tokens, &ntok);
if (ntok == 0)
return;
/*
* Find the appropriate command description.
*/
i = findcmd(tokens[0], builtins, opcmds, &xcmd);
if (i == 0) {
(void) fprintf(stderr, "***Command `%s' unknown\n",
tokens[0]);
return;
} else if (i >= 2) {
(void) fprintf(stderr, "***Command `%s' ambiguous\n",
tokens[0]);
return;
}
/*
* Save the keyword, then walk through the arguments, interpreting
* as we go.
*/
pcmd.keyword = tokens[0];
pcmd.nargs = 0;
for (i = 0; i < MAXARGS && xcmd->arg[i] != NO; i++) {
if ((i+1) >= ntok) {
if (!(xcmd->arg[i] & OPT)) {
printusage(xcmd, stderr);
return;
}
break;
}
if ((xcmd->arg[i] & OPT) && (*tokens[i+1] == '>'))
break;
if (!getarg(tokens[i+1], (int)xcmd->arg[i], &pcmd.argval[i]))
return;
pcmd.nargs++;
}
i++;
if (i < ntok && *tokens[i] == '>') {
char *fname;
if (*(tokens[i]+1) != '\0')
fname = tokens[i]+1;
else if ((i+1) < ntok)
fname = tokens[i+1];
else {
(void) fprintf(stderr, "***No file for redirect\n");
return;
}
current_output = fopen(fname, "w");
if (current_output == NULL) {
(void) fprintf(stderr, "***Error opening %s: ", fname);
perror("");
return;
}
i = 1; /* flag we need a close */
} else {
current_output = stdout;
i = 0; /* flag no close */
}
if (interactive && setjmp(interrupt_buf)) {
jump = 0;
return;
} else {
jump++;
(xcmd->handler)(&pcmd, current_output);
jump = 0; /* HMS: 961106: was after fclose() */
if (i) (void) fclose(current_output);
}
}
/*
* tokenize - turn a command line into tokens
*/
static void
tokenize(
const char *line,
char **tokens,
int *ntok
)
{
register const char *cp;
register char *sp;
static char tspace[MAXLINE];
sp = tspace;
cp = line;
for (*ntok = 0; *ntok < MAXTOKENS; (*ntok)++) {
tokens[*ntok] = sp;
while (ISSPACE(*cp))
cp++;
if (ISEOL(*cp))
break;
do {
*sp++ = *cp++;
} while (!ISSPACE(*cp) && !ISEOL(*cp));
*sp++ = '\0';
}
}
/*
* findcmd - find a command in a command description table
*/
static int
findcmd(
register char *str,
struct xcmd *clist1,
struct xcmd *clist2,
struct xcmd **cmd
)
{
register struct xcmd *cl;
register int clen;
int nmatch;
struct xcmd *nearmatch = NULL;
struct xcmd *clist;
clen = strlen(str);
nmatch = 0;
if (clist1 != 0)
clist = clist1;
else if (clist2 != 0)
clist = clist2;
else
return 0;
again:
for (cl = clist; cl->keyword != 0; cl++) {
/* do a first character check, for efficiency */
if (*str != *(cl->keyword))
continue;
if (strncmp(str, cl->keyword, (unsigned)clen) == 0) {
/*
* Could be extact match, could be approximate.
* Is exact if the length of the keyword is the
* same as the str.
*/
if (*((cl->keyword) + clen) == '\0') {
*cmd = cl;
return 1;
}
nmatch++;
nearmatch = cl;
}
}
/*
* See if there is more to do. If so, go again. Sorry about the
* goto, too much looking at BSD sources...
*/
if (clist == clist1 && clist2 != 0) {
clist = clist2;
goto again;
}
/*
* If we got extactly 1 near match, use it, else return number
* of matches.
*/
if (nmatch == 1) {
*cmd = nearmatch;
return 1;
}
return nmatch;
}
/*
* getarg - interpret an argument token
*/
static int
getarg(
char *str,
int code,
arg_v *argp
)
{
int isneg;
char *cp, *np;
static const char *digits = "0123456789";
switch (code & ~OPT) {
case STR:
argp->string = str;
break;
case ADD:
if (!getnetnum(str, &(argp->netnum), (char *)0)) {
return 0;
}
break;
case INT:
case UINT:
isneg = 0;
np = str;
if (*np == '&') {
np++;
isneg = atoi(np);
if (isneg <= 0) {
(void) fprintf(stderr,
"***Association value `%s' invalid/undecodable\n", str);
return 0;
}
if (isneg > numassoc) {
(void) fprintf(stderr,
"***Association for `%s' unknown (max &%d)\n",
str, numassoc);
return 0;
}
argp->uval = assoc_cache[isneg-1].assid;
break;
}
if (*np == '-') {
np++;
isneg = 1;
}
argp->uval = 0;
do {
cp = strchr(digits, *np);
if (cp == NULL) {
(void) fprintf(stderr,
"***Illegal integer value %s\n", str);
return 0;
}
argp->uval *= 10;
argp->uval += (cp - digits);
} while (*(++np) != '\0');
if (isneg) {
if ((code & ~OPT) == UINT) {
(void) fprintf(stderr,
"***Value %s should be unsigned\n", str);
return 0;
}
argp->ival = -argp->ival;
}
break;
}
return 1;
}
/*
* getnetnum - given a host name, return its net number
* and (optional) full name
*/
int
getnetnum(
const char *hname,
u_int32 *num,
char *fullhost
)
{
struct hostent *hp;
if (decodenetnum(hname, num)) {
if (fullhost != 0) {
(void) sprintf(fullhost, "%lu.%lu.%lu.%lu",
(u_long)((htonl(*num) >> 24) & 0xff),
(u_long)((htonl(*num) >> 16) & 0xff),
(u_long)((htonl(*num) >> 8) & 0xff),
(u_long)(htonl(*num) & 0xff));
}
return 1;
} else if ((hp = gethostbyname(hname)) != 0) {
memmove((char *)num, hp->h_addr, sizeof(u_int32));
if (fullhost != 0)
(void) strcpy(fullhost, hp->h_name);
return 1;
} else {
(void) fprintf(stderr, "***Can't find host %s\n", hname);
return 0;
}
/*NOTREACHED*/
}
/*
* nntohost - convert network number to host name. This routine enforces
* the showhostnames setting.
*/
char *
nntohost(
u_int32 netnum
)
{
if (!showhostnames)
return numtoa(netnum);
if ((ntohl(netnum) & REFCLOCK_MASK) == REFCLOCK_ADDR)
return refnumtoa(netnum);
return numtohost(netnum);
}
/*
* rtdatetolfp - decode an RT-11 date into an l_fp
*/
static int
rtdatetolfp(
char *str,
l_fp *lfp
)
{
register char *cp;
register int i;
struct calendar cal;
char buf[4];
static const char *months[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
cal.yearday = 0;
/*
* An RT-11 date looks like:
*
* d[d]-Mth-y[y] hh:mm:ss
*
* (No docs, but assume 4-digit years are also legal...)
*
* d[d]-Mth-y[y[y[y]]] hh:mm:ss
*/
cp = str;
if (!isdigit((int)*cp)) {
if (*cp == '-') {
/*
* Catch special case
*/
L_CLR(lfp);
return 1;
}
return 0;
}
cal.monthday = *cp++ - '0'; /* ascii dependent */
if (isdigit((int)*cp)) {
cal.monthday = (cal.monthday << 3) + (cal.monthday << 1);
cal.monthday += *cp++ - '0';
}
if (*cp++ != '-')
return 0;
for (i = 0; i < 3; i++)
buf[i] = *cp++;
buf[3] = '\0';
for (i = 0; i < 12; i++)
if (STREQ(buf, months[i]))
break;
if (i == 12)
return 0;
cal.month = i + 1;
if (*cp++ != '-')
return 0;
if (!isdigit((int)*cp))
return 0;
cal.year = *cp++ - '0';
if (isdigit((int)*cp)) {
cal.year = (cal.year << 3) + (cal.year << 1);
cal.year += *cp++ - '0';
}
if (isdigit((int)*cp)) {
cal.year = (cal.year << 3) + (cal.year << 1);
cal.year += *cp++ - '0';
}
if (isdigit((int)*cp)) {
cal.year = (cal.year << 3) + (cal.year << 1);
cal.year += *cp++ - '0';
}
/*
* Catch special case. If cal.year == 0 this is a zero timestamp.
*/
if (cal.year == 0) {
L_CLR(lfp);
return 1;
}
if (*cp++ != ' ' || !isdigit((int)*cp))
return 0;
cal.hour = *cp++ - '0';
if (isdigit((int)*cp)) {
cal.hour = (cal.hour << 3) + (cal.hour << 1);
cal.hour += *cp++ - '0';
}
if (*cp++ != ':' || !isdigit((int)*cp))
return 0;
cal.minute = *cp++ - '0';
if (isdigit((int)*cp)) {
cal.minute = (cal.minute << 3) + (cal.minute << 1);
cal.minute += *cp++ - '0';
}
if (*cp++ != ':' || !isdigit((int)*cp))
return 0;
cal.second = *cp++ - '0';
if (isdigit((int)*cp)) {
cal.second = (cal.second << 3) + (cal.second << 1);
cal.second += *cp++ - '0';
}
/*
* For RT-11, 1972 seems to be the pivot year
*/
if (cal.year < 72)
cal.year += 2000;
if (cal.year < 100)
cal.year += 1900;
lfp->l_ui = caltontp(&cal);
lfp->l_uf = 0;
return 1;
}
/*
* decodets - decode a timestamp into an l_fp format number, with
* consideration of fuzzball formats.
*/
int
decodets(
char *str,
l_fp *lfp
)
{
/*
* If it starts with a 0x, decode as hex.
*/
if (*str == '0' && (*(str+1) == 'x' || *(str+1) == 'X'))
return hextolfp(str+2, lfp);
/*
* If it starts with a '"', try it as an RT-11 date.
*/
if (*str == '"') {
register char *cp = str+1;
register char *bp;
char buf[30];
bp = buf;
while (*cp != '"' && *cp != '\0' && bp < &buf[29])
*bp++ = *cp++;
*bp = '\0';
return rtdatetolfp(buf, lfp);
}
/*
* Might still be hex. Check out the first character. Talk
* about heuristics!
*/
if ((*str >= 'A' && *str <= 'F') || (*str >= 'a' && *str <= 'f'))
return hextolfp(str, lfp);
/*
* Try it as a decimal. If this fails, try as an unquoted
* RT-11 date. This code should go away eventually.
*/
if (atolfp(str, lfp))
return 1;
return rtdatetolfp(str, lfp);
}
/*
* decodetime - decode a time value. It should be in milliseconds
*/
int
decodetime(
char *str,
l_fp *lfp
)
{
return mstolfp(str, lfp);
}
/*
* decodeint - decode an integer
*/
int
decodeint(
char *str,
long *val
)
{
if (*str == '0') {
if (*(str+1) == 'x' || *(str+1) == 'X')
return hextoint(str+2, (u_long *)&val);
return octtoint(str, (u_long *)&val);
}
return atoint(str, val);
}
/*
* decodeuint - decode an unsigned integer
*/
int
decodeuint(
char *str,
u_long *val
)
{
if (*str == '0') {
if (*(str + 1) == 'x' || *(str + 1) == 'X')
return (hextoint(str + 2, val));
return (octtoint(str, val));
}
return (atouint(str, val));
}
/*
* decodearr - decode an array of time values
*/
static int
decodearr(
char *str,
int *narr,
l_fp *lfparr
)
{
register char *cp, *bp;
register l_fp *lfp;
char buf[60];
lfp = lfparr;
cp = str;
*narr = 0;
while (*narr < 8) {
while (isspace((int)*cp))
cp++;
if (*cp == '\0')
break;
bp = buf;
while (!isspace((int)*cp) && *cp != '\0')
*bp++ = *cp++;
*bp++ = '\0';
if (!decodetime(buf, lfp))
return 0;
(*narr)++;
lfp++;
}
return 1;
}
/*
* Finally, the built in command handlers
*/
/*
* help - tell about commands, or details of a particular command
*/
static void
help(
struct parse *pcmd,
FILE *fp
)
{
int i;
int n;
struct xcmd *xcp;
char *cmd;
const char *cmdsort[100];
int length[100];
int maxlength;
int numperline;
static const char *spaces = " "; /* 20 spaces */
if (pcmd->nargs == 0) {
n = 0;
for (xcp = builtins; xcp->keyword != 0; xcp++) {
if (*(xcp->keyword) != '?')
cmdsort[n++] = xcp->keyword;
}
for (xcp = opcmds; xcp->keyword != 0; xcp++)
cmdsort[n++] = xcp->keyword;
#ifdef QSORT_USES_VOID_P
qsort(cmdsort, (size_t)n, sizeof(char *), helpsort);
#else
qsort((char *)cmdsort, (size_t)n, sizeof(char *), helpsort);
#endif
maxlength = 0;
for (i = 0; i < n; i++) {
length[i] = strlen(cmdsort[i]);
if (length[i] > maxlength)
maxlength = length[i];
}
maxlength++;
numperline = 76 / maxlength;
(void) fprintf(fp, "Commands available:\n");
for (i = 0; i < n; i++) {
if ((i % numperline) == (numperline-1)
|| i == (n-1))
(void) fprintf(fp, "%s\n", cmdsort[i]);
else
(void) fprintf(fp, "%s%s", cmdsort[i],
spaces+20-maxlength+length[i]);
}
} else {
cmd = pcmd->argval[0].string;
n = findcmd(cmd, builtins, opcmds, &xcp);
if (n == 0) {
(void) fprintf(stderr,
"Command `%s' is unknown\n", cmd);
return;
} else if (n >= 2) {
(void) fprintf(stderr,
"Command `%s' is ambiguous\n", cmd);
return;
}
(void) fprintf(fp, "function: %s\n", xcp->comment);
printusage(xcp, fp);
}
}
/*
* helpsort - do hostname qsort comparisons
*/
#ifdef QSORT_USES_VOID_P
static int
helpsort(
const void *t1,
const void *t2
)
{
const char **name1 = (const char **)t1;
const char **name2 = (const char **)t2;
return strcmp(*name1, *name2);
}
#else
static int
helpsort(
char **name1,
char **name2
)
{
return strcmp(*name1, *name2);
}
#endif
/*
* printusage - print usage information for a command
*/
static void
printusage(
struct xcmd *xcp,
FILE *fp
)
{
register int i;
(void) fprintf(fp, "usage: %s", xcp->keyword);
for (i = 0; i < MAXARGS && xcp->arg[i] != NO; i++) {
if (xcp->arg[i] & OPT)
(void) fprintf(fp, " [ %s ]", xcp->desc[i]);
else
(void) fprintf(fp, " %s", xcp->desc[i]);
}
(void) fprintf(fp, "\n");
}
/*
* timeout - set time out time
*/
static void
timeout(
struct parse *pcmd,
FILE *fp
)
{
int val;
if (pcmd->nargs == 0) {
val = tvout.tv_sec * 1000 + tvout.tv_usec / 1000;
(void) fprintf(fp, "primary timeout %d ms\n", val);
} else {
tvout.tv_sec = pcmd->argval[0].uval / 1000;
tvout.tv_usec = (pcmd->argval[0].uval - (tvout.tv_sec * 1000))
* 1000;
}
}
/*
* auth_delay - set delay for auth requests
*/
static void
auth_delay(
struct parse *pcmd,
FILE *fp
)
{
int isneg;
u_long val;
if (pcmd->nargs == 0) {
val = delay_time.l_ui * 1000 + delay_time.l_uf / 4294967;
(void) fprintf(fp, "delay %lu ms\n", val);
} else {
if (pcmd->argval[0].ival < 0) {
isneg = 1;
val = (u_long)(-pcmd->argval[0].ival);
} else {
isneg = 0;
val = (u_long)pcmd->argval[0].ival;
}
delay_time.l_ui = val / 1000;
val %= 1000;
delay_time.l_uf = val * 4294967; /* 2**32/1000 */
if (isneg)
L_NEG(&delay_time);
}
}
/*
* host - set the host we are dealing with.
*/
static void
host(
struct parse *pcmd,
FILE *fp
)
{
if (pcmd->nargs == 0) {
if (havehost)
(void) fprintf(fp, "current host is %s\n", currenthost);
else
(void) fprintf(fp, "no current host\n");
} else if (openhost(pcmd->argval[0].string)) {
(void) fprintf(fp, "current host set to %s\n", currenthost);
numassoc = 0;
} else {
if (havehost)
(void) fprintf(fp,
"current host remains %s\n", currenthost);
else
(void) fprintf(fp, "still no current host\n");
}
}
/*
* poll - do one (or more) polls of the host via NTP
*/
/*ARGSUSED*/
static void
ntp_poll(
struct parse *pcmd,
FILE *fp
)
{
(void) fprintf(fp, "poll not implemented yet\n");
}
/*
* keyid - get a keyid to use for authenticating requests
*/
static void
keyid(
struct parse *pcmd,
FILE *fp
)
{
if (pcmd->nargs == 0) {
if (info_auth_keyid > NTP_MAXKEY)
(void) fprintf(fp, "no keyid defined\n");
else
(void) fprintf(fp, "keyid is %lu\n", (u_long)info_auth_keyid);
} else {
info_auth_keyid = pcmd->argval[0].uval;
}
}
/*
* keytype - get type of key to use for authenticating requests
*/
static void
keytype(
struct parse *pcmd,
FILE *fp
)
{
if (pcmd->nargs == 0)
fprintf(fp, "keytype is %s\n",
(info_auth_keytype == KEY_TYPE_MD5) ? "MD5" : "DES");
else
switch (*(pcmd->argval[0].string)) {
case 'm':
case 'M':
info_auth_keytype = KEY_TYPE_MD5;
break;
case 'd':
case 'D':
info_auth_keytype = KEY_TYPE_DES;
break;
default:
fprintf(fp, "keytype must be 'md5' or 'des'\n");
}
}
/*
* passwd - get an authentication key
*/
/*ARGSUSED*/
static void
passwd(
struct parse *pcmd,
FILE *fp
)
{
char *pass;
if (info_auth_keyid > NTP_MAXKEY) {
info_auth_keyid = getkeyid("Keyid: ");
if (info_auth_keyid > NTP_MAXKEY) {
(void)fprintf(fp, "Keyid must be defined\n");
return;
}
}
pass = getpass((info_auth_keytype == KEY_TYPE_DES)
? "DES Password: "
: "MD5 Password: "
);
if (*pass == '\0')
(void) fprintf(fp, "Password unchanged\n");
else
authusekey(info_auth_keyid, info_auth_keytype, (u_char *)pass);
}
/*
* hostnames - set the showhostnames flag
*/
static void
hostnames(
struct parse *pcmd,
FILE *fp
)
{
if (pcmd->nargs == 0) {
if (showhostnames)
(void) fprintf(fp, "hostnames being shown\n");
else
(void) fprintf(fp, "hostnames not being shown\n");
} else {
if (STREQ(pcmd->argval[0].string, "yes"))
showhostnames = 1;
else if (STREQ(pcmd->argval[0].string, "no"))
showhostnames = 0;
else
(void)fprintf(stderr, "What?\n");
}
}
/*
* setdebug - set/change debugging level
*/
static void
setdebug(
struct parse *pcmd,
FILE *fp
)
{
if (pcmd->nargs == 0) {
(void) fprintf(fp, "debug level is %d\n", debug);
return;
} else if (STREQ(pcmd->argval[0].string, "no")) {
debug = 0;
} else if (STREQ(pcmd->argval[0].string, "more")) {
debug++;
} else if (STREQ(pcmd->argval[0].string, "less")) {
debug--;
} else {
(void) fprintf(fp, "What?\n");
return;
}
(void) fprintf(fp, "debug level set to %d\n", debug);
}
/*
* quit - stop this nonsense
*/
/*ARGSUSED*/
static void
quit(
struct parse *pcmd,
FILE *fp
)
{
if (havehost)
closesocket(sockfd); /* cleanliness next to godliness */
exit(0);
}
/*
* version - print the current version number
*/
/*ARGSUSED*/
static void
version(
struct parse *pcmd,
FILE *fp
)
{
(void) fprintf(fp, "%s\n", Version);
return;
}
/*
* raw - set raw mode output
*/
/*ARGSUSED*/
static void
raw(
struct parse *pcmd,
FILE *fp
)
{
rawmode = 1;
(void) fprintf(fp, "Output set to raw\n");
}
/*
* cooked - set cooked mode output
*/
/*ARGSUSED*/
static void
cooked(
struct parse *pcmd,
FILE *fp
)
{
rawmode = 0;
(void) fprintf(fp, "Output set to cooked\n");
return;
}
/*
* authenticate - always authenticate requests to this host
*/
static void
authenticate(
struct parse *pcmd,
FILE *fp
)
{
if (pcmd->nargs == 0) {
if (always_auth) {
(void) fprintf(fp,
"authenticated requests being sent\n");
} else
(void) fprintf(fp,
"unauthenticated requests being sent\n");
} else {
if (STREQ(pcmd->argval[0].string, "yes")) {
always_auth = 1;
} else if (STREQ(pcmd->argval[0].string, "no")) {
always_auth = 0;
} else
(void)fprintf(stderr, "What?\n");
}
}
/*
* ntpversion - choose the NTP version to use
*/
static void
ntpversion(
struct parse *pcmd,
FILE *fp
)
{
if (pcmd->nargs == 0) {
(void) fprintf(fp,
"NTP version being claimed is %d\n", pktversion);
} else {
if (pcmd->argval[0].uval < NTP_OLDVERSION
|| pcmd->argval[0].uval > NTP_VERSION) {
(void) fprintf(stderr, "versions %d to %d, please\n",
NTP_OLDVERSION, NTP_VERSION);
} else {
pktversion = (u_char) pcmd->argval[0].uval;
}
}
}
/*
* warning - print a warning message
*/
static void
warning(
const char *fmt,
const char *st1,
const char *st2
)
{
(void) fprintf(stderr, "%s: ", progname);
(void) fprintf(stderr, fmt, st1, st2);
(void) fprintf(stderr, ": ");
perror("");
}
/*
* error - print a message and exit
*/
static void
error(
const char *fmt,
const char *st1,
const char *st2
)
{
warning(fmt, st1, st2);
exit(1);
}
/*
* getkeyid - prompt the user for a keyid to use
*/
static u_long
getkeyid(
const char *keyprompt
)
{
register char *p;
register int c;
FILE *fi;
char pbuf[20];
#ifndef SYS_WINNT
if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
#else
if ((fi = _fdopen((int)GetStdHandle(STD_INPUT_HANDLE), "r")) == NULL)
#endif /* SYS_WINNT */
fi = stdin;
else
setbuf(fi, (char *)NULL);
fprintf(stderr, "%s", keyprompt); fflush(stderr);
for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
if (p < &pbuf[18])
*p++ = c;
}
*p = '\0';
if (fi != stdin)
fclose(fi);
if (strcmp(pbuf, "0") == 0)
return 0;
return (u_long) atoi(pbuf);
}
/*
* atoascii - printable-ize possibly ascii data using the character
* transformations cat -v uses.
*/
static void
atoascii(
int length,
char *data,
char *outdata
)
{
register u_char *cp;
register u_char *ocp;
register u_char c;
if (!data)
{
*outdata = '\0';
return;
}
ocp = (u_char *)outdata;
for (cp = (u_char *)data; cp < (u_char *)data + length; cp++) {
c = *cp;
if (c == '\0')
break;
if (c == '\0')
break;
if (c > 0177) {
*ocp++ = 'M';
*ocp++ = '-';
c &= 0177;
}
if (c < ' ') {
*ocp++ = '^';
*ocp++ = c + '@';
} else if (c == 0177) {
*ocp++ = '^';
*ocp++ = '?';
} else {
*ocp++ = c;
}
if (ocp >= ((u_char *)outdata + length - 4))
break;
}
*ocp++ = '\0';
}
/*
* makeascii - print possibly ascii data using the character
* transformations that cat -v uses.
*/
static void
makeascii(
int length,
char *data,
FILE *fp
)
{
register u_char *cp;
register int c;
for (cp = (u_char *)data; cp < (u_char *)data + length; cp++) {
c = (int)*cp;
if (c > 0177) {
putc('M', fp);
putc('-', fp);
c &= 0177;
}
if (c < ' ') {
putc('^', fp);
putc(c+'@', fp);
} else if (c == 0177) {
putc('^', fp);
putc('?', fp);
} else {
putc(c, fp);
}
}
}
/*
* asciize - same thing as makeascii except add a newline
*/
void
asciize(
int length,
char *data,
FILE *fp
)
{
makeascii(length, data, fp);
putc('\n', fp);
}
/*
* Some circular buffer space
*/
#define CBLEN 80
#define NUMCB 6
char circ_buf[NUMCB][CBLEN];
int nextcb = 0;
/*
* nextvar - find the next variable in the buffer
*/
int
nextvar(
int *datalen,
char **datap,
char **vname,
char **vvalue
)
{
register char *cp;
register char *np;
register char *cpend;
register char *npend; /* character after last */
int quoted = 0;
static char name[MAXVARLEN];
static char value[MAXVALLEN];
cp = *datap;
cpend = cp + *datalen;
/*
* Space past commas and white space
*/
while (cp < cpend && (*cp == ',' || isspace((int)*cp)))
cp++;
if (cp == cpend)
return 0;
/*
* Copy name until we hit a ',', an '=', a '\r' or a '\n'. Backspace
* over any white space and terminate it.
*/
np = name;
npend = &name[MAXVARLEN];
while (cp < cpend && np < npend && *cp != ',' && *cp != '='
&& *cp != '\r' && *cp != '\n')
*np++ = *cp++;
/*
* Check if we ran out of name space, without reaching the end or a
* terminating character
*/
if (np == npend && !(cp == cpend || *cp == ',' || *cp == '=' ||
*cp == '\r' || *cp == '\n'))
return 0;
while (isspace((int)(*(np-1))))
np--;
*np = '\0';
*vname = name;
/*
* Check if we hit the end of the buffer or a ','. If so we are done.
*/
if (cp == cpend || *cp == ',' || *cp == '\r' || *cp == '\n') {
if (cp != cpend)
cp++;
*datap = cp;
*datalen = cpend - cp;
*vvalue = (char *)0;
return 1;
}
/*
* So far, so good. Copy out the value
*/
cp++; /* past '=' */
while (cp < cpend && (isspace((int)*cp) && *cp != '\r' && *cp != '\n'))
cp++;
np = value;
npend = &value[MAXVALLEN];
while (cp < cpend && np < npend && ((*cp != ',') || quoted))
{
quoted ^= ((*np++ = *cp++) == '"');
}
/*
* Check if we overran the value buffer while still in a quoted string
* or without finding a comma
*/
if (np == npend && (quoted || *cp != ','))
return 0;
/*
* Trim off any trailing whitespace
*/
while (np > value && isspace((int)(*(np-1))))
np--;
*np = '\0';
/*
* Return this. All done.
*/
if (cp != cpend)
cp++;
*datap = cp;
*datalen = cpend - cp;
*vvalue = value;
return 1;
}
/*
* findvar - see if this variable is known to us
*/
int
findvar(
char *varname,
struct ctl_var *varlist
)
{
register char *np;
register struct ctl_var *vl;
vl = varlist;
np = varname;
while (vl->fmt != EOV) {
if (vl->fmt != PADDING && STREQ(np, vl->text))
return vl->code;
vl++;
}
return 0;
}
/*
* printvars - print variables returned in response packet
*/
void
printvars(
int length,
char *data,
int status,
int sttype,
FILE *fp
)
{
if (rawmode)
rawprint(sttype, length, data, status, fp);
else
cookedprint(sttype, length, data, status, fp);
}
/*
* rawprint - do a printout of the data in raw mode
*/
static void
rawprint(
int datatype,
int length,
char *data,
int status,
FILE *fp
)
{
register char *cp;
register char *cpend;
/*
* Essentially print the data as is. We reformat unprintables, though.
*/
cp = data;
cpend = data + length;
(void) fprintf(fp, "status=0x%04x,\n", status);
while (cp < cpend) {
if (*cp == '\r') {
/*
* If this is a \r and the next character is a
* \n, supress this, else pretty print it. Otherwise
* just output the character.
*/
if (cp == (cpend-1) || *(cp+1) != '\n')
makeascii(1, cp, fp);
} else if (isspace((int)*cp) || isprint((int)*cp)) {
putc(*cp, fp);
} else {
makeascii(1, cp, fp);
}
cp++;
}
}
/*
* Global data used by the cooked output routines
*/
int out_chars; /* number of characters output */
int out_linecount; /* number of characters output on this line */
/*
* startoutput - get ready to do cooked output
*/
static void
startoutput(void)
{
out_chars = 0;
out_linecount = 0;
}
/*
* output - output a variable=value combination
*/
static void
output(
FILE *fp,
char *name,
char *value
)
{
int lenname;
int lenvalue;
lenname = strlen(name);
lenvalue = strlen(value);
if (out_chars != 0) {
putc(',', fp);
out_chars++;
out_linecount++;
if ((out_linecount + lenname + lenvalue + 3) > MAXOUTLINE) {
putc('\n', fp);
out_chars++;
out_linecount = 0;
} else {
putc(' ', fp);
out_chars++;
out_linecount++;
}
}
fputs(name, fp);
putc('=', fp);
fputs(value, fp);
out_chars += lenname + 1 + lenvalue;
out_linecount += lenname + 1 + lenvalue;
}
/*
* endoutput - terminate a block of cooked output
*/
static void
endoutput(
FILE *fp
)
{
if (out_chars != 0)
putc('\n', fp);
}
/*
* outputarr - output an array of values
*/
static void
outputarr(
FILE *fp,
char *name,
int narr,
l_fp *lfp
)
{
register char *bp;
register char *cp;
register int i;
register int len;
char buf[256];
bp = buf;
/*
* Hack to align delay and offset values
*/
for (i = (int)strlen(name); i < 11; i++)
*bp++ = ' ';
for (i = narr; i > 0; i--) {
if (i != narr)
*bp++ = ' ';
cp = lfptoms(lfp, 2);
len = strlen(cp);
if (len > 7) {
cp[7] = '\0';
len = 7;
}
while (len < 7) {
*bp++ = ' ';
len++;
}
while (*cp != '\0')
*bp++ = *cp++;
lfp++;
}
*bp = '\0';
output(fp, name, buf);
}
static char *
tstflags(
u_long val
)
{
register char *cb, *s;
register int i;
register const char *sep;
sep = "";
i = 0;
s = cb = &circ_buf[nextcb][0];
if (++nextcb >= NUMCB)
nextcb = 0;
sprintf(cb, "%02lx", val);
cb += strlen(cb);
if (!val) {
strcat(cb, " ok");
cb += strlen(cb);
} else {
*cb++ = ' ';
for (i = 0; i < 11; i++) {
if (val & 0x1) {
sprintf(cb, "%s%s", sep, tstflagnames[i]);
sep = ", ";
cb += strlen(cb);
}
val >>= 1;
}
}
*cb = '\0';
return s;
}
/*
* cookedprint - output variables in cooked mode
*/
static void
cookedprint(
int datatype,
int length,
char *data,
int status,
FILE *fp
)
{
register int varid;
char *name;
char *value;
int output_raw;
int fmt;
struct ctl_var *varlist;
l_fp lfp;
long ival;
u_int32 hval;
u_long uval;
l_fp lfparr[8];
int narr;
switch (datatype) {
case TYPE_PEER:
varlist = peer_var;
break;
case TYPE_SYS:
varlist = sys_var;
break;
case TYPE_CLOCK:
varlist = clock_var;
break;
default:
(void) fprintf(stderr, "Unknown datatype(0x%x) in cookedprint\n", datatype);
return;
}
(void) fprintf(fp, "status=%04x %s,\n", status,
statustoa(datatype, status));
startoutput();
while (nextvar(&length, &data, &name, &value)) {
varid = findvar(name, varlist);
if (varid == 0) {
output_raw = '*';
} else {
output_raw = 0;
fmt = varlist[varid].fmt;
switch(fmt) {
case TS:
if (!decodets(value, &lfp))
output_raw = '?';
else
output(fp, name, prettydate(&lfp));
break;
case FL:
case FU:
case FS:
if (!decodetime(value, &lfp))
output_raw = '?';
else {
switch (fmt) {
case FL:
output(fp, name,
lfptoms(&lfp, 3));
break;
case FU:
output(fp, name,
ulfptoms(&lfp, 3));
break;
case FS:
output(fp, name,
lfptoms(&lfp, 3));
break;
}
}
break;
case UI:
if (!decodeuint(value, &uval))
output_raw = '?';
else
output(fp, name, uinttoa(uval));
break;
case SI:
if (!decodeint(value, &ival))
output_raw = '?';
else
output(fp, name, inttoa(ival));
break;
case HA:
case NA:
if (!decodenetnum(value, &hval))
output_raw = '?';
else if (fmt == HA)
output(fp, name, nntohost(hval));
else
output(fp, name, numtoa(hval));
break;
case ST:
output_raw = '*';
break;
case RF:
if (decodenetnum(value, &hval))
output(fp, name, nntohost(hval));
else if ((int)strlen(value) <= 4)
output(fp, name, value);
else
output_raw = '?';
break;
case LP:
if (!decodeuint(value, &uval) || uval > 3)
output_raw = '?';
else {
char b[3];
b[0] = b[1] = '0';
if (uval & 0x2)
b[0] = '1';
if (uval & 0x1)
b[1] = '1';
b[2] = '\0';
output(fp, name, b);
}
break;
case OC:
if (!decodeuint(value, &uval))
output_raw = '?';
else {
char b[10];
(void) sprintf(b, "%03lo", uval);
output(fp, name, b);
}
break;
case MD:
if (!decodeuint(value, &uval))
output_raw = '?';
else
output(fp, name, uinttoa(uval));
break;
case AR:
if (!decodearr(value, &narr, lfparr))
output_raw = '?';
else
outputarr(fp, name, narr, lfparr);
break;
case FX:
if (!decodeuint(value, &uval))
output_raw = '?';
else
output(fp, name, tstflags(uval));
break;
default:
(void) fprintf(stderr,
"Internal error in cookedprint, %s=%s, fmt %d\n",
name, value, fmt);
break;
}
}
if (output_raw != 0) {
char bn[401];
char bv[401];
int len;
atoascii(400, name, bn);
atoascii(400, value, bv);
if (output_raw != '*') {
len = strlen(bv);
bv[len] = output_raw;
bv[len+1] = '\0';
}
output(fp, bn, bv);
}
}
endoutput(fp);
}
/*
* sortassoc - sort associations in the cache into ascending order
*/
void
sortassoc(void)
{
if (numassoc > 1)
qsort(
#ifdef QSORT_USES_VOID_P
(void *)
#else
(char *)
#endif
assoc_cache, (size_t)numassoc,
sizeof(struct association), assoccmp);
}
/*
* assoccmp - compare two associations
*/
#ifdef QSORT_USES_VOID_P
static int
assoccmp(
const void *t1,
const void *t2
)
{
const struct association *ass1 = (const struct association *)t1;
const struct association *ass2 = (const struct association *)t2;
if (ass1->assid < ass2->assid)
return -1;
if (ass1->assid > ass2->assid)
return 1;
return 0;
}
#else
static int
assoccmp(
struct association *ass1,
struct association *ass2
)
{
if (ass1->assid < ass2->assid)
return -1;
if (ass1->assid > ass2->assid)
return 1;
return 0;
}
#endif /* not QSORT_USES_VOID_P */
| 20.532734 | 103 | 0.574664 |
a27a57225981100e8d0fd3ae5f119559ea8aa2fe | 261 | h | C | arduino/timerservice.h | 980f/dro | 571452d480ea6f428c16a016e629dc3722a7fc7d | [
"MIT"
] | null | null | null | arduino/timerservice.h | 980f/dro | 571452d480ea6f428c16a016e629dc3722a7fc7d | [
"MIT"
] | null | null | null | arduino/timerservice.h | 980f/dro | 571452d480ea6f428c16a016e629dc3722a7fc7d | [
"MIT"
] | null | null | null | #ifndef TIMERSERVICE_H
#define TIMERSERVICE_H
#include "polledtimer.h"
extern "C" int sysTickHook(){
PolledTimerServer();//all of our millisecond stuff hangs off of here.
return false; //allowed standard code to run
}
#include "tableofpointers.h"
#endif
| 20.076923 | 71 | 0.758621 |
a2dc99fe33a575019c5fe75fc44ababc2f58d6d4 | 8,898 | c | C | components/coap/libcoap/ext/tinydtls/tests/unit-tests/test_ecc.c | jonathandreyer/framework-espidf | 521fb3cba210326d4ed160c6f9f49ee0f6e8f42d | [
"Apache-2.0"
] | null | null | null | components/coap/libcoap/ext/tinydtls/tests/unit-tests/test_ecc.c | jonathandreyer/framework-espidf | 521fb3cba210326d4ed160c6f9f49ee0f6e8f42d | [
"Apache-2.0"
] | null | null | null | components/coap/libcoap/ext/tinydtls/tests/unit-tests/test_ecc.c | jonathandreyer/framework-espidf | 521fb3cba210326d4ed160c6f9f49ee0f6e8f42d | [
"Apache-2.0"
] | null | null | null | /*******************************************************************************
*
* Copyright (c) 2020 Olaf Bergmann (TZI) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
*
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
#include <assert.h>
#include "dtls_config.h"
#include "dtls_prng.h"
#include "test_ecc.h"
#include "ecc/ecc.h"
#include "tinydtls.h"
#include "crypto.h"
#include <stdio.h>
//These are testvalues taken from the NIST P-256 definition
//6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296
uint32_t BasePointx[8] = { 0xd898c296, 0xf4a13945, 0x2deb33a0, 0x77037d81,
0x63a440f2, 0xf8bce6e5, 0xe12c4247, 0x6b17d1f2};
//4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5
uint32_t BasePointy[8] = { 0x37bf51f5, 0xcbb64068, 0x6b315ece, 0x2bce3357,
0x7c0f9e16, 0x8ee7eb4a, 0xfe1a7f9b, 0x4fe342e2};
//de2444be bc8d36e6 82edd27e 0f271508 617519b3 221a8fa0 b77cab39 89da97c9
uint32_t Sx[8] = { 0x89da97c9, 0xb77cab39, 0x221a8fa0, 0x617519b3,
0x0f271508, 0x82edd27e, 0xbc8d36e6, 0xde2444be};
//c093ae7f f36e5380 fc01a5aa d1e66659 702de80f 53cec576 b6350b24 3042a256
uint32_t Sy[8] = { 0x3042a256, 0xb6350b24, 0x53cec576, 0x702de80f,
0xd1e66659, 0xfc01a5aa, 0xf36e5380, 0xc093ae7f};
//55a8b00f 8da1d44e 62f6b3b2 5316212e 39540dc8 61c89575 bb8cf92e 35e0986b
uint32_t Tx[8] = { 0x35e0986b, 0xbb8cf92e, 0x61c89575, 0x39540dc8,
0x5316212e, 0x62f6b3b2, 0x8da1d44e, 0x55a8b00f};
//5421c320 9c2d6c70 4835d82a c4c3dd90 f61a8a52 598b9e7a b656e9d8 c8b24316
uint32_t Ty[8] = { 0xc8b24316, 0xb656e9d8, 0x598b9e7a, 0xf61a8a52,
0xc4c3dd90, 0x4835d82a, 0x9c2d6c70, 0x5421c320};
//c51e4753 afdec1e6 b6c6a5b9 92f43f8d d0c7a893 3072708b 6522468b 2ffb06fd
uint32_t secret[8] = { 0x2ffb06fd, 0x6522468b, 0x3072708b, 0xd0c7a893,
0x92f43f8d, 0xb6c6a5b9, 0xafdec1e6, 0xc51e4753};
//72b13dd4 354b6b81 745195e9 8cc5ba69 70349191 ac476bd4 553cf35a 545a067e
uint32_t resultAddx[8] = { 0x545a067e, 0x553cf35a, 0xac476bd4, 0x70349191,
0x8cc5ba69, 0x745195e9, 0x354b6b81, 0x72b13dd4};
//8d585cbb 2e1327d7 5241a8a1 22d7620d c33b1331 5aa5c9d4 6d013011 744ac264
uint32_t resultAddy[8] = { 0x744ac264, 0x6d013011, 0x5aa5c9d4, 0xc33b1331,
0x22d7620d, 0x5241a8a1, 0x2e1327d7, 0x8d585cbb};
//7669e690 1606ee3b a1a8eef1 e0024c33 df6c22f3 b17481b8 2a860ffc db6127b0
uint32_t resultDoublex[8] = { 0xdb6127b0, 0x2a860ffc, 0xb17481b8, 0xdf6c22f3,
0xe0024c33, 0xa1a8eef1, 0x1606ee3b, 0x7669e690};
//fa878162 187a54f6 c39f6ee0 072f33de 389ef3ee cd03023d e10ca2c1 db61d0c7
uint32_t resultDoubley[8] = { 0xdb61d0c7, 0xe10ca2c1, 0xcd03023d, 0x389ef3ee,
0x072f33de, 0xc39f6ee0, 0x187a54f6, 0xfa878162};
//51d08d5f 2d427888 2946d88d 83c97d11 e62becc3 cfc18bed acc89ba3 4eeca03f
uint32_t resultMultx[8] = { 0x4eeca03f, 0xacc89ba3, 0xcfc18bed, 0xe62becc3,
0x83c97d11, 0x2946d88d, 0x2d427888, 0x51d08d5f};
//75ee68eb 8bf626aa 5b673ab5 1f6e744e 06f8fcf8 a6c0cf30 35beca95 6a7b41d5
uint32_t resultMulty[8] = { 0x6a7b41d5, 0x35beca95, 0xa6c0cf30, 0x06f8fcf8,
0x1f6e744e, 0x5b673ab5, 0x8bf626aa, 0x75ee68eb};
static const uint32_t ecdsaTestMessage[] = { 0x65637572, 0x20612073, 0x68206F66, 0x20686173, 0x69732061, 0x68697320, 0x6F2C2054, 0x48616C6C};
static const uint32_t ecdsaTestSecret[] = {0x94A949FA, 0x401455A1, 0xAD7294CA, 0x896A33BB, 0x7A80E714, 0x4321435B, 0x51247A14, 0x41C1CB6B};
static const uint32_t ecdsaTestRand1[] = { 0x1D1E1F20, 0x191A1B1C, 0x15161718, 0x11121314, 0x0D0E0F10, 0x090A0B0C, 0x05060708, 0x01020304};
static const uint32_t ecdsaTestresultR1[] = { 0xC3B4035F, 0x515AD0A6, 0xBF375DCA, 0x0CC1E997, 0x7F54FDCD, 0x04D3FECA, 0xB9E396B9, 0x515C3D6E};
static const uint32_t ecdsaTestresultS1[] = { 0x5366B1AB, 0x0F1DBF46, 0xB0C8D3C4, 0xDB755B6F, 0xB9BF9243, 0xE644A8BE, 0x55159A59, 0x6F9E52A6};
static const uint32_t ecdsaTestRand2[] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x01FFFFFF};
static const uint32_t ecdsaTestresultR2[] = { 0x14146C91, 0xE878724D, 0xCD4FF928, 0xCC24BC04, 0xAC403390, 0x650C0060, 0x4A30B3F1, 0x9C69B726};
static const uint32_t ecdsaTestresultS2[] = { 0x433AAB6F, 0x808250B1, 0xE46F90F4, 0xB342E972, 0x18B2F7E4, 0x2DB981A2, 0x6A288FA4, 0x41CF59DB};
static void
t_test_ecc_add(void) {
uint32_t tempx[8];
uint32_t tempy[8];
ecc_ec_add(Tx, Ty, Sx, Sy, tempx, tempy);
CU_ASSERT(ecc_isSame(tempx, resultAddx, arrayLength));
CU_ASSERT(ecc_isSame(tempy, resultAddy, arrayLength));
}
static void
t_test_ecc_double(void) {
uint32_t tempx[8];
uint32_t tempy[8];
ecc_ec_double(Sx, Sy, tempx, tempy);
CU_ASSERT(ecc_isSame(tempx, resultDoublex, arrayLength));
CU_ASSERT(ecc_isSame(tempy, resultDoubley, arrayLength));
}
static void
t_test_ecc_mult(void) {
uint32_t tempx[8];
uint32_t tempy[8];
ecc_ec_mult(Sx, Sy, secret, tempx, tempy);
CU_ASSERT(ecc_isSame(tempx, resultMultx, arrayLength));
CU_ASSERT(ecc_isSame(tempy, resultMulty, arrayLength));
}
static void
t_test_ecc_dh(void) {
uint32_t tempx[8];
uint32_t tempy[8];
uint32_t tempAx2[8];
uint32_t tempAy2[8];
uint32_t tempBx1[8];
uint32_t tempBy1[8];
uint32_t tempBx2[8];
uint32_t tempBy2[8];
uint32_t secretA[8];
uint32_t secretB[8];
int ret;
ret = dtls_prng((void *)secretA, sizeof(secretA));
CU_ASSERT(ret > 1);
ret = dtls_prng((void *)secretB, sizeof(secretB));
CU_ASSERT(ret > 1);
ecc_ec_mult(BasePointx, BasePointy, secretA, tempx, tempy);
ecc_ec_mult(BasePointx, BasePointy, secretB, tempBx1, tempBy1);
//public key exchange
ecc_ec_mult(tempBx1, tempBy1, secretA, tempAx2, tempAy2);
ecc_ec_mult(tempx, tempy, secretB, tempBx2, tempBy2);
CU_ASSERT(ecc_isSame(tempAx2, tempBx2, arrayLength));
CU_ASSERT(ecc_isSame(tempAy2, tempBy2, arrayLength));
}
static void
t_test_ecc_ecdsa(void) {
int ret;
uint32_t tempx[9];
uint32_t tempy[9];
uint32_t pub_x[8];
uint32_t pub_y[8];
ecc_ec_mult(BasePointx, BasePointy, ecdsaTestSecret, pub_x, pub_y);
ret = ecc_ecdsa_sign(ecdsaTestSecret, ecdsaTestMessage, ecdsaTestRand1, tempx, tempy);
assert(ecc_isSame(tempx, ecdsaTestresultR1, arrayLength));
assert(ecc_isSame(tempy, ecdsaTestresultS1, arrayLength));
assert(ret == 0);
ret = ecc_ecdsa_validate(pub_x, pub_y, ecdsaTestMessage, tempx, tempy);
assert(ret == 0);
ret = ecc_ecdsa_sign(ecdsaTestSecret, ecdsaTestMessage, ecdsaTestRand2, tempx, tempy);
assert(ecc_isSame(tempx, ecdsaTestresultR2, arrayLength));
assert(ecc_isSame(tempy, ecdsaTestresultS2, arrayLength));
assert(ret == 0);
ret = ecc_ecdsa_validate(pub_x, pub_y, ecdsaTestMessage, tempx, tempy);
assert(ret == 0);
}
static void
t_test_ecc_ecdsa0(void) {
int ret;
uint32_t tempx[9] = {0x433aab6f, 0x36dfe2c6, 0xf9f2ed29, 0xda0a9a8f, 0x62684e91, 0x6375ba10, 0x300c28c5, 0xe47cfbf2, 0x5fa58f52};
uint32_t tempy[9];
uint32_t pub_x[8];
uint32_t pub_y[8];
ecc_ec_mult(BasePointx, BasePointy, ecdsaTestSecret, pub_x, pub_y);
ret = ecc_ecdsa_sign(ecdsaTestSecret, ecdsaTestMessage, ecdsaTestRand1, tempx, tempy);
memset(tempy, 0, sizeof(tempy));
ret = ecc_ecdsa_validate(pub_x, pub_y, ecdsaTestMessage, tempx, tempy);
CU_ASSERT(ret == -1);
}
CU_pSuite
t_init_ecc_tests(void) {
CU_pSuite suite;
suite = CU_add_suite("ECC", NULL, NULL);
if (!suite) { /* signal error */
fprintf(stderr, "W: cannot add ECC test suite (%s)\n",
CU_get_error_msg());
return NULL;
}
/* On POSIX system, getrandom() is used where available, ignoring
* the seed. For other platforms, the random sequence will be the
* same for each run. */
dtls_prng_init(0);
if (!CU_ADD_TEST(suite,t_test_ecc_add)) {
fprintf(stderr, "W: cannot add test for ECC add (%s)\n",
CU_get_error_msg());
}
if (!CU_ADD_TEST(suite,t_test_ecc_double)) {
fprintf(stderr, "W: cannot add test for ECC double (%s)\n",
CU_get_error_msg());
}
if (!CU_ADD_TEST(suite,t_test_ecc_mult)) {
fprintf(stderr, "W: cannot add test for ECC mult (%s)\n",
CU_get_error_msg());
}
if (!CU_ADD_TEST(suite,t_test_ecc_dh)) {
fprintf(stderr, "W: cannot add test for ECC DH (%s)\n",
CU_get_error_msg());
}
if (!CU_ADD_TEST(suite,t_test_ecc_ecdsa)) {
fprintf(stderr, "W: cannot add test for ECC ECDSA (%s)\n",
CU_get_error_msg());
}
if (!CU_ADD_TEST(suite,t_test_ecc_ecdsa0)) {
fprintf(stderr, "W: cannot add test for ECC ECDSA with invalid argument (%s)\n",
CU_get_error_msg());
}
return suite;
}
| 36.617284 | 142 | 0.73612 |
bd5136438bee68317e75e5ddcd78cdff1777ca4c | 364 | h | C | server/src/requests/IRequestHandler.h | kosiacz3q/IRC | bef36e8321b15763c1826c903f9a976a5f51ba58 | [
"MIT"
] | null | null | null | server/src/requests/IRequestHandler.h | kosiacz3q/IRC | bef36e8321b15763c1826c903f9a976a5f51ba58 | [
"MIT"
] | null | null | null | server/src/requests/IRequestHandler.h | kosiacz3q/IRC | bef36e8321b15763c1826c903f9a976a5f51ba58 | [
"MIT"
] | null | null | null | #ifndef IREQUESTHANDLER_H_
#define IREQUESTHANDLER_H_
#include <memory>
#include "jsonParserFwd.h"
class IRequestHandler
{
public:
virtual ~IRequestHandler(){};
virtual void handleRequest(rapidjson::Document& doc) = 0;
virtual std::string getType() = 0;
};
typedef std::shared_ptr<IRequestHandler> IRequestHandlerPtr;
#endif /* IREQUESTHANDLER_H_ */
| 17.333333 | 60 | 0.755495 |
0321b400d53c8bd8296da680cdc54b40170f2c72 | 1,433 | h | C | include/public/serviceinstall.h | webosce/serviceinstaller | b556d29ffa6a9be9665ee897654c4632fea10b05 | [
"Apache-2.0"
] | 3 | 2018-03-22T18:52:34.000Z | 2019-05-06T05:23:42.000Z | include/public/serviceinstall.h | webosose/serviceinstaller | f7ac01e06bba81de4f21f004533dbee507a85f1c | [
"Apache-2.0"
] | null | null | null | include/public/serviceinstall.h | webosose/serviceinstaller | f7ac01e06bba81de4f21f004533dbee507a85f1c | [
"Apache-2.0"
] | 3 | 2018-03-22T18:52:36.000Z | 2022-02-26T15:56:47.000Z | // Copyright (c) 2010-2018 LG Electronics, Inc.
//
// 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.
//
// SPDX-License-Identifier: Apache-2.0
#include <string>
#include <iostream>
#include <fstream>
#include <dirent.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <glib.h>
#include <luna-service2/lunaservice.h>
#include <string.h>
#include <pbnjson.hpp>
#include "rolegen.h"
//#define DEBUG 1
#define CONFIGURATOR_REGISTER_URL "palm://com.palm.configurator/scan"
#define CONFIGURATOR_UNREGISTER_URL "palm://com.palm.configurator/unconfigure"
#define PUBLIC_ENDPOINT_ROOT WEBOS_INSTALL_SYSBUS_DYNPUBSERVICESDIR
#define PRIVATE_ENDPOINT_ROOT WEBOS_INSTALL_SYSBUS_DYNPRVSERVICESDIR
#define TYPE_SERVICE "services"
#define TYPE_APP "applications"
using namespace std;
void installApp(string id, string type, string root);
void uninstallApp(string id, string type, string root);
| 30.489362 | 78 | 0.769714 |
643d681633a717216a55d3d9cec4109ef49c8fa1 | 327 | c | C | dip_switch.c | Compotes/master-2018 | 50084319bbe70cf5f361d4ef42b726f4c2b0295b | [
"MIT"
] | null | null | null | dip_switch.c | Compotes/master-2018 | 50084319bbe70cf5f361d4ef42b726f4c2b0295b | [
"MIT"
] | null | null | null | dip_switch.c | Compotes/master-2018 | 50084319bbe70cf5f361d4ef42b726f4c2b0295b | [
"MIT"
] | null | null | null | #include "dip_switch.h"
uint8_t get_dip_switch(void){
uint8_t ret;
ret = palReadPad(GPIOD, 9);
ret = (ret << 1) | palReadPad(GPIOD, 8);
ret = (ret << 1) | palReadPad(GPIOB, 15);
ret = (ret << 1) | palReadPad(GPIOB, 14);
ret = (ret << 1) | palReadPad(GPIOB, 13);
ret = (ret << 1) | palReadPad(GPIOB, 12);
return ret;
}
| 25.153846 | 42 | 0.611621 |
ea9e885e52f9679d6e3ffe44968865eb074aabfe | 526 | h | C | objcProperty/NSObject+VDProperty.h | vilyever/objcProperty | 982977ec9485c16bbd30d736cb24208e2cc1cc41 | [
"MIT"
] | 1 | 2019-07-31T09:14:13.000Z | 2019-07-31T09:14:13.000Z | objcProperty/NSObject+VDProperty.h | vilyever/objcProperty | 982977ec9485c16bbd30d736cb24208e2cc1cc41 | [
"MIT"
] | null | null | null | objcProperty/NSObject+VDProperty.h | vilyever/objcProperty | 982977ec9485c16bbd30d736cb24208e2cc1cc41 | [
"MIT"
] | null | null | null | //
// NSObject+VDProperty.h
// objcProperty
//
// Created by Deng on 16/8/5.
// Copyright © Deng. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "VDProperty.h"
@interface NSObject (VDProperty)
#pragma mark Constructor
#pragma mark Public Method
+ (NSArray *)vd_properties;
+ (NSArray *)vd_propertiesTraceToAncestorClass:(Class)ancestorClass;
+ (VDProperty *)vd_propertyWithName:(NSString *)propertyName;
#pragma mark Properties
#pragma mark Protected Method
#pragma mark Private Method
@end
| 16.4375 | 68 | 0.745247 |
c123e4e457eaa8b5467a97237418e4bfed1b945d | 563 | h | C | WeChat/WeChat/Model/Search/MHSearch.h | xwlxwl/WeChat | a21453e848efb42309d3a9fdcdecbd86ab3fa42b | [
"MIT"
] | 1,067 | 2017-09-04T14:30:18.000Z | 2022-03-29T07:02:42.000Z | WeChat/WeChat/Model/Search/MHSearch.h | xwlxwl/WeChat | a21453e848efb42309d3a9fdcdecbd86ab3fa42b | [
"MIT"
] | 27 | 2018-01-22T08:33:11.000Z | 2022-03-10T05:58:28.000Z | WeChat/WeChat/Model/Search/MHSearch.h | xwlxwl/WeChat | a21453e848efb42309d3a9fdcdecbd86ab3fa42b | [
"MIT"
] | 245 | 2017-11-01T05:57:50.000Z | 2022-03-25T12:53:30.000Z | //
// MHSearch.h
// WeChat
//
// Created by 何千元 on 2020/5/16.
// Copyright © 2020 CoderMikeHe. All rights reserved.
//
#import "MHObject.h"
NS_ASSUME_NONNULL_BEGIN
@interface MHSearch : MHObject
/// keyword
@property (nonatomic, readwrite, copy) NSString *keyword;
/// searchMode
@property (nonatomic, readwrite, assign) MHSearchMode searchMode;
+ (instancetype) searchWithKeyword:(NSString *)keyword searchMode:(MHSearchMode)searchMode;
- (instancetype) initWithKeyword:(NSString *)keyword searchMode:(MHSearchMode)searchMode;
@end
NS_ASSUME_NONNULL_END
| 24.478261 | 91 | 0.763766 |
26b788bdbb8bc876e8aa0a82d7b017812e619f31 | 1,675 | h | C | include/dwt/os.h | dwtscript/dwt | ca0c0b0edb5cc6318f384121fe5630fc7fced598 | [
"MIT"
] | 1 | 2022-01-05T21:31:50.000Z | 2022-01-05T21:31:50.000Z | include/dwt/os.h | dwtscript/dwt | ca0c0b0edb5cc6318f384121fe5630fc7fced598 | [
"MIT"
] | 1 | 2022-03-27T14:13:42.000Z | 2022-03-27T14:13:42.000Z | include/dwt/os.h | dwtscript/dwt | ca0c0b0edb5cc6318f384121fe5630fc7fced598 | [
"MIT"
] | 1 | 2021-12-02T22:42:24.000Z | 2021-12-02T22:42:24.000Z | /* SPDX-FileCopyrightText: (c) 2021 Andrew Scott-Jones <andrew@dwtscript.org>
* SPDX-License-Identifier: MIT
*/
#ifndef GUARD_DWT_OS_H
#define GUARD_DWT_OS_H
#include <dwt/config.h>
#include <dwt/macros.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#define dwt_snprintf snprintf
#define dwt_assert assert
#define dwt_dwt_memset dwt_memset
#define dwt_memset memset
#define dwt_memmove memmove
#define dwt_memcpy memcpy
#define dwt_memcmp memcmp
#define dwt_strlen strlen
#define dwt_getchar getchar
#define dwt_putchar putchar
#define dwt_isalpha isalpha
#define dwt_isdigit isdigit
#define dwt_ptrdiff_t ptrdiff_t
#define dwt_srand srand
#define dwt_rand rand
#define dwt_clock clock
#define DWT_CLOCKS_PER_SEC CLOCKS_PER_SEC
#define DWT_EOF EOF
BEGIN_C_DECLS
CFG_CHECK
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
typedef int64_t s64;
typedef int32_t s32;
typedef int16_t s16;
typedef int8_t s8;
typedef void (*dwt_out_fn)(const char *fmt, ...);
EXPORT void
dwt_printf(const char *fmt, ...);
EXPORT void
dwt_debugf(const char *fmt, ...);
EXPORT void
dwt_vdebugf(const char *fmt, va_list va);
EXPORT void *
dwt_fopen(const char *filename, const char *mode);
EXPORT size_t
dwt_fread(void *ptr, size_t size, size_t nmemb, void *file);
EXPORT size_t
dwt_fwrite(const void *ptr, size_t size, size_t nmemb, void *file);
EXPORT int
dwt_fseek(void *file, long int offset, int whence);
EXPORT long int
dwt_ftell(void *file);
EXPORT int
dwt_fclose(void *file);
ENDOF_C_DECLS
#endif
| 19.705882 | 77 | 0.773134 |
142508cbeb031f0592338268f2dca75beb9caced | 1,332 | h | C | vm_tools/pstore_dump/persistent_ram_buffer.h | Toromino/chromiumos-platform2 | 97e6ba18f0e5ab6723f3448a66f82c1a07538d87 | [
"BSD-3-Clause"
] | null | null | null | vm_tools/pstore_dump/persistent_ram_buffer.h | Toromino/chromiumos-platform2 | 97e6ba18f0e5ab6723f3448a66f82c1a07538d87 | [
"BSD-3-Clause"
] | null | null | null | vm_tools/pstore_dump/persistent_ram_buffer.h | Toromino/chromiumos-platform2 | 97e6ba18f0e5ab6723f3448a66f82c1a07538d87 | [
"BSD-3-Clause"
] | null | null | null | // Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef VM_TOOLS_PSTORE_DUMP_PERSISTENT_RAM_BUFFER_H_
#define VM_TOOLS_PSTORE_DUMP_PERSISTENT_RAM_BUFFER_H_
#include <stdint.h>
#include <string>
#include <utility>
#include <base/files/file_path.h>
namespace vm_tools {
namespace pstore_dump {
// From fs/pstore/ram_core.c
/**
* struct persistent_ram_buffer - persistent circular RAM buffer
*
* @sig:
* signature to indicate header (PERSISTENT_RAM_SIG xor PRZ-type value)
* @start:
* offset into @data where the beginning of the stored bytes begin
* @size:
* number of valid bytes stored in @data
*/
struct persistent_ram_buffer {
uint32_t sig;
uint32_t start;
uint32_t size;
uint8_t data[0];
};
// From fs/pstore/ram_core.c
#define PERSISTENT_RAM_SIG (0x43474244) /* DBGC */
bool GetPersistentRamBufferContent(const persistent_ram_buffer* buf,
size_t buf_capacity,
std::string* out_content);
bool HandlePstore(const base::FilePath& path);
bool HandlePstoreDmesg(const base::FilePath& path);
} // namespace pstore_dump
} // namespace vm_tools
#endif // VM_TOOLS_PSTORE_DUMP_PERSISTENT_RAM_BUFFER_H_
| 27.183673 | 76 | 0.720721 |
144485e8d061f98125e9956141d53bbaa52e5c6a | 233,629 | c | C | sdk-6.5.20/src/bcm/common/tx.c | copslock/broadcom_cpri | 8e2767676e26faae270cf485591902a4c50cf0c5 | [
"Spencer-94"
] | null | null | null | sdk-6.5.20/src/bcm/common/tx.c | copslock/broadcom_cpri | 8e2767676e26faae270cf485591902a4c50cf0c5 | [
"Spencer-94"
] | null | null | null | sdk-6.5.20/src/bcm/common/tx.c | copslock/broadcom_cpri | 8e2767676e26faae270cf485591902a4c50cf0c5 | [
"Spencer-94"
] | null | null | null | /*
*
* This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
*
* Copyright 2007-2020 Broadcom Inc. All rights reserved.
*/
#ifdef BCM_HIDE_DISPATCHABLE
#undef BCM_HIDE_DISPATCHABLE
#endif
#include <shared/bsl.h>
#include <assert.h>
#include <sal/types.h>
#include <sal/core/time.h>
#include <sal/core/boot.h>
#include <shared/bsl.h>
#include <soc/dma.h>
#include <soc/cm.h>
#include <soc/dcbformats.h>
#include <soc/debug.h>
#include <soc/drv.h>
#include <soc/util.h>
#include <soc/error.h>
#include <soc/higig.h>
#include <soc/pbsmh.h>
#include <soc/enet.h>
#include <soc/loopback.h>
#if defined(BCM_CPU_TX_PROC_SUPPORT)
#include <soc/proc_hdr.h>
#endif /* BCM_CPU_TX_PROC_SUPPORT */
#if defined(BCM_BRADLEY_SUPPORT)
#include <soc/bradley.h>
#endif
#if defined(BCM_TRIUMPH_SUPPORT)
#include <bcm_int/esw/triumph.h>
#endif
#if defined(BCM_TRIDENT2_SUPPORT)
#include <soc/trident2.h>
#endif
#if defined(BCM_APACHE_SUPPORT)
#include <soc/apache.h>
#endif
#if defined(BCM_MONTEREY_SUPPORT)
#include <soc/monterey.h>
#endif
#if defined(BCM_TOMAHAWK3_SUPPORT)
#include <soc/tomahawk3.h>
#endif
#include <soc/dnxc/multithread_analyzer.h>
#ifdef BCM_DNX_SUPPORT
#include <soc/dnx/dnx_er_threading.h>
#endif
#if defined(BCM_ESW_SUPPORT)
#include <bcm_int/esw/tx.h>
#if defined(BCM_INSTRUMENTATION_SUPPORT)
#include <bcm_int/esw/instrumentation.h>
#endif /* BCM_INSTRUMENTATION_SUPPORT */
#endif
#include <bcm_int/control.h>
#include <bcm/pkt.h>
#include <bcm/tx.h>
#include <bcm/stack.h>
#include <bcm/error.h>
#if defined(BCM_ESW_SUPPORT)
#include <bcm_int/common/multicast.h>
#include <bcm_int/esw/rcpu.h>
#include <bcm_int/esw/stack.h>
#endif
#include <bcm_int/api_xlate_port.h>
#include <bcm_int/common/tx.h>
#if defined(BCM_ESW_SUPPORT)
#include <bcm_int/esw/tx.h>
#endif
#if defined(INCLUDE_L3) && defined(BCM_XGS_SWITCH_SUPPORT)
#include <bcm_int/esw/firebolt.h>
#endif /* INCLUDE_L3 && BCM_XGS_SWITCH_SUPPORT */
#if defined(INCLUDE_L3) && defined(BCM_TRX_SUPPORT)
#include <bcm_int/esw/vpn.h>
#endif /* INCLUDE_L3 && BCM_TRX_SUPPORT */
#if defined (BCM_ARAD_SUPPORT)
#include <soc/dpp/ARAD/arad_action_cmd.h>
#endif
#if defined(BCM_ESW_SUPPORT) || defined (BCM_ARAD_SUPPORT) || defined (BCM_DNX_SUPPORT)
#if defined (BCM_OLP_SUPPORT)
#include <soc/shared/olp_pkt.h>
#include <soc/shared/olp_pack.h>
#endif
#if defined(BCM_TRIDENT2PLUS_SUPPORT) || defined (BCM_SABER2_SUPPORT)
#include <bcm_int/esw/flex_ctr.h>
#include <bcm_int/esw/switch.h>
#endif
#if defined(BCM_TRIDENT3_SUPPORT)
#include <bcm_int/esw/trident3.h>
#endif
#if defined(BCM_HGPROXY_COE_SUPPORT)
#include <bcm_int/esw/subport.h>
#include <bcm_int/esw/xgs5.h>
#endif
#if defined(BROADCOM_DEBUG)
int bcm_tx_pkt_count[BCM_COS_COUNT];
int bcm_tx_pkt_count_bad_cos;
#endif /* BROADCOM_DEBUG */
#if defined(BCM_TRIDENT2PLUS_SUPPORT) && defined(BCM_TX_HGOE_LIMITED_SOLUTION)
#if defined (BROADCOM_DEBUG) && defined(BCM_TX_HGOE_DBG)
typedef struct _bcm_tx_hgoe_dbg_ctr_s {
sal_sem_t tx_hgoe_ctr_sem;
uint32 both_cb_cnt;
uint32 internal_fail_cnt;
uint32 dma_alloc_cnt;
uint32 dma_free_cnt;
uint32 blk_alloc_cnt;
uint32 blk_free_cnt;
uint32 ck_alloc_cnt;
uint32 ck_free_cnt;
uint32 pkt_blk_chg_cnt;
uint32 pkt_blk_rvt_cnt;
uint32 tx_list_master_ck_cnt;
uint32 tx_list_pkt_ck_arr_cnt;
uint32 tx_list_port_info_cnt;
} bcm_tx_hgoe_dbg_ctr_t;
volatile bcm_tx_hgoe_dbg_ctr_t g_hgoe_dbg_ctrs = {0};
#define BCM_TX_HGOE_DBG_CTR_SEM_ACQ \
sal_sem_take(g_hgoe_dbg_ctrs.tx_hgoe_ctr_sem, sal_sem_FOREVER);
#define BCM_TX_HGOE_DBG_CTR_SEM_REL \
sal_sem_give(g_hgoe_dbg_ctrs.tx_hgoe_ctr_sem);
#define BCM_TX_HGOE_DBG_CTR_SEM_INCR(_ctr_) \
{\
BCM_TX_HGOE_DBG_CTR_SEM_ACQ; \
(g_hgoe_dbg_ctrs._ctr_)++; \
BCM_TX_HGOE_DBG_CTR_SEM_REL; \
}
#define BCM_TX_HGOE_DBG_CTR_SEM_DECR(_ctr_) \
{\
BCM_TX_HGOE_DBG_CTR_SEM_ACQ; \
(g_hgoe_dbg_ctrs._ctr_)--;\
BCM_TX_HGOE_DBG_CTR_SEM_REL; \
}
#define BCM_TX_HGOE_DBG_CTR_INCR(_ctr_) { (g_hgoe_dbg_ctrs._ctr_)++; }
#define BCM_TX_HGOE_DBG_CTR_DECR(_ctr_) { (g_hgoe_dbg_ctrs._ctr_)--; }
#else
#define BCM_TX_HGOE_DBG_CTR_SEM_ACQ
#define BCM_TX_HGOE_DBG_CTR_SEM_REL
#define BCM_TX_HGOE_DBG_CTR_SEM_INCR(_ctr_)
#define BCM_TX_HGOE_DBG_CTR_SEM_DECR(_ctr_)
#define BCM_TX_HGOE_DBG_CTR_INCR(_ctr_)
#define BCM_TX_HGOE_DBG_CTR_DECR(_ctr_)
#endif
#endif /* BCM_TRIDENT2PLUS_SUPPORT && BCM_TX_HGOE_LIMITED_SOLUTION */
/* Forward declarations of static functions */
STATIC dv_t *_tx_dv_alloc(int unit, int pkt_count, int dcb_count,
bcm_pkt_cb_f call_back, void *cookie, int pkt_cb);
STATIC void _tx_dv_free(int unit, dv_t *dv);
STATIC int _tx_pkt_desc_add(int unit, bcm_pkt_t *pkt, dv_t *dv, int pkt_idx);
#if defined(BCM_PETRA_SUPPORT) || defined(BCM_DNX_SUPPORT)
STATIC int _sand_tx_pkt_desc_add(int unit, bcm_pkt_t *pkt, dv_t *dv, int pkt_idx);
#endif
STATIC int _bcm_tx_chain_send(int unit, dv_t *dv, int async);
STATIC void _bcm_tx_chain_done_cb(int unit, dv_t *dv);
STATIC void _bcm_tx_desc_done_cb(int unit, dv_t *dv, dcb_t *dcb);
STATIC void _bcm_tx_reload_done_cb(int unit, dv_t *dv);
STATIC void _bcm_tx_chain_done(int unit, dv_t *dv);
STATIC void _bcm_tx_desc_done(int unit, dv_t *dv, dcb_t *dcb);
STATIC void _bcm_tx_reload_done(int unit, dv_t *dv);
STATIC void _bcm_tx_packet_done_cb(int unit, dv_t *dv, dcb_t *dcb);
STATIC void _bcm_tx_packet_done(bcm_pkt_t *pkt);
STATIC void _bcm_tx_callback_thread(void *param);
#if defined (BCM_ARAD_SUPPORT) || defined (BCM_DNX_SUPPORT)
STATIC INLINE int _bcm_tx_pkt_tag_setup(int unit, bcm_pkt_t *pkt);
#if (defined (BCM_ARAD_SUPPORT) || defined (BCM_DNX_SUPPORT)) && !defined (BCM_ESW_SUPPORT)
typedef struct stk_tag_s {
#if defined(LE_HOST)
uint32 rsvp:2;
uint32 stk_modid:5;
uint32 ed:1;
uint32 em:1;
uint32 md:1;
uint32 mirr:1;
uint32 pfm:2;
uint32 dst_rtag:3;
uint32 dst_tgid:3;
uint32 dst_t:1;
uint32 src_rtag:3;
uint32 src_tgid:3;
uint32 src_t:1;
uint32 stk_cnt:5;
#else
uint32 stk_cnt:5;
uint32 src_t:1;
uint32 src_tgid:3;
uint32 src_rtag:3;
uint32 dst_t:1;
uint32 dst_tgid:3;
uint32 dst_rtag:3;
uint32 pfm:2;
uint32 mirr:1;
uint32 md:1;
uint32 em:1;
uint32 ed:1;
uint32 stk_modid:5;
uint32 rsvp:2;
#endif
} stk_tag_t;
typedef struct tx_dv_info_s {
volatile bcm_pkt_t **pkt;
int pkt_count;
volatile uint8 pkt_done_cnt;
bcm_pkt_cb_f chain_done_cb;
void *cookie;
} tx_dv_info_t;
#define TX_INFO_SET(dv, val) ((dv)->dv_public1.ptr = val)
#define TX_INFO(dv) ((tx_dv_info_t *)((dv)->dv_public1.ptr))
#define TX_INFO_PKT_ADD(dv, pkt) \
TX_INFO(dv)->pkt[TX_INFO(dv)->pkt_count++] = (pkt)
#define TX_INFO_CUR_PKT(dv) (TX_INFO(dv)->pkt[TX_INFO(dv)->pkt_done_cnt])
#define TX_INFO_PKT_MARK_DONE(dv) ((TX_INFO(dv)->pkt_done_cnt)++)
#define TX_DV_NEXT(dv) ((dv_t *)((dv)->dv_public2.ptr))
#define TX_DV_NEXT_SET(dv, dv_next) \
((dv)->dv_public2.ptr = (void *)(dv_next))
#define TX_EXTRA_DCB_COUNT 4
#endif
#endif
#ifdef BCM_XGS3_SWITCH_SUPPORT
typedef struct _xgs3_async_queue_s {
struct _xgs3_async_queue_s * next;
int unit;
bcm_pkt_t * pkt;
void * cookie;
} _xgs3_async_queue_t;
static _xgs3_async_queue_t * _xgs3_async_head;
static _xgs3_async_queue_t * _xgs3_async_tail;
static sal_sem_t _xgs3_async_tx_sem;
static sal_spinlock_t _xgs3_async_queue_lock;
STATIC void _xgs3_async_thread(void * param);
#endif
/* Some macros:
*
* _ON_ERROR_GOTO: Check the return code of an action;
* if error, goto the label provided.
* _PROCESS_ERROR: If rv indicates an error, free the DV (if non-NULL)
* and display the "err_msg" if provided.
*/
#define _ON_ERROR_GOTO(act, rv, label) if (((rv) = (act)) < 0) goto label
#define _PROCESS_ERROR(unit, rv, dv, err_msg) \
do { \
if ((rv) < 0) { /* Error detected */ \
if (dv != NULL) { \
_tx_dv_free(unit, dv); \
} \
if (err_msg) { \
LOG_ERROR(BSL_LS_BCM_TX, \
(BSL_META_U(unit, \
"bcm_tx: %s\n"), err_msg)); \
} \
} \
} while (0)
/* Call back synchronization and lists */
static sal_sem_t tx_cb_sem = NULL;
/* Used to notify tx DV available */
static sal_sem_t tx_dv_done = NULL;
/* used to notify tx thread had exit */
static sal_sem_t tx_exit_notify = NULL;
volatile static dv_t *dv_pend_first;
volatile static dv_t *dv_pend_last;
volatile static dv_t *dvdesc_pend_first;
volatile static dv_t *dvdesc_pend_last;
volatile static dv_t *dvrld_pend_first;
volatile static dv_t *dvrld_pend_last;
volatile static bcm_pkt_t *pkt_pend_first;
volatile static bcm_pkt_t *pkt_pend_last;
static sal_spinlock_t sal_tx_spinlock = NULL;
static int tx_queue_size;
#define TX_SPIN_LOCK() sal_spinlock_lock(sal_tx_spinlock)
#define TX_SPIN_UNLOCK() sal_spinlock_unlock(sal_tx_spinlock)
#define DEFAULT_TX_PRI 50 /* Default Thread Priority */
static uint8* _null_crc_ptr = NULL;
static uint8* _pkt_pad_ptr = NULL;
static int _tx_init = FALSE;
static int _bcm_tx_run = FALSE;
static sal_thread_t _tx_tid = SAL_THREAD_ERROR;
#ifdef BCM_XGS3_SWITCH_SUPPORT
static sal_thread_t _xgs3_async_tid = SAL_THREAD_ERROR;
static int _bcm_async_run = FALSE;
static sal_sem_t xgs3_async_tx_exit_notify = NULL;
#endif
volatile static int _tx_chain_send;
volatile static int _tx_chain_done;
volatile static int _tx_desc_done;
volatile static int _tx_rld_done;
volatile static int _tx_chain_done_intr;
volatile static int _tx_desc_done_intr;
volatile static int _tx_rld_done_intr;
#ifdef BCM_XGS3_SWITCH_SUPPORT
/* Lookup table: Return the first bit set. -1 if no bit set. */
static int8 bpos[256] = {
/* 0x00 */ -1, /* 0x01 */ 0, /* 0x02 */ 1, /* 0x03 */ 0,
/* 0x04 */ 2, /* 0x05 */ 0, /* 0x06 */ 1, /* 0x07 */ 0,
/* 0x08 */ 3, /* 0x09 */ 0, /* 0x0a */ 1, /* 0x0b */ 0,
/* 0x0c */ 2, /* 0x0d */ 0, /* 0x0e */ 1, /* 0x0f */ 0,
/* 0x10 */ 4, /* 0x11 */ 0, /* 0x12 */ 1, /* 0x13 */ 0,
/* 0x14 */ 2, /* 0x15 */ 0, /* 0x16 */ 1, /* 0x17 */ 0,
/* 0x18 */ 3, /* 0x19 */ 0, /* 0x1a */ 1, /* 0x1b */ 0,
/* 0x1c */ 2, /* 0x1d */ 0, /* 0x1e */ 1, /* 0x1f */ 0,
/* 0x20 */ 5, /* 0x21 */ 0, /* 0x22 */ 1, /* 0x23 */ 0,
/* 0x24 */ 2, /* 0x25 */ 0, /* 0x26 */ 1, /* 0x27 */ 0,
/* 0x28 */ 3, /* 0x29 */ 0, /* 0x2a */ 1, /* 0x2b */ 0,
/* 0x2c */ 2, /* 0x2d */ 0, /* 0x2e */ 1, /* 0x2f */ 0,
/* 0x30 */ 4, /* 0x31 */ 0, /* 0x32 */ 1, /* 0x33 */ 0,
/* 0x34 */ 2, /* 0x35 */ 0, /* 0x36 */ 1, /* 0x37 */ 0,
/* 0x38 */ 3, /* 0x39 */ 0, /* 0x3a */ 1, /* 0x3b */ 0,
/* 0x3c */ 2, /* 0x3d */ 0, /* 0x3e */ 1, /* 0x3f */ 0,
/* 0x40 */ 6, /* 0x41 */ 0, /* 0x42 */ 1, /* 0x43 */ 0,
/* 0x44 */ 2, /* 0x45 */ 0, /* 0x46 */ 1, /* 0x47 */ 0,
/* 0x48 */ 3, /* 0x49 */ 0, /* 0x4a */ 1, /* 0x4b */ 0,
/* 0x4c */ 2, /* 0x4d */ 0, /* 0x4e */ 1, /* 0x4f */ 0,
/* 0x50 */ 4, /* 0x51 */ 0, /* 0x52 */ 1, /* 0x53 */ 0,
/* 0x54 */ 2, /* 0x55 */ 0, /* 0x56 */ 1, /* 0x57 */ 0,
/* 0x58 */ 3, /* 0x59 */ 0, /* 0x5a */ 1, /* 0x5b */ 0,
/* 0x5c */ 2, /* 0x5d */ 0, /* 0x5e */ 1, /* 0x5f */ 0,
/* 0x60 */ 5, /* 0x61 */ 0, /* 0x62 */ 1, /* 0x63 */ 0,
/* 0x64 */ 2, /* 0x65 */ 0, /* 0x66 */ 1, /* 0x67 */ 0,
/* 0x68 */ 3, /* 0x69 */ 0, /* 0x6a */ 1, /* 0x6b */ 0,
/* 0x6c */ 2, /* 0x6d */ 0, /* 0x6e */ 1, /* 0x6f */ 0,
/* 0x70 */ 4, /* 0x71 */ 0, /* 0x72 */ 1, /* 0x73 */ 0,
/* 0x74 */ 2, /* 0x75 */ 0, /* 0x76 */ 1, /* 0x77 */ 0,
/* 0x78 */ 3, /* 0x79 */ 0, /* 0x7a */ 1, /* 0x7b */ 0,
/* 0x7c */ 2, /* 0x7d */ 0, /* 0x7e */ 1, /* 0x7f */ 0,
/* 0x80 */ 7, /* 0x81 */ 0, /* 0x82 */ 1, /* 0x83 */ 0,
/* 0x84 */ 2, /* 0x85 */ 0, /* 0x86 */ 1, /* 0x87 */ 0,
/* 0x88 */ 3, /* 0x89 */ 0, /* 0x8a */ 1, /* 0x8b */ 0,
/* 0x8c */ 2, /* 0x8d */ 0, /* 0x8e */ 1, /* 0x8f */ 0,
/* 0x90 */ 4, /* 0x91 */ 0, /* 0x92 */ 1, /* 0x93 */ 0,
/* 0x94 */ 2, /* 0x95 */ 0, /* 0x96 */ 1, /* 0x97 */ 0,
/* 0x98 */ 3, /* 0x99 */ 0, /* 0x9a */ 1, /* 0x9b */ 0,
/* 0x9c */ 2, /* 0x9d */ 0, /* 0x9e */ 1, /* 0x9f */ 0,
/* 0xa0 */ 5, /* 0xa1 */ 0, /* 0xa2 */ 1, /* 0xa3 */ 0,
/* 0xa4 */ 2, /* 0xa5 */ 0, /* 0xa6 */ 1, /* 0xa7 */ 0,
/* 0xa8 */ 3, /* 0xa9 */ 0, /* 0xaa */ 1, /* 0xab */ 0,
/* 0xac */ 2, /* 0xad */ 0, /* 0xae */ 1, /* 0xaf */ 0,
/* 0xb0 */ 4, /* 0xb1 */ 0, /* 0xb2 */ 1, /* 0xb3 */ 0,
/* 0xb4 */ 2, /* 0xb5 */ 0, /* 0xb6 */ 1, /* 0xb7 */ 0,
/* 0xb8 */ 3, /* 0xb9 */ 0, /* 0xba */ 1, /* 0xbb */ 0,
/* 0xbc */ 2, /* 0xbd */ 0, /* 0xbe */ 1, /* 0xbf */ 0,
/* 0xc0 */ 6, /* 0xc1 */ 0, /* 0xc2 */ 1, /* 0xc3 */ 0,
/* 0xc4 */ 2, /* 0xc5 */ 0, /* 0xc6 */ 1, /* 0xc7 */ 0,
/* 0xc8 */ 3, /* 0xc9 */ 0, /* 0xca */ 1, /* 0xcb */ 0,
/* 0xcc */ 2, /* 0xcd */ 0, /* 0xce */ 1, /* 0xcf */ 0,
/* 0xd0 */ 4, /* 0xd1 */ 0, /* 0xd2 */ 1, /* 0xd3 */ 0,
/* 0xd4 */ 2, /* 0xd5 */ 0, /* 0xd6 */ 1, /* 0xd7 */ 0,
/* 0xd8 */ 3, /* 0xd9 */ 0, /* 0xda */ 1, /* 0xdb */ 0,
/* 0xdc */ 2, /* 0xdd */ 0, /* 0xde */ 1, /* 0xdf */ 0,
/* 0xe0 */ 5, /* 0xe1 */ 0, /* 0xe2 */ 1, /* 0xe3 */ 0,
/* 0xe4 */ 2, /* 0xe5 */ 0, /* 0xe6 */ 1, /* 0xe7 */ 0,
/* 0xe8 */ 3, /* 0xe9 */ 0, /* 0xea */ 1, /* 0xeb */ 0,
/* 0xec */ 2, /* 0xed */ 0, /* 0xee */ 1, /* 0xef */ 0,
/* 0xf0 */ 4, /* 0xf1 */ 0, /* 0xf2 */ 1, /* 0xf3 */ 0,
/* 0xf4 */ 2, /* 0xf5 */ 0, /* 0xf6 */ 1, /* 0xf7 */ 0,
/* 0xf8 */ 3, /* 0xf9 */ 0, /* 0xfa */ 1, /* 0xfb */ 0,
/* 0xfc */ 2, /* 0xfd */ 0, /* 0xfe */ 1, /* 0xff */ 0,
};
/*
* Extract port from PBM
*/
#define _pbm2port(bmp) \
((bpos[(bmp >> 0) & 0xFF] != -1) ? (0 + bpos[(bmp >> 0) & 0xFF]) : \
(bpos[(bmp >> 8) & 0xFF] != -1) ? (8 + bpos[(bmp >> 8) & 0xFF]) : \
(bpos[(bmp >> 16) & 0xFF] != -1) ? (16 + bpos[(bmp >> 16) & 0xFF]) : \
(bpos[(bmp >> 24) & 0xFF] != -1) ? (24 + bpos[(bmp >> 24) & 0xFF]) : \
(-1) \
)
STATIC INLINE void
_bcm_xgs3_tx_pipe_handle_timestamp_flags(int unit, bcm_pkt_t *pkt)
{
soc_pbsmh_hdr_t *pbh = (soc_pbsmh_hdr_t *)pkt->_pb_hdr;
if (pkt->flags & BCM_PKT_F_TIMESYNC) {
/* TD2+ timestamp fields set */
if (SOC_DCB_TYPE(unit) == 33) {
if (pkt->timestamp_flags & BCM_TX_TIMESYNC_ONE_STEP) {
/* one step timestamp */
soc_pbsmh_field_set(unit, pbh, PBSMH_osts, 1 );
} else {
/* Two-step time stamping */
soc_pbsmh_field_set(unit, pbh, PBSMH_tx_ts, 1 );
}
if ( pkt->timestamp_flags & BCM_TX_TIMESYNC_INGRESS_SIGN) {
soc_pbsmh_field_set(unit, pbh, PBSMH_its_sign, 1 );
}
if ( pkt->timestamp_flags & BCM_TX_TIMESYNC_HDR_START_OFFSET) {
soc_pbsmh_field_set(unit, pbh, PBSMH_hdr_offset,
pkt->timestamp_offset);
}
if ( pkt->timestamp_flags & BCM_TX_TIMESYNC_REGEN_UDP_CHKSUM) {
soc_pbsmh_field_set(unit, pbh, PBSMH_regen_udp_checksum, 1 );
}
} /* if (SOC_DCB_TYPE(unit) == 33) */
} /* if (pkt->flags & BCM_PKT_F_TIMESYNC) */
}
/*
* Function:
* _bcm_xgs3_tx_pipe_bypass_header_setup
* Purpose:
* Setup up header required to steer raw packet data stream
* out of a port.
* Parameters:
* unit - transmission unit
* pkt - To be updated
* Returns:
* BCM_E_XXX
* Notes:
* The TX port is extracted from tx_pbmp. If port is a member
* of tx_upbmp then the VLAN TAG is removed.
*/
static INLINE int
_bcm_xgs3_tx_pipe_bypass_header_setup(int unit, bcm_pkt_t *pkt)
{
soc_pbsmh_hdr_t *pbh = (soc_pbsmh_hdr_t *)pkt->_pb_hdr;
uint32 bmap = SOC_PBMP_WORD_GET(pkt->tx_pbmp, 0);
int port = _pbm2port(bmap);
int port_adj = 0;
uint32 prio_val;
uint32 src_mod;
int qnum;
int max_num_port = 0;
int unicast = 1;
int dst_subport_num=0;
#ifdef BCM_XGS3_SWITCH_SUPPORT
int check_port;
if (SOC_IS_XGS3_SWITCH(unit)) {
BCM_PBMP_ITER(pkt->tx_pbmp, check_port) {
if (IS_CPU_PORT(unit, check_port)) {
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_bcm_xgs3_tx_pipe_bypass_header_setup: trying to set "
"cpu port as target port!!!\n")));
return BCM_E_PARAM;
}
}
BCM_PBMP_ITER(pkt->tx_upbmp, check_port) {
if (IS_CPU_PORT(unit, check_port)) {
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_bcm_xgs3_tx_pipe_bypass_header_setup: trying to set "
"cpu port as untagged target port!!!\n")));
return BCM_E_PARAM;
}
}
}
#endif
if (SOC_MAX_NUM_PP_PORTS > SOC_MAX_NUM_PORTS) {
max_num_port = SOC_MAX_NUM_PP_PORTS;
} else {
max_num_port = SOC_INFO(unit).port_addr_max > SOC_INFO(unit).port_num ?
SOC_INFO(unit).port_addr_max:SOC_INFO(unit).port_num;
}
/* If this is a TD2P CoE port, get the physical-port from the
subport-gport passed in */
#if defined BCM_HGPROXY_COE_SUPPORT
if (soc_feature(unit, soc_feature_hgproxy_subtag_coe) ||
(soc_feature(unit, soc_feature_channelized_switching))) {
if (_BCM_COE_GPORT_IS_SUBTAG_SUBPORT_PORT(unit, pkt->dst_gport)) {
if (soc_feature(unit, soc_feature_channelized_switching)) {
BCM_IF_ERROR_RETURN(_bcm_coe_subtag_subport_port_subport_num_get(unit,
pkt->dst_gport, NULL, &dst_subport_num));
}
BCM_IF_ERROR_RETURN(
_bcmi_coe_subport_physical_port_get(unit, pkt->dst_gport, &port));
/* Update the bmap with the physical port retrieved */
BCM_PBMP_PORT_ADD(pkt->tx_pbmp, port);
bmap = SOC_PBMP_WORD_GET(pkt->tx_pbmp, 0);
} else {
dst_subport_num = port;
}
}
#endif
src_mod = (pkt->flags & BCM_TX_SRC_MOD) ?
pkt->src_mod : SOC_DEFAULT_DMA_SRCMOD_GET(unit);
prio_val = (pkt->flags & BCM_TX_PRIO_INT) ? pkt->prio_int : pkt->cos;
#ifdef BCM_INSTRUMENTATION_SUPPORT
if (soc_feature(unit, soc_feature_visibility)) {
if ((port == -1) && (pkt->flags2 & BCM_PKT_F2_RX_PORT)) {
/* Set the masquerad source port */
port = pkt->rx_port;
_bcm_esw_pkt_trace_src_port_set(unit, port);
} else if (pkt->flags2 & BCM_PKT_F2_RX_PORT) {
if (pkt->rx_port != 0) {
port = pkt->rx_port;
}
_bcm_esw_pkt_trace_src_port_set(unit, port);
}
}
#endif /* BCM_INSTRUMENTATION_SUPPORT */
#ifdef BCM_CPU_TX_PROC_SUPPORT
if (soc_feature(unit, soc_feature_cpu_tx_proc)) {
if ((port == -1) && (pkt->flags2 & BCM_PKT_F2_CPU_TX_PROC)) {
port = pkt->rx_port;
} else if (pkt->flags2 & BCM_PKT_F2_CPU_TX_PROC) {
if (pkt->rx_port != 0) {
port = pkt->rx_port;
}
}
}
#endif /* BCM_CPU_TX_PROC_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if (SOC_IS_KATANA2(unit)) {
if (BCM_GPORT_IS_UCAST_SUBSCRIBER_QUEUE_GROUP(pkt->dst_gport)) {
port = BCM_GPORT_UCAST_SUBSCRIBER_QUEUE_GROUP_SYSPORTID_GET(
pkt->dst_gport);
BCM_PBMP_PORT_ADD(pkt->tx_pbmp, port);
bmap = SOC_PBMP_WORD_GET(pkt->tx_pbmp, 0);
}
}
#endif
if (port == -1) {
if (soc_feature(unit, soc_feature_register_hi) || SOC_IS_TR_VL(unit)) {
bmap = SOC_PBMP_WORD_GET(pkt->tx_pbmp, 1);
port = _pbm2port(bmap);
port_adj = 32;
if (port == -1) {
if (max_num_port > 64) {
bmap = SOC_PBMP_WORD_GET(pkt->tx_pbmp, 2);
port = _pbm2port(bmap);
port_adj = 64;
if (port == -1) {
if (max_num_port > 96) {
bmap = SOC_PBMP_WORD_GET(pkt->tx_pbmp, 3);
port = _pbm2port(bmap);
port_adj = 96;
}
if (port == -1) {
if (max_num_port > 128) {
bmap = SOC_PBMP_WORD_GET(pkt->tx_pbmp, 4);
port = _pbm2port(bmap);
port_adj = 128;
}
if (port == -1) {
if (max_num_port > 160) {
bmap = SOC_PBMP_WORD_GET(pkt->tx_pbmp, 5);
port = _pbm2port(bmap);
port_adj = 160;
}
}
}
}
}
}
}
if (port == -1) {
return BCM_E_PARAM;
}
}
if ((bmap & (~(1 << port))) != 0) {
return BCM_E_PARAM;
}
port += port_adj;
/* Check untag membership before translating */
if (PBMP_MEMBER(pkt->tx_upbmp, port)) {
pkt->flags |= BCM_PKT_F_TX_UNTAG;
} else {
pkt->flags &= (~BCM_PKT_F_TX_UNTAG);
}
BCM_API_XLATE_PORT_A2P(unit, &port);
if ((SOC_DCB_TYPE(unit) == 23) || (SOC_DCB_TYPE(unit) == 26) ||
(SOC_DCB_TYPE(unit) == 29) || (SOC_DCB_TYPE(unit) == 30) ||
(SOC_DCB_TYPE(unit) == 31) || (SOC_DCB_TYPE(unit) == 33) ||
(SOC_DCB_TYPE(unit) == 35) || (SOC_DCB_TYPE(unit) == 34) ||
(SOC_DCB_TYPE(unit) == 37) || (SOC_DCB_TYPE(unit) == 40)) {
qnum = SOC_INFO(unit).port_uc_cosq_base[port] + pkt->cos;
#if defined(BCM_TRIDENT2_SUPPORT) || defined(BCM_TRIDENT2PLUS_SUPPORT)
if ((SOC_DCB_TYPE(unit) == 26) || (SOC_DCB_TYPE(unit) == 33)) {
qnum = soc_td2_logical_qnum_hw_qnum(unit, port, qnum, 1);
}
#endif /* BCM_TRIDENT2_SUPPORT */
#if defined (BCM_APACHE_SUPPORT)
if ((SOC_DCB_TYPE(unit) == 35)) {
#if defined (BCM_MONTEREY_SUPPORT)
if (SOC_IS_MONTEREY(unit)) {
qnum = soc_monterey_logical_qnum_hw_qnum(unit, port, qnum, 1);
} else
#endif
{
qnum = soc_apache_logical_qnum_hw_qnum(unit, port, qnum, 1);
}
}
#endif /* BCM_APACHE_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
if ((SOC_DCB_TYPE(unit) == 29) && (pkt->flags2 & BCM_PKT_F2_MA_PTR)) {
/* OAM case */
qnum = SOC_INFO(unit).port_uc_cosq_base[port] + pkt->cos;
/*
* KATANA2:
* For UPMEP Packet tx, queue num is not valid
* Refer to SOBMH format for more details on
* UPMEP packet fields.
*/
if(!(pkt->flags2 & BCM_PKT_F2_MEP_TYPE_UPMEP)) {
PBS_MH_V8_W2_SMOD_COS_QNUM_SET(pbh, src_mod, 1, pkt->cos, qnum);
}
soc_pbsmh_field_set(unit, pbh, PBSMH_pp_port, port);
if(pkt->flags2 & BCM_PKT_F2_MEP_TYPE_UPMEP) {
PBS_MH_V8_W0_OAM_UPMEP_START_SET(pbh);
/* set internal priority */
soc_pbsmh_field_set(unit, pbh, PBSMH_int_pri, prio_val);
} else {
PBS_MH_V8_W0_OAM_DOWNMEP_START_SET(pbh);
PBS_MH_V8_W0_OAM_DOWNMEP_CTR_LOCATION_SET(unit, pbh);
}
soc_pbsmh_field_set(unit, pbh, PBSMH_oam_ma_ptr, pkt->ma_ptr);
if(pkt->flags2 & BCM_PKT_F2_TIMESTAMP_MODE) {
soc_pbsmh_field_set(unit, pbh, PBSMH_ts_action, pkt->timestamp_mode);
}
if(pkt->flags2 & BCM_PKT_F2_SAMPLE_RDI) {
soc_pbsmh_field_set(unit, pbh, PBSMH_sample_rdi, 1);
}
if((pkt->flags2 & BCM_PKT_F2_REPLACEMENT_OFFSET)) {
soc_pbsmh_field_set(unit, pbh, PBSMH_oam_replacement_offset,
pkt->oam_replacement_offset);
}
if(pkt->flags2 & BCM_PKT_F2_LM_COUNTER_INDEX) {
soc_pbsmh_field_set(unit, pbh, PBSMH_lm_ctr1_index,
pkt->oam_lm_counter_index);
if(pkt->flags2 & BCM_PKT_F2_COUNTER_MODE_1) {
soc_pbsmh_field_set(unit, pbh, PBSMH_ctr1_action,
pkt->counter_mode_1);
}
}
if(pkt->flags2 & BCM_PKT_F2_LM_COUNTER_INDEX_2) {
soc_pbsmh_field_set(unit, pbh, PBSMH_lm_ctr2_index,
pkt->oam_lm_counter_index_2);
if(pkt->flags2 & BCM_PKT_F2_COUNTER_MODE_2) {
soc_pbsmh_field_set(unit, pbh, PBSMH_ctr2_action,
pkt->counter_mode_2);
}
}
} else if (SOC_DCB_TYPE(unit) == 29) {
if (BCM_GPORT_IS_UCAST_SUBSCRIBER_QUEUE_GROUP(pkt->dst_gport)) {
qnum = BCM_GPORT_UCAST_SUBSCRIBER_QUEUE_GROUP_QID_GET(
pkt->dst_gport);
}
PBS_MH_V7_W0_START_SET(pbh);
PBS_MH_V8_W1_DPORT_IPRI_SET(pbh, port,prio_val);
PBS_MH_V8_W2_SMOD_COS_QNUM_SET(pbh, src_mod, 1, pkt->cos, qnum);
soc_pbsmh_field_set(unit, pbh, PBSMH_dst_port, port);
} else
#endif /* BCM_KATANA2_SUPPORT */
if ((SOC_DCB_TYPE(unit) == 33) || (SOC_DCB_TYPE(unit) == 35)) {
soc_pbsmh_field_set(unit, pbh, PBSMH_start, SOC_PBSMH_START_INTERNAL );
soc_pbsmh_field_set(unit, pbh, PBSMH_header_type, SOC_SOBMH_FROM_CPU );
soc_pbsmh_field_set(unit, pbh, PBSMH_unicast, 1 ); /* unicast */
soc_pbsmh_field_set(unit, pbh, PBSMH_queue_num, qnum);
soc_pbsmh_field_set(unit, pbh, PBSMH_src_mod, src_mod);
soc_pbsmh_field_set(unit, pbh, PBSMH_cos, pkt->cos);
soc_pbsmh_field_set(unit, pbh, PBSMH_pri, prio_val);
soc_pbsmh_field_set(unit, pbh, PBSMH_dst_port, port);
} else {
PBS_MH_V7_W0_START_SET(pbh);
PBS_MH_V7_W1_DPORT_QNUM_SET(pbh, port, qnum);
PBS_MH_V7_W2_SMOD_COS_QNUM_SET(pbh, src_mod, 1, pkt->cos, qnum,
prio_val);
}
if (SOC_DCB_TYPE(unit) == 23) {
if((pkt->flags2 & BCM_PKT_F2_REPLACEMENT_TYPE) &&
(pkt->flags2 & BCM_PKT_F2_REPLACEMENT_OFFSET)) {
soc_pbsmh_field_set(unit, pbh, PBSMH_oam_replacement_type,
pkt->oam_replacement_type);
soc_pbsmh_field_set(unit, pbh, PBSMH_oam_replacement_offset,
pkt->oam_replacement_offset);
if(pkt->flags2 & BCM_PKT_F2_LM_COUNTER_INDEX) {
soc_pbsmh_field_set(unit, pbh, PBSMH_lm_ctr_index,
pkt->oam_lm_counter_index);
}
}
}
} else if ((SOC_DCB_TYPE(unit) == 32) || (SOC_DCB_TYPE(unit) == 38)) {
/* 32 for TH, 38 for TH3 */
PBS_MH_V9_W0_START_SET(pbh);
PBS_MH_V9_W1_DPORT_SET(pbh, port);
#ifdef BCM_INSTRUMENTATION_SUPPORT
if ((soc_feature(unit, soc_feature_visibility)) &&
(pkt->flags2 & BCM_PKT_F2_RX_PORT)) {
uint32 loopback_port = soc_loopback_lbport_num_get(unit,
_bcm_esw_pkt_trace_src_pipe_get(unit));
uint32 use_unicast_queues = 0;
if (loopback_port == -1) {
return BCM_E_PARAM;
}
PBS_MH_V9_W1_DPORT_SET(pbh, loopback_port);
if (SOC_DCB_TYPE(unit) == 38) {
use_unicast_queues = soc_property_get(unit, spn_LB_PORT_USE_UC_QUEUES, 0);
if (use_unicast_queues) {
/* for visibility packet, when using unicast queues unicast bit must be 1 and l2bm 0 */
PBS_MH_V9_W2_SMOD_COS_L2BM_SET(pbh, src_mod, unicast, pkt->cos, 0);
} else {
/* for visibility packet, when using multicast queues unicast bit must be 0 and l2bm 1 */
PBS_MH_V9_W2_SMOD_COS_L2BM_SET(pbh, src_mod, !(unicast), pkt->cos, 1);
}
} else {
/* for visibility packet, unicast bit must be 0 and l2bm 1 */
PBS_MH_V9_W2_SMOD_COS_L2BM_SET(pbh, src_mod, !(unicast), pkt->cos, 1);
}
} else
#endif /* BCM_INSTRUMENTATION_SUPPORT */
#ifdef BCM_CPU_TX_PROC_SUPPORT
if ((soc_feature(unit, soc_feature_cpu_tx_proc)) &&
(pkt->flags2 & BCM_PKT_F2_CPU_TX_PROC)) {
uint32 pipe_num = soc_pipe_get(unit, pkt->rx_port);
uint32 sobmh_loopback_port = soc_lbport_num_get(unit, pipe_num);
uint32 use_unicast_queues = 0;
#ifdef BCM_TOMAHAWK3_SUPPORT
if (SOC_IS_TOMAHAWK3(unit)) {
if (pkt->rx_port == _TH3_MMU_SPARE_SRC_PORT) {
pipe_num = _TH3_MMU_SPARE_SRC_PORT_PIPE;
}
}
#endif
if (sobmh_loopback_port == -1) {
return BCM_E_PARAM;
}
use_unicast_queues = soc_property_get(unit, spn_LB_PORT_USE_UC_QUEUES, 0);
PBS_MH_V9_W1_DPORT_SET(pbh, sobmh_loopback_port);
if (use_unicast_queues) {
/* for cpu tx proc packet, when using unicast queues unicast bit must be 1 and l2bm 0 */
PBS_MH_V9_W2_SMOD_COS_L2BM_SET(pbh, src_mod, unicast, pkt->cos, 0);
} else {
/* for cpu tx proc packet, when using multicast queues unicast bit must be 0 and l2bm 1 */
PBS_MH_V9_W2_SMOD_COS_L2BM_SET(pbh, src_mod, !(unicast), pkt->cos, 1);
}
} else
#endif /* BCM_CPU_TX_PROC_SUPPORT */
{
if (port == CMIC_PORT(unit)) {
/* send to multicast queue of CPU port */
PBS_MH_V9_W2_SMOD_COS_L2BM_SET(pbh, src_mod, !(unicast), pkt->cos, 1);
} else {
PBS_MH_V9_W2_SMOD_COS_SET(pbh, src_mod, unicast, pkt->cos);
}
}
if (pkt->flags2 & BCM_PKT_F2_SPID_OVERRIDE) {
soc_pbsmh_field_set(unit, pbh, PBSMH_spid_override, pkt->spid_override);
soc_pbsmh_field_set(unit, pbh, PBSMH_spid, pkt->spid);
}
if (pkt->flags & BCM_PKT_F_TIMESYNC) {
/* Triumph3 timestamp fields set */
if (pkt->timestamp_flags & BCM_TX_TIMESYNC_ONE_STEP) {
/* one step timestamp */
soc_pbsmh_field_set(unit, pbh, PBSMH_osts, 1);
} else {
/* Two-step time stamping */
soc_pbsmh_field_set(unit, pbh, PBSMH_tx_ts, 1);
}
if (pkt->timestamp_flags &
BCM_TX_TIMESYNC_INGRESS_SIGN) {
soc_pbsmh_field_set(unit, pbh, PBSMH_its_sign, 1);
}
if (pkt->timestamp_flags &
BCM_TX_TIMESYNC_HDR_START_OFFSET) {
soc_pbsmh_field_set(unit, pbh, PBSMH_hdr_offset,
pkt->timestamp_offset);
}
if (pkt->timestamp_flags &
BCM_TX_TIMESYNC_REGEN_UDP_CHKSUM) {
soc_pbsmh_field_set(unit, pbh, PBSMH_regen_udp_checksum, 1);
}
}
/* Set internal priority in the tx header */
soc_pbsmh_field_set(unit, pbh, PBSMH_pri, prio_val);
#ifdef BCM_TOMAHAWK3_SUPPORT
if (pkt->rqe_q_num) {
PBS_MH_V9_W2_RQE_SET(pbh, pkt->rqe_q_num);
}
#endif
} else if (SOC_DCB_TYPE(unit) == 36) { /* TD3 */
PBS_MH_V11_W0_START_SET(pbh);
PBS_MH_V11_W1_DPORT_SET(pbh, port);
#ifdef BCM_INSTRUMENTATION_SUPPORT
if ((soc_feature(unit, soc_feature_visibility)) &&
(pkt->flags2 & BCM_PKT_F2_RX_PORT)) {
uint32 loopback_port = soc_loopback_lbport_num_get(unit,
_bcm_esw_pkt_trace_src_pipe_get(unit));
if (loopback_port == -1) {
return BCM_E_PARAM;
}
PBS_MH_V11_W1_DPORT_SET(pbh, loopback_port);
/* for visibility packet, unicast bit must be 0 and l2bm 1*/
PBS_MH_V11_W2_SMOD_COS_L2BM_SET(pbh, src_mod, !(unicast), pkt->cos, 1);
} else
#endif /* BCM_INSTRUMENTATION_SUPPORT */
{
if (port == CMIC_PORT(unit)) {
/* send to multicast queue of CPU port */
PBS_MH_V11_W2_SMOD_COS_L2BM_SET(pbh, src_mod, !(unicast), pkt->cos, 1);
} else {
PBS_MH_V11_W2_SMOD_COS_SET(pbh, src_mod, unicast, pkt->cos);
}
}
if (pkt->flags & BCM_PKT_F_TIMESYNC) {
/* Triumph3 timestamp fields set */
if (pkt->timestamp_flags & BCM_TX_TIMESYNC_ONE_STEP) {
/* one step timestamp */
soc_pbsmh_field_set(unit, pbh, PBSMH_osts, 1);
} else {
/* Two-step time stamping */
soc_pbsmh_field_set(unit, pbh, PBSMH_tx_ts, 1);
}
if (pkt->timestamp_flags &
BCM_TX_TIMESYNC_INGRESS_SIGN) {
soc_pbsmh_field_set(unit, pbh, PBSMH_its_sign, 1);
}
if (pkt->timestamp_flags &
BCM_TX_TIMESYNC_HDR_START_OFFSET) {
soc_pbsmh_field_set(unit, pbh, PBSMH_hdr_offset,
pkt->timestamp_offset);
}
if (pkt->timestamp_flags &
BCM_TX_TIMESYNC_REGEN_UDP_CHKSUM) {
soc_pbsmh_field_set(unit, pbh, PBSMH_regen_udp_checksum, 1);
}
}
if (soc_feature(unit, soc_feature_channelized_switching)) {
if (dst_subport_num == -1) {
if (port != -1) {
dst_subport_num = port;
} else {
dst_subport_num = 0;
}
}
soc_pbsmh_field_set(unit, pbh, PBSMH_dst_subport_num,
dst_subport_num);
}
/* TWAMP/OWAMP specific bits to be set in
* SOBMH header during TX */
if (pkt->flags2 & BCM_PKT_F2_TWAMP_OWAMP_TS) {
if (soc_feature(unit, soc_feature_twamp_owamp_support)) {
soc_pbsmh_field_set(unit, pbh, PBSMH_amp_ts_act, 1);
soc_pbsmh_field_set(unit, pbh, PBSMH_hdr_offset,
BCM_PKT_HDR_TS_OFFSET_TWAMP_OWAMP);
} else {
return BCM_E_UNAVAIL;
}
}
if (soc_feature(unit, soc_feature_hr4_a0_sobmh_war)) {
soc_pbsmh_field_set(unit, pbh, PBSMH_sobmh_flex, 1);
}
} else {
PBS_MH_W0_START_SET(pbh);
PBS_MH_W1_RSVD_SET(pbh);
if ((SOC_DCB_TYPE(unit) == 11) || (SOC_DCB_TYPE(unit) == 12) ||
(SOC_DCB_TYPE(unit) == 15) || (SOC_DCB_TYPE(unit) == 17) ||
(SOC_DCB_TYPE(unit) == 18)) {
PBS_MH_V2_W2_SMOD_DPORT_COS_SET(pbh, src_mod, port,
pkt->cos, prio_val, 0);
if (pkt->flags & BCM_PKT_F_TIMESYNC) {
PBS_MH_V2_TS_PKT_SET(pbh);
}
} else if ((SOC_DCB_TYPE(unit) == 14) || (SOC_DCB_TYPE(unit) == 19) ||
(SOC_DCB_TYPE(unit) == 20)) {
if (!(pkt->flags & BCM_TX_PRIO_INT)) {
/* If BCM_TX_PRIO_INT is not specified, the int_pri
* is set to the cos value. However in version 3 of
* the PBS_MH, cos is 6 bit, but int_prio is only 4.
* To be safe, set the int_prio to 0 if it wasn't
* explicitly set as indicated by BCM_TX_PRIO_INT flag.
*/
prio_val = 0;
}
PBS_MH_V3_W2_SMOD_DPORT_COS_SET(pbh, src_mod, port,
pkt->cos, prio_val, 0);
if (pkt->flags & BCM_PKT_F_TIMESYNC) {
PBS_MH_V3_TS_PKT_SET(pbh);
}
} else if (SOC_DCB_TYPE(unit) == 16) {
PBS_MH_V4_W2_SMOD_DPORT_COS_SET(pbh, src_mod, port,
pkt->cos, prio_val, 0);
} else if (SOC_DCB_TYPE(unit) == 21) {
PBS_MH_V5_W1_SMOD_SET(pbh, src_mod, 1, 0, 0);
PBS_MH_V5_W2_DPORT_COS_SET(pbh, port, pkt->cos, prio_val);
if (pkt->flags & BCM_PKT_F_TIMESYNC) {
PBS_MH_V5_TS_PKT_SET(pbh);
}
} else if (SOC_DCB_TYPE(unit) == 24) {
PBS_MH_V5_W1_SMOD_SET(pbh, src_mod, 1, 0, 0);
PBS_MH_V6_W2_DPORT_COS_QNUM_SET(pbh, port, pkt->cos,
(SOC_INFO(unit).port_cosq_base[port] + pkt->cos),
prio_val);
if (pkt->flags & BCM_PKT_F_TIMESYNC) {
PBS_MH_V5_TS_PKT_SET(pbh);
}
} else if ((SOC_DCB_TYPE(unit) == 16) || (SOC_DCB_TYPE(unit) == 22)) {
PBS_MH_V4_W2_SMOD_DPORT_COS_SET(pbh, src_mod, port,
pkt->cos, prio_val, 0);
} else {
PBS_MH_V1_W2_SMOD_DPORT_COS_SET(pbh, src_mod, port,
pkt->cos, prio_val, 0);
}
}
#ifdef BCM_TRIDENT_SUPPORT
if (pkt->flags2 & BCM_PKT_F2_MC_QUEUE) {
/*TD,TD2,TD2+,TH&TR3 support this feature*/
if ((SOC_DCB_TYPE(unit) == 21) || (SOC_DCB_TYPE(unit) == 23) ||
(SOC_DCB_TYPE(unit) == 26) || (SOC_DCB_TYPE(unit) == 32) ||
(SOC_DCB_TYPE(unit) == 33) || (SOC_DCB_TYPE(unit) == 36) ||
(SOC_DCB_TYPE(unit) == 38)) {
/* send to multicast queue of TX port */
soc_pbsmh_field_set(unit, pbh, PBSMH_unicast, 0);
soc_pbsmh_field_set(unit, pbh, PBSMH_l2pbm_sel, 1);
}
}
#endif
if (pkt->flags & BCM_PKT_F_TIMESYNC) {
if (SOC_DCB_TYPE(unit) == 23 || SOC_DCB_TYPE(unit) == 26 || \
SOC_DCB_TYPE(unit) == 30 || SOC_DCB_TYPE(unit) == 31 || \
SOC_DCB_TYPE(unit) == 34 || \
SOC_DCB_TYPE(unit) == 37 || SOC_DCB_TYPE(unit) == 40) {
/* Triumph3 timestamp fields set */
if (pkt->timestamp_flags & BCM_TX_TIMESYNC_ONE_STEP) {
PBS_MH_V7_TS_ONE_STEP_PKT_SET(pbh);
} else {
/* Two-step time stamping */
PBS_MH_V7_TS_PKT_SET(pbh);
}
if ( pkt->timestamp_flags &
BCM_TX_TIMESYNC_INGRESS_SIGN) {
PBS_MH_V7_TS_ONE_STEP_INGRESS_SIGN_PKT_SET(pbh);
}
if ( pkt->timestamp_flags &
BCM_TX_TIMESYNC_HDR_START_OFFSET) {
PBS_MH_V7_TS_ONE_STEP_HDR_START_OFFSET_PKT_SET(pbh,
pkt->timestamp_offset);
}
if ( pkt->timestamp_flags &
BCM_TX_TIMESYNC_REGEN_UDP_CHKSUM) {
PBS_MH_V7_TS_ONE_STEP_HDR_START_REGEN_UDP_CHEKSUM_PKT_SET(pbh);
}
} else if (SOC_DCB_TYPE(unit) == 35) {
/* Triumph3 timestamp fields set */
if (pkt->timestamp_flags & BCM_TX_TIMESYNC_ONE_STEP) {
soc_pbsmh_field_set(unit, pbh, PBSMH_osts, 1 ); /* one step timestamp */
} else {
/* Two-step time stamping */
soc_pbsmh_field_set(unit, pbh, PBSMH_tx_ts, 1 );
}
if ( pkt->timestamp_flags &
BCM_TX_TIMESYNC_INGRESS_SIGN) {
soc_pbsmh_field_set(unit, pbh, PBSMH_its_sign, 1 );
}
if ( pkt->timestamp_flags &
BCM_TX_TIMESYNC_HDR_START_OFFSET) {
soc_pbsmh_field_set(unit, pbh, PBSMH_hdr_offset,
pkt->timestamp_offset);
}
if ( pkt->timestamp_flags &
BCM_TX_TIMESYNC_REGEN_UDP_CHKSUM) {
soc_pbsmh_field_set(unit, pbh, PBSMH_regen_udp_checksum, 1 );
}
} else if (SOC_DCB_TYPE(unit) == 33) {
/* TD2+ timestamp fields set */
_bcm_xgs3_tx_pipe_handle_timestamp_flags(unit, pkt);
} else if (SOC_DCB_TYPE(unit) == 24) {
/* Katana timestamp fields set */
if (pkt->timestamp_flags & BCM_TX_TIMESYNC_ONE_STEP) {
PBS_MH_V6_TS_ONE_STEP_PKT_SET(pbh);
} else {
/* Two-step time stamping */
PBS_MH_V6_TS_PKT_SET(pbh);
}
if ( pkt->timestamp_flags &
BCM_TX_TIMESYNC_INGRESS_SIGN) {
PBS_MH_V6_TS_ONE_STEP_INGRESS_SIGN_PKT_SET(pbh);
}
if ( pkt->timestamp_flags &
BCM_TX_TIMESYNC_HDR_START_OFFSET) {
PBS_MH_V6_TS_ONE_STEP_HDR_START_OFFSET_PKT_SET(pbh,
pkt->timestamp_offset);
}
if ( pkt->timestamp_flags &
BCM_TX_TIMESYNC_REGEN_UDP_CHKSUM) {
PBS_MH_V6_TS_ONE_STEP_HDR_START_REGEN_UDP_CHEKSUM_PKT_SET(pbh);
}
}
else if (SOC_DCB_TYPE(unit) == 29) {
if (pkt->timestamp_flags & BCM_TX_TIMESYNC_ONE_STEP) {
soc_pbsmh_field_set(unit, pbh, PBSMH_osts, 1);
} else {
soc_pbsmh_field_set(unit, pbh, PBSMH_tx_ts, 1);
}
if ( pkt->timestamp_flags &
BCM_TX_TIMESYNC_INGRESS_SIGN) {
soc_pbsmh_field_set(unit, pbh, PBSMH_its_sign, 1);
}
if ( pkt->timestamp_flags &
BCM_TX_TIMESYNC_HDR_START_OFFSET) {
soc_pbsmh_field_set(unit, pbh, PBSMH_hdr_offset,
pkt->timestamp_offset);
}
if ( pkt->timestamp_flags &
BCM_TX_TIMESYNC_REGEN_UDP_CHKSUM) {
soc_pbsmh_field_set(unit, pbh,
PBSMH_regen_udp_checksum, 1);
}
}
}
return BCM_E_NONE;
}
#endif
#if defined(BCM_XGS_SUPPORT) && defined(BCM_HIGIG2_SUPPORT)
/*
* Function:
* _bcm_tx_gport_resolve
* Purpose:
* Analyze the provided gport and convert it into Higig2 PPD2/3
* suitable format, if appropriate.
* Parameters:
* gport - provided potential virtual port to resolve
* vp - (OUT) resolved port info in Higig2 PD2/3 format
* physical - (OUT) TRUE if physical port, FALSE if virtual port
* Returns:
* BCM_E_XXX
* Notes:
*/
STATIC INLINE int
_bcm_tx_gport_resolve(bcm_gport_t gport, bcm_port_t *vp)
{
bcm_port_t port;
if (BCM_GPORT_IS_MPLS_PORT(gport)) {
port = BCM_GPORT_MPLS_PORT_ID_GET(gport);
} else if (BCM_GPORT_IS_MIM_PORT(gport)) {
port = BCM_GPORT_MIM_PORT_ID_GET(gport);
} else if (BCM_GPORT_IS_WLAN_PORT(gport)) {
port = BCM_GPORT_WLAN_PORT_ID_GET(gport);
} else if (BCM_GPORT_IS_VLAN_PORT(gport)) {
port = BCM_GPORT_VLAN_PORT_ID_GET(gport);
} else if (BCM_GPORT_IS_SUBPORT_PORT(gport)) {
port = BCM_GPORT_SUBPORT_PORT_GET(gport);
} else if (BCM_GPORT_IS_NIV_PORT(gport)) {
port = BCM_GPORT_NIV_PORT_ID_GET(gport);
} else if (BCM_GPORT_IS_FLOW_PORT(gport)) {
port = BCM_GPORT_FLOW_PORT_ID_GET(gport);
} else if (BCM_GPORT_IS_VXLAN_PORT(gport)) {
port = BCM_GPORT_VXLAN_PORT_ID_GET(gport);
} else {
/* Can't parse */
return BCM_E_PORT;
}
*vp = port;
return BCM_E_NONE;
}
STATIC INLINE int
_bcm_tx_pkt_stk_forward_to_hg2(int forward, int *fwd_type, int *multicast)
{
/* Note: All multicast types are translated to SOC_HIGIG_OP_IPMC
* because the MC index must be translated into the IPMC range for
* the FRC multicast field.
*/
switch (forward) {
case BCM_PKT_STK_FORWARD_CPU:
*fwd_type = 0;
*multicast = 0;
break;
case BCM_PKT_STK_FORWARD_L2_UNICAST:
*fwd_type = 4;
*multicast = 0;
break;
case BCM_PKT_STK_FORWARD_L3_UNICAST:
*fwd_type = 2;
*multicast = 0;
break;
case BCM_PKT_STK_FORWARD_L2_MULTICAST:
*fwd_type = 4;
*multicast = SOC_HIGIG_OP_IPMC;
break;
case BCM_PKT_STK_FORWARD_L2_MULTICAST_UNKNOWN:
*fwd_type = 5;
*multicast = SOC_HIGIG_OP_IPMC;
break;
case BCM_PKT_STK_FORWARD_L3_MULTICAST:
*fwd_type = 2;
*multicast = SOC_HIGIG_OP_IPMC;
break;
case BCM_PKT_STK_FORWARD_L3_MULTICAST_UNKNOWN:
*fwd_type = 3;
*multicast = SOC_HIGIG_OP_IPMC;
break;
case BCM_PKT_STK_FORWARD_L2_UNICAST_UNKNOWN:
*fwd_type = 6;
*multicast = SOC_HIGIG_OP_IPMC;
break;
case BCM_PKT_STK_FORWARD_BROADCAST:
*fwd_type = 7;
*multicast = SOC_HIGIG_OP_IPMC;
break;
default:
return BCM_E_PARAM;
}
return BCM_E_NONE;
}
#if defined(INCLUDE_L3) && defined(BCM_XGS3_SWITCH_SUPPORT)
STATIC INLINE int
_bcm_tx_pkt_stk_encap_to_repl_id(int unit, bcm_if_t encap, uint32 *repl_id)
{
if (encap > 0) {
if (encap < BCM_XGS3_EGRESS_IDX_MIN(unit)) {
*repl_id = encap;
} else if (encap < BCM_XGS3_MPATH_EGRESS_IDX_MIN(unit)) {
*repl_id = encap - BCM_XGS3_EGRESS_IDX_MIN(unit);
} else if (encap < BCM_XGS3_MPLS_IF_EGRESS_IDX_MIN(unit)) {
*repl_id = encap - BCM_XGS3_MPATH_EGRESS_IDX_MIN(unit);
} else if (encap < BCM_XGS3_DVP_EGRESS_IDX_MIN(unit)) {
*repl_id = encap - BCM_XGS3_MPLS_IF_EGRESS_IDX_MIN(unit);
} else {
*repl_id = encap - BCM_XGS3_DVP_EGRESS_IDX_MIN(unit);
}
} else {
return BCM_E_PARAM;
}
return BCM_E_NONE;
}
#endif /* INCLUDE_L3 && BCM_XGS3_SWITCH_SUPPORT */
/*
* Function:
* _bcm_tx_hg2hdr_setup
* Purpose:
* Setup HiGig2 header local buffer consistently with packet's
* data members. Legacy HiGig header members are done by
* _bcm_tx_hghdr_setup.
* Parameters:
* pkt - Packet to set up header from
* Returns:
* BCM_E_XXX
* Notes:
*/
STATIC INLINE int
_bcm_tx_hg2hdr_setup(bcm_pkt_t *pkt)
{
soc_higig2_hdr_t *xgh = (soc_higig2_hdr_t *)pkt->_higig;
int unit = pkt->unit;
uint32 vlan_val, prio_val, color, pfm, ppd = 0;
uint32 src_port, src_mod;
bcm_port_t dst_vp = 0, src_vp = 0;
int multicast, fwd_type, mc_index_offset, mc_index;
#if defined(BCM_BRADLEY_SUPPORT)
int bcast_size, mcast_size, ipmc_size;
#endif
bcm_vlan_t vfi = 0;
#if defined(INCLUDE_L3) && defined(BCM_XGS3_SWITCH_SUPPORT)
uint32 repl_id;
#endif /* INCLUDE_L3 && BCM_XGS3_SWITCH_SUPPORT */
/* This must be first, so all of the following operate properly */
soc_higig2_field_set(unit, xgh, HG_start, SOC_HIGIG2_START);
if (pkt->flags2 & BCM_PKT_F2_EXT_HG_HDR) {
soc_higig2_field_set(unit, xgh, HG_ehv, 1);
}
/* Analyze the GPORTS */
if (pkt->stk_flags & BCM_PKT_STK_F_DST_PORT) {
if (pkt->stk_flags & BCM_PKT_STK_F_ENCAP_ID) {
/* Can't mix dest port and encap ID */
return BCM_E_PARAM;
}
BCM_IF_ERROR_RETURN
(_bcm_tx_gport_resolve(pkt->dst_gport, &dst_vp));
}
if (pkt->stk_flags & BCM_PKT_STK_F_SRC_PORT) {
BCM_IF_ERROR_RETURN
(_bcm_tx_gport_resolve(pkt->src_gport, &src_vp));
}
/* What kind of PPD are we dealing with? */
if (pkt->stk_flags &
(BCM_PKT_STK_F_DEFERRED_DROP |
BCM_PKT_STK_F_DEFERRED_CHANGE_PKT_PRIO |
BCM_PKT_STK_F_DEFERRED_CHANGE_DSCP |
BCM_PKT_STK_F_VLAN_TRANSLATE_NONE |
BCM_PKT_STK_F_VLAN_TRANSLATE_UNCHANGED |
BCM_PKT_STK_F_VLAN_TRANSLATE_CHANGED)) {
ppd = 3;
}
if (dst_vp) {
if (ppd > 2) { /* Conflict */
return BCM_E_PARAM;
}
ppd = 2; /* Virtual dest port type */
}
if (pkt->stk_forward != BCM_PKT_STK_FORWARD_CPU) {
if (ppd > 2) { /* Conflict */
return BCM_E_PARAM;
}
ppd = 2; /* Virtual dest port type */
}
if (pkt->stk_flags &
(BCM_PKT_STK_F_TRUNK_FAILOVER | BCM_PKT_STK_F_DO_NOT_MODIFY)) {
if (ppd > 2) { /* Conflict */
return BCM_E_PARAM;
}
}
if (pkt->stk_flags & BCM_PKT_STK_F_FAILOVER) {
if (ppd > 2) { /* Conflict */
return BCM_E_PARAM;
}
ppd = 2; /* Protection nexthop only availabe in PPD 2 */
}
#if defined(INCLUDE_L3) && defined(BCM_TRX_SUPPORT)
if (_BCM_VPN_IS_VPLS(pkt->vlan) || _BCM_VPN_IS_MIM(pkt->vlan)) {
if (ppd > 2) { /* Conflict */
return BCM_E_PARAM;
}
_BCM_VPN_GET(vfi, _BCM_VPN_TYPE_VFI, pkt->vlan);
ppd = 2; /* Only PPD with VFI */
}
#endif /* INCLUDE_L3 && BCM_TRX_SUPPORT */
if (pkt->stk_flags & BCM_PKT_STK_F_CLASSIFICATION_TAG) {
if (ppd == 2) { /* Conflict */
return BCM_E_PARAM;
}
/* coverity[new_values] */
if (ppd != 3) { /* Conflict */
ppd = 1; /* Only PPD with VFI */
if (pkt->stk_flags & (BCM_PKT_STK_F_PRESERVE_DSCP |
BCM_PKT_STK_F_PRESERVE_PKT_PRIO)) {
return BCM_E_PARAM;
}
}
}
if ((pkt->stk_flags & BCM_PKT_STK_F_MIRROR) ||
(pkt->stk_flags & BCM_PKT_STK_F_ENCAP_ID) ){
if ((ppd == 1) || (ppd == 3)) { /* Conflict */
return BCM_E_PARAM;
}
}
/* Otherwise, we will just use PPD0 */
/* We must fill in the type before filling in the PPD-specific fields */
soc_higig2_field_set(unit, xgh, HG_ppd_type, ppd);
/* This field is common to all PPDs */
soc_higig2_field_set(unit, xgh, HG_opcode, pkt->opcode);
/* Get multicast from opcode. Override if PPD2 */
multicast = ((pkt->opcode == SOC_HIGIG_OP_CPU) ||
(pkt->opcode == SOC_HIGIG_OP_UC)) ? 0 : pkt->opcode;
/* Now fill in by type */
switch (ppd) {
case 3:
soc_higig2_field_set(unit, xgh, HG_src_vp, src_vp);
soc_higig2_field_set(unit, xgh, HG_src_type, 0);
if (pkt->stk_flags & BCM_PKT_STK_F_PRESERVE_DSCP) {
soc_higig2_field_set(unit, xgh, HG_preserve_dscp, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_PRESERVE_PKT_PRIO) {
soc_higig2_field_set(unit, xgh, HG_preserve_dot1p, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_DO_NOT_LEARN) {
soc_higig2_field_set(unit, xgh, HG_donot_learn, 1);
}
soc_higig2_field_set(unit, xgh, HG_opcode, pkt->opcode);
soc_higig2_field_set(unit, xgh, HG_data_container_type, 1);
/* Container info */
if (pkt->stk_flags & BCM_PKT_STK_F_CLASSIFICATION_TAG) {
soc_higig2_field_set(unit, xgh, HG_ctag,
pkt->stk_classification_tag);
}
if (pkt->stk_flags & BCM_PKT_STK_F_DEFERRED_DROP) {
soc_higig2_field_set(unit, xgh, HG_deferred_drop, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_DEFERRED_CHANGE_PKT_PRIO) {
soc_higig2_field_set(unit, xgh, HG_deferred_change_pkt_pri, 1);
soc_higig2_field_set(unit, xgh, HG_new_pkt_pri, pkt->stk_pkt_prio);
}
if (pkt->stk_flags & BCM_PKT_STK_F_DEFERRED_CHANGE_DSCP) {
soc_higig2_field_set(unit, xgh, HG_deferred_change_dscp, 1);
soc_higig2_field_set(unit, xgh, HG_new_dscp, pkt->stk_dscp);
}
if (pkt->stk_flags & BCM_PKT_STK_F_VLAN_TRANSLATE_CHANGED) {
soc_higig2_field_set(unit, xgh, HG_vxlt_done, 3);
} else if (pkt->stk_flags & BCM_PKT_STK_F_VLAN_TRANSLATE_UNCHANGED) {
soc_higig2_field_set(unit, xgh, HG_vxlt_done, 1);
} else if (pkt->stk_flags & BCM_PKT_STK_F_VLAN_TRANSLATE_NONE) {
soc_higig2_field_set(unit, xgh, HG_vxlt_done, 0);
}
/* Must transmit VLAN tag with this format */
pkt->stk_flags |= BCM_PKT_STK_F_TX_TAG;
break;
case 2:
BCM_IF_ERROR_RETURN
(_bcm_tx_pkt_stk_forward_to_hg2(pkt->stk_forward, &fwd_type,
&multicast));
soc_higig2_field_set(unit, xgh, HG_fwd_type, fwd_type);
soc_higig2_field_set(unit, xgh, HG_multipoint, multicast ? 1 : 0);
#if defined(INCLUDE_L3) && defined(BCM_XGS3_SWITCH_SUPPORT)
if (pkt->stk_flags & BCM_PKT_STK_F_ENCAP_ID) {
BCM_IF_ERROR_RETURN
(_bcm_tx_pkt_stk_encap_to_repl_id(unit, pkt->stk_encap_id,
&repl_id));
soc_higig2_field_set(unit, xgh, HG_replication_id, repl_id);
} else
#endif /* INCLUDE_L3 && BCM_XGS3_SWITCH_SUPPORT */
{
if (multicast) {
mc_index = _BCM_MULTICAST_ID_GET(pkt->multicast_group);
/* This field is idetified as valid dvp on TD3X.
* Keep hg_dst_vp as zero instead of mc index on TD3X, in the case
* of multicast packets with ppd2 header injected by CPU.
*/
if (!SOC_IS_TRIDENT3X(unit)) {
soc_higig2_field_set(unit, xgh, HG_dst_vp, mc_index);
}
} else {
soc_higig2_field_set(unit, xgh, HG_dst_vp, dst_vp);
soc_higig2_field_set(unit, xgh, HG_dst_type, 0);
}
}
soc_higig2_field_set(unit, xgh, HG_src_vp, src_vp);
soc_higig2_field_set(unit, xgh, HG_src_type, 0);
soc_higig2_field_set(unit, xgh, HG_vni, vfi);
if (pkt->stk_flags & BCM_PKT_STK_F_MIRROR) {
soc_higig2_field_set(unit, xgh, HG_mirror, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_DO_NOT_MODIFY) {
soc_higig2_field_set(unit, xgh, HG_donot_modify, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_DO_NOT_LEARN) {
soc_higig2_field_set(unit, xgh, HG_donot_learn, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_TRUNK_FAILOVER) {
soc_higig2_field_set(unit, xgh, HG_lag_failover, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_FAILOVER) {
soc_higig2_field_set(unit, xgh, HG_protection_status, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_PRESERVE_DSCP) {
soc_higig2_field_set(unit, xgh, HG_preserve_dscp, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_PRESERVE_PKT_PRIO) {
soc_higig2_field_set(unit, xgh, HG_preserve_dot1p, 1);
}
/* Must transmit VLAN tag with this format */
pkt->stk_flags |= BCM_PKT_STK_F_TX_TAG;
break;
case 1:
if (pkt->stk_flags & BCM_PKT_STK_F_CLASSIFICATION_TAG) {
soc_higig2_field_set(unit, xgh, HG_ctag,
pkt->stk_classification_tag);
}
vlan_val = BCM_PKT_VLAN_CONTROL(pkt);
soc_higig2_field_set(unit, xgh, HG_vlan_tag, vlan_val);
pfm = (pkt->flags & BCM_TX_PFM) ?
pkt->pfm : SOC_DEFAULT_DMA_PFM_GET(unit);
soc_higig2_field_set(unit, xgh, HG_pfm, pfm);
break;
case 0:
if (!(pkt->rx_untagged & BCM_PKT_OUTER_UNTAGGED)) {
soc_higig2_field_set(unit, xgh, HG_ingress_tagged, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_MIRROR) {
soc_higig2_field_set(unit, xgh, HG_mirror_only, 1);
soc_higig2_field_set(unit, xgh, HG_mirror, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_DO_NOT_MODIFY) {
soc_higig2_field_set(unit, xgh, HG_donot_modify, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_DO_NOT_LEARN) {
soc_higig2_field_set(unit, xgh, HG_donot_learn, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_TRUNK_FAILOVER) {
soc_higig2_field_set(unit, xgh, HG_lag_failover, 1);
}
if (pkt->flags & BCM_PKT_F_ROUTED) {
soc_higig2_field_set(unit, xgh, HG_l3, 1);
}
vlan_val = BCM_PKT_VLAN_CONTROL(pkt);
soc_higig2_field_set(unit, xgh, HG_vlan_tag, vlan_val);
pfm = (pkt->flags & BCM_TX_PFM) ?
pkt->pfm : SOC_DEFAULT_DMA_PFM_GET(unit);
soc_higig2_field_set(unit, xgh, HG_pfm, pfm);
if (pkt->stk_flags & BCM_PKT_STK_F_PRESERVE_DSCP) {
soc_higig2_field_set(unit, xgh, HG_preserve_dscp, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_PRESERVE_PKT_PRIO) {
soc_higig2_field_set(unit, xgh, HG_preserve_dot1p, 1);
}
#if defined(INCLUDE_L3) && defined(BCM_XGS3_SWITCH_SUPPORT)
if (pkt->stk_flags & BCM_PKT_STK_F_ENCAP_ID) {
BCM_IF_ERROR_RETURN
(_bcm_tx_pkt_stk_encap_to_repl_id(unit, pkt->stk_encap_id,
&repl_id));
soc_higig2_field_set(unit, xgh, HG_replication_id, repl_id);
}
#endif /* INCLUDE_L3 && BCM_XGS3_SWITCH_SUPPORT */
break;
/* Defensive Default */
/* coverity[dead_error_begin] */
default:
return BCM_E_INTERNAL;
}
/* Finally, fill in the common FRC fields */
prio_val = (pkt->flags & BCM_TX_PRIO_INT) ? pkt->prio_int : pkt->cos;
soc_higig2_field_set(unit, xgh, HG_tc, prio_val);
/* multicast from opcode or PPD2 flags */
if (multicast) {
mc_index_offset = 0;
#if defined(BCM_BRADLEY_SUPPORT)
/* Higig2 has different ranges for different multicast types */
BCM_IF_ERROR_RETURN
(soc_hbx_higig2_mcast_sizes_get(unit, &bcast_size, &mcast_size,
&ipmc_size));
switch (multicast) {
case SOC_HIGIG_OP_IPMC:
mc_index_offset += mcast_size;
/* Fall thru */
case SOC_HIGIG_OP_MC:
mc_index_offset += bcast_size;
/* Fall thru */
case SOC_HIGIG_OP_BC:
break;
default:
/* Unknown opcode */
return BCM_E_PARAM;
}
#endif
soc_higig2_field_set(unit, xgh, HG_mcst, 1);
mc_index = _BCM_MULTICAST_ID_GET(pkt->multicast_group);
soc_higig2_field_set(unit, xgh, HG_mgid,
mc_index + mc_index_offset);
} else {
soc_higig2_field_set(unit, xgh, HG_dst_mod, pkt->dest_mod);
soc_higig2_field_set(unit, xgh, HG_dst_port, pkt->dest_port);
}
src_mod = (pkt->flags & BCM_TX_SRC_MOD) ?
pkt->src_mod : SOC_DEFAULT_DMA_SRCMOD_GET(unit);
soc_higig2_field_set(unit, xgh, HG_src_mod, src_mod);
src_port = (pkt->flags & BCM_TX_SRC_PORT) ?
pkt->src_port : SOC_DEFAULT_DMA_SRCPORT_GET(unit);
soc_higig2_field_set(unit, xgh, HG_src_port, src_port);
soc_higig2_field_set(unit, xgh, HG_lbid, pkt->stk_load_balancing_number);
switch (pkt->color) {
case bcmColorGreen:
color = 0;
break;
case bcmColorYellow:
color = 3;
break;
case bcmColorRed:
color = 1;
break;
case bcmColorBlack:
default:
return BCM_E_PARAM;
}
soc_higig2_field_set(unit, xgh, HG_dp, color);
return BCM_E_NONE;
}
#endif /* defined(BCM_XGS_SUPPORT) && defined(BCM_HIGIG2_SUPPORT) */
/*
* Function:
* _bcm_tx_hghdr_setup
* Purpose:
* Setup HiGig header local buffer consistently with packet's
* data members.
* Parameters:
* pkt - Packet to set up header from
* Returns:
* BCM_E_XXX
* Notes:
* The VLAN value is generally gotten from packet data (determined
* by flags; The HG priority field (aka HG_cos) is either the
* prio_int or cos field of the packet depending on the TX_PRIO_INT
* flag.
*/
STATIC INLINE int
_bcm_tx_hghdr_setup(bcm_pkt_t *pkt)
{
#ifdef BCM_XGS_SUPPORT
soc_higig_hdr_t *xgh = (soc_higig_hdr_t *)pkt->_higig;
int unit = pkt->unit;
uint32 vlan_val;
uint32 prio_val;
uint32 src_port;
uint32 src_mod;
uint32 pfm, color;
sal_memset(xgh, 0, sizeof(pkt->_higig));
soc_higig_field_set(unit, xgh, HG_start, SOC_HIGIG_START);
#ifdef BCM_HIGIG2_SUPPORT
if (SOC_IS_XGS3_SWITCH(unit)) {
if (!BCM_PKT_TX_ETHER(pkt)) { /* Raw mode */
bcm_pbmp_t tx_pbmp;
int port;
/*
* Use HiGig2 format if port is configured for HiGig2 encapsulation.
* Note that tx_pbmp only contains a single port at this point.
*/
BCM_PBMP_ASSIGN(tx_pbmp, pkt->tx_pbmp);
BCM_API_XLATE_PORT_PBMP_A2P(unit, &tx_pbmp);
BCM_PBMP_ITER(tx_pbmp, port) {
/* Use cached info about HiGig2 instead of reading h/w registers */
if (IS_HG2_ENABLED_PORT(unit, port)) {
return _bcm_tx_hg2hdr_setup(pkt);
}
#if defined(BCM_TRIDENT3_SUPPORT)
else if (SOC_IS_TRIDENT3X(unit) &&
soc_feature(unit, soc_feature_higig_over_ethernet)) {
bcm_port_encap_config_t encap_cfg;
BCM_IF_ERROR_RETURN(
bcm_port_encap_config_get(unit, port, &encap_cfg));
if (encap_cfg.encap == BCM_PORT_ENCAP_HIGIG_OVER_ETHERNET) {
return _bcm_tx_hg2hdr_setup(pkt);
}
}
#endif
#if defined(BCM_TRIDENT2PLUS_SUPPORT) && defined(BCM_TX_HGOE_LIMITED_SOLUTION)
else if (SOC_IS_TRIDENT2PLUS(unit)) {
int rv = BCM_E_NONE;
bcm_port_encap_config_t encap_cfg;
rv = bcm_port_encap_config_get(unit, port, &encap_cfg);
if (!BCM_FAILURE(rv) &&
encap_cfg.encap==BCM_PORT_ENCAP_HIGIG_OVER_ETHERNET) {
return _bcm_tx_hg2hdr_setup(pkt);
}
}
#endif /* BCM_TRIDENT2PLUS_SUPPORT && BCM_TX_HGOE_LIMITED_SOLUTION */
break;
}
} else { /* Packet to be sent through ingress logic */
/* If unit is Higig2 capable, set up Higig2 header */
if (soc_feature(unit, soc_feature_higig2)) {
return _bcm_tx_hg2hdr_setup(pkt);
}
}
}
#endif /* BCM_HIGIG2_SUPPORT */
soc_higig_field_set(unit, xgh, HG_hgi, SOC_HIGIG_HGI);
soc_higig_field_set(unit, xgh, HG_opcode, pkt->opcode);
soc_higig_field_set(unit, xgh, HG_hdr_format, SOC_HIGIG_HDR_DEFAULT);
vlan_val = BCM_PKT_VLAN_CONTROL(pkt);
soc_higig_field_set(unit, xgh, HG_vlan_tag, vlan_val);
if ((pkt->opcode == SOC_HIGIG_OP_MC) ||
(pkt->opcode == SOC_HIGIG_OP_IPMC)) {
soc_higig_field_set(unit, xgh, HG_l2mc_ptr,
_BCM_MULTICAST_ID_GET(pkt->multicast_group));
} else {
soc_higig_field_set(unit, xgh, HG_dst_mod, pkt->dest_mod);
soc_higig_field_set(unit, xgh, HG_dst_port, pkt->dest_port);
}
src_mod = (pkt->flags & BCM_TX_SRC_MOD) ?
pkt->src_mod : SOC_DEFAULT_DMA_SRCMOD_GET(unit);
soc_higig_field_set(unit, xgh, HG_src_mod, src_mod);
src_port = (pkt->flags & BCM_TX_SRC_PORT) ?
pkt->src_port : SOC_DEFAULT_DMA_SRCPORT_GET(unit);
soc_higig_field_set(unit, xgh, HG_src_port, src_port);
pfm = (pkt->flags & BCM_TX_PFM) ?
pkt->pfm : SOC_DEFAULT_DMA_PFM_GET(unit);
soc_higig_field_set(unit, xgh, HG_pfm, pfm);
prio_val = (pkt->flags & BCM_TX_PRIO_INT) ? pkt->prio_int : pkt->cos;
soc_higig_field_set(unit, xgh, HG_cos, prio_val);
if (pkt->stk_flags & BCM_PKT_STK_F_CLASSIFICATION_TAG) {
/* Overlay 2 */
if ((pkt->stk_flags & (BCM_PKT_STK_F_MIRROR |
BCM_PKT_STK_F_DO_NOT_MODIFY |
BCM_PKT_STK_F_DO_NOT_LEARN |
BCM_PKT_STK_F_TRUNK_FAILOVER)) |
(pkt->flags & BCM_PKT_F_ROUTED)) {
/* Conflict */
return BCM_E_PARAM;
}
soc_higig_field_set(unit, xgh, HG_ctag,
pkt->stk_classification_tag);
soc_higig_field_set(unit, xgh, HG_hdr_format, 1);
} else {
/* Overlay 1 */
if (pkt->stk_flags & BCM_PKT_STK_F_MIRROR) {
soc_higig_field_set(unit, xgh, HG_mirror_only, 1);
soc_higig_field_set(unit, xgh, HG_mirror, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_DO_NOT_MODIFY) {
soc_higig_field_set(unit, xgh, HG_donot_modify, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_DO_NOT_LEARN) {
soc_higig_field_set(unit, xgh, HG_donot_learn, 1);
}
if (pkt->stk_flags & BCM_PKT_STK_F_TRUNK_FAILOVER) {
soc_higig_field_set(unit, xgh, HG_lag_failover, 1);
}
if (pkt->flags & BCM_PKT_F_ROUTED) {
soc_higig_field_set(unit, xgh, HG_l3, 1);
}
/* Header format 0 */
}
switch (pkt->color) {
case bcmColorGreen:
color = 0;
break;
case bcmColorYellow:
color = 3;
break;
case bcmColorRed:
color = 1;
break;
case bcmColorBlack:
default:
return BCM_E_PARAM;
}
soc_higig_field_set(unit, xgh, HG_cng, color);
return BCM_E_NONE;
#endif /* BCM_XGS_SUPPORT */
return BCM_E_UNAVAIL;
}
/*
* Function:
* _bcm_tx_sltag_setup
* Purpose:
* Setup the SL tag consistently with data in packet.
* Parameters:
* pkt - Packet to set up header from
* Returns:
* BCM_E_XXX
* Notes:
*/
STATIC INLINE int
_bcm_tx_sltag_setup(bcm_pkt_t *pkt)
{
stk_tag_t *sltag = (stk_tag_t *)pkt->_sltag;
int slcount;
sal_memset(sltag, 0, sizeof(*sltag));
if (pkt->opcode == BCM_HG_OPCODE_CPU) {
slcount = 1;
} else {
slcount = 0;
}
sltag->stk_cnt = slcount;
sltag->src_tgid = (pkt->src_port >> 3) & 0x7;
sltag->src_rtag = pkt->src_port & 0x7;
sltag->pfm = pkt->pfm;
sltag->ed = 1;
sltag->stk_modid = pkt->src_mod;
return BCM_E_NONE;
}
/*
* Set up SL/HG tags according to system setup;
* Assumes unit is local and packet is non-NULL
*/
STATIC INLINE int
_bcm_tx_pkt_tag_setup(int unit, bcm_pkt_t *pkt)
{
if (pkt == NULL) {
return BCM_E_PARAM;
}
if (!(SOC_IS_ARAD(unit) || SOC_IS_DNX(unit))) {
/*
* Ignore user provided BCM_PKT_F_HGHDR flag
* keep it on Dune devices to indicate incoming CPU channel is set
*/
BCM_PKT_HGHDR_CLR(pkt);
}
if (SOC_IS_XGS3_SWITCH(unit)) {
/*
* XGS3: Higig header in packet data stream (Raw mode)
*/
bcm_pbmp_t tmp_pbm;
SOC_PBMP_ASSIGN(tmp_pbm, PBMP_HG_ALL(unit));
SOC_PBMP_OR(tmp_pbm, PBMP_HL_ALL(unit));
BCM_API_XLATE_PORT_PBMP_P2A(unit, &tmp_pbm);
SOC_PBMP_AND(tmp_pbm, pkt->tx_pbmp);
if ((!BCM_PKT_TX_ETHER(pkt)) &&
(SOC_PBMP_NOT_NULL(tmp_pbm))) { /* Raw mode on HG port */
BCM_PKT_HGHDR_REQUIRE(pkt);
}
/*
* Construct higig header from discrete members in the pkt
* if one is not provided.
*/
if (!BCM_PKT_TX_HG_READY(pkt)) {
BCM_IF_ERROR_RETURN(_bcm_tx_hghdr_setup(pkt));
}
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit) &&
soc_feature(unit, soc_feature_higig_over_ethernet)) {
int rv = BCM_E_NONE;
bcm_port_t tmp_port = 0;
bcm_port_encap_config_t encap_config = {0};
BCM_PBMP_ITER(pkt->tx_pbmp, tmp_port) {
rv = bcm_port_encap_config_get(unit, tmp_port, &encap_config);
if (!BCM_FAILURE(rv)
&& encap_config.encap==BCM_PORT_ENCAP_HIGIG_OVER_ETHERNET) {
/* clear HG flag in packet*/
BCM_PKT_HGHDR_CLR(pkt);
break;
}
}
}
#endif
} else if (SOC_IS_XGS12_FABRIC(unit)) {
BCM_PKT_HGHDR_REQUIRE(pkt);
if (!BCM_PKT_TX_HG_READY(pkt)) {
BCM_IF_ERROR_RETURN(_bcm_tx_hghdr_setup(pkt));
}
} else if (SOC_SL_MODE(unit)) {
BCM_PKT_SLTAG_REQUIRE(pkt);
BCM_IF_ERROR_RETURN(_bcm_tx_sltag_setup(pkt));
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_tx_pkt_setup
* Purpose:
* Default packet setup routine for transmit
* Parameters:
* unit - Unit on which being transmitted
* tx_pkt - Packet to update
* Returns:
* BCM_E_XXX
* Notes:
* tx_pkt->tx_pbmp should be set before calling this function
* Currently, the main thing this does is force the HG header
* on Hercules.
*/
int
bcm_common_tx_pkt_setup(int unit, bcm_pkt_t *tx_pkt)
{
if (tx_pkt == NULL) {
return BCM_E_PARAM;
}
if (!BCM_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!BCM_IS_LOCAL(unit)) {
/* Don't need to do special setup for tunnelled packets */
return BCM_E_NONE;
}
return _bcm_tx_pkt_tag_setup(unit, tx_pkt);
}
/*
* Function:
* bcm_tx_init
* Purpose:
* Initialize BCM TX API
* Parameters:
* unit - transmission unit
* Returns:
* BCM_E_XXX
* Notes:
* Currently, this just allocates shared memory space for the
* CRC append memory. This memory is zero and used by all packets
* that require CRC append (allocate).
*
* This pointer is only allocated once. If allocation fails,
* BCM_E_MEMORY is returned.
*/
int
bcm_common_tx_init(int unit)
{
if (!BCM_CONTROL_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!BCM_IS_LOCAL(unit)) {
/* Set up TX tunnel receiver and transmitter */
/* Currently this is done elsewhere */
return BCM_E_NONE;
}
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (SOC_IS_RCPU_ONLY(unit)) {
return BCM_E_NONE;
}
if (_null_crc_ptr == NULL) {
_null_crc_ptr = soc_cm_salloc(unit, sizeof(uint32), "Static CRC");
if (_null_crc_ptr == NULL) {
goto error;
}
sal_memset(_null_crc_ptr, 0, sizeof(uint32));
}
if (tx_cb_sem == NULL) {
tx_cb_sem = sal_sem_create("tx cb", sal_sem_BINARY, 0);
if (tx_cb_sem == NULL) {
goto error;
}
}
if (tx_dv_done == NULL) {
tx_queue_size = soc_property_get(unit, spn_BCM_TX_QUEUE_SIZE, 0);
if (tx_queue_size) {
tx_dv_done = sal_sem_create("tx dv notify", 0, tx_queue_size);
} else {
tx_dv_done = sal_sem_create("tx dv notify", sal_sem_BINARY, 1);
}
if (tx_dv_done == NULL) {
goto error;
}
}
if (tx_exit_notify == NULL) {
tx_exit_notify = sal_sem_create("tx exit notify", sal_sem_BINARY, 0);
if (tx_exit_notify == NULL) {
goto error;
}
}
if (sal_tx_spinlock == NULL) {
sal_tx_spinlock = sal_spinlock_create("sal_tx_lock");
if (sal_tx_spinlock == NULL) {
goto error;
}
}
/* Allocate a min size pkt for padding */
if (_pkt_pad_ptr == NULL) {
_pkt_pad_ptr = soc_cm_salloc(unit, ENET_MIN_PKT_SIZE, "TX Pkt Pad");
if (_pkt_pad_ptr == NULL) {
goto error;
}
sal_memset(_pkt_pad_ptr, 0, ENET_MIN_PKT_SIZE);
}
if (!_tx_init) { /* Only create the thread once */
_bcm_tx_run = TRUE;
/* Start up the tx callback handler thread */
_tx_tid = sal_thread_create("bcmTX", SAL_THREAD_STKSZ,
soc_property_get(unit,
spn_BCM_TX_THREAD_PRI,
DEFAULT_TX_PRI),
_bcm_tx_callback_thread, NULL);
if (_tx_tid == SAL_THREAD_ERROR) {
_bcm_tx_run = FALSE;
goto error;
}
#ifdef BCM_XGS3_SWITCH_SUPPORT
if (SOC_IS_XGS3_SWITCH(unit)) {
if (xgs3_async_tx_exit_notify == NULL) {
_bcm_async_run = TRUE;
xgs3_async_tx_exit_notify = sal_sem_create
("xgs3 async tx exit notify",
sal_sem_BINARY, 0);
if (xgs3_async_tx_exit_notify == NULL) {
_bcm_async_run = FALSE;
goto error;
}
}
_xgs3_async_tx_sem = sal_sem_create("xgs3 tx async",
sal_sem_COUNTING, 0);
if (_xgs3_async_tx_sem == NULL) {
goto error;
}
_xgs3_async_queue_lock = sal_spinlock_create("xgs3 tx async");
if (_xgs3_async_queue_lock == NULL) {
goto error;
}
_xgs3_async_tid = sal_thread_create("bcmXGS3AsyncTX",
SAL_THREAD_STKSZ,
soc_property_get(unit,
spn_BCM_TX_THREAD_PRI,
DEFAULT_TX_PRI),
_xgs3_async_thread, NULL);
if (_xgs3_async_tid == SAL_THREAD_ERROR) {
goto error;
}
}
#endif
#if defined(BCM_TRIDENT2PLUS_SUPPORT) && defined(BCM_TX_HGOE_LIMITED_SOLUTION)
#if defined(BROADCOM_DEBUG) && defined(BCM_TX_HGOE_DBG)
if (!g_hgoe_dbg_ctrs.tx_hgoe_ctr_sem) {
g_hgoe_dbg_ctrs.tx_hgoe_ctr_sem =
sal_sem_create("hgoe dbg sem", sal_sem_BINARY, 1);
if (g_hgoe_dbg_ctrs.tx_hgoe_ctr_sem == NULL) {
goto error;
}
}
#endif /*BROADCOM_DEBUG*/
#endif /*TD2P && TX_HGOE_LIMITED_SOL*/
}
_tx_init = TRUE;
return BCM_E_NONE;
error:
/* Clean up any allocated resources */
#ifdef BCM_XGS3_SWITCH_SUPPORT
if (xgs3_async_tx_exit_notify) {
sal_sem_destroy(xgs3_async_tx_exit_notify);
}
if (_xgs3_async_tx_sem) {
sal_sem_destroy(_xgs3_async_tx_sem);
}
if (_xgs3_async_queue_lock) {
sal_spinlock_destroy(_xgs3_async_queue_lock);
}
#endif
if (_tx_tid != SAL_THREAD_ERROR) {
sal_thread_destroy(_tx_tid);
_tx_tid = SAL_THREAD_ERROR;
}
if (_pkt_pad_ptr) {
soc_cm_sfree(unit, _pkt_pad_ptr);
_pkt_pad_ptr = NULL;
}
if (tx_cb_sem) {
sal_sem_destroy(tx_cb_sem);
tx_cb_sem = NULL;
}
if (tx_dv_done) {
sal_sem_destroy(tx_dv_done);
tx_dv_done = NULL;
}
if (tx_exit_notify) {
sal_sem_destroy(tx_exit_notify);
tx_exit_notify = NULL;
}
if (sal_tx_spinlock != NULL) {
sal_spinlock_destroy(sal_tx_spinlock);
sal_tx_spinlock = NULL;
}
if (_null_crc_ptr) {
soc_cm_sfree(unit, _null_crc_ptr);
_null_crc_ptr = NULL;
}
#if defined(BCM_TRIDENT2PLUS_SUPPORT) && defined(BCM_TX_HGOE_LIMITED_SOLUTION)
#if defined(BROADCOM_DEBUG) && defined(BCM_TX_HGOE_DBG)
if (g_hgoe_dbg_ctrs.tx_hgoe_ctr_sem) {
sal_sem_destroy(g_hgoe_dbg_ctrs.tx_hgoe_ctr_sem);
g_hgoe_dbg_ctrs.tx_hgoe_ctr_sem = NULL;
}
#endif
#endif /*TD2P && TX_HGOE_LIMITED_SOL && BCM_DEBUG */
return BCM_E_MEMORY;
}
/*
* Function:
* bcm_common_tx_deinit
* Purpose:
* De-Initialize BCM TX API
* Parameters:
* unit - transmission unit
* Returns:
* BCM_E_XXX
* Notes:
* Currently, this just free memory allocated in bcm_tx_init
*/
int
bcm_common_tx_deinit(int unit)
{
if (!BCM_CONTROL_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!BCM_IS_LOCAL(unit)) {
return BCM_E_NONE;
}
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (SOC_IS_RCPU_ONLY(unit)) {
return BCM_E_NONE;
}
if (soc_ndev_attached == 1) {
if (_tx_tid != SAL_THREAD_ERROR) {
_bcm_tx_run = FALSE;
/* Request exit */
_tx_init = FALSE;
sal_sem_give(tx_cb_sem);
/*wait tx thread had exit*/
(void)sal_sem_take(tx_exit_notify, sal_sem_FOREVER);
}
if (sal_tx_spinlock != NULL) {
sal_spinlock_destroy(sal_tx_spinlock);
sal_tx_spinlock = NULL;
}
if (tx_cb_sem != NULL) {
sal_sem_destroy(tx_cb_sem);
tx_cb_sem = NULL;
}
if (tx_dv_done != NULL) {
sal_sem_destroy(tx_dv_done);
tx_dv_done = NULL;
}
if (tx_exit_notify != NULL) {
sal_sem_destroy(tx_exit_notify);
tx_exit_notify = NULL;
}
if (_pkt_pad_ptr != NULL) {
soc_cm_sfree(unit, _pkt_pad_ptr);
_pkt_pad_ptr = NULL;
}
if (_null_crc_ptr != NULL) {
soc_cm_sfree(unit, _null_crc_ptr);
_null_crc_ptr = NULL;
}
}
return BCM_E_NONE;
}
#ifdef BCM_XGS3_SWITCH_SUPPORT
/*
* Function:
* bcm_common_xgs3_async_tx_thread_term
* Purpose:
* Tear down BCM XGS3AsyncTX thread
* Parameters:
* None
* Returns:
* Nothing
*/
void
bcm_common_xgs3_async_tx_thread_term(void)
{
if (soc_ndev_attached == 1) {
if (_xgs3_async_tid != SAL_THREAD_ERROR) {
_bcm_async_run = FALSE;
sal_sem_give(_xgs3_async_tx_sem);
/* Wait for xgs3_async_tx thread to exit */
sal_sem_take(xgs3_async_tx_exit_notify, sal_sem_FOREVER);
}
if (_xgs3_async_tx_sem) {
sal_sem_destroy(_xgs3_async_tx_sem);
_xgs3_async_tx_sem = NULL;
}
if (xgs3_async_tx_exit_notify) {
sal_sem_destroy(xgs3_async_tx_exit_notify);
xgs3_async_tx_exit_notify = NULL;
}
if (_xgs3_async_queue_lock) {
sal_spinlock_destroy(_xgs3_async_queue_lock);
_xgs3_async_queue_lock = NULL;
}
}
return;
}
#endif
/* Check the packet flags for inconsistencies or unsupported configs */
STATIC int
_tx_flags_check(int unit, bcm_pkt_t *pkt)
{
if (pkt == NULL) {
return BCM_E_PARAM;
}
/* Check for acceptable/consistent flags */
if (pkt->flags & BCM_TX_PRIO_INT) {
if (SOC_IS_DRACO1(unit) || SOC_IS_LYNX(unit)) {
if (pkt->cos != pkt->prio_int) {
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"Cannot set cos != prio_int on TX for 5690/74\n")));
return BCM_E_PARAM;
}
}
}
return BCM_E_NONE;
}
STATIC INLINE int
_bcm_tx_cb_intr_enabled(void)
{
#ifdef TX_CB_INTR
return BCM_E_NONE;
#else
return BCM_E_UNAVAIL;
#endif
}
#ifdef BCM_XGS3_SWITCH_SUPPORT
STATIC void
_xgs3_calculate_tx_packet_size(int unit, dv_t *dv, int *bytes)
{
int i;
switch (SOC_DCB_TYPE(unit)) {
default:
case 9:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb9_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#ifdef BCM_EASYRIDER_SUPPORT
case 10:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb10_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_EASYRIDER_SUPPORT */
#ifdef BCM_BRADLEY_SUPPORT
case 11:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb11_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_BRADLEY_SUPPORT */
#ifdef BCM_RAPTOR_SUPPORT
case 12:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb12_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_RAPTOR_SUPPORT */
#if defined(BCM_FIREBOLT2_SUPPORT) || defined(BCM_FIREBOLT_SUPPORT)
case 13:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb13_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_FIREBOLT2_SUPPORT || BCM_FIREBOLT_SUPPORT */
#ifdef BCM_TRIUMPH_SUPPORT
case 14:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb14_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_TRIUMPH_SUPPORT */
#ifdef BCM_RAPTOR_SUPPORT
case 15:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb15_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_RAPTOR_SUPPORT */
#ifdef BCM_SCORPION_SUPPORT
case 16:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb16_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_SCORPION_SUPPORT */
#ifdef BCM_HAWKEYE_SUPPORT
case 17:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb17_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_HAWKEYE_SUPPORT */
#ifdef BCM_RAPTOR_SUPPORT
case 18:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb18_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_RAPTOR_SUPPORT */
#ifdef BCM_TRIUMPH2_SUPPORT
case 19:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb19_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_TRIUMPH2_SUPPORT */
#ifdef BCM_ENDURO_SUPPORT
case 20:
case 30:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb20_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_ENDURO_SUPPORT */
#ifdef BCM_TRIDENT_SUPPORT
case 21:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb21_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_TRIDENT_SUPPORT */
#ifdef BCM_SHADOW_SUPPORT
case 22:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb22_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_SHADOW_SUPPORT */
#ifdef BCM_TRIUMPH3_SUPPORT
case 23:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb23_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_TRIUMPH3_SUPPORT */
#ifdef BCM_KATANA_SUPPORT
case 24:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb24_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_KATANA_SUPPORT */
#if defined(BCM_TRIDENT2_SUPPORT)
case 26:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb26_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_TRIDENT2_SUPPORT */
#ifdef BCM_KATANA2_SUPPORT
case 29:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb29_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_KATANA2_SUPPORT */
#ifdef BCM_GREYHOUND_SUPPORT
case 31:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb31_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_GREYHOUND_SUPPORT */
#if defined(BCM_TOMAHAWK_SUPPORT)
case 32:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes += ((dcb32_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_TOMAHAWK_SUPPORT */
#if defined(BCM_TRIDENT2PLUS_SUPPORT)
case 33:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes +=
((dcb33_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_TRIDENT2PLUS_SUPPORT */
#if defined(BCM_APACHE_SUPPORT)
case 35:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes +=
((dcb35_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_APACHE_SUPPORT */
#if defined(BCM_TRIDENT3_SUPPORT)
case 36:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes +=
((dcb36_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_TRIDENT3_SUPPORT */
#if defined(BCM_TOMAHAWK3_SUPPORT)
case 38:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes +=
((dcb38_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_TOMAHAWK3_SUPPORT */
#if defined(BCM_FIRELIGHT_SUPPORT)
case 40:
for (i = 0; i < dv->dv_vcnt; i++) {
*bytes +=
((dcb40_t *)SOC_DCB_IDX2PTR(dv->dv_unit, dv->dv_dcb, i))->c_count;
}
return;
#endif /* BCM_FIRELIGHT_SUPPORT */
}
}
#endif /* BCM_XGS3_SWITCH_SUPPORT */
/*
* Function:
* _bcm_tx
* Purpose:
* Transmit a single packet
* Parameters:
* unit - transmission unit
* pkt - The tx packet structure
* cookie - Callback cookie when tx done
* Returns:
* BCM_E_XXX
* Notes:
* To send unicast, broadcast or multicast packets from a switch
* chip, one must include all the outgoing ports in the port bitmap
* (pkt->pi_pbmp, pkt->pi_upbmp) and include the appropriate MAC DA
* in the packet data. To send different types of packet from a
* fabric chip, it is different and the Higig opcode
* (BCM_HG_OPCODE_xxx) indicates the type of packet.
*
* If the pkt->call_back function is non-null, executes async.
* Otherwise, will not return until DMA completes.
*
* Packet format is described by the packet flags. In particular,
* if the packet has a HiGig header (as indicated in the packet's
* flags) it will not have a VLAN tag set up for DMA. Care should
* be taken as this should only happen for Hercules (5670, 71).
* No provision is made for forcing the addition of both a VLAN
* tag and a HiGig header.
*
* If the unit is not local, TX tunneling is automatically
* invoked. CURRENT RESTRICTION: Asynchronous tunneled packets
* cannot receive cookie on callback.
*/
int
_bcm_tx(int unit, bcm_pkt_t *pkt, void *cookie)
{
dv_t *dv = NULL;
int rv = BCM_E_NONE;
char fmt[SOC_PBMP_FMT_LEN];
char *err_msg = NULL;
const int pkt_unit = (int) pkt->unit;
int async = pkt->call_back != NULL;
#if defined(BCM_CMICX_SUPPORT)
uint32 prefetch = 0;
#endif
int tx_sem_taken = 0;
int retry = 0;
int debug_enabled = 0;
if (!BCM_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!pkt || !pkt->pkt_data || (pkt->blk_count == 0) ||
!BCM_UNIT_VALID(pkt_unit)
) {
return BCM_E_PARAM;
}
#ifdef BCM_PETRA_SUPPORT
if (SOC_IS_ARAD(unit))
{
debug_enabled = bsl_check(bslLayerBcm, bslSourceTx, bslSeverityInfo, unit);
}
else
#endif
#ifdef BCM_DNX_SUPPORT
if (SOC_IS_DNX(unit))
{
debug_enabled = bsl_check(bslLayerBcm, bslSourceTx, bslSeverityInfo, unit);
}
else
#endif
{
debug_enabled = bsl_check(bslLayerSoc, bslSourceTx, bslSeverityNormal, unit);
}
if (debug_enabled) {
bcm_pbmp_t tx_pbmp, tx_upbmp;
BCM_PBMP_ASSIGN(tx_pbmp, pkt->tx_pbmp);
BCM_PBMP_ASSIGN(tx_upbmp, pkt->tx_upbmp);
BCM_API_XLATE_PORT_PBMP_A2P(unit, &tx_pbmp);
BCM_API_XLATE_PORT_PBMP_A2P(unit, &tx_upbmp);
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"bcm_tx: pkt, u %d. len[0] %d to %s. "),
unit, pkt->pkt_data[0].len,
SOC_PBMP_FMT(tx_pbmp, fmt)
));
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"%s. flags 0x%x\n"),
SOC_PBMP_FMT(tx_upbmp, fmt),
pkt->flags));
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"bcm_tx: dmod %d, dport %d, chan %d, op %d cos %d\n"),
pkt->dest_mod, pkt->dest_port, pkt->dma_channel, pkt->opcode,
pkt->cos));
{
uint16 i;
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"bcm_tx: packet: ")));
for (i=0; i<pkt->pkt_data[0].len ; i++) {
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"%.2x"),pkt->pkt_data[0].data[i]));
}
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"\n")));
}
}
#ifdef BCM_RPC_SUPPORT
if (!BCM_IS_LOCAL(unit)) { /* Tunnel the packet to the remote CPU */
bcm_cpu_tunnel_mode_t mode = BCM_CPU_TUNNEL_PACKET; /* default */
if (pkt->call_back != NULL && cookie != NULL) {
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"bcm_tx ERROR: "
"Cookie non-NULL on async tunnel call\n")));
return BCM_E_PARAM;
}
if (pkt->flags & BCM_TX_BEST_EFFORT) {
mode = BCM_CPU_TUNNEL_PACKET_BEST_EFFORT;
} else if (pkt->flags & BCM_TX_RELIABLE) {
mode = BCM_CPU_TUNNEL_PACKET_RELIABLE;
}
return bcm_tx_cpu_tunnel(pkt, unit, 0, BCM_CPU_TUNNEL_F_PBMP, mode);
}
#endif /* BCM_RPC_SUPPORT */
err_msg = "Bad flags for bcm_tx";
/* coverity[overrun-call] */
_ON_ERROR_GOTO(_tx_flags_check(unit, pkt), rv, error);
err_msg = "Could not set up pkt for bcm_tx";
/* coverity[overrun-call] */
_ON_ERROR_GOTO(_bcm_tx_pkt_tag_setup(unit, pkt), rv, error);
#if defined (INCLUDE_RCPU) && defined(BCM_XGS3_SWITCH_SUPPORT)
if ((SOC_UNIT_VALID(unit)) && (SOC_IS_RCPU_UNIT(unit))) {
if (!BCM_PKT_TX_ETHER(pkt)) {
BCM_IF_ERROR_RETURN(_bcm_xgs3_tx_pipe_bypass_header_setup(unit, pkt));
}
return _bcm_rcpu_tx(unit, pkt, cookie);
}
#endif /* INCLUDE_RCPU && BCM_XGS3_SWITCH_SUPPORT */
if (sal_sem_take(tx_dv_done, sal_sem_FOREVER) < 0) {
err_msg = "Failed to take tx_dv_done";
rv = BCM_E_FAIL;
goto error;
}
tx_sem_taken = 1;
err_msg = "Could not allocate dv/dv info";
do {
dv = _tx_dv_alloc(unit, 1, pkt->blk_count + TX_EXTRA_DCB_COUNT,
NULL, cookie, pkt->call_back != NULL);
if (!dv) {
if (BCM_SUCCESS(_bcm_tx_cb_intr_enabled()) || retry++ > 1000) {
rv = BCM_E_MEMORY;
goto error;
}
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit, "%s%s\n"), err_msg, ", will retry ..."));
sal_usleep(10000);
}
} while (!dv);
err_msg = "Could not setup or add pkt to DV";
#ifdef BCM_PETRA_SUPPORT
if (SOC_IS_ARAD(unit))
{
_ON_ERROR_GOTO(_sand_tx_pkt_desc_add(unit, pkt, dv, 0), rv, error);
}
else
#endif
#ifdef BCM_DNX_SUPPORT
if (SOC_IS_DNX(unit))
{
_ON_ERROR_GOTO(_sand_tx_pkt_desc_add(unit, pkt, dv, 0), rv, error);
}
else
#endif
{
_ON_ERROR_GOTO(_tx_pkt_desc_add(unit, pkt, dv, 0), rv, error);
}
if (SOC_DMA_MODE(unit) == SOC_DMA_MODE_CONTINUOUS) {
if (dv->dv_vcnt > 0) { /* Only add reload dcb if pkt dcb added */
err_msg = "Could not allocate a reload descriptor";
if (soc_dma_rld_desc_add(dv, 0) < 0) {
rv = BCM_E_MEMORY;
goto error;
}
#if defined(BCM_CMICX_SUPPORT)
prefetch = 1;
#endif
}
}
#if defined(BCM_CMICX_SUPPORT)
if (!prefetch) {
soc_dma_contiguous_desc_add(dv);
}
#endif
#ifdef BCM_XGS3_SWITCH_SUPPORT
if ((pkt->flags & BCM_TX_NO_PAD) && (dv->dv_vcnt > 0)) {
int bytes = 0;
_xgs3_calculate_tx_packet_size(unit, dv, &bytes);
if (SOC_IS_XGS3_SWITCH(unit)) {
if ((BCM_PKT_NO_VLAN_TAG(pkt) && bytes < 60) ||
(!BCM_PKT_NO_VLAN_TAG(pkt) && BCM_PKT_HAS_HGHDR(pkt) &&
BCM_PKT_TX_FABRIC_MAPPED(pkt) && bytes < 60) ||
(!BCM_PKT_NO_VLAN_TAG(pkt) && !BCM_PKT_HAS_HGHDR(pkt) &&
!BCM_PKT_TX_FABRIC_MAPPED(pkt) && bytes < 64)) {
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"bcm_tx: Discarding %s runt packet %s higig header %d\n"),
BCM_PKT_NO_VLAN_TAG(pkt) ? "untagged" : "tagged",
BCM_PKT_HAS_HGHDR(pkt) ? "with" : "without", bytes));
err_msg = "";
rv = BCM_E_PARAM;
goto error;
}
}
}
#ifdef BCM_INSTRUMENTATION_SUPPORT
if (pkt->flags2 & BCM_PKT_F2_VISIBILITY_PKT) {
_bcm_esw_pkt_trace_hw_reset(unit);
}
#endif /* BCM_INSTRUMENTATION_SUPPORT */
#endif /* BCM_XGS3_SWITCH_SUPPORT */
err_msg = "Could not send pkt";
if ((dv->dv_vcnt > 0) || (SOC_IS_ARAD(unit)) || (SOC_IS_DNX(unit))) {
rv = _bcm_tx_chain_send(unit, dv, async);
/*
* sem_give() is needed when packet is sent synchronously or non-queued.
* Tx callback thread will do sem_give() once the packet done completes
* asynchronously.
*/
if (BCM_SUCCESS(rv) && (!async || !tx_queue_size)) {
sal_sem_give(tx_dv_done);
}
} else {
/* Call the registered callback if any */
if (pkt->call_back != NULL) {
(pkt->call_back)(unit, pkt, cookie);
}
if (dv != NULL) {
_tx_dv_free(unit, dv);
}
sal_sem_give(tx_dv_done);
LOG_WARN(BSL_LS_BCM_TX,
(BSL_META_U(unit, "%s%s\n"), err_msg, " with dv_vcnt = 0"));
rv = BCM_E_NONE;
}
error:
if (BCM_FAILURE(rv)) {
if (tx_sem_taken) {
sal_sem_give(tx_dv_done);
}
}
_PROCESS_ERROR(unit, rv, dv, err_msg);
return rv;
}
/*
* Function:
* _xgs3_async_thread
* Purpose:
* Handles anync transmit for XGS3 devices
* Parameters:
*/
#ifdef BCM_XGS3_SWITCH_SUPPORT
STATIC int
_xgs3_async_tx(int unit, bcm_pkt_t * pkt, void * cookie)
{
_xgs3_async_queue_t * item;
item = sal_alloc(sizeof(_xgs3_async_queue_t), "Async packet info");
if (item == NULL) {
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"Can't allocate packet info\n")));
return BCM_E_MEMORY;
}
sal_memset(item, 0, sizeof(_xgs3_async_queue_t));
item->unit = unit;
item->pkt = pkt;
item->cookie = cookie;
item->next = NULL;
sal_spinlock_lock(_xgs3_async_queue_lock);
if (_xgs3_async_head == NULL) {
_xgs3_async_head = item;
} else {
_xgs3_async_tail->next = item;
}
_xgs3_async_tail = item;
sal_spinlock_unlock(_xgs3_async_queue_lock);
sal_sem_give(_xgs3_async_tx_sem);
return BCM_E_NONE;
}
STATIC int
_xgs3_async_queue_fetch(int * unit, bcm_pkt_t ** pkt, void ** cookie)
{
_xgs3_async_queue_t * item;
if (sal_sem_take(_xgs3_async_tx_sem, sal_sem_FOREVER) < 0) {
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META("async fetch: Can't take async TX semaphore\n")));
return BCM_E_RESOURCE;
}
if (_bcm_async_run) {
sal_spinlock_lock(_xgs3_async_queue_lock);
item = _xgs3_async_head;
_xgs3_async_head = item->next;
if (_xgs3_async_head == NULL) {
_xgs3_async_tail = NULL;
}
sal_spinlock_unlock(_xgs3_async_queue_lock);
*unit = item->unit;
*pkt = item->pkt;
*cookie = item->cookie;
sal_free(item);
}
return BCM_E_NONE;
}
typedef struct _xgs3_tx_cb_cookie_s {
bcm_pkt_t *orig_pkt;
void *orig_cookie;
void *cleanup_mem;
} _xgs3_tx_cb_cookie_t;
void _xgs3_tx_cb(int unit, bcm_pkt_t *pkt, void *cookie)
{
_xgs3_tx_cb_cookie_t *mycookie = cookie;
if (mycookie->orig_pkt->call_back != NULL) {
(mycookie->orig_pkt->call_back)(unit, mycookie->orig_pkt, mycookie->orig_cookie);
}
if(mycookie->cleanup_mem != NULL) {
sal_free(mycookie->cleanup_mem);
}
sal_free (cookie);
return;
}
#ifdef BCM_SHADOW_SUPPORT
STATIC int
_shadow_tx(int unit, bcm_pkt_t *pkt, void *cookie)
{
/* int pkt_cnt; */
int port;
int rv = BCM_E_NONE;
bcm_pkt_t *packet_p;
bcm_pkt_t packet;
/* _xgs3_tx_cb_cookie_t *_xgs3_tx_cb_cookie; */
packet_p = &packet;
BCM_PBMP_ITER(pkt->tx_pbmp, port)
{
sal_memcpy(packet_p, pkt, sizeof(bcm_pkt_t));
/* Set port control */
soc_reg_field32_modify(unit, UFLOW_PORT_CONTROLr, 0,
DEST_PORTf, port);
BCM_PBMP_PORT_SET(packet_p->tx_pbmp, port);
BCM_PBMP_PORT_SET(packet_p->tx_upbmp, port);
BCM_PBMP_AND(packet_p->tx_upbmp, pkt->tx_upbmp);
BCM_PBMP_CLEAR(packet_p->tx_l3pbmp);
/* Check untag membership before translating */
if (PBMP_MEMBER(pkt->tx_upbmp, port)) {
packet_p->flags |= BCM_PKT_F_TX_UNTAG;
} else {
packet_p->flags &= (~BCM_PKT_F_TX_UNTAG);
}
packet_p->call_back = NULL; /* Synchronus send */
rv = _bcm_tx(unit, packet_p, cookie);
/* Revert back port control */
soc_reg_field32_modify(unit, UFLOW_PORT_CONTROLr, 0,
DEST_PORTf, 0);
}
return rv;
}
#endif /* BCM_SHADOW_SUPPORT */
STATIC int
_xgs3_tx(int unit, bcm_pkt_t *pkt, void *cookie)
{
int pkt_cnt;
int port;
int rv;
bcm_pkt_t *packets_p;
bcm_pkt_t *packet_p;
bcm_pkt_t **packet_pointers_p;
bcm_pkt_t **packet_pointer_p;
_xgs3_tx_cb_cookie_t *_xgs3_tx_cb_cookie;
BCM_PBMP_COUNT(pkt->tx_pbmp, pkt_cnt);
/* Create an array of packets, one per port */
packets_p = sal_alloc(pkt_cnt * sizeof(bcm_pkt_t), "Packet copies");
if (packets_p == NULL) {
return BCM_E_MEMORY;
}
packet_pointers_p = sal_alloc(pkt_cnt * sizeof(bcm_pkt_t *),
"Packet pointers");
if (packet_pointers_p == NULL) {
sal_free(packets_p);
return BCM_E_MEMORY;
}
packet_p = packets_p;
packet_pointer_p = packet_pointers_p;
BCM_PBMP_ITER(pkt->tx_pbmp, port)
{
sal_memcpy(packet_p, pkt, sizeof(bcm_pkt_t));
BCM_PBMP_PORT_SET(packet_p->tx_pbmp, port);
BCM_PBMP_PORT_SET(packet_p->tx_upbmp, port);
BCM_PBMP_AND(packet_p->tx_upbmp, pkt->tx_upbmp);
BCM_PBMP_CLEAR(packet_p->tx_l3pbmp);
packet_p->call_back = NULL; /* We don't need individual Callbacks for each packet */
*packet_pointer_p = packet_p;
++packet_p;
++packet_pointer_p;
}
if (NULL != pkt->call_back) {
_xgs3_tx_cb_cookie = sal_alloc(sizeof(_xgs3_tx_cb_cookie_t), "Callback Cookie");
if (_xgs3_tx_cb_cookie == NULL) {
sal_free(packet_pointers_p);
sal_free(packets_p);
return BCM_E_MEMORY;
}
_xgs3_tx_cb_cookie->orig_pkt = pkt;
_xgs3_tx_cb_cookie->orig_cookie = cookie;
_xgs3_tx_cb_cookie->cleanup_mem = packets_p;
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit) &&
soc_feature(unit, soc_feature_higig_over_ethernet)) {
rv = bcm_td3_tx_hgoe_array(unit, packet_pointers_p, pkt_cnt,
&_xgs3_tx_cb, _xgs3_tx_cb_cookie);
} else
#endif
{
rv = bcm_common_tx_array(unit, packet_pointers_p, pkt_cnt, &_xgs3_tx_cb,
_xgs3_tx_cb_cookie);
}
sal_free(packet_pointers_p);
/* packets_p and _xgs3_tx_cb_cookie will be freed by _xgs3_tx_cb */
} else {
#ifdef BCM_TRIDENT3_SUPPORT
if (SOC_IS_TRIDENT3X(unit) &&
soc_feature(unit, soc_feature_higig_over_ethernet)) {
rv = bcm_td3_tx_hgoe_array(unit, packet_pointers_p,
pkt_cnt, NULL, NULL);
} else
#endif
{
rv = bcm_common_tx_array(unit, packet_pointers_p, pkt_cnt, NULL, NULL);
}
sal_free(packet_pointers_p);
sal_free(packets_p);
}
return rv;
}
STATIC void
_xgs3_async_thread(void * param)
{
int unit = 0;
bcm_pkt_t * pkt;
void * cookie;
int rv;
char thread_name[SAL_THREAD_NAME_MAX_LEN];
sal_thread_t thread;
COMPILER_REFERENCE(param);
while(_bcm_async_run) {
if ((rv = _xgs3_async_queue_fetch(&unit, &pkt, &cookie)) < 0) {
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"Async TX: fetch: %s\n"), bcm_errmsg(rv)));
break;
}
/*_bcm_async_run will be set to false if thread is terminated, hence
* check this condition again
*/
if (_bcm_async_run) {
if ((rv = _xgs3_tx(unit, pkt, cookie)) < 0) {
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"Async TX: tx: %s\n"), bcm_errmsg(rv)));
break;
}
}
}
if (_bcm_async_run) {
thread = sal_thread_self();
thread_name[0] = 0;
sal_thread_name(thread, thread_name, sizeof (thread_name));
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"AbnormalThreadExit:%s\n"), thread_name));
}
sal_sem_give(xgs3_async_tx_exit_notify);
sal_thread_exit(0);
}
#endif
#if defined(BCM_TRIDENT2PLUS_SUPPORT) && defined(BCM_TX_HGOE_LIMITED_SOLUTION)
typedef struct bcm_tx_hgoe_cookie_s {
bcm_pkt_cb_f chain_cb;
bcm_pkt_cb_f pkt_cb;
bcm_pkt_t *org_pkt;
void *org_cookie;
uint32 org_pkt_flags;
bcm_pkt_blk_t *org_pkt_blk_addr;
bcm_pkt_blk_t *new_pkt_blk_addr;
} bcm_tx_hgoe_cookie_t;
typedef struct bcm_tx_hgoe_chain_cb_cookie_s {
bcm_pkt_cb_f user_given_chain_cb;
void *user_given_cookie;
uint32 pkt_cnt;
bcm_tx_hgoe_cookie_t *pkt_cookie_arr;
} bcm_tx_hgoe_chain_cb_cookie_t;
STATIC void
bcm_common_tx_hgoe_pkt_cb(int unit, bcm_pkt_t *pkt, void *cookie) {
bcm_tx_hgoe_cookie_t *my_cookie = (bcm_tx_hgoe_cookie_t *)cookie;
if (my_cookie) {
if (my_cookie->pkt_cb || !my_cookie->chain_cb) {
/* Revert the changes done to the original pkt blk data */
pkt->pkt_data = my_cookie->org_pkt_blk_addr;
pkt->blk_count--;
pkt->flags |=
(my_cookie->org_pkt_flags & (BCM_TX_ETHER | BCM_TX_HG_READY));
pkt->call_back = my_cookie->pkt_cb;
BCM_TX_HGOE_DBG_CTR_SEM_INCR(pkt_blk_rvt_cnt)
}
if (my_cookie->pkt_cb) {
/* Now call the org call back*/
my_cookie->pkt_cb(unit, pkt, my_cookie->org_cookie);
}
/* If chain cb is not defined then release the pkt blk related
* memories, otherwise let chain_cb take care of releasing them.
*/
if (!my_cookie->chain_cb) {
if (my_cookie->new_pkt_blk_addr) {
if (my_cookie->new_pkt_blk_addr->data) {
sal_dma_free(my_cookie->new_pkt_blk_addr->data);
BCM_TX_HGOE_DBG_CTR_SEM_INCR(dma_free_cnt)
}
sal_free(my_cookie->new_pkt_blk_addr);
BCM_TX_HGOE_DBG_CTR_SEM_INCR(blk_free_cnt)
}
sal_free(my_cookie);
BCM_TX_HGOE_DBG_CTR_SEM_INCR(ck_free_cnt)
}
}
}
STATIC void *
_bcm_common_tx_hgoe_cb_cookie_set(bcm_pkt_t *pkt,
bcm_pkt_cb_f chain_cb,
void *org_cookie,
uint32 org_flags,
bcm_pkt_blk_t *org_blk_addr) {
if (pkt->call_back || chain_cb) {
bcm_tx_hgoe_cookie_t *cookie = sal_alloc(sizeof(*cookie), "hgoecookie");
if (cookie) {
sal_memset(cookie, 0, sizeof(bcm_tx_hgoe_cookie_t));
cookie->pkt_cb = pkt->call_back;
cookie->chain_cb = chain_cb;
cookie->org_pkt = pkt;
cookie->org_cookie = org_cookie;
cookie->org_pkt_flags = org_flags;
cookie->org_pkt_blk_addr = org_blk_addr;
cookie->new_pkt_blk_addr = pkt->pkt_data;
pkt->call_back = pkt->call_back ? bcm_common_tx_hgoe_pkt_cb : NULL;
BCM_TX_HGOE_DBG_CTR_SEM_INCR(ck_alloc_cnt)
}
return (void *)cookie;
}
else
return org_cookie;
}
STATIC void
_bcm_common_tx_hgoe_manual_cleanup(bcm_pkt_t *pkt,
uint32 org_flags, bcm_pkt_blk_t *org_blk_addr, bcm_pkt_cb_f org_pkt_cb) {
BCM_TX_HGOE_DBG_CTR_SEM_ACQ
if (pkt->pkt_data) {
if (pkt->pkt_data[0].data) {
sal_dma_free(pkt->pkt_data[0].data);
BCM_TX_HGOE_DBG_CTR_INCR(dma_free_cnt)
}
sal_free(pkt->pkt_data);
BCM_TX_HGOE_DBG_CTR_INCR(blk_free_cnt)
}
pkt->pkt_data = org_blk_addr;
pkt->flags |= (org_flags & (BCM_TX_ETHER | BCM_TX_HG_READY));
pkt->blk_count--;
pkt->call_back = org_pkt_cb;
BCM_TX_HGOE_DBG_CTR_INCR(pkt_blk_rvt_cnt)
BCM_TX_HGOE_DBG_CTR_SEM_REL
return;
}
STATIC void
bcm_common_tx_hgoe_tx_chain_cb(int unit, bcm_pkt_t *pkt, void *cookie) {
uint32 pkt_idx;
bcm_tx_hgoe_cookie_t *per_pkt_info = NULL;
bcm_tx_hgoe_chain_cb_cookie_t *my_cookie =
(bcm_tx_hgoe_chain_cb_cookie_t *) cookie;
if (my_cookie) {
per_pkt_info = my_cookie->pkt_cookie_arr;
if (per_pkt_info) {
/* Revert the pkt data blk changes for eack packet in the chain */
for (pkt_idx=0 ; pkt_idx<my_cookie->pkt_cnt ; pkt_idx++) {
if (per_pkt_info[pkt_idx].chain_cb) {
_bcm_common_tx_hgoe_manual_cleanup(
per_pkt_info[pkt_idx].org_pkt,
per_pkt_info[pkt_idx].org_pkt_flags,
per_pkt_info[pkt_idx].org_pkt_blk_addr,
per_pkt_info[pkt_idx].pkt_cb);
}
}
/* Call any user given pkt cb for eack packet */
for (pkt_idx=0 ; pkt_idx<my_cookie->pkt_cnt ; pkt_idx++) {
if (per_pkt_info[pkt_idx].pkt_cb) {
(per_pkt_info[pkt_idx].pkt_cb)(unit,
per_pkt_info[pkt_idx].org_pkt,
per_pkt_info[pkt_idx].org_cookie);
}
}
/* Remove the per packet info/cookie */
sal_free(per_pkt_info);
BCM_TX_HGOE_DBG_CTR_SEM_DECR(tx_list_pkt_ck_arr_cnt)
}
/* Call user given chain cb, if any */
if (my_cookie->user_given_chain_cb) {
my_cookie->user_given_chain_cb(unit, pkt,
my_cookie->user_given_cookie);
}
/* Remove the master cookie */
sal_free(my_cookie);
BCM_TX_HGOE_DBG_CTR_SEM_DECR(tx_list_master_ck_cnt)
}
return;
}
STATIC int
_bcm_common_tx_hgoe_prepare_pkt(int unit,
bcm_pkt_t *pkt,
uint32 *org_flags,
bcm_pkt_blk_t **org_blk_start,
bcm_port_encap_config_t encap_cfg) {
int rv = BCM_E_NONE;
int blk_idx = 0;
uint8 vlan_adj = 0;
bcm_pkt_blk_t *tmpPktBlkArr = NULL;
uint8 *dma_buffer = NULL;
uint16 htons_val = 0;
if (!pkt || !org_blk_start || !org_flags) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
return(BCM_E_PARAM);
}
/* Re-Adjust the size for VLAN tag */
if (!BCM_PKT_NO_VLAN_TAG(pkt)) {
vlan_adj = 4;
}
/* Blk 0 should have DMAC, SMAC and VLAN (if VLAN tag exists) */
if (pkt->pkt_data[0].len < (12 + vlan_adj)) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
return (BCM_E_FAIL);
}
/* Create a HG2 hdr if not provided */
if( SOC_HIGIG2_START != *BCM_PKT_HG_HDR(pkt) ) {
rv = _bcm_tx_pkt_tag_setup(unit, pkt);
/* If HG Hdr build fails then bail out as HGoE requires the HG Hdr. */
if (BCM_FAILURE(rv)) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
return rv;
}
/* If HG Hdr was not built return back error. */
if (SOC_HIGIG2_START != *BCM_PKT_HG_HDR(pkt)) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
return (BCM_E_FAIL);
}
}
/* Create a dma'able block of memory */
dma_buffer = sal_dma_alloc(32, "HGoEHdrs");
if (!dma_buffer) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
return BCM_E_MEMORY;
}
/* Create a pkt data block */
tmpPktBlkArr =
sal_alloc(sizeof(bcm_pkt_blk_t) * (pkt->blk_count + 1), "HGoEBlks");
if (!tmpPktBlkArr) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
sal_dma_free(dma_buffer);
return BCM_E_MEMORY;
}
/* Fill in the block details */
tmpPktBlkArr[0].data = dma_buffer;
tmpPktBlkArr[0].len = 32;
for (blk_idx=0 ; blk_idx<pkt->blk_count ; blk_idx++ ) {
tmpPktBlkArr[blk_idx+1] = pkt->pkt_data[blk_idx];
}
/* Create and copy 16 byte HGoE HDR */
sal_memcpy(dma_buffer, pkt->pkt_data[0].data, 12);
htons_val = bcm_htons(encap_cfg.higig_ethertype);
sal_memcpy(dma_buffer + 12, &htons_val, 2);
htons_val = bcm_htons(encap_cfg.hgoe_reserved);
sal_memcpy(dma_buffer + 14, &htons_val, 2);
/* Copy 16 byte HG2 HDR */
sal_memcpy(dma_buffer + 16, BCM_PKT_HG_HDR(pkt), 16);
/* Rewrite the SOP as HGoE requires the SOP to be 0xFB */
dma_buffer[16] = SOC_HIGIG_START;
/* Keep hold of the start of the org blk address */
*org_blk_start = pkt->pkt_data;
/* Replace the block list with new blk list */
pkt->pkt_data = tmpPktBlkArr;
pkt->blk_count++;
/* Readjust the len of org payload as SMAC/DMAC are already in HGoE Hdr */
tmpPktBlkArr[1].len -= (12 + vlan_adj);
tmpPktBlkArr[1].data += (12 + vlan_adj);
BCM_TX_HGOE_DBG_CTR_SEM_ACQ
BCM_TX_HGOE_DBG_CTR_INCR(dma_alloc_cnt)
BCM_TX_HGOE_DBG_CTR_INCR(blk_alloc_cnt)
BCM_TX_HGOE_DBG_CTR_INCR(pkt_blk_chg_cnt)
BCM_TX_HGOE_DBG_CTR_SEM_REL
/* Store the org flags */
*org_flags = pkt->flags;
/* Mark the packet as SoBMH */
pkt->flags &= ~BCM_TX_ETHER;
pkt->flags &= ~BCM_TX_HG_READY;
return rv;
}
#endif /* BCM_TRIDENT2PLUS_SUPPORT && BCM_TX_HGOE_LIMITED_SOLUTION */
/*
* Function:
* bcm_tx
* Purpose:
* Wrapper for _bcm_tx to work around a lack of XGS3 support for
* transmitting to a bitmap.
* Parameters:
* unit - transmission unit
* pkt - The tx packet structure
* cookie - Callback cookie when tx done
* Returns:
* BCM_E_XXX
* Notes:
* XGS3 devices cannot dispatch packets to multiple ports. To emulate this
* functionality, bcm_tx iterates over the requested bitmaps. The callback,
* if applicable, shall be called only once.
*/
int
bcm_common_tx(int unit, bcm_pkt_t *pkt, void *cookie)
{
int rv = BCM_E_NONE;
#if defined(BCM_TRIDENT2PLUS_SUPPORT) && defined(BCM_TX_HGOE_LIMITED_SOLUTION)
void *my_cookie = NULL;
bcm_port_t tx_port = 0;
uint32 org_pkt_flags = 0;
bcm_pkt_cb_f pkt_org_cb = NULL;
bcm_pkt_blk_t *org_pkt_blk_addr = NULL;
bcm_port_encap_config_t encap_cfg = {0};
#endif /* BCM_TRIDENT2PLUS_SUPPORT && BCM_TX_HGOE_LIMITED_SOLUTION */
#ifdef BCM_SHADOW_SUPPORT
if (BCM_IS_LOCAL(unit) && SOC_IS_SHADOW(unit)) {
/* In BCM88732 device the packets tx is handled differntly than an XGS
* device, although there are many similarites hence most of the code
* is reused.
*/
_shadow_tx(unit, pkt, cookie);
} else
#endif
#ifdef BCM_XGS3_SWITCH_SUPPORT
if (BCM_IS_LOCAL(unit) && SOC_IS_XGS3_SWITCH(unit)) {
int pkt_cnt;
BCM_PBMP_COUNT(pkt->tx_pbmp, pkt_cnt);
if ((pkt_cnt <= 1) || (BCM_PKT_TX_ETHER(pkt))) {
#if defined(BCM_TRIDENT3_SUPPORT)
if (SOC_IS_TRIDENT3X(unit) &&
soc_feature(unit, soc_feature_higig_over_ethernet)) {
if (1 == pkt_cnt && !BCM_PKT_TX_ETHER(pkt)) {
bcm_port_t tmp_port = 0;
bcm_port_encap_config_t encap_config = {0};
BCM_PBMP_ITER(pkt->tx_pbmp, tmp_port) {
rv = bcm_port_encap_config_get(unit, tmp_port, &encap_config);
if (!BCM_FAILURE(rv)
&& encap_config.encap == BCM_PORT_ENCAP_HIGIG_OVER_ETHERNET) {
/* Tx a HGOE packet */
rv = bcm_td3_tx_hgoe_pkt(unit, pkt, &encap_config, cookie, _bcm_tx);
} else if (!BCM_FAILURE(rv)) {
/* Tx a normal packet */
rv = _bcm_tx(unit, pkt, cookie);
}
/* End the port iteration as only 1 TX prt */
break;
}
} else {
rv = _bcm_tx(unit, pkt, cookie);
}
return rv;
}
#endif
#if defined(BCM_TRIDENT2PLUS_SUPPORT) && defined(BCM_TX_HGOE_LIMITED_SOLUTION)
/* Check for TD2P and other limitations */
if (SOC_IS_TRIDENT2PLUS(unit)
&& 1==pkt_cnt && !BCM_PKT_TX_ETHER(pkt)) {
/* Iterate through given pbmp to find the one TX port */
BCM_PBMP_ITER(pkt->tx_pbmp, tx_port)
{
rv = bcm_port_encap_config_get(unit, tx_port, &encap_cfg);
/* If the tx port is HGoE then go through the trouble of
* forming a sobmh pkt otherwise just use the default way
*/
if (!BCM_FAILURE(rv)
&& encap_cfg.encap==BCM_PORT_ENCAP_HIGIG_OVER_ETHERNET) {
/* Prepare the packet */
rv =
_bcm_common_tx_hgoe_prepare_pkt(unit, pkt,
&org_pkt_flags, &org_pkt_blk_addr, encap_cfg);
/* Sanity check for copied data length */
if (!BCM_FAILURE(rv)) {
pkt_org_cb = pkt->call_back;
/* cookie setup*/
my_cookie =
_bcm_common_tx_hgoe_cb_cookie_set(pkt, NULL,
cookie, org_pkt_flags, org_pkt_blk_addr);
/* Send the pkt if the cookie creation succeeded */
if (my_cookie || !pkt_org_cb) {
rv = _bcm_tx(unit, pkt, my_cookie);
} else { /* cookie alloc err */
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
rv = BCM_E_MEMORY;
}
/* Cookie cleanup in an event of failure */
if (BCM_FAILURE(rv)
&& my_cookie && cookie!=my_cookie) {
sal_free(my_cookie);
BCM_TX_HGOE_DBG_CTR_SEM_INCR(ck_free_cnt)
}
/* Pkt cleanup if no callback or failure to send */
if (BCM_FAILURE(rv) || !pkt_org_cb) {
_bcm_common_tx_hgoe_manual_cleanup(pkt,
org_pkt_flags,
org_pkt_blk_addr,
pkt_org_cb);
}
}
} else { /* Dest. port is not HGoE default to the old way */
rv= _bcm_tx(unit, pkt, cookie);
}
/* End the port iteration as only 1 TX prt */
break;
} /* Loop on the tx port bitmap */
} else { /* NonTD2P or limitations not satisfied use the old way */
rv= _bcm_tx(unit, pkt, cookie);
}
return rv;
#else
return _bcm_tx(unit, pkt, cookie);
#endif /* BCM_TRIDENT2PLUS_SUPPORT && BCM_TX_HGOE_LIMITED_SOLUTION */
} else if (pkt->call_back == NULL) {
return _xgs3_tx(unit, pkt, cookie);
} else {
return _xgs3_async_tx(unit, pkt, cookie);
}
} else
#endif
{
rv = _bcm_tx(unit, pkt, cookie);
}
return rv;
}
/*
* Function:
* bcm_tx_array
* Purpose:
* Transmit an array of packets
* Parameters:
* unit - transmission unit
* pkt - array of pointers to packets to transmit
* count - Number of packets in list
* all_done_cb - Callback function (if non-NULL) when all pkts tx'd
* cookie - Callback cookie.
* Returns:
* BCM_E_XXX
* Notes:
* If all_done_cb is non-NULL, the packets are sent asynchronously
* (the routine returns before all the pkts are sent)
*
* The "packet callback" will be set according to the value
* in each packet's "call_back" member, so that must be initialized
* for all packets in the chain.
*
* If any packet requires a callback, the packet-done callback is
* enabled for all packets in the chain.
*
* This routine does not support tunnelling to a remote CPU for
* forwarding.
*
* CURRENTLY: The TX parameters, src mod, src port, PFM
* and internal priority, are determined by the first packet in
* the array. This may change to break the array into subchains
* when differences are detected.
*/
#if defined(BCM_TRIDENT2PLUS_SUPPORT) && defined(BCM_TX_HGOE_LIMITED_SOLUTION)
STATIC int
_bcm_common_tx_array(int unit, bcm_pkt_t **pkt, int count,
bcm_pkt_cb_f all_done_cb, void *cookie);
int
bcm_common_tx_array(int unit, bcm_pkt_t **pkt_arr, int count,
bcm_pkt_cb_f all_done_cb, void *cookie)
{
int rv = BCM_E_NONE;
int port_cnt = 0;
bcm_pbmp_t pbmp;
uint32 pkt_idx = 0;
uint32 prt_idx = 0;
uint8 is_pkt_cb = 0;
bcm_port_t tx_port = 0;
uint32 org_pkt_flags = 0;
uint8 use_dflt_method = 1;
bcm_pkt_t *cur_pkt = NULL;
bcm_pkt_blk_t *org_pkt_blk_addr = NULL;
bcm_port_encap_config_t encapcfg = {0};
bcm_tx_hgoe_cookie_t *pkt_info_arr = NULL;
bcm_tx_hgoe_chain_cb_cookie_t *master_cookie = NULL;
typedef struct {
bcm_port_t port;
uint16 ether_type;
uint16 hgoe_rsvd;
} hgoe_port_info_t;
hgoe_port_info_t *port_info_arr = NULL;
/* Input paramter check */
if (!pkt_arr) {
return BCM_E_PARAM;
}
if (count<1 || !*pkt_arr) {
return BCM_E_PARAM;
}
if (!BCM_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!BCM_IS_LOCAL(unit)) { /* Tunnel the packet to the remote CPU */
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"bcm_tx_array ERROR: Cannot tunnel\n")));
return BCM_E_PARAM;
}
if (SOC_IS_TRIDENT2PLUS(unit)) {
BCM_PBMP_CLEAR(pbmp);
/* Do fast check if the HGoE logic can be invoked or not */
for ( pkt_idx=0 ; pkt_idx<count ; pkt_idx++) {
/* Get hold of the current packet */
cur_pkt = pkt_arr[pkt_idx];
/* If even a single pkt is smart switched then go default route */
if (BCM_PKT_TX_ETHER(cur_pkt)) {
break;
}
/* If pkt has to be sent on multiple ports then go default route */
BCM_PBMP_COUNT(cur_pkt->tx_pbmp, port_cnt);
if (1!=port_cnt) {
break;
}
BCM_PBMP_OR(pbmp, cur_pkt->tx_pbmp);
/* Mark if individual pkt call back exists. */
if (!is_pkt_cb && cur_pkt->call_back) {
is_pkt_cb = 1;
}
}
/* If previous loop did not complete successfully or there is a case
* where individual pkt callback esists but chain done callback not then
* the HGoE logic cannot be invoked as it wont handle the said scenario.
* Hence send the pkt using default way and hope TX happens successfully
*/
if ((pkt_idx >= count) && !(is_pkt_cb && !all_done_cb) ) {
use_dflt_method = 0;
}
}
if (use_dflt_method) {
return(_bcm_common_tx_array(unit, pkt_arr, count, all_done_cb, cookie));
}
/*** Check for port encapsulation type ***/
/* Create a buffer to hold HGoE tag to be used later */
BCM_PBMP_COUNT(pbmp, port_cnt);
port_info_arr=sal_alloc(sizeof(hgoe_port_info_t) * port_cnt, "HGoEPrtInfo");
if (!port_info_arr) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
return (BCM_E_MEMORY);
}
BCM_TX_HGOE_DBG_CTR_SEM_INCR(tx_list_port_info_cnt)
/* If all tx ports are HGoE then go through the trouble of
* forming a sobmh pkt otherwise just use the default way
*/
prt_idx = 0;
rv = BCM_E_NONE;
BCM_PBMP_ITER(pbmp, tx_port)
{
if (prt_idx >= port_cnt) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
rv = BCM_E_FAIL;
break;
}
rv = bcm_port_encap_config_get(unit, tx_port, &encapcfg);
if (BCM_FAILURE(rv)
|| (encapcfg.encap != BCM_PORT_ENCAP_HIGIG_OVER_ETHERNET)) {
rv = BCM_E_FAIL;
break;
} else {
port_info_arr[prt_idx].port = tx_port;
port_info_arr[prt_idx].ether_type = encapcfg.higig_ethertype;
port_info_arr[prt_idx++].hgoe_rsvd = encapcfg.hgoe_reserved;
}
}
if (BCM_FAILURE(rv)) {
/* Error in getting the port encap. info or port is non HGoE */
sal_free(port_info_arr);
BCM_TX_HGOE_DBG_CTR_SEM_DECR(tx_list_port_info_cnt)
return(_bcm_common_tx_array(unit, pkt_arr, count, all_done_cb, cookie));
}
/*** Past this point the pkt tx has to go through HGoE logic ***/
/* Allocate memory to hold per pkt cookie */
pkt_info_arr =
sal_alloc(sizeof(bcm_tx_hgoe_cookie_t)*count, "PerPktCkArr");
if (!pkt_info_arr) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
sal_free(port_info_arr);
BCM_TX_HGOE_DBG_CTR_SEM_DECR(tx_list_port_info_cnt)
return (BCM_E_MEMORY);
}
BCM_TX_HGOE_DBG_CTR_SEM_INCR(tx_list_pkt_ck_arr_cnt)
/* Allocate memory for master cookie */
master_cookie =
sal_alloc(sizeof(bcm_tx_hgoe_chain_cb_cookie_t), "ChainCBCk");
if (!master_cookie) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
sal_free(port_info_arr);
sal_free(pkt_info_arr);
BCM_TX_HGOE_DBG_CTR_SEM_ACQ
BCM_TX_HGOE_DBG_CTR_DECR(tx_list_pkt_ck_arr_cnt)
BCM_TX_HGOE_DBG_CTR_DECR(tx_list_port_info_cnt)
BCM_TX_HGOE_DBG_CTR_SEM_REL
return (BCM_E_MEMORY);
}
BCM_TX_HGOE_DBG_CTR_SEM_INCR(tx_list_master_ck_cnt)
/* Fill in master cookie */
master_cookie->pkt_cnt = count;
master_cookie->user_given_chain_cb = all_done_cb;
master_cookie->user_given_cookie = cookie;
master_cookie->pkt_cookie_arr = pkt_info_arr;
/* Initialize the per pkt cookie arr */
sal_memset(pkt_info_arr, 0, sizeof(bcm_tx_hgoe_cookie_t)*count);
sal_memset(&encapcfg, 0, sizeof(encapcfg));
for (pkt_idx=0, rv=BCM_E_NONE; pkt_idx<count ; pkt_idx++) {
org_pkt_flags = 0;
org_pkt_blk_addr = NULL;
/* Get hold of the current packet */
cur_pkt = pkt_arr[pkt_idx];
/* Find out the appr. HGoE tag from the cached copy. It is sure that the
* information will be retrieved succesfully every time as the logic
* dictates no failure, hence no need to worry if hgoe tag is not found
*/
BCM_PBMP_ITER(cur_pkt->tx_pbmp, tx_port)
{
for (prt_idx=0 ; prt_idx<port_cnt ;prt_idx++) {
if (port_info_arr[prt_idx].port == tx_port) {
encapcfg.higig_ethertype =port_info_arr[prt_idx].ether_type;
encapcfg.hgoe_reserved = port_info_arr[prt_idx].hgoe_rsvd;
break;
}
}
break; /* Only one TX port limitation */
}
/* Prepare the packet */
rv = _bcm_common_tx_hgoe_prepare_pkt(
unit, cur_pkt, &org_pkt_flags, &org_pkt_blk_addr, encapcfg);
if (BCM_FAILURE(rv)) {
break;
}
/* Fill in the per packet callback info*/
pkt_info_arr[pkt_idx].chain_cb = bcm_common_tx_hgoe_tx_chain_cb;
pkt_info_arr[pkt_idx].org_cookie = cookie;
pkt_info_arr[pkt_idx].org_pkt = cur_pkt;
pkt_info_arr[pkt_idx].pkt_cb = cur_pkt->call_back;
pkt_info_arr[pkt_idx].org_pkt_flags = org_pkt_flags;
pkt_info_arr[pkt_idx].org_pkt_blk_addr = org_pkt_blk_addr;
pkt_info_arr[pkt_idx].new_pkt_blk_addr = cur_pkt->pkt_data;
/* Remove the call back from the pkt */
cur_pkt->call_back = NULL;
}
if (!BCM_FAILURE(rv)) {
/* All packets processed, now send the call down */
if (all_done_cb) {
rv = _bcm_common_tx_array(unit, pkt_arr,
count, bcm_common_tx_hgoe_tx_chain_cb, master_cookie);
} else {
rv = _bcm_common_tx_array(unit, pkt_arr, count, NULL, cookie);
}
}
if (BCM_FAILURE(rv) || !all_done_cb) {
/* Something went wrong or no callback requested, cleanup */
for (pkt_idx=0 ; pkt_idx<count ; pkt_idx++) {
if (pkt_info_arr[pkt_idx].chain_cb) {
_bcm_common_tx_hgoe_manual_cleanup(
pkt_info_arr[pkt_idx].org_pkt,
pkt_info_arr[pkt_idx].org_pkt_flags,
pkt_info_arr[pkt_idx].org_pkt_blk_addr,
pkt_info_arr[pkt_idx].pkt_cb);
}
}
sal_free(pkt_info_arr);
sal_free(master_cookie);
BCM_TX_HGOE_DBG_CTR_SEM_ACQ
BCM_TX_HGOE_DBG_CTR_DECR(tx_list_pkt_ck_arr_cnt)
BCM_TX_HGOE_DBG_CTR_DECR(tx_list_master_ck_cnt)
BCM_TX_HGOE_DBG_CTR_SEM_REL
}
sal_free(port_info_arr);
BCM_TX_HGOE_DBG_CTR_SEM_DECR(tx_list_port_info_cnt)
return rv;
}
STATIC int
_bcm_common_tx_array(int unit, bcm_pkt_t **pkt, int count,
bcm_pkt_cb_f all_done_cb, void *cookie)
#else
int
bcm_common_tx_array(int unit, bcm_pkt_t **pkt, int count, bcm_pkt_cb_f all_done_cb,
void *cookie)
#endif /* BCM_TRIDENT2PLUS_SUPPORT && BCM_TX_HGOE_LIMITED_SOLUTION */
{
dv_t *dv = NULL;
int rv = BCM_E_NONE;
int tot_blks = 0; /* How many dcbs needed for packets */
#if defined(BCM_CMICX_SUPPORT)
uint32 prefetch = 0;
#endif
int i;
char *err_msg = NULL;
int pkt_cb = FALSE; /* Are any pkts asking for callback? */
volatile bcm_pkt_t *pkt_ptr;
#if !defined(BCM_TRIDENT2PLUS_SUPPORT) || !defined(BCM_TX_HGOE_LIMITED_SOLUTION)
if (!pkt) {
return BCM_E_PARAM;
}
if (!BCM_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!BCM_IS_LOCAL(unit)) { /* Tunnel the packet to the remote CPU */
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"bcm_tx_array ERROR: Cannot tunnel\n")));
return BCM_E_PARAM;
}
#endif /* !BCM_TRIDENT2PLUS_SUPPORT || !BCM_TX_HGOE_LIMITED_SOLUTION */
#if defined (INCLUDE_RCPU) && defined(BCM_XGS3_SWITCH_SUPPORT)
if (SOC_IS_RCPU_UNIT(unit)) {
for (i = 0; i < count; i++) {
if (!pkt[i]) {
return BCM_E_PARAM;
}
BCM_IF_ERROR_RETURN(_bcm_tx_pkt_tag_setup(unit, pkt[i]));
if (!BCM_PKT_TX_ETHER(pkt[i])) {
BCM_IF_ERROR_RETURN(_bcm_xgs3_tx_pipe_bypass_header_setup(unit, pkt[i]));
}
}
return _bcm_rcpu_tx_array(unit, pkt, count, all_done_cb, cookie);
}
#endif /* INCLUDE_RCPU && BCM_XGS3_SWITCH_SUPPORT */
/* Count the blocks and check for per-packet callback */
for (i = 0; i < count; i++) {
if (!pkt[i]) {
return BCM_E_PARAM;
}
tot_blks += pkt[i]->blk_count;
if (pkt[i]->call_back) {
pkt_cb = TRUE;
}
}
err_msg = "Bad flags for bcm_tx_array";
_ON_ERROR_GOTO(_tx_flags_check(unit, pkt[0]), rv, error);
err_msg = "Could not set up pkt for bcm_tx_array";
for (i = 0; i < count; i++) {
_ON_ERROR_GOTO(_bcm_tx_pkt_tag_setup(unit, pkt[i]), rv, error);
}
/* Allocate the DV */
err_msg = "Could not allocate dv/dv info";
do {
dv = _tx_dv_alloc(unit, count, tot_blks + count * TX_EXTRA_DCB_COUNT,
all_done_cb, cookie, pkt_cb);
if (!dv) {
if (BCM_SUCCESS(_bcm_tx_cb_intr_enabled())) {
rv = BCM_E_MEMORY;
goto error;
}
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit, "%s%s\n"), err_msg, ", will retry ..."));
if (sal_sem_take(tx_dv_done, sal_sem_FOREVER) < 0) {
err_msg = "Failed to take tx_dv_done";
rv = BCM_E_FAIL;
goto error;
}
}
} while (!dv);
err_msg = "Could not set up or add pkt to DV";
for (i = 0; i < count; i++) {
#ifdef BCM_PETRA_SUPPORT
if (SOC_IS_ARAD(unit))
{
_ON_ERROR_GOTO(_sand_tx_pkt_desc_add(unit, pkt[i], dv, 0), rv, error);
}
else
#endif
#ifdef BCM_DNX_SUPPORT
if (SOC_IS_DNX(unit))
{
_ON_ERROR_GOTO(_sand_tx_pkt_desc_add(unit, pkt[i], dv, 0), rv, error);
}
else
#endif
{
_ON_ERROR_GOTO(_tx_pkt_desc_add(unit, pkt[i], dv, i), rv, error);
}
}
if (SOC_DMA_MODE(unit) == SOC_DMA_MODE_CONTINUOUS) {
if (dv->dv_vcnt > 0) { /* Only add reload dcb if pkt dcb added */
err_msg = "Could not allocate a reload descriptor";
if (soc_dma_rld_desc_add(dv, 0) < 0) {
rv = BCM_E_MEMORY;
goto error;
}
#if defined(BCM_CMICX_SUPPORT)
prefetch = 1;
#endif
}
}
#if defined(BCM_CMICX_SUPPORT)
if (!prefetch) {
soc_dma_contiguous_desc_add(dv);
}
#endif
err_msg = "Could not send array";
if (dv->dv_vcnt > 0) {
rv = _bcm_tx_chain_send(unit, dv, 0); /* all_done_cb != NULL);*/
/* if (SOC_IS_ARAD(unit)) {
if (all_done_cb != NULL) {
pkt_ptr = TX_INFO(dv)->pkt[0];
(all_done_cb)(unit, (bcm_pkt_t *)pkt_ptr, cookie);
}
} */
} else {
/* Call the registered callback if any */
if (all_done_cb != NULL) {
pkt_ptr = TX_INFO(dv)->pkt[0];
(all_done_cb)(unit, (bcm_pkt_t *)pkt_ptr, cookie);
}
if (dv != NULL) {
_tx_dv_free(unit, dv);
}
rv = BCM_E_NONE;
}
error:
_PROCESS_ERROR(unit, rv, dv, err_msg);
return rv;
}
/*
* Function:
* bcm_tx_list
* Purpose:
* Transmit a linked list of packets
* Parameters:
* unit - transmission unit
* pkt - Pointer to linked list of packets
* all_done_cb - Callback function (if non-NULL) when all pkts tx'd
* cookie - Callback cookie.
* Returns:
* BCM_E_XXX
* Notes:
* If callback is non-NULL, the packets are sent asynchronously
* (the routine returns before all the pkts are sent)
*
* The "packet callback" will be set according to the value
* in each packet's "call_back" member, so that must be initialized
* for all packets in the chain.
*
* The "next" member of the packet is used for the linked list.
* CAREFUL: The internal _next member is not used for this.
*
* This routine does not support tunnelling to a remote CPU for
* forwarding.
*
* The TX parameters, src mod, src port, PFM and internal priority,
* are currently determined by the first packet in the list.
*/
#if defined(BCM_TRIDENT2PLUS_SUPPORT) && defined(BCM_TX_HGOE_LIMITED_SOLUTION)
STATIC int
_bcm_common_tx_list(int unit, bcm_pkt_t *pkt,
bcm_pkt_cb_f all_done_cb, void *cookie);
int
bcm_common_tx_list(int unit, bcm_pkt_t *pkt,
bcm_pkt_cb_f all_done_cb, void *cookie) {
int rv = BCM_E_NONE;
int port_cnt = 0;
bcm_pbmp_t pbmp;
uint32 pkt_cnt = 0;
uint32 pkt_idx = 0;
uint32 prt_idx = 0;
uint8 is_pkt_cb = 0;
bcm_port_t tx_port = 0;
uint32 org_pkt_flags = 0;
uint8 use_dflt_method = 1;
bcm_pkt_t *cur_pkt = NULL;
bcm_pkt_blk_t *org_pkt_blk_addr = NULL;
bcm_port_encap_config_t encapcfg = {0};
bcm_tx_hgoe_cookie_t *pkt_info_arr = NULL;
bcm_tx_hgoe_chain_cb_cookie_t *master_cookie = NULL;
typedef struct {
bcm_port_t port;
uint16 ether_type;
uint16 hgoe_rsvd;
} hgoe_port_info_t;
hgoe_port_info_t *port_info_arr = NULL;
/* Input parameter check */
if (!pkt) {
return BCM_E_PARAM;
}
if (!BCM_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!BCM_IS_LOCAL(unit)) { /* Tunnel the packet to the remote CPU */
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"bcm_tx_list ERROR: Cannot tunnel\n")));
return BCM_E_PARAM;
}
if (SOC_IS_TRIDENT2PLUS(unit)) {
BCM_PBMP_CLEAR(pbmp);
/* Do fast check if the HGoE logic can be invoked or not */
for (cur_pkt=pkt ; cur_pkt ; cur_pkt=cur_pkt->next, pkt_cnt++) {
/* If even a single pkt is smart switched then go default route */
if (BCM_PKT_TX_ETHER(cur_pkt)) {
break;
}
/* If pkt has to be sent on multiple ports then go default route */
BCM_PBMP_COUNT(cur_pkt->tx_pbmp, port_cnt);
if (1!=port_cnt) {
break;
}
BCM_PBMP_OR(pbmp, cur_pkt->tx_pbmp);
/* Mark if individual pkt call back exists. */
if (!is_pkt_cb && cur_pkt->call_back) {
is_pkt_cb = 1;
}
}
/* If previous loop did not complete successfully or there is a case
* where individual pkt callback esists but chain done callback not then
* the HGoE logic cannot be invoked as it wont handle the said scenario.
* Hence send the pkt using default way and hope TX happens successfully
*/
if (!cur_pkt && !(is_pkt_cb && !all_done_cb) ) {
use_dflt_method = 0;
}
}
if (use_dflt_method) {
rv = _bcm_common_tx_list(unit, pkt, all_done_cb, cookie);
return rv;
}
/* Check for port encapsulation type */
/* Create a buffer to hold HGoE tag to be used later */
BCM_PBMP_COUNT(pbmp, port_cnt);
port_info_arr=sal_alloc(sizeof(hgoe_port_info_t) * port_cnt, "HGoEPrtInfo");
if (!port_info_arr) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
return (BCM_E_MEMORY);
}
BCM_TX_HGOE_DBG_CTR_SEM_INCR(tx_list_port_info_cnt)
/* If all tx ports are HGoE then go through the trouble of
* forming a sobmh pkt otherwise just use the default way
*/
prt_idx = 0;
rv = BCM_E_NONE;
BCM_PBMP_ITER(pbmp, tx_port)
{
if (prt_idx >= port_cnt) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
rv = BCM_E_FAIL;
break;
}
rv = bcm_port_encap_config_get(unit, tx_port, &encapcfg);
if (BCM_FAILURE(rv)
|| (encapcfg.encap != BCM_PORT_ENCAP_HIGIG_OVER_ETHERNET)) {
rv = BCM_E_FAIL;
break;
} else {
port_info_arr[prt_idx].port = tx_port;
port_info_arr[prt_idx].ether_type = encapcfg.higig_ethertype;
port_info_arr[prt_idx++].hgoe_rsvd = encapcfg.hgoe_reserved;
}
}
if (BCM_FAILURE(rv)) {
/* Error in getting the port encap. info or port is non HGoE */
sal_free(port_info_arr);
BCM_TX_HGOE_DBG_CTR_SEM_DECR(tx_list_port_info_cnt)
return(_bcm_common_tx_list(unit, pkt, all_done_cb, cookie));
}
/* Past this point the pkt tx has to go through HGoE logic */
/* Allocate memory to hold per pkt cookie */
pkt_info_arr =
sal_alloc(sizeof(bcm_tx_hgoe_cookie_t)*pkt_cnt, "PerPktCkArr");
if (!pkt_info_arr) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
sal_free(port_info_arr);
BCM_TX_HGOE_DBG_CTR_SEM_DECR(tx_list_port_info_cnt)
return (BCM_E_MEMORY);
}
BCM_TX_HGOE_DBG_CTR_SEM_INCR(tx_list_pkt_ck_arr_cnt)
/* Allocate memory for master cookie */
master_cookie =
sal_alloc(sizeof(bcm_tx_hgoe_chain_cb_cookie_t), "ChainCBCk");
if (!master_cookie) {
BCM_TX_HGOE_DBG_CTR_INCR(internal_fail_cnt)
sal_free(port_info_arr);
sal_free(pkt_info_arr);
BCM_TX_HGOE_DBG_CTR_SEM_ACQ
BCM_TX_HGOE_DBG_CTR_DECR(tx_list_port_info_cnt)
BCM_TX_HGOE_DBG_CTR_DECR(tx_list_pkt_ck_arr_cnt)
BCM_TX_HGOE_DBG_CTR_SEM_REL
return (BCM_E_MEMORY);
}
BCM_TX_HGOE_DBG_CTR_SEM_INCR(tx_list_master_ck_cnt)
/* Fill in master cookie */
master_cookie->pkt_cnt = pkt_cnt;
master_cookie->user_given_chain_cb = all_done_cb;
master_cookie->user_given_cookie = cookie;
master_cookie->pkt_cookie_arr = pkt_info_arr;
/* Initialize the per pkt cookie arr */
sal_memset(pkt_info_arr, 0, sizeof(bcm_tx_hgoe_cookie_t)*pkt_cnt);
sal_memset(&encapcfg, 0, sizeof(encapcfg));
for (cur_pkt=pkt, rv=BCM_E_NONE, pkt_idx=0 ;
cur_pkt ; cur_pkt=cur_pkt->next, pkt_idx++) {
org_pkt_flags = 0;
org_pkt_blk_addr = NULL;
/* Find out the appr. HGoE tag from the cached copy. It is sure that the
* information will be retrieved succesfully every time as the logic
* dictates no failure, hence no need to worry if hgoe tag is not found
*/
BCM_PBMP_ITER(cur_pkt->tx_pbmp, tx_port)
{
for (prt_idx=0 ; prt_idx<port_cnt ;prt_idx++) {
if (port_info_arr[prt_idx].port == tx_port) {
encapcfg.higig_ethertype =port_info_arr[prt_idx].ether_type;
encapcfg.hgoe_reserved = port_info_arr[prt_idx].hgoe_rsvd;
break;
}
}
break; /* Only one TX port limitation */
}
/* Prepare the packet */
rv = _bcm_common_tx_hgoe_prepare_pkt(
unit, cur_pkt, &org_pkt_flags, &org_pkt_blk_addr, encapcfg);
if (BCM_FAILURE(rv)) {
break;
}
/* Fill in the per packet callback info*/
pkt_info_arr[pkt_idx].chain_cb = bcm_common_tx_hgoe_tx_chain_cb;
pkt_info_arr[pkt_idx].org_cookie = cookie;
pkt_info_arr[pkt_idx].org_pkt = cur_pkt;
pkt_info_arr[pkt_idx].pkt_cb = cur_pkt->call_back;
pkt_info_arr[pkt_idx].org_pkt_flags = org_pkt_flags;
pkt_info_arr[pkt_idx].org_pkt_blk_addr = org_pkt_blk_addr;
pkt_info_arr[pkt_idx].new_pkt_blk_addr = cur_pkt->pkt_data;
/* Remove the call back from the pkt */
cur_pkt->call_back = NULL;
}
if (!BCM_FAILURE(rv)) {
/* All packets processed, now send the call down */
if (all_done_cb) {
rv = _bcm_common_tx_list(unit,
pkt, bcm_common_tx_hgoe_tx_chain_cb, master_cookie);
} else {
rv = _bcm_common_tx_list(unit, pkt, NULL, cookie);
}
}
if (BCM_FAILURE(rv) || !all_done_cb) {
/* Something went wrong or no callback requested, cleanup */
for (pkt_idx=0 ; pkt_idx<pkt_cnt ; pkt_idx++) {
if (pkt_info_arr[pkt_idx].chain_cb) {
_bcm_common_tx_hgoe_manual_cleanup(
pkt_info_arr[pkt_idx].org_pkt,
pkt_info_arr[pkt_idx].org_pkt_flags,
pkt_info_arr[pkt_idx].org_pkt_blk_addr,
pkt_info_arr[pkt_idx].pkt_cb);
}
}
sal_free(pkt_info_arr);
sal_free(master_cookie);
BCM_TX_HGOE_DBG_CTR_SEM_ACQ
BCM_TX_HGOE_DBG_CTR_DECR(tx_list_pkt_ck_arr_cnt)
BCM_TX_HGOE_DBG_CTR_DECR(tx_list_master_ck_cnt)
BCM_TX_HGOE_DBG_CTR_SEM_REL
}
sal_free(port_info_arr);
BCM_TX_HGOE_DBG_CTR_SEM_DECR(tx_list_port_info_cnt)
return rv;
}
STATIC int
_bcm_common_tx_list(int unit, bcm_pkt_t *pkt,
bcm_pkt_cb_f all_done_cb, void *cookie)
#else
int
bcm_common_tx_list(int unit, bcm_pkt_t *pkt, bcm_pkt_cb_f all_done_cb, void *cookie)
#endif /* BCM_TRIDENT2PLUS_SUPPORT && BCM_TX_HGOE_LIMITED_SOLUTION */
{
dv_t *dv = NULL;
int rv = BCM_E_NONE;
int tot_blks = 0; /* How many dcbs needed for packets */
int count;
#if defined(BCM_CMICX_SUPPORT)
uint32 prefetch = 0;
#endif
bcm_pkt_t *cur_pkt;
char *err_msg = NULL;
int pkt_cb = FALSE; /* Are any pkts asking for callback? */
int i = 0;
volatile bcm_pkt_t *pkt_ptr;
#if !defined(BCM_TRIDENT2PLUS_SUPPORT) || !defined(BCM_TX_HGOE_LIMITED_SOLUTION)
if (!pkt) {
return BCM_E_PARAM;
}
if (!BCM_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!SOC_UNIT_VALID(unit)) {
return BCM_E_UNIT;
}
if (!BCM_IS_LOCAL(unit)) { /* Tunnel the packet to the remote CPU */
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"bcm_tx_list ERROR: Cannot tunnel\n")));
return BCM_E_PARAM;
}
#endif /* !BCM_TRIDENT2PLUS_SUPPORT || !BCM_TX_HGOE_LIMITED_SOLUTION */
#if defined (INCLUDE_RCPU) && defined(BCM_XGS3_SWITCH_SUPPORT)
if (SOC_IS_RCPU_UNIT(unit)) {
for (cur_pkt = pkt; cur_pkt; cur_pkt = cur_pkt->next) {
BCM_IF_ERROR_RETURN(_bcm_tx_pkt_tag_setup(unit, cur_pkt));
if (!BCM_PKT_TX_ETHER(cur_pkt)) {
BCM_IF_ERROR_RETURN(_bcm_xgs3_tx_pipe_bypass_header_setup(unit, cur_pkt));
}
}
return _bcm_rcpu_tx_list(unit, pkt, all_done_cb, cookie);
}
#endif /* INCLUDE_RCPU && BCM_XGS3_SWITCH_SUPPORT */
/* Count the blocks and check for per-packet callback */
count = 0;
for (cur_pkt = pkt; cur_pkt; cur_pkt = cur_pkt->next) {
tot_blks += cur_pkt->blk_count;
if (cur_pkt->call_back) {
pkt_cb = TRUE;
}
++count;
}
err_msg = "Bad flags for bcm_tx_list";
_ON_ERROR_GOTO(_tx_flags_check(unit, pkt), rv, error);
err_msg = "Could not set up pkt for bcm_tx_list";
for (cur_pkt = pkt; cur_pkt != NULL; cur_pkt = cur_pkt->next) {
_ON_ERROR_GOTO(_bcm_tx_pkt_tag_setup(unit, cur_pkt), rv, error);
}
/* Allocate the DV */
err_msg = "Could not allocate dv/dv info";
do {
dv = _tx_dv_alloc(unit, count, tot_blks + count * TX_EXTRA_DCB_COUNT,
all_done_cb, cookie, pkt_cb);
if (!dv) {
if (BCM_SUCCESS(_bcm_tx_cb_intr_enabled())) {
rv = BCM_E_MEMORY;
goto error;
}
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit, "%s%s\n"), err_msg, ", will retry ..."));
if (sal_sem_take(tx_dv_done, sal_sem_FOREVER) < 0) {
err_msg = "Failed to take tx_dv_done";
rv = BCM_E_FAIL;
goto error;
}
}
} while (!dv);
err_msg = "Could not set up or add pkt to DV";
for (i = 0, cur_pkt = pkt; cur_pkt; cur_pkt = cur_pkt->next, i++) {
#ifdef BCM_PETRA_SUPPORT
if (SOC_IS_ARAD(unit))
{
_ON_ERROR_GOTO(_sand_tx_pkt_desc_add(unit, cur_pkt, dv, 0), rv, error);
}
else
#endif
#ifdef BCM_DNX_SUPPORT
if (SOC_IS_DNX(unit))
{
_ON_ERROR_GOTO(_sand_tx_pkt_desc_add(unit, cur_pkt, dv, 0), rv, error);
}
else
#endif
{
_ON_ERROR_GOTO(_tx_pkt_desc_add(unit, cur_pkt, dv, i), rv, error);
}
}
if (SOC_DMA_MODE(unit) == SOC_DMA_MODE_CONTINUOUS) {
if (dv->dv_vcnt > 0) { /* Only add reload dcb if pkt dcb added */
err_msg = "Could not allocate a reload descriptor";
if (soc_dma_rld_desc_add(dv, 0) < 0) {
rv = BCM_E_MEMORY;
goto error;
}
#if defined(BCM_CMICX_SUPPORT)
prefetch = 1;
#endif
}
}
#if defined(BCM_CMICX_SUPPORT)
if (!prefetch) {
soc_dma_contiguous_desc_add(dv);
}
#endif
err_msg = "Could not send list";
if (dv->dv_vcnt > 0) {
rv = _bcm_tx_chain_send(unit, dv, all_done_cb != NULL);
#if 0
if (SOC_IS_ARAD(unit)) {
if (all_done_cb != NULL) {
pkt_ptr = TX_INFO(dv)->pkt[0];
(all_done_cb)(unit, (bcm_pkt_t *)pkt_ptr, cookie);
}
}
#endif
} else {
/* Call the registered callback if any */
if (all_done_cb != NULL) {
pkt_ptr = TX_INFO(dv)->pkt[0];
if (pkt_ptr == NULL) {
LOG_VERBOSE(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"NULL pkt\n")));
pkt_ptr = pkt;
}
(all_done_cb)(unit, (bcm_pkt_t *)pkt_ptr, cookie);
}
if (dv != NULL) {
_tx_dv_free(unit, dv);
}
rv = BCM_E_NONE;
}
error:
_PROCESS_ERROR(unit, rv, dv, err_msg);
return rv;
}
/*
* Function:
* _bcm_tx_chain_send
* Purpose:
* Send out a chain of one or more packets
*/
STATIC int
_bcm_tx_chain_send(int unit, dv_t *dv, int async)
{
++_tx_chain_send;
#if defined(BROADCOM_DEBUG)
if (!bsl_check(bslLayerSoc, bslSourcePacketdma, bslSeverityNormal, unit) &&
bsl_check(bslLayerSoc, bslSourceTx, bslSeverityVerbose, unit)) {
int i = 0, j, k, len, dv_cnt = 0;
dcb_t *dcb;
uint8 *addr;
char linebuf[128], *s;
dv_t *dv_i;
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_bcm_tx_chain_send: packet send\n")));
for (dv_i = dv; dv_i != NULL; dv_i = dv_i->dv_chain, dv_cnt++) {
for (k = 0; k < dv_i->dv_vcnt; k++) {
soc_dma_dump_dv_dcb(unit, "tx Dma descr: ", dv, k);
dcb = SOC_DCB_IDX2PTR(unit, dv_i->dv_dcb, k);
addr = (uint8*)SOC_DCB_ADDR_GET(unit, dcb);
len = SOC_DCB_REQCOUNT_GET(unit, dcb);
for (i = 0; i < len; i += 16) {
s = linebuf;
sal_sprintf(s, "TXDV %d data[%04x]: ", dv_cnt, i);
while (*s != 0) s++;
for (j = i; j < i + 16 && j < len; j++) {
sal_sprintf(s, "%02x%s", addr[j], j & 1 ? " " : "");
while (*s != 0) s++;
}
LOG_CLI((BSL_META_U(unit,
"%s\n"), linebuf));
}
}
}
}
#endif /* BROADCOM_DEBUG */
if (async) { /* Send packet(s) asynchronously */
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"bcm_tx: async send\n")));
if (SOC_DMA_MODE(unit) == SOC_DMA_MODE_CONTINUOUS) {
dv->dv_flags |= DV_F_NOTIFY_DSC;
} else {
dv->dv_flags |= DV_F_NOTIFY_CHN;
}
SOC_IF_ERROR_RETURN(soc_dma_start(unit, -1, dv));
} else { /* Send sync */
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"bcm_tx: sync send\n")));
SOC_IF_ERROR_RETURN(soc_dma_wait(unit, dv));
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"bcm_tx: Sent synchronously.\n")));
if (SOC_DMA_MODE(unit) != SOC_DMA_MODE_CONTINUOUS) {
_bcm_tx_chain_done_cb(unit, dv);
}
}
return BCM_E_NONE;
}
/****************************************************************
*
* Map a destination MAC address to port bitmaps. Uses
* the dest_mac passed as a parameter. Sets the
* bitmaps in the pkt structure.
*/
/*
* Function:
* bcm_tx_pkt_l2_map
* Purpose:
* Resolve the packet's L2 destination and update the necessary
* fields of the packet.
* Parameters:
* unit - Transmit unit
* pkt - Pointer to pkt being transmitted
* dest_mac - use for L2 lookup
* vid - use for L2 lookup
* Returns:
* BCM_E_XXX
* Notes:
* Deprecated, not implemented.
*/
int
bcm_common_tx_pkt_l2_map(int unit, bcm_pkt_t *pkt, bcm_mac_t dest_mac, int vid)
{
return BCM_E_UNAVAIL;
}
/****************************************************************
*
* Functions to setup DVs and DCBs.
* _tx_dv_alloc: Allocate and init a TX DV
* _tx_pkt_desc_add: Add all the descriptors for a packet to a DV
*
* Minor functions:
* _dcb_flags_get: Calculate the DCB flags.
* _get_mac_vlan_ptrs: Determine DMA pointers for src_mac and
* vlan. This is in case the src_mac is not
* in the same pkt block as the dest_mac; or
* the packet is untagged. Also sets the
* byte and block offsets for data that follows.
*/
/*
* Function:
* _tx_dv_alloc
* Purpose:
* Allocate a DV, a dv_info structure and initialize.
* Parameters:
* unit - Strata unit number for allocation
* pkt_count - Number of packets to TX
* dcb_count - The number of DCBs to provide
* chain_done_cb - Chain done callback function
* cookie - User cookie used for chain done and packet callbacks.
* per_pkt_cb - Do we need to callback on each packet complete?
* Returns:
* BCM_E_XXX
* Notes:
* Always sets the dv_done_chain callback; sets packet done
* call back according to per_pkt_cb parameter.
*/
STATIC dv_t *
_tx_dv_alloc(int unit, int pkt_count, int dcb_count,
bcm_pkt_cb_f chain_done_cb, void *cookie, int per_pkt_cb)
{
dv_t *dv;
tx_dv_info_t *dv_info;
volatile bcm_pkt_t **pkt;
int packet_count_limit = SOC_DV_PKTS_MAX;
#ifdef BCM_XGS3_SWITCH_SUPPORT
if (SOC_IS_XGS3_SWITCH(unit)) {
int port_count;
/* On XGS3 we allow a larger DV chain to allow a single TX to
all ports */
BCM_PBMP_COUNT(PBMP_PORT_ALL(unit), port_count);
if (packet_count_limit < port_count) {
packet_count_limit = port_count;
}
}
#endif
if (pkt_count > packet_count_limit) {
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"TX array: Cannot TX more than %d pkts. "
"Attempting %d.\n"),
packet_count_limit, pkt_count));
return NULL;
}
/* In continuous mode, make room for the reload descriptor */
/* This check assumes that TX is always on channel 0 */
if (SOC_DMA_MODE(unit) == SOC_DMA_MODE_CONTINUOUS) {
dcb_count++;
}
LOG_DEBUG(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"pkt_cnt %d dcb_cnt %d\n"),
pkt_count, dcb_count));
if ((dv = soc_dma_dv_alloc_by_port(unit, DV_TX, dcb_count,
pkt_count)) == NULL) {
return NULL;
}
/* not a queued dv */
if (TX_INFO(dv) == NULL) {
if ((dv_info = soc_at_alloc(unit, sizeof(tx_dv_info_t), "tx_dv")) == NULL) {
soc_dma_dv_free(unit, dv);
return NULL;
}
pkt = soc_at_alloc(unit, (sizeof(bcm_pkt_t *) * packet_count_limit), "tx_dv pkt");
if (pkt == NULL) {
soc_dma_dv_free(unit, dv);
soc_at_free(unit, dv_info);
return NULL;
}
} else {
dv_info = TX_INFO(dv);
pkt = dv_info->pkt;
}
TX_INFO_SET(dv, dv_info);
sal_memset(TX_INFO(dv), 0, sizeof(tx_dv_info_t));
TX_INFO(dv)->pkt = pkt;
/*
* Clear memory depending on the pkt_count to avoid trashing the "pkt"
* buffer allocated before the flex port operation; flexing can increase
* the packet_count_limit. Allocation happens in soc_dma_dv_alloc_by_port,
* depending on pkt_count.
*/
if (pkt_count <= SOC_DV_PKTS_MAX) {
sal_memset(TX_INFO(dv)->pkt, 0,
(sizeof(bcm_pkt_t *) * SOC_DV_PKTS_MAX));
} else {
sal_memset(TX_INFO(dv)->pkt, 0,
(sizeof(bcm_pkt_t *) * packet_count_limit));
}
TX_INFO(dv)->cookie = cookie;
TX_INFO(dv)->chain_done_cb = chain_done_cb;
dv->dv_done_chain = _bcm_tx_chain_done_cb;
dv->dv_done_desc = _bcm_tx_desc_done_cb;
dv->dv_done_desc_subs = _bcm_tx_desc_done_cb;
dv->dv_done_reload = _bcm_tx_reload_done_cb;
if (per_pkt_cb) {
dv->dv_done_packet = _bcm_tx_packet_done_cb;
}
return dv;
}
/*
* Function:
* _tx_dv_free
* Purpose:
* Free a DV and associated dv_info structure
* Parameters:
* unit - Strata unit number for allocation
* dv - The DV to free
* Returns:
* None
*/
STATIC void
_tx_dv_free(int unit, dv_t *dv)
{
tx_dv_info_t *dv_info;
LOG_DEBUG(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"Freeing DV %p\n"),
(void *)dv));
if (dv) {
dv_info = TX_INFO(dv);
/* release dv_info, no matter it's queued dv or not */
if (dv_info) {
if (dv_info->pkt) {
soc_at_free(unit, dv_info->pkt);
}
soc_at_free(unit, dv_info);
TX_INFO_SET(dv, NULL);
}
soc_dma_dv_free(unit, dv);
}
}
void
tx_dv_free_cb(int unit, dv_t *dv)
{
tx_dv_info_t *dv_info;
if (dv) {
if (dv->dv_done_chain == _bcm_tx_chain_done_cb) {
dv_info = TX_INFO(dv);
if (dv_info) {
if (dv_info->pkt) {
soc_at_free(unit, dv_info->pkt);
}
soc_at_free(unit, dv_info);
}
}
}
}
/* Set up the DV for bcm_tx;
* Assert: unit is local
*/
STATIC INLINE uint32
_dcb_flags_get(int unit, bcm_pkt_t *pkt, dv_t *dv)
{
uint32 dcb_flags = 0;
COMPILER_REFERENCE(dv);
if (SOC_IS_XGS3_SWITCH(unit)) {
/*
* XGS3: HG bit in descriptor needs to be set
* 1. Raw mode HG/Ethernet TX (Unmodified Packet steering).
* 2. Fabric mapped TX
* For fully mapped Ethernet transmit this should not be set.
*/
if ((! BCM_PKT_TX_ETHER(pkt)) || /* Raw mode TX */
BCM_TX_PKT_PROP_ANY_TST(pkt) || /* Fabric mapped TX */
BCM_PKT_TX_HG_READY(pkt)) {
SOC_DMA_HG_SET(dcb_flags, 1);
}
if (pkt->flags & BCM_TX_PURGE) {
SOC_DMA_PURGE_SET(dcb_flags, 1);
}
return dcb_flags;
}
#ifdef BCM_ARAD_SUPPORT
else if (SOC_IS_ARAD(unit)) {
if (pkt->flags & BCM_TX_PURGE) {
SOC_DMA_PURGE_SET(dcb_flags, 1);
}
if (pkt->flags & BCM_PKT_F_HGHDR) {
SOC_DMA_HG_SET(dcb_flags, 1);
}
}
#endif
#ifdef BCM_DNX_SUPPORT
else if (SOC_IS_DNX(unit))
{
if (pkt->flags & BCM_TX_PURGE)
{
SOC_DMA_PURGE_SET(dcb_flags, 1);
}
if (pkt->flags & BCM_PKT_F_HGHDR) {
SOC_DMA_HG_SET(dcb_flags, 1);
}
}
#endif
dcb_flags |= SOC_DMA_COS(pkt->cos);
/* This level does not handle CRC append, but marks for HW to generate */
if (pkt->flags & (BCM_TX_CRC_APPEND | BCM_TX_CRC_REGEN)) {
dcb_flags |= SOC_DMA_CRC_REGEN;
}
return dcb_flags;
}
/*
* Based on packet settings, get pointers to vlan, and src mac
* Update the "current" block and byte offset
*/
STATIC INLINE void
_get_mac_vlan_ptrs(dv_t *dv, bcm_pkt_t *pkt, uint8 **src_mac,
uint8 **vlan_ptr, int *block_offset, int *byte_offset,
int pkt_idx)
{
/* Assume everything is in block 0 */
*src_mac = &pkt->pkt_data[0].data[sizeof(bcm_mac_t)];
*block_offset = 0;
if (BCM_PKT_NO_VLAN_TAG(pkt)) { /* Get VLAN from _vtag pkt member */
*byte_offset = 2 * sizeof(bcm_mac_t);
sal_memcpy(SOC_DV_VLAN_TAG(dv, pkt_idx), pkt->_vtag, sizeof(uint32));
*vlan_ptr = SOC_DV_VLAN_TAG(dv, pkt_idx);
if (pkt->pkt_data[0].len < 2 * sizeof(bcm_mac_t)) {
/* Src MAC in block 1 */
*src_mac = pkt->pkt_data[1].data;
*block_offset = 1;
*byte_offset = sizeof(bcm_mac_t);
}
} else { /* Packet has VLAN tag */
*byte_offset = 2 * sizeof(bcm_mac_t) + sizeof(uint32);
*vlan_ptr = &pkt->pkt_data[0].data[2 * sizeof(bcm_mac_t)];
if (pkt->pkt_data[0].len < 2 * sizeof(bcm_mac_t)) {
/* Src MAC in block 1; assume VLAN there too at first */
*src_mac = pkt->pkt_data[1].data;
*vlan_ptr = &pkt->pkt_data[1].data[sizeof(bcm_mac_t)];
*block_offset = 1;
*byte_offset = sizeof(bcm_mac_t) + sizeof(uint32);
if (pkt->pkt_data[1].len < sizeof(bcm_mac_t) + sizeof(uint32)) {
/* Oops, VLAN in block 2 */
*vlan_ptr = pkt->pkt_data[2].data;
*block_offset = 2;
*byte_offset = sizeof(uint32);
}
} else if (pkt->pkt_data[0].len <
2 * sizeof(bcm_mac_t) + sizeof(uint32)) {
/* VLAN in block 2 */
*block_offset = 1;
*byte_offset = sizeof(uint32);
*vlan_ptr = pkt->pkt_data[1].data;
}
}
}
/* Set up the SOC layer TX packet according to flags and BCM pkt */
/* PFM is two bits */
#define PFM_MASK 0x3
STATIC INLINE void
_soc_tx_pkt_setup(int unit, bcm_pkt_t *pkt, soc_tx_param_t *tx_param)
{
/* Decide which source mod/port to use */
tx_param->src_mod = (pkt->flags & BCM_TX_SRC_MOD) ? pkt->src_mod :
SOC_DEFAULT_DMA_SRCMOD_GET(unit);
tx_param->src_port = (pkt->flags & BCM_TX_SRC_PORT) ? pkt->src_port :
SOC_DEFAULT_DMA_SRCPORT_GET(unit);
tx_param->pfm = (pkt->flags & BCM_TX_PFM) ? pkt->pfm :
SOC_DEFAULT_DMA_PFM_GET(unit);
if ((tx_param->pfm & (~PFM_MASK)) != 0) {
LOG_WARN(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"bcm_tx: PFM too big, truncating\n")));
tx_param->pfm &= PFM_MASK;
}
/*
* the default ought to be BCM_PKT_VLAN_PRI(pkt),
* but we need backwards compatibility with 5690
*/
tx_param->prio_int = (pkt->flags & BCM_TX_PRIO_INT) ? pkt->prio_int :
pkt->cos;
tx_param->cos = pkt->cos;
}
#define BCM_PKT_TX_OLP(pkt) \
(((pkt)->flags2 & BCM_PKT_F2_OAM_TX) != 0)
#define BCM_PKT_TX_HAS_OLP_READY(pkt) \
(((pkt)->flags2 & BCM_PKT_F2_OLP_READY) != 0)
#define BCM_PKT_OLP_HDR(pkt) \
((pkt)->_olp_hdr)
#define _OLP_OAM_MIN_OFFSET 14
#if defined (BCM_TRIDENT2PLUS_SUPPORT) || defined (BCM_SABER2_SUPPORT)
/*
* Function:
* _bcm_olp_l2_hdr_get
* Purpose:
* Get the OLP L2 header
* Parameters:
* unit - (IN) BCM device number
* glp - (IN) OLP port
* nbo - (IN) Switch to indicate if each member in l2hdr has to
* be converted to NBO
* l2hdr - (OUT) OLP header
* Returns:
* BCM_E_XXX
*/
int _bcm_olp_l2_hdr_get(int unit, int glp, uint8 nbo, soc_olp_l2_hdr_t *l2hdr)
{
int rv = BCM_E_NONE;
uint64 rval;
uint64 mac_field;
int index;
BCM_IF_ERROR_RETURN(_bcm_switch_olp_dglp_get(
unit, glp, (bcm_mac_t *)(l2hdr->src_mac), &index));
COMPILER_64_ZERO(rval);
SOC_IF_ERROR_RETURN(READ_IARB_OLP_CONFIGr(unit, &rval));
mac_field = soc_reg64_field_get(unit, IARB_OLP_CONFIGr, rval,MACDAf);
SAL_MAC_ADDR_FROM_UINT64(l2hdr->dst_mac,mac_field);
l2hdr->etherType = soc_reg64_field32_get(unit, IARB_OLP_CONFIGr, rval,ETHERTYPEf);
COMPILER_64_ZERO(rval);
SOC_IF_ERROR_RETURN(READ_IARB_OLP_CONFIG_1r(unit, &rval));
l2hdr->vlan = soc_reg64_field32_get(unit, IARB_OLP_CONFIG_1r, rval,VLAN_IDf);
l2hdr->tpid = soc_reg64_field32_get(unit, IARB_OLP_CONFIG_1r, rval, VLAN_TPIDf);
if (nbo) {
/* Convert to Network Byte Order */
l2hdr->etherType = soc_htons(l2hdr->etherType);
l2hdr->vlan = soc_htons(l2hdr->vlan);
l2hdr->tpid = soc_htons(l2hdr->tpid);
}
LOG_DEBUG(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"%s,dmac 0x%x:0x%x,smac 0x%x:0x%x,tpid 0x%x,vlan %d,ether 0x%x"
"\n"),FUNCTION_NAME(),l2hdr->dst_mac[5],l2hdr->dst_mac[0],l2hdr->src_mac[5],l2hdr->src_mac[0],
soc_htons(l2hdr->tpid),soc_htons(l2hdr->vlan),soc_htons(l2hdr->etherType)));
return rv;
}
#if defined (BCM_TRIDENT2PLUS_SUPPORT)
STATIC int
_bcm_td2plus_tx_olp_hdr_ts_lm_offset_fill(int unit,
bcm_pkt_t *pkt,
soc_olp_tx_hdr_t *otxhdr)
{
if(pkt->flags2 & BCM_PKT_F2_TIMESTAMP_MODE) {
SOC_OLP_TX_TIMESTAMP_ACTION(otxhdr) = pkt->timestamp_mode;
}
if((pkt->flags2 & BCM_PKT_F2_REPLACEMENT_OFFSET)) {
if(pkt->oam_replacement_offset <= _OLP_OAM_MIN_OFFSET) {
return BCM_E_PARAM;
}
SOC_OLP_TX_OAM_OFFSET(otxhdr) =
(pkt->oam_replacement_offset - _OLP_OAM_MIN_OFFSET) / 2;
}
return BCM_E_NONE;
}
#endif
#if defined (BCM_SABER2_SUPPORT)
STATIC int _bcm_sb2_tx_olp_hdr_ts_lm_offset_fill(int unit,
bcm_pkt_t *pkt,
soc_olp_tx_hdr_t *otxhdr)
{
int add_sub = 0;
uint8 dm_replacement_offset = 0;
uint8 lm_replacement_offset = 0;
if (SOC_IS_SABER2(unit)) {
if (pkt->flags2 & BCM_PKT_F2_LM_REPLACEMENT_OFFSET) {
lm_replacement_offset = pkt->oam_lm_replacement_offset;
if (lm_replacement_offset == 0){
return BCM_E_PARAM;
}
}
if (pkt->flags2 & BCM_PKT_F2_REPLACEMENT_OFFSET) {
if(pkt->oam_replacement_offset <= _OLP_OAM_MIN_OFFSET) {
return BCM_E_PARAM;
}
dm_replacement_offset = pkt->oam_replacement_offset;
if (dm_replacement_offset == 0){
return BCM_E_PARAM;
}
}
if (lm_replacement_offset == 0 && dm_replacement_offset == 0) {
/* Nothing to do */
} else if (dm_replacement_offset == 0) { /* Only LM case */
if (pkt->flags2 & BCM_PKT_F2_TIMESTAMP_MODE) {
/* Timestamp mode given when no timestamp
* replacment offset is given. */
return BCM_E_PARAM;
}
SOC_OLP_TX_OAM_OFFSET(otxhdr) =
(lm_replacement_offset - _OLP_OAM_MIN_OFFSET) / 2;
} else if (lm_replacement_offset == 0) { /* Only DM case */
SOC_OLP_TX_OAM_OFFSET(otxhdr) =
(dm_replacement_offset - _OLP_OAM_MIN_OFFSET) / 2;
SOC_OLP_TX_TIMESTAMP_ACTION(otxhdr) = pkt->timestamp_mode;
} else { /* LM + DM case */
/* Check if lm replacement offset is bigger/smaller than
* dm replacement offset */
if (lm_replacement_offset > dm_replacement_offset) {
add_sub = 0; /* Add */
} else if (lm_replacement_offset < dm_replacement_offset) {
add_sub = 1; /* Sub */
} else {
return BCM_E_PARAM; /* both should not be equal */
}
SOC_OLP_TX_OAM_OFFSET(otxhdr) =
(dm_replacement_offset - _OLP_OAM_MIN_OFFSET) / 2;
SOC_OLP_TX_TIMESTAMP_ACTION(otxhdr) = pkt->timestamp_mode;
if (add_sub == 0) {
SOC_OLP_TX_REL_LM_REP_OFF(otxhdr) =
(lm_replacement_offset - dm_replacement_offset - 4)/2;
} else if (add_sub == 1) {
SOC_OLP_TX_REL_LM_REP_OFF(otxhdr) =
(dm_replacement_offset - lm_replacement_offset + 4)/2;
}
SOC_OLP_TX_REL_LM_REP_OP(otxhdr) = add_sub;
}
}
return BCM_E_NONE;
}
#endif
int _bcm_tx_olp_hdr_fill(int unit, bcm_pkt_t *pkt,soc_olp_tx_hdr_t *otxhdr)
{
int rv = BCM_E_NONE;
int index, max_ctr, max_index;
uint32 pool_number=0;
uint32 base_index=0;
bcm_stat_flex_mode_t offset_mode=0;
bcm_stat_object_t object=bcmStatObjectIngPort;
bcm_stat_group_mode_t group_mode= bcmStatGroupModeSingle;
bcm_stat_flex_direction_t flex_direction = bcmStatFlexDirectionIngress;
int direction = 1;/* Default down mep
direction is EP */
SOC_OLP_TX_HDR_TYPE(otxhdr) = 0;
if(pkt->flags2 & BCM_PKT_F2_MEP_TYPE_UPMEP) {
SOC_OLP_TX_HDR_STYPE(otxhdr) = 1;
direction = 0; /* For UpMEP direction must be IP */
} else if (pkt->flags2 & BCM_PKT_F2_MEP_TYPE_SAT_DOWNMEP) {
SOC_OLP_TX_HDR_STYPE(otxhdr) = 2; /* For DnMEP default direction */
} else if (pkt->flags2 & BCM_PKT_F2_MEP_TYPE_SAT_UPMEP) {
SOC_OLP_TX_HDR_STYPE(otxhdr) = 3;
direction = 0; /* For UpMEP direction must be IP */
}
SOC_OLP_TX_PRI(otxhdr) = (pkt->flags & BCM_TX_PRIO_INT) ?
pkt->prio_int : pkt->cos;
SOC_OLP_TX_MODID(otxhdr) = pkt->dest_mod;
SOC_OLP_TX_PORT(otxhdr) = pkt->dest_port;
#if defined (BCM_TRIDENT2PLUS_SUPPORT)
if (SOC_IS_TRIDENT2PLUS(unit) || SOC_IS_APACHE(unit)) {
rv = _bcm_td2plus_tx_olp_hdr_ts_lm_offset_fill(unit, pkt, otxhdr);
}
#endif
#if defined (BCM_SABER2_SUPPORT)
if (SOC_IS_SABER2(unit)) {
rv = _bcm_sb2_tx_olp_hdr_ts_lm_offset_fill(unit, pkt, otxhdr);
}
#endif
if (BCM_FAILURE(rv)) {
return rv;
}
/*Counter index*/
if(pkt->oam_counter_size) {
max_ctr = SOC_IS_TRIDENT2PLUS(unit) ?
(BCM_PKT_OAM_COUNTER_MAX-1) : BCM_PKT_OAM_COUNTER_MAX;
max_index = (pkt->oam_counter_size < max_ctr) ?
pkt->oam_counter_size : max_ctr;
for(index = 0; index < max_index; index++) {
if (pkt->oam_counter[index].counter_object ==
bcmOamCounterObjectEndpointId) {
pool_number =
pkt->oam_counter[index].counter_object_id >> 24;
base_index =
pkt->oam_counter[index].counter_object_id & 0xffffff;
switch (pool_number) {
case 0:
SOC_OLP_TX_CTR1_LOCATION(otxhdr) = direction;
SOC_OLP_TX_CTR1_ID(otxhdr) = base_index;
SOC_OLP_TX_CTR1_ACTION(otxhdr) = pkt->oam_counter[index].counter_mode;
break;
case 1:
SOC_OLP_TX_CTR2_LOCATION(otxhdr) = direction;
SOC_OLP_TX_CTR2_ID_SET(otxhdr, base_index);
SOC_OLP_TX_CTR2_ACTION(otxhdr) = pkt->oam_counter[index].counter_mode;
break;
case 2:
#if defined (BCM_SABER2_SUPPORT)
SOC_OLP_TX_CTR3_LOCATION(otxhdr) = direction;
SOC_OLP_TX_CTR3_ID_SET(otxhdr, base_index);
SOC_OLP_TX_CTR3_ACTION(otxhdr) = pkt->oam_counter[index].counter_mode;
#endif
break;
default:
break;
}
} else if (pkt->oam_counter[index].counter_object ==
bcmOamCounterObjectFlexStatId) {
_bcm_esw_stat_get_counter_id_info(
unit, pkt->oam_counter[index].counter_object_id,
&group_mode,&object,&offset_mode,&pool_number,&base_index);
BCM_IF_ERROR_RETURN(_bcm_esw_stat_validate_object(unit,object,&flex_direction));
BCM_IF_ERROR_RETURN(_bcm_esw_stat_validate_group(unit,group_mode));
switch(index) {
case 0:
SOC_OLP_TX_CTR1_LOCATION(otxhdr) = flex_direction;
SOC_OLP_TX_CTR1_ID(otxhdr) = SOC_OLP_TX_CTR(pool_number,
(base_index + pkt->oam_counter[index].counter_offset));
SOC_OLP_TX_CTR1_ACTION(otxhdr) = pkt->oam_counter[index].counter_mode;
break;
case 1:
SOC_OLP_TX_CTR2_LOCATION(otxhdr) = flex_direction;
SOC_OLP_TX_CTR2_ID_SET(otxhdr,SOC_OLP_TX_CTR(pool_number,
(base_index + pkt->oam_counter[index].counter_offset)));
SOC_OLP_TX_CTR2_ACTION(otxhdr) = pkt->oam_counter[index].counter_mode;
break;
case 2:
#if defined (BCM_APACHE_SUPPORT)
SOC_OLP_TX_CTR3_LOCATION(otxhdr) = flex_direction;
SOC_OLP_TX_CTR3_ID_SET(otxhdr,SOC_OLP_TX_CTR(pool_number,
(base_index + pkt->oam_counter[index].counter_offset)));
SOC_OLP_TX_CTR3_ACTION(otxhdr) = pkt->oam_counter[index].counter_mode;
#endif
break;
default:
break;
}
}
}
}
LOG_DEBUG(BSL_LS_BCM_TX,
(BSL_META_U(0,
"%s,hdr 0x%x,hdrst 0x%x,destmod %d,destport %d,cos %d\n"
"timestamp ac 0x%x, oamOff 0x%x, ctr2 id 0x%x,pool 0x%x, base 0x%x\n"),
FUNCTION_NAME(),SOC_OLP_TX_HDR_TYPE_GET(otxhdr),
SOC_OLP_TX_HDR_STYPE_GET(otxhdr),SOC_OLP_TX_MODID_GET(otxhdr),
SOC_OLP_TX_PORT_GET(otxhdr),SOC_OLP_TX_PRI_GET(otxhdr),
SOC_OLP_TX_TIMESTAMP_ACTION_GET(otxhdr),
SOC_OLP_TX_OAM_OFFSET_GET(otxhdr),SOC_OLP_TX_CTR2_ID_GET(otxhdr),pool_number,base_index));
shr_olp_tx_header_pack(pkt->_olp_hdr,otxhdr);
return rv;
}
/*
* Function:
* _tx_pkt_olp_desc_add
* Purpose:
* Add all descriptors to a DV for a given packet.
* Parameters:
* unit - Strataswitch device ID
* pkt - Pointer to packet
* dv - DCB vector to update
* pkt_idx - Index of packet.
* Index value is 0, except for arrays or link lists.
* For arrays or link lists, the value must be the
* the index number of the packet.
* Returns:
* BCM_E_XXX
* Notes:
* Uses tx info pkt_count member to get packet index; then advances
* the pkt_count member.
*
* See sdk/doc/pkt.txt for info about restrictions on MACs,
* and the VLAN not crossing block boundaries.
*
* Assert: unit is local
*/
STATIC int
_tx_pkt_olp_desc_add(int unit, bcm_pkt_t *pkt, dv_t *dv, int pkt_idx)
{
int pkt_len = 0; /* Length calculation for byte padding */
int tmp_len;
int min_len = ENET_MIN_PKT_SIZE; /* Min length pkt before padded */
int block_offset = 0;
int i;
uint32 dcb_flags = 0;
uint32 *pkt_hg_hdr = NULL;
bcm_pbmp_t tx_pbmp, tx_upbmp, tx_l3pbmp;
soc_persist_t *sop = SOC_PERSIST(unit);
soc_olp_tx_pkt_t opkt;
bcm_port_t sglp;
bcm_module_t modid;
COMPILER_REFERENCE(pkt_idx); /* May not be ref'd depending on defines */
/* Calculate the DCB flags for this packet. */
dcb_flags = _dcb_flags_get(unit, pkt, dv);
#if defined(BROADCOM_DEBUG)
if (pkt->cos < BCM_COS_COUNT) { /* COS is unsigned */
bcm_tx_pkt_count[pkt->cos]++;
} else {
bcm_tx_pkt_count_bad_cos++;
}
#endif /* BROADCOM_DEBUG */
_soc_tx_pkt_setup(unit, pkt, &dv->tx_param);
BCM_PBMP_ASSIGN(tx_pbmp, pkt->tx_pbmp);
BCM_PBMP_ASSIGN(tx_upbmp, pkt->tx_upbmp);
BCM_PBMP_ASSIGN(tx_l3pbmp, pkt->tx_l3pbmp);
BCM_API_XLATE_PORT_PBMP_A2P(unit, &tx_pbmp);
BCM_API_XLATE_PORT_PBMP_A2P(unit, &tx_upbmp);
BCM_API_XLATE_PORT_PBMP_A2P(unit, &tx_l3pbmp);
/*
* bcm_attach_early_txrx can be used to initialise tx and rx modules before
* other modules. However checking link status of the port has to be avoided
* until warmboot is complete, because the link status will not be available
* until linkscan module is initialised. Port module initialization and link
* module recovery and successful linkscan processing will ensure avoiding
* transmitting the packets to linked down ports.
*/
if (!(pkt->flags & BCM_TX_LINKDOWN_TRANSMIT)) {
if (!SOC_WARM_BOOT(unit)) {
BCM_PBMP_AND(tx_pbmp, sop->lc_pbm_link);
}
}
if (pkt->pkt_data[0].len < sizeof(bcm_mac_t)) {
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_tx_pkt_olp_desc_add: pkt->pkt_data[0].len < sizeof(bcm_mac_t) exit ")));
return BCM_E_PARAM;
}
sal_memset(&opkt, 0, sizeof(soc_olp_tx_pkt_t));
BCM_PKT_HGHDR_CLR(pkt);
(pkt)->flags &= (~BCM_TX_HG_READY);
pkt_hg_hdr = NULL;
BCM_IF_ERROR_RETURN(bcm_esw_stk_my_modid_get(unit, &modid));
_bcm_esw_glp_construct(unit, BCM_TRUNK_INVALID, modid, CMIC_PORT(unit) , &sglp);
_bcm_olp_l2_hdr_get(unit, sglp, 1, &(opkt.l2_hdr));
if(!BCM_PKT_TX_HAS_OLP_READY(pkt)) {
_bcm_tx_olp_hdr_fill(unit, pkt, &(opkt.tx_hdr));
}
sal_memcpy((uint8 *)&(opkt.tx_hdr),BCM_PKT_OLP_HDR(pkt),sizeof(soc_olp_tx_hdr_t));
sal_memcpy(SOC_DV_HG_HDR(dv, pkt_idx),(uint8*) &opkt, sizeof(soc_olp_tx_pkt_t));
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) SOC_DV_HG_HDR(dv, pkt_idx), sizeof(soc_olp_tx_pkt_t),
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, (uint32 *)BCM_PKT_OLP_HDR(pkt)));
pkt_len = sizeof(soc_olp_tx_pkt_t);
/* Set up pointer to the packet in TX info structure. */
TX_INFO_PKT_ADD(dv, pkt);
pkt_hg_hdr = NULL;
SOC_DMA_HG_SET(dcb_flags, 0);
/* Add DCBs for the remainder of the blocks. */
for (i = block_offset; i < pkt->blk_count; i++) {
tmp_len = pkt->pkt_data[i].len;
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) pkt->pkt_data[i].data,
tmp_len, tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
pkt_len += tmp_len;
}
/* If CRC allocated, adjust min length */
if (pkt->flags & BCM_TX_CRC_ALLOC) {
min_len = ENET_MIN_PKT_SIZE - ENET_FCS_SIZE;
}
/* Pad runt packets */
if ((pkt_len < min_len) && !(pkt->flags & BCM_TX_NO_PAD)) {
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) _pkt_pad_ptr, min_len - pkt_len,
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
}
/* If "CRC allocate" set (includes append), add static ptr to it */
if (pkt->flags & BCM_TX_CRC_ALLOC) {
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) _null_crc_ptr, sizeof(uint32),
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
}
/* Mark the end of the packet */
soc_dma_desc_end_packet(dv);
return BCM_E_NONE;
}
#endif /* BCM_TRIDENT2PLUS_SUPPORT || BCM_SABER2_SUPPORT */
/*
* Function:
* _tx_pkt_desc_add
* Purpose:
* Add all descriptors to a DV for a given packet.
* Parameters:
* unit - Strataswitch device ID
* pkt - Pointer to packet
* dv - DCB vector to update
* pkt_idx - Index of packet.
* Index value is 0, except for arrays or link lists.
* For arrays or link lists, the value must be the
* the index number of the packet.
* Returns:
* BCM_E_XXX
* Notes:
* Uses tx info pkt_count member to get packet index; then advances
* the pkt_count member.
*
* See sdk/doc/pkt.txt for info about restrictions on MACs,
* and the VLAN not crossing block boundaries.
*
* Assert: unit is local
*/
STATIC int
_tx_pkt_desc_add(int unit, bcm_pkt_t *pkt, dv_t *dv, int pkt_idx)
{
int byte_offset = 0;
int pkt_len = 0; /* Length calculation for byte padding */
int tmp_len;
int min_len = ENET_MIN_PKT_SIZE; /* Min length pkt before padded */
uint8 *vlan_ptr = NULL;
uint8 *src_mac;
int block_offset = 0;
int i;
uint32 dcb_flags = 0;
uint32 *pkt_hg_hdr = NULL;
int clear_crc = FALSE;
int crc_block_offset = 0;
bcm_pbmp_t tx_pbmp, tx_upbmp, tx_l3pbmp;
bcm_pbmp_t tx_macpbmp;
soc_persist_t *sop = SOC_PERSIST(unit);
#if defined(BCM_CMICX_SUPPORT)
int pb_hdr = 0;
#endif
COMPILER_REFERENCE(pkt_idx); /* May not be ref'd depending on defines */
/* Clear private UNTAG flag */
#ifdef BCM_SHADOW_SUPPORT
/* BCM88732 device doesn't introduce any headers */
if (!SOC_IS_SHADOW(unit)) {
#endif
pkt->flags &= (~BCM_PKT_F_TX_UNTAG);
#ifdef BCM_SHADOW_SUPPORT
}
#endif
#if defined (BCM_TRIDENT2PLUS_SUPPORT) || defined (BCM_SABER2_SUPPORT)
if(soc_feature(unit, soc_feature_cpu_as_olp) &&
BCM_PKT_TX_OLP(pkt)) {
return _tx_pkt_olp_desc_add(unit, pkt, dv, pkt_idx);
}
#endif
/* Calculate the DCB flags for this packet. */
dcb_flags = _dcb_flags_get(unit, pkt, dv);
#if defined(BROADCOM_DEBUG)
if (pkt->cos < BCM_COS_COUNT) { /* COS is unsigned */
bcm_tx_pkt_count[pkt->cos]++;
} else {
bcm_tx_pkt_count_bad_cos++;
}
#endif /* BROADCOM_DEBUG */
_soc_tx_pkt_setup(unit, pkt, &dv->tx_param);
/* If the CRC is being regenerated and the transmit device
* is a fabric, zero out the last four bytes by subtracting
* four bytes from the end and appending four byte zero'd out
* tx descriptor.
*/
if (SOC_IS_HERCULES1(unit) &&
(pkt->flags & BCM_TX_CRC_REGEN) &&
(!(pkt->flags & BCM_TX_CRC_ALLOC))) {
/* Assumes the CRC is in the last block containing data */
for (i = pkt->blk_count - 1; i > 0; i--) {
if (pkt->pkt_data[i].len > 0) {
break;
}
}
byte_offset = pkt->pkt_data[i].len - ENET_FCS_SIZE;
if (byte_offset < 0) {
LOG_WARN(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"TX CRC clear: CRC not contiguous or runt pkt\n")));
} else {
clear_crc = TRUE;
crc_block_offset = i;
}
}
BCM_PBMP_ASSIGN(tx_pbmp, pkt->tx_pbmp);
BCM_PBMP_ASSIGN(tx_upbmp, pkt->tx_upbmp);
BCM_PBMP_ASSIGN(tx_l3pbmp, pkt->tx_l3pbmp);
BCM_API_XLATE_PORT_PBMP_A2P(unit, &tx_pbmp);
BCM_API_XLATE_PORT_PBMP_A2P(unit, &tx_upbmp);
BCM_API_XLATE_PORT_PBMP_A2P(unit, &tx_l3pbmp);
/*
* bcm_attach_early_txrx can be used to initialise tx and rx modules before
* other modules. However checking link status of the port has to be avoided
* until warmboot is complete, because the link status will not be available
* until linkscan module is initialised. Port module initialization and link
* module recovery and successful linkscan processing will ensure avoiding
* transmitting the packets to linked down ports.
*/
if (!(pkt->flags & BCM_TX_LINKDOWN_TRANSMIT)) {
if (!SOC_WARM_BOOT(unit)) {
soc_link_mask2_get(unit, &tx_macpbmp);
BCM_PBMP_AND(tx_pbmp, tx_macpbmp);
BCM_PBMP_AND(tx_pbmp, sop->lc_pbm_link);
SOC_PBMP_REMOVE(tx_pbmp, sop->lc_pbm_remote_fault);
}
}
if (!SOC_IS_ARAD(unit) && !SOC_IS_DNX(unit)) {
if (BCM_PBMP_IS_NULL(tx_pbmp) && !BCM_PBMP_IS_NULL(pkt->tx_pbmp)) {
return BCM_E_NONE;
}
}
/*
* XGS3 devices do not take TXPBM/TXUBM.
* This is emulated below using PBS TX mode.
* Only used on 5675 now.
*/
#if defined(BCM_XGS12_SUPPORT)
if (soc_feature(unit, soc_feature_tx_fast_path)) {
/* Just set up the packet as is and return */
if (pkt->flags & BCM_TX_FAST_PATH) {
for (i = 0; i < pkt->blk_count; i++) {
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) pkt->pkt_data[i].data, pkt->pkt_data[i].len,
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, (uint32 *)BCM_PKT_HG_HDR(pkt)));
}
/* Mark the end of the packet */
soc_dma_desc_end_packet(dv);
return BCM_E_NONE;
}
}
#endif /* BCM_XGS12_SUPPORT */
if (pkt->pkt_data[0].len < sizeof(bcm_mac_t)) {
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_tx_pkt_desc_add: pkt->pkt_data[0].len < sizeof(bcm_mac_t) exit ")));
return BCM_E_PARAM;
}
/* Get pointers to srcmac and vlan; check if bad block count */
_get_mac_vlan_ptrs(dv, pkt, &src_mac, &vlan_ptr, &block_offset,
&byte_offset, pkt_idx);
if (block_offset >= pkt->blk_count) {
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_tx_pkt_desc_add: block_offset >= pkt->blk_count exit ")));
return BCM_E_PARAM;
}
if (byte_offset >= pkt->pkt_data[block_offset].len) {
byte_offset = 0;
block_offset++;
}
/* Set up pointer to the packet in TX info structure. */
TX_INFO_PKT_ADD(dv, pkt);
#ifdef BCM_XGS3_SWITCH_SUPPORT
/*
* XGS3: Decide whether to put Higig header or PB (Pipe Bypass)
* header in the TX descriptor
* 1. Fabric mapped mode (HG header in descriptor)
* 2. Raw Ethernet packet steered mode (PB header in descriptor)
*/
if ((!SOC_IS_SHADOW(unit) &&
SOC_IS_XGS3_SWITCH(unit) &&
(!BCM_PKT_TX_ETHER(pkt))) ||
(pkt->flags2 & BCM_PKT_F2_RX_PORT) ||
(pkt->flags2 & BCM_PKT_F2_CPU_TX_PROC)) {
/*
* Raw packet steered mode (PB header in descriptor)
*/
BCM_IF_ERROR_RETURN(_bcm_xgs3_tx_pipe_bypass_header_setup(unit, pkt));
pkt_hg_hdr = (uint32 *)BCM_PKT_PB_HDR(pkt);
#if defined(BCM_CMICX_SUPPORT)
pb_hdr = 1;
#endif
} else {
pkt_hg_hdr = (uint32 *)BCM_PKT_HG_HDR(pkt);
if (PBS_MH_START_IS_SET(pkt_hg_hdr)) {
/* A PBSMH tag was supplied.
* Clear the HG flags so the VLAN tag isn't stripped off.
*/
BCM_PKT_HGHDR_CLR(pkt);
(pkt)->flags &= (~BCM_TX_HG_READY);
}
}
#else
pkt_hg_hdr = NULL;
#endif
#ifdef BCM_SHADOW_SUPPORT
if(SOC_IS_SHADOW(unit)) {
/* No Module header for BCM88732 device */
pkt_hg_hdr = NULL;
SOC_DMA_HG_SET(dcb_flags, 0);
}
#endif
#ifdef BCM_XGS_SUPPORT
/*
* BCM_PKT_F_HGHDR flag indicates higig header is part of
* packet data stream.
*/
if (BCM_PKT_HAS_HGHDR(pkt)
#ifdef BCM_ARAD_SUPPORT
&& (!SOC_IS_ARAD(unit))
#endif
#ifdef BCM_DNX_SUPPORT
&& (!SOC_IS_DNX(unit))
#endif
)
{
uint8 *tmp_pkt_hg_hdr = BCM_PKT_HG_HDR(pkt);
int hg_hdr_len = SOC_HIGIG_HDR_SIZE;
/*
* XGS3: Raw Higig packet steered mode.
* Make higig header part of packet stream and PB
* header part of descriptor
*/
#ifdef BCM_HIGIG2_SUPPORT
if (tmp_pkt_hg_hdr[0] == SOC_HIGIG2_START) {
hg_hdr_len = SOC_HIGIG2_HDR_SIZE;
}
#endif /* BCM_HIGIG2_SUPPORT */
sal_memcpy(SOC_DV_HG_HDR(dv, pkt_idx), tmp_pkt_hg_hdr, hg_hdr_len);
if (!soc_feature(unit, soc_feature_cmicx)) {
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) SOC_DV_HG_HDR(dv, pkt_idx), hg_hdr_len,
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, (uint32 *)BCM_PKT_PB_HDR(pkt)));
}
}
#endif /* BCM_XGS_SUPPORT */
#ifdef BCM_ARAD_SUPPORT
if (SOC_IS_ARAD(unit)) {
pkt_hg_hdr = (uint32 *)((pkt)->_dpp_hdr);
}
#endif
#if defined(ADAPTER_SERVER_MODE)
if (SOC_IS_DNX(unit))
{
if (pkt->flags & BCM_PKT_F_HGHDR)
{
/*
* Module Header is not supported on adapter
* Clear BCM_PKT_F_HGHDR, indicate no Module Header
* CPU channel will be register CpuChannel, always 0 by default
*/
pkt->flags &= ~BCM_PKT_F_HGHDR;
SOC_DMA_HG_SET(dcb_flags, 0);
}
}
#elif defined(BCM_DNX_SUPPORT)
if (SOC_IS_DNX(unit))
{
if (pkt->flags & BCM_PKT_F_HGHDR)
{
/*
* HiGig flag indicates Module header is present, Module Header is 20 bytes at the start of the packet
* Update first byte of Module header to CPU Channel
*/
pkt->pkt_data[0].data[0] = pkt ->_dpp_hdr[0];
}
}
#endif
#if defined(BCM_CMICX_SUPPORT)
#if defined(BCM_CMICX_TX_PREALLOC_SUPPORT)
pkt->tx_header = NULL;
if (soc_feature(unit, soc_feature_cmicx) && (pkt_hg_hdr != NULL)) {
if (SOC_DMA_HG_GET(dcb_flags)) {
if (pb_hdr == 1) {
/* We cannot have pkt_hg_dhr as NULL, This is also checked in SOC_DMA_HG_GET */
/* coverity[var_deref_model] */
sal_memcpy(SOC_DV_TX_HDR(dv, pkt_idx), pkt_hg_hdr, sizeof(pkt->_pb_hdr));
} else {
sal_memcpy(SOC_DV_TX_HDR(dv, pkt_idx), pkt_hg_hdr, sizeof(pkt->_higig));
}
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t)(sal_vaddr_t) SOC_DV_TX_HDR(dv, pkt_idx), sizeof(pkt->_higig),
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
}
/*
* BCM_PKT_F_HGHDR flag indicates higig header is part of
* packet data stream.
*/
if ((pb_hdr == 1) && BCM_PKT_HAS_HGHDR(pkt)) {
uint8 *tmp_hg_hdr = BCM_PKT_HG_HDR(pkt);
int hg_hdr_len = SOC_HIGIG_HDR_SIZE;
#ifdef BCM_HIGIG2_SUPPORT
if (tmp_hg_hdr[0] == SOC_HIGIG2_START) {
hg_hdr_len = SOC_HIGIG2_HDR_SIZE;
}
#endif /* BCM_HIGIG2_SUPPORT */
sal_memcpy(SOC_DV_HG_HDR(dv, pkt_idx), tmp_hg_hdr, hg_hdr_len);
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) SOC_DV_HG_HDR(dv, pkt_idx), hg_hdr_len,
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, (uint32 *)BCM_PKT_PB_HDR(pkt)));
}
if ((pkt->_higig[7] & BCM_TX_EXT_HG_HDR) && !SOC_IS_TOMAHAWK3(unit)) {
sal_memcpy(SOC_DV_EXT_HG_HDR(dv, pkt_idx), pkt->_ext_higig, sizeof(pkt->_ext_higig));
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) SOC_DV_EXT_HG_HDR(dv, pkt_idx), sizeof(pkt->_ext_higig),
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
}
if (bsl_check(bslLayerSoc, bslSourceTx, bslSeverityVerbose, unit)) {
soc_dma_higig_dump(unit, "TX Header ", (uint8 *)pkt_hg_hdr, sizeof(pkt->_higig), 0, NULL);
}
}
#else
if (soc_feature(unit, soc_feature_cmicx) && (pkt_hg_hdr != NULL)) {
if (NULL != pkt->tx_header) {
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_tx_pkt_desc_add: Cannot re-allocate mem to"
" tx_header as Pkt might me in-flight!!!\n")));
return BCM_E_MEMORY;
}
if ((pkt->_higig[7] & BCM_TX_EXT_HG_HDR) && !SOC_IS_TOMAHAWK3(unit)) {
pkt->tx_header = soc_cm_salloc(unit, sizeof(pkt->_higig) + sizeof(pkt->_ext_higig), "tx_header");
if (pkt->tx_header == NULL) {
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_tx_pkt_desc_add: unable to obtain dma'ble memory\n")));
return BCM_E_MEMORY;
}
sal_memset(pkt->tx_header, 0, sizeof(pkt->_higig) + sizeof(pkt->_ext_higig));
} else {
pkt->tx_header = soc_cm_salloc(unit, sizeof(pkt->_higig), "tx_header");
if (pkt->tx_header == NULL) {
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_tx_pkt_desc_add: unable to obtain dma'ble memory\n")));
return BCM_E_MEMORY;
}
sal_memset(pkt->tx_header, 0, sizeof(pkt->_higig));
}
if (SOC_DMA_HG_GET(dcb_flags)) {
if (pb_hdr == 1) {
/* We cannot have pkt_hg_dhr as NULL, This is also checked in SOC_DMA_HG_GET */
/* coverity[var_deref_model] */
sal_memcpy(pkt->tx_header, pkt_hg_hdr, sizeof(pkt->_pb_hdr));
} else {
sal_memcpy(pkt->tx_header, pkt_hg_hdr, sizeof(pkt->_higig));
}
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t)(uint8 *)pkt->tx_header, sizeof(pkt->_higig),
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
}
/*
* BCM_PKT_F_HGHDR flag indicates higig header is part of
* packet data stream.
*/
if ((pb_hdr == 1) && BCM_PKT_HAS_HGHDR(pkt)) {
uint8 *tmp_hg_hdr = BCM_PKT_HG_HDR(pkt);
int hg_hdr_len = SOC_HIGIG_HDR_SIZE;
#ifdef BCM_HIGIG2_SUPPORT
if (tmp_hg_hdr[0] == SOC_HIGIG2_START) {
hg_hdr_len = SOC_HIGIG2_HDR_SIZE;
}
#endif /* BCM_HIGIG2_SUPPORT */
sal_memcpy(SOC_DV_HG_HDR(dv, pkt_idx), tmp_hg_hdr, hg_hdr_len);
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) SOC_DV_HG_HDR(dv, pkt_idx), hg_hdr_len,
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, (uint32 *)BCM_PKT_PB_HDR(pkt)));
}
if ((pkt->_higig[7] & BCM_TX_EXT_HG_HDR) && !SOC_IS_TOMAHAWK3(unit)) {
uint8 *c = (uint8 *)pkt->tx_header;
c += sizeof(pkt->_higig);
sal_memcpy(c, pkt->_ext_higig, sizeof(pkt->_ext_higig));
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t)(uint8 *)c, sizeof(pkt->_ext_higig),
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
}
if (bsl_check(bslLayerSoc, bslSourceTx, bslSeverityVerbose, unit)) {
soc_dma_higig_dump(unit, "TX Header ", (uint8 *)pkt->tx_header, sizeof(pkt->_higig), 0, NULL);
}
} else {
pkt->tx_header = NULL;
}
#endif /* BCM_CMICX_TX_PREALLOC_SUPPORT */
#endif /* BCM_CMICX_SUPPORT */
#ifdef BCM_XGS_SUPPORT
#ifdef BCM_INSTRUMENTATION_SUPPORT
if ((soc_feature(unit, soc_feature_visibility)) &&
(pkt->flags2 & BCM_PKT_F2_RX_PORT)) {
bcm_gport_t visibility_source_gport;
soc_loopback_hdr_t loopback_hdr;
bcm_trunk_t pkt_trace_src_tgid;
bcm_port_t pkt_trace_src_pp_port;
int id;
bcm_module_t pkt_trace_src_modid;
uint16 pkt_trace_src;
uint32 visibility_cpu_profile_id = 0;
uint32 pkt_trace_src_port = pkt->rx_port;
SOC_IF_ERROR_RETURN(bcm_port_gport_get(unit, pkt_trace_src_port,
&visibility_source_gport));
SOC_IF_ERROR_RETURN(_bcm_esw_gport_resolve(unit, visibility_source_gport,
&pkt_trace_src_modid, &pkt_trace_src_pp_port,
&pkt_trace_src_tgid, &id));
pkt_trace_src = (pkt_trace_src_modid << 8) | (pkt_trace_src_pp_port & 0xFF);
sal_memset(&loopback_hdr, 0, sizeof(soc_loopback_hdr_t));
soc_loopback_hdr_field_set(unit, &loopback_hdr, LBMH_start, START_LBMH_HDR);
soc_loopback_hdr_field_set(unit, &loopback_hdr, LBMH_pp_port, pkt_trace_src_port);
/* LBMH_src is GPP associate with pp_port, and modid,
in tomahawk, GPP is same as the logical port number */
soc_loopback_hdr_field_set(unit, &loopback_hdr, LBMH_src, pkt_trace_src );
/* fixed configuration of loopback header for visibilty packet */
if (SOC_IS_TRIDENT3X(unit)) {
soc_loopback_hdr_field_set(unit, &loopback_hdr, LBMH_common_hdr, TD3X_LBMH_HDR);
} else {
soc_loopback_hdr_field_set(unit, &loopback_hdr, LBMH_common_hdr, COMMON_LBMH_HDR);
}
soc_loopback_hdr_field_set(unit, &loopback_hdr, LBMH_src_type, SRC_TYPE_GPP_LBMH_HDR);
if (pkt->flags2 & BCM_PKT_F2_VISIBILITY_PKT) {
soc_loopback_hdr_field_set(unit, &loopback_hdr, LBMH_visibility, VIS_LBMH_HDR);
BCM_IF_ERROR_RETURN(_bcm_esw_pkt_trace_cpu_profile_get(
unit, &visibility_cpu_profile_id));
soc_loopback_hdr_field_set(unit, &loopback_hdr,
LBMH_pkt_profile, visibility_cpu_profile_id);
} else {
/* set masquerade packet profile to default - learn, forward, and ifp apply */
soc_loopback_hdr_field_set(unit, &loopback_hdr,
LBMH_pkt_profile, 2);
}
sal_memcpy(SOC_DV_HG_HDR(dv, pkt_idx), &loopback_hdr, LOOPBACK_HDR_SIZE);
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) SOC_DV_HG_HDR(dv, pkt_idx), LOOPBACK_HDR_SIZE,
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
if (bsl_check(bslLayerSoc, bslSourceTx, bslSeverityVerbose, unit)) {
soc_loopback_hdr_dump(unit, "Loopback Header", &loopback_hdr);
}
}
#endif /* BCM_INSTRUMENTATION_SUPPORT */
#endif
#ifdef BCM_XGS_SUPPORT
#ifdef BCM_CPU_TX_PROC_SUPPORT
if ((soc_feature(unit, soc_feature_cpu_tx_proc)) &&
(pkt->flags2 & BCM_PKT_F2_CPU_TX_PROC)) {
int id;
bcm_gport_t proc_hdr_source_gport;
soc_proc_hdr_t proc_hdr;
bcm_trunk_t proc_hdr_src_tgid;
bcm_port_t proc_hdr_src_pp_port;
bcm_module_t proc_hdr_src_modid;
uint16 proc_hdr_src;
uint32 proc_hdr_cpu_profile_id = 0;
#ifdef BCM_TOMAHAWK3_SUPPORT
if ((pkt->rx_port == _TH3_MMU_SPARE_SRC_PORT) && SOC_IS_TOMAHAWK3(unit)) {
proc_hdr_src_modid = 0;
proc_hdr_src_pp_port = pkt->rx_port;
} else
#endif
{
SOC_IF_ERROR_RETURN(bcm_port_gport_get(unit, pkt->rx_port,
&proc_hdr_source_gport));
SOC_IF_ERROR_RETURN(_bcm_esw_gport_resolve(unit, proc_hdr_source_gport,
&proc_hdr_src_modid, &proc_hdr_src_pp_port,
&proc_hdr_src_tgid, &id));
}
proc_hdr_src = (proc_hdr_src_modid << 8) | (proc_hdr_src_pp_port & 0xFF);
sal_memset(&proc_hdr, 0, sizeof(soc_proc_hdr_t));
/* fixed configuration of cpu tx proc packet */
soc_proc_hdr_field_set(unit, &proc_hdr, PH_start, SOC_TX_PROC_START);
soc_proc_hdr_field_set(unit, &proc_hdr, PH_header_types, SOC_TX_PROC_ETHERNET_HEADER_TYPE);
soc_proc_hdr_field_set(unit, &proc_hdr, PH_source_type, SOC_TX_PROC_SOURCE_TYPE);
soc_proc_hdr_field_set(unit, &proc_hdr, PH_visibility_pkt, SOC_TX_PROC_VISIBILITY_PKT);
soc_proc_hdr_field_set(unit, &proc_hdr, PH_subflow_type, SOC_TX_PROC_SUBFLOW_TYPE);
soc_proc_hdr_field_set(unit, &proc_hdr, PH_pp_port, pkt->rx_port);
/*
* LBMH_src is GPP associate with pp_port, and modid,
* GPP is same as the logical port number
*/
soc_proc_hdr_field_set(unit, &proc_hdr, PH_source, proc_hdr_src);
/* Program the destination type/opcode and destination */
soc_proc_hdr_field_set(unit, &proc_hdr, PH_destination_type, pkt->txprocmh_destination_type);
if ((pkt->txprocmh_destination_type == SOC_TX_PROC_OP_ECMP_MEMBER) ||
(pkt->txprocmh_destination_type == SOC_TX_PROC_OP_ECMP)) {
soc_proc_hdr_field_set(unit, &proc_hdr, PH_destination, pkt->txprocmh_ecmp_group_index);
} else {
soc_proc_hdr_field_set(unit, &proc_hdr, PH_destination, pkt->txprocmh_destination);
}
if (pkt->txprocmh_destination_type == SOC_TX_PROC_OP_ECMP_MEMBER) {
soc_proc_hdr_field_set(unit, &proc_hdr, PH_ecmp_member_id, pkt->txprocmh_ecmp_member_index);
}
if (pkt->txprocmh_mcast_lb_index_valid) {
soc_proc_hdr_field_set(unit, &proc_hdr, PH_mcast_lb_idx_valid, pkt->txprocmh_mcast_lb_index_valid);
soc_proc_hdr_field_set(unit, &proc_hdr, PH_mcast_lb_idx, pkt->txprocmh_mcast_lb_index);
}
if (pkt->txprocmh_qos_fields_valid) {
uint32 prio_int, color;
soc_proc_hdr_field_set(unit, &proc_hdr, PH_qos_fields_valid, pkt->txprocmh_qos_fields_valid);
prio_int = (pkt->flags & BCM_TX_PRIO_INT) ? pkt->prio_int : pkt->cos;
soc_proc_hdr_field_set(unit, &proc_hdr, PH_int_pri, prio_int);
if (pkt->flags2 & BCM_PKT_F2_CONG_INT) {
soc_proc_hdr_field_set(unit, &proc_hdr, PH_int_cn, pkt->txprocmh_congestion_int);
}
switch (pkt->color) {
case bcmColorGreen:
color = 0;
break;
case bcmColorYellow:
color = 3;
break;
case bcmColorRed:
color = 1;
break;
case bcmColorBlack:
default:
return BCM_E_PARAM;
}
soc_proc_hdr_field_set(unit, &proc_hdr, PH_dp, color);
}
if (pkt->flags & BCM_PKT_F_ROUTED) {
soc_proc_hdr_field_set(unit, &proc_hdr, PH_routed_pkt, SOC_TX_PROC_ROUTED_PKT);
}
soc_proc_hdr_field_set(unit, &proc_hdr,
PH_pkt_profile, proc_hdr_cpu_profile_id);
/* Move the cpu tx proc hdr to dma capable memory */
sal_memcpy(SOC_DV_HG_HDR(dv, pkt_idx), &proc_hdr, SOC_PROC_HDR_SIZE);
/* Add a descriptor for the cpu tx proc header to the chain */
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) SOC_DV_HG_HDR(dv, pkt_idx), SOC_PROC_HDR_SIZE,
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
if (bsl_check(bslLayerSoc, bslSourceTx, bslSeverityVerbose, unit)) {
soc_proc_hdr_dump(unit, "CPU_TX_PROC Header ", &proc_hdr);
}
}
#endif /* BCM_CPU_TX_PROC_SUPPORT */
#endif
/* Dest mac */
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) pkt->pkt_data[0].data, sizeof(bcm_mac_t),
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
pkt_len = ENET_MAC_SIZE;
/* Source mac */
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) src_mac, sizeof(bcm_mac_t),
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
pkt_len += ENET_MAC_SIZE;
/* VLAN tag */
/* No VLAN tag for Fabric mapped Higig TX as well */
if ((!BCM_PKT_HAS_HGHDR(pkt)
#ifdef BCM_ARAD_SUPPORT
||(BCM_PKT_HAS_HGHDR(pkt) && SOC_IS_ARAD(unit))
#endif
#ifdef BCM_DNX_SUPPORT
||(BCM_PKT_HAS_HGHDR(pkt) && SOC_IS_DNX(unit))
#endif
)
&& !(pkt->flags & BCM_PKT_F_TX_UNTAG)
&& !BCM_PKT_TX_FABRIC_MAPPED(pkt) && (vlan_ptr != NULL))
{ /* No HG Hdr, so add VLAN tag */
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) vlan_ptr, sizeof(uint32),
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
pkt_len += sizeof(uint32);
}
#ifdef BCM_HIGIG2_SUPPORT
else if (pkt->stk_flags & BCM_PKT_STK_F_TX_TAG) {
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) vlan_ptr, sizeof(uint32),
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
}
#endif /* BCM_HIGIG2_SUPPORT */
/* SL TAG */
if (pkt->flags & BCM_PKT_F_SLTAG) {
sal_memcpy(SOC_DV_SL_TAG(dv, pkt_idx), pkt->_sltag, sizeof(uint32));
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t)SOC_DV_SL_TAG(dv, pkt_idx), sizeof(uint32),
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
}
/*
* If byte offset indicates we're not at the end of a packet's data
* block, add a DCB for the rest of the current block.
*/
if (byte_offset != 0) {
tmp_len = pkt->pkt_data[block_offset].len - byte_offset;
if (clear_crc && (block_offset == crc_block_offset)) {
tmp_len -= ENET_FCS_SIZE;
}
#ifdef BCM_ARAD_SUPPORT
if (((pkt->flags & BCM_TX_CRC_REGEN) && (!(pkt->flags & BCM_TX_CRC_ALLOC)))
&& (pkt->pkt_data[block_offset].len >= ENET_MIN_PKT_SIZE) && SOC_IS_ARAD(unit)) {
tmp_len -= ENET_FCS_SIZE; /*For DNX CRC regen,subtract CRC len*/
}
#endif /*BCM_ARAD_SUPPORT*/
#ifdef BCM_DNX_SUPPORT
if (((pkt->flags & BCM_TX_CRC_REGEN) && (!(pkt->flags & BCM_TX_CRC_ALLOC)))
&& SOC_IS_DNX(unit))
{
/** Last 4 bytes of packet are taken as CRC field */
tmp_len -= ENET_FCS_SIZE;
}
#endif /*BCM_DNX_SUPPORT*/
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) &pkt->pkt_data[block_offset].data[byte_offset],
tmp_len, tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
block_offset++;
pkt_len += tmp_len;
}
/* Add DCBs for the remainder of the blocks. */
for (i = block_offset; i < pkt->blk_count; i++) {
tmp_len = pkt->pkt_data[i].len;
if (clear_crc && (i == crc_block_offset)) {
tmp_len -= ENET_FCS_SIZE;
}
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) pkt->pkt_data[i].data,
tmp_len, tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
pkt_len += tmp_len;
}
/* If CRC allocated, adjust min length */
if (((pkt->flags & BCM_TX_CRC_ALLOC) || clear_crc)
#ifdef BCM_ARAD_SUPPORT
&& !SOC_IS_ARAD(unit) /*DNX device has different MAC behavior*/
#endif /*BCM_ARAD_SUPPORT*/
#ifdef BCM_DNX_SUPPORT
&& !SOC_IS_DNX(unit) /*Dune device has different MAC behavior*/
#endif /*BCM_DNX_SUPPORT*/
) {
min_len = ENET_MIN_PKT_SIZE - ENET_FCS_SIZE;
}
#ifdef BCM_DNX_SUPPORT
if (SOC_IS_DNX(unit))
{
/** Module Header */
min_len += 16;
}
#endif
/* Pad runt packets */
if ((pkt_len < min_len) && !(pkt->flags & BCM_TX_NO_PAD)) {
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) _pkt_pad_ptr, min_len - pkt_len,
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
}
/* If "CRC allocate" set (includes append), add static ptr to it */
if (((pkt->flags & BCM_TX_CRC_ALLOC) || clear_crc)
#ifdef BCM_ARAD_SUPPORT
&& !SOC_IS_ARAD(unit)
#endif /*BCM_ARAD_SUPPORT*/
#ifdef BCM_DNX_SUPPORT
&& !SOC_IS_DNX(unit)
#endif /*BCM_DNX_SUPPORT*/
) {
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) _null_crc_ptr, sizeof(uint32),
tx_pbmp, tx_upbmp, tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
}
/* Mark the end of the packet */
soc_dma_desc_end_packet(dv);
return BCM_E_NONE;
}
#if defined(BCM_PETRA_SUPPORT) || defined(BCM_DNX_SUPPORT)
/*
* Function:
* _sand_tx_pkt_desc_add
* Purpose:
* Add all descriptors to a DV for a given packet.
* Parameters:
* unit - Strataswitch device ID
* pkt - Pointer to packet
* dv - DCB vector to update
* pkt_idx - Index of packet.
* Index value is 0, except for arrays or link lists.
* For arrays or link lists, the value must be the
* the index number of the packet.
* Returns:
* BCM_E_XXX
* Notes:
* Uses tx info pkt_count member to get packet index; then advances
* the pkt_count member.
*
* See sdk/doc/pkt.txt for info about restrictions on MACs,
* and the VLAN not crossing block boundaries.
*
* Assert: unit is local
*/
STATIC int
_sand_tx_pkt_desc_add(int unit, bcm_pkt_t *pkt, dv_t *dv, int pkt_idx)
{
int pkt_len = 0; /* Length calculation for byte padding */
int tmp_len = 0;
int min_len = ENET_MIN_PKT_SIZE; /* Min length pkt before padded */
int i = 0;
uint32 dcb_flags = 0;
int crc_block_offset = 0;
uint32 *pkt_hg_hdr = NULL;
/* May not be ref'd depending on defines */
COMPILER_REFERENCE(pkt_idx);
/* Calculate the DCB flags for this packet. */
dcb_flags = _dcb_flags_get(unit, pkt, dv);
#if defined(BROADCOM_DEBUG)
if (pkt->cos < BCM_COS_COUNT)
{
bcm_tx_pkt_count[pkt->cos]++;
}
else
{
bcm_tx_pkt_count_bad_cos++;
}
#endif
if (pkt->pkt_data[0].len < sizeof(bcm_mac_t))
{
LOG_INFO(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_tx_pkt_desc_add: pkt->pkt_data[0].len < sizeof(bcm_mac_t) exit ")));
return BCM_E_PARAM;
}
/* Set up pointer to the packet in TX info structure. */
TX_INFO_PKT_ADD(dv, pkt);
/* Assumes the CRC is in the last block containing data */
for (i = pkt->blk_count - 1; i >= 0; i--)
{
if (pkt->pkt_data[i].len > 0)
{
break;
}
}
if (pkt->pkt_data[i].len >= ENET_MIN_PKT_SIZE)
{
crc_block_offset = i;
}
else
{
LOG_WARN(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"TX CRC clear: CRC not contiguous or runt pkt\n")));
}
#if defined(ADAPTER_SERVER_MODE)
if (SOC_IS_DNX(unit))
{
if (pkt->flags & BCM_PKT_F_HGHDR)
{
/*
* Module Header is not supported on adapter
* Clear BCM_PKT_F_HGHDR, indicate no Module Header
*/
pkt->flags &= ~BCM_PKT_F_HGHDR;
SOC_DMA_HG_SET(dcb_flags, 0);
}
}
#endif
if (SOC_IS_ARAD(unit))
{
pkt_hg_hdr = (uint32 *)((pkt)->_dpp_hdr);
}
if (SOC_IS_DNX(unit))
{
if (pkt->flags & BCM_PKT_F_HGHDR)
{
/*
* Update CPU channel value here
* HiGig flag indicates Module header is present, Module Header is 16 bytes at the start of the packet
* Update first byte of Module header to CPU Channel
*/
pkt->pkt_data[0].data[0] = pkt ->_dpp_hdr[0];
}
}
/* Add DCBs for the remainder of the blocks. */
for (i = 0; i <= crc_block_offset; i++) {
tmp_len = pkt->pkt_data[i].len;
/*
* BCM_TX_CRC_ALLOC: append 4 bytes CRC to packet data, default action, so BCM_TX_CRC_ALLOC we do nothing
* BCM_TX_CRC_REGEN: regenerate 4 bytes CRC at last 4 bytes of packet data, remove last 4 bytes at first, HW appends 4 bytes CRC.
*/
if ((i == crc_block_offset) && ((pkt->flags & BCM_TX_CRC_REGEN) && (!(pkt->flags & BCM_TX_CRC_ALLOC)))) {
tmp_len -= ENET_FCS_SIZE;
}
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) pkt->pkt_data[i].data,
tmp_len, pkt->tx_pbmp, pkt->tx_upbmp, pkt->tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
pkt_len += tmp_len;
}
if (SOC_IS_DNX(unit))
{
/* Module Header */
min_len += 16;
}
/* Pad runt packets */
if ((pkt_len < min_len) && !(pkt->flags & BCM_TX_NO_PAD)) {
SOC_IF_ERROR_RETURN(SOC_DCB_ADDTX(unit, dv,
(sal_vaddr_t) _pkt_pad_ptr, min_len - pkt_len,
pkt->tx_pbmp, pkt->tx_upbmp, pkt->tx_l3pbmp,
dcb_flags, pkt_hg_hdr));
}
/* Mark the end of the packet */
soc_dma_desc_end_packet(dv);
return BCM_E_NONE;
}
#endif
/****************************************************************
*
* Functions to handle callbacks:
*
* _bcm_tx_callback_thread: The non-interrupt thread that manages
* packet done completions.
* _bcm_tx_chain_done_cb: The interrupt handler callback for chain
* done. Adds dv-s to pending list.
* _bcm_tx_chain_done: Makes user level call back and
* frees the DV.
* _bcm_tx_packet_done_cb: Interrupt handler for packet done.
* Adds pkt to callback list if needed.
* _bcm_tx_packet_done: Makes user level call back.
*/
/*
* Function:
* _bcm_tx_callback_thread
* Purpose:
* Non-interrupt tx callback context
* Parameters:
* param - ignored
* Returns:
* BCM_E_XXX
* Notes:
* Currently assumes that the packet done interrupt will
* be handled before (or at same time) as the corresponding
* chain done interrupt. This only matters when there's
* a per-packet callback since that refers to the cookie
* in the dv.
*/
STATIC void
_bcm_tx_callback_thread(void *param)
{
dv_t *dv_list, *dv, *dv_next;
dv_t *dvdesc_list, *dvdesc, *dvdesc_next, *dvdesc_list_end;
dv_t *dvrld_list, *dvrld, *dvrld_next, *dvrld_list_end;
bcm_pkt_t *pkt_list, *pkt, *pkt_next, *pkt_list_end;
dcb_t * null_dcb = NULL;
COMPILER_REFERENCE(param);
#ifdef BCM_DNX_SUPPORT
DNX_ERR_RECOVERY_UTILS_EXCLUDED_THREADS_ADD_ALL_UNITS(DNX_ERR_RECOVERY_INTERNAL_THREAD_TX);
#endif
while (_bcm_tx_run) {
if (sal_sem_take(tx_cb_sem, sal_sem_FOREVER) < 0) {
LOG_ERROR(BSL_LS_BCM_TX,
(BSL_META("TX callback thread error\n")));
break;
}
if (_tx_init == FALSE) {
break;
}
TX_SPIN_LOCK(); /* Grab the lists from the interrupt handler */
dv_list = (dv_t *)dv_pend_first;
dv_pend_first = dv_pend_last = NULL;
dvdesc_list = (dv_t *)dvdesc_pend_first;
dvdesc_list_end = (dv_t *)dvdesc_pend_last;
dvdesc_pend_first = dvdesc_pend_last = NULL;
dvrld_list = (dv_t *)dvrld_pend_first;
dvrld_list_end = (dv_t *)dvrld_pend_last;
dvrld_pend_first = dvrld_pend_last = NULL;
pkt_list = (bcm_pkt_t *)pkt_pend_first;
pkt_list_end = (bcm_pkt_t *)pkt_pend_last;
pkt_pend_first = pkt_pend_last = NULL;
TX_SPIN_UNLOCK();
/*
* Handle the per pkt callbacks first (which use DVs),
* then the DVs. See notes above
*/
pkt = pkt_list;
while (pkt) {
pkt_next = pkt->_next;
_bcm_tx_packet_done(pkt);
if (pkt == pkt_list_end) {
break;
}
pkt = pkt_next;
}
dvdesc = dvdesc_list;
while (dvdesc) {
/*
* In continuous mode, we must process the
* controlled descriptor done interrupts for data desc
*/
dvdesc_next = TX_DV_NEXT(dvdesc);
DNXC_MTA(dnxc_multithread_analyzer_declare_api_in_play(dvdesc->dv_unit, FUNCTION_NAME(), MTA_FLAG_THREAD_MAIN_FUNC, TRUE));
_bcm_tx_desc_done(dvdesc->dv_unit, dvdesc, null_dcb);
DNXC_MTA(dnxc_multithread_analyzer_declare_api_in_play(dvdesc->dv_unit, FUNCTION_NAME(), MTA_FLAG_THREAD_MAIN_FUNC, FALSE));
if (dvdesc == dvdesc_list_end) {
break;
}
dvdesc = dvdesc_next;
}
LOG_DEBUG(BSL_LS_BCM_TX,
(BSL_META_U(0,
"rld list start=%p end=%p\n"),
(void *)dvrld_list, (void *)dvrld_list_end));
dvrld = dvrld_list;
while (dvrld) {
/*
* In continuous mode, we must process the
* controlled descriptor done interrupts for rld desc
*/
LOG_DEBUG(BSL_LS_BCM_TX,
(BSL_META_U(0,
"looping through rld list cur_dv=%p\n"),
(void *)dvrld));
dvrld_next = TX_DV_NEXT(dvrld);
DNXC_MTA(dnxc_multithread_analyzer_declare_api_in_play(dvrld->dv_unit, FUNCTION_NAME(), MTA_FLAG_THREAD_MAIN_FUNC, TRUE));
_bcm_tx_reload_done(dvrld->dv_unit, dvrld);
DNXC_MTA(dnxc_multithread_analyzer_declare_api_in_play(dvrld->dv_unit, FUNCTION_NAME(), MTA_FLAG_THREAD_MAIN_FUNC, FALSE));
sal_sem_give(tx_dv_done);
if (dvrld == dvrld_list_end) {
break;
}
dvrld = dvrld_next;
}
dv = dv_list;
while (dv) {
/* Chain done may deallocate dv */
dv_next = TX_DV_NEXT(dv);
DNXC_MTA(dnxc_multithread_analyzer_declare_api_in_play(dv->dv_unit, FUNCTION_NAME(), MTA_FLAG_THREAD_MAIN_FUNC, TRUE));
_bcm_tx_chain_done(dv->dv_unit, dv);
DNXC_MTA(dnxc_multithread_analyzer_declare_api_in_play(dv->dv_unit, FUNCTION_NAME(), MTA_FLAG_THREAD_MAIN_FUNC, FALSE));
sal_sem_give(tx_dv_done);
dv = dv_next;
}
}
_tx_tid = SAL_THREAD_ERROR;
(void)sal_sem_give(tx_exit_notify);
#ifdef BCM_DNX_SUPPORT
DNX_ERR_RECOVERY_UTILS_EXCLUDED_THREADS_REMOVE_ALL_UNITS(DNX_ERR_RECOVERY_INTERNAL_THREAD_TX);
#endif
sal_thread_exit(0);
}
/*
* Function:
* _bcm_tx_desc_done_cb
* Purpose:
* Interrupt handler callback to schedule desc done processing
* Parameters:
* unit - SOC unit #
* dv - pointer to dv that has completed.
* dcb - pointer to dcb (not used for TX)
* Returns:
* Nothing
* Notes:
* All the handler does is put the DVDCB on a queue and
* check if the handler thread needs to be awakened.
*
* This function is called in INTERRUPT CONTEXT,
* but is also called in non-interrupt context from
* _bcm_tx_chain_send, so TX_SPIN_LOCK must be used.
*/
STATIC void
_bcm_tx_desc_done_cb(int unit, dv_t *dv, dcb_t *dcb)
{
#if defined(BCM_CMICX_SUPPORT)
if (soc_feature(unit, soc_feature_cmicx)) {
soc_stat_t *stat = &SOC_CONTROL(unit)->stat;
tx_dv_info_t *dv_info;
int i;
dv_info = TX_INFO(dv);
for (i = 0; i < dv_info->pkt_count; ++i) {
#if defined(BCM_CMICX_TX_PREALLOC_SUPPORT)
if (dv_info->pkt[i]) {
stat->dma_tbyt -= sizeof(dv_info->pkt[i]->_higig);
}
#else
if (dv_info->pkt[i] && dv_info->pkt[i]->tx_header) {
stat->dma_tbyt -= sizeof(dv_info->pkt[i]->_higig);
soc_cm_sfree(unit, dv_info->pkt[i]->tx_header);
dv_info->pkt[i]->tx_header = NULL;
}
#endif
}
}
#endif
if (BCM_SUCCESS(_bcm_tx_cb_intr_enabled())) {
_bcm_tx_desc_done(unit, dv, dcb);
} else {
TX_SPIN_LOCK();
++_tx_desc_done_intr;
dv->dv_unit = unit;
TX_DV_NEXT_SET(dv, NULL);
if (dvdesc_pend_last) { /* Queue is non-empty */
TX_DV_NEXT_SET(dvdesc_pend_last, dv);
LOG_DEBUG(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_tx_desc_done_cb appending dv=%p"
" to dv=%p for processing\n"),
(void *)dv, (void *)dvdesc_pend_last));
dvdesc_pend_last = dv;
} else { /* Empty queue; init first and last */
dvdesc_pend_first = dv;
dvdesc_pend_last = dv;
LOG_DEBUG(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_tx_desc_done_cb adding dv=%p"
" for processing\n"),
(void *)dv));
}
TX_SPIN_UNLOCK();
sal_sem_give(tx_cb_sem);
}
}
/*
* Function:
* _bcm_tx_reload_done_cb
* Purpose:
* Interrupt handler callback to schedule reload done processing
* Parameters:
* unit - SOC unit #
* dv - pointer to dv that has completed.
* Returns:
* Nothing
* Notes:
* All the handler does is put the DVDCB on a queue and
* check if the handler thread needs to be awakened.
*
* This function is called in INTERRUPT CONTEXT,
* but is also called in non-interrupt context from
* _bcm_tx_chain_send, so TX_SPIN_LOCK must be used.
*/
STATIC void
_bcm_tx_reload_done_cb(int unit, dv_t *dv)
{
if (BCM_SUCCESS(_bcm_tx_cb_intr_enabled())) {
_bcm_tx_reload_done(unit, dv);
} else {
TX_SPIN_LOCK();
++_tx_rld_done_intr;
dv->dv_unit = unit;
TX_DV_NEXT_SET(dv, NULL);
if (dvrld_pend_last) { /* Queue is non-empty */
TX_DV_NEXT_SET(dvrld_pend_last, dv);
LOG_DEBUG(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_tx_reload_done_cb appending dv=%p"
" to dv=%p for processing\n"),
(void *)dv, (void *)dvrld_pend_last));
dvrld_pend_last = dv;
} else { /* Empty queue; init first and last */
dvrld_pend_first = dv;
dvrld_pend_last = dv;
LOG_DEBUG(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"_tx_reload_done_cb adding dv=%p"
" for processing\n"),
(void *)dv));
}
TX_SPIN_UNLOCK();
sal_sem_give(tx_cb_sem);
}
}
/*
* Function:
* _bcm_tx_chain_done_cb
* Purpose:
* Interrupt handler callback to schedule chain done processing
* Parameters:
* unit - SOC unit #
* dv - pointer to dv that has completed.
* Returns:
* Nothing
* Notes:
* All the handler does is put the DV on a queue and
* check if the handler thread needs to be awakened.
*
* This function is called in INTERRUPT CONTEXT,
* but is also called in non-interrupt context from
* _bcm_tx_chain_send, so TX_SPIN_LOCK must be used.
*/
STATIC void
_bcm_tx_chain_done_cb(int unit, dv_t *dv)
{
#if defined(BCM_CMICX_SUPPORT)
if (soc_feature(unit, soc_feature_cmicx)) {
soc_stat_t *stat = &SOC_CONTROL(unit)->stat;
tx_dv_info_t *dv_info;
int i;
dv_info = TX_INFO(dv);
for (i = 0; i < dv_info->pkt_count; ++i) {
#if defined(BCM_CMICX_TX_PREALLOC_SUPPORT)
if (dv_info->pkt[i]) {
stat->dma_tbyt -= sizeof(dv_info->pkt[i]->_higig);
}
#else
if (dv_info->pkt[i]->tx_header) {
stat->dma_tbyt -= sizeof(dv_info->pkt[i]->_higig);
soc_cm_sfree(unit, dv_info->pkt[i]->tx_header);
dv_info->pkt[i]->tx_header = NULL;
}
#endif
}
}
#endif
if (BCM_SUCCESS(_bcm_tx_cb_intr_enabled())) {
_bcm_tx_chain_done(unit, dv);
} else {
TX_SPIN_LOCK();
++_tx_chain_done_intr;
dv->dv_unit = unit;
TX_DV_NEXT_SET(dv, NULL);
if (dv_pend_last) { /* Queue is non-empty */
TX_DV_NEXT_SET(dv_pend_last, dv);
dv_pend_last = dv;
} else { /* Empty queue; init first and last */
dv_pend_first = dv;
dv_pend_last = dv;
}
TX_SPIN_UNLOCK();
sal_sem_give(tx_cb_sem);
}
}
/*
* Function:
* _bcm_tx_desc_done
* Purpose:
* Process the completion of a TX DMA controlled descriptor.
* Parameters:
* unit - SOC unit number.
* dv - pointer to DV containing the completed DMA descriptor.
* Returns:
* Nothing.
* Notes:
* This is new for continuous mode. The controlled desc intr
* is only enabled for the final data descriptor and the reload
* descriptor. Call all_done_callback for non reload descriptors.
* De-allocate the DV on reload done.
*/
STATIC void
_bcm_tx_desc_done(int unit, dv_t *dv, dcb_t *dcb)
{
bcm_pkt_cb_f callback;
volatile bcm_pkt_t *pkt;
void *cookie;
assert(dv != NULL);
assert(soc_dma_dv_valid(dv));
++_tx_desc_done;
/* Operation complete; call user's completion callback routine, if any */
callback = TX_INFO(dv)->chain_done_cb;
if (callback) {
pkt = TX_INFO(dv)->pkt[0];
cookie = TX_INFO(dv)->cookie;
callback(unit, (bcm_pkt_t *)pkt, cookie);
}
LOG_DEBUG(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"TX Desc Done for c=%d, dv=%p, dcb=%p\n"),
dv->dv_channel, (void *)dv, (void *)dcb));
}
/*
* Function:
* _bcm_tx_reload_done
* Purpose:
* Process the completion of a TX DMA reload descriptor.
* Parameters:
* unit - SOC unit number.
* dv - pointer to DV containing the completed DMA descriptor.
* dcb - pointer to the completed descriptor
* Returns:
* Nothing.
* Notes:
* This is new for continuous mode. The controlled desc intr
* is only enabled for the final data descriptor and the reload
* descriptor. De-allocate the DV on reload done.
*/
STATIC void
_bcm_tx_reload_done(int unit, dv_t *dv)
{
++_tx_rld_done;
if (dv != NULL) {
LOG_DEBUG(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"TX Reload Done for c=%d, dv=%p\n"),
dv->dv_channel,
(void *)dv));
_tx_dv_free(unit, dv);
}
}
/*
* Function:
* _bcm_tx_chain_done
* Purpose:
* Process the completion of a TX DMA chain.
* Parameters:
* unit - SOC unit number.
* dv - pointer to completed DMA chain.
* dcb - ignored
* Returns:
* Nothing.
* Notes:
*/
STATIC void
_bcm_tx_chain_done(int unit, dv_t *dv)
{
bcm_pkt_cb_f callback;
volatile bcm_pkt_t *pkt;
void *cookie;
assert(dv != NULL);
++_tx_chain_done;
/* Operation complete; call user's completion callback routine, if any */
callback = TX_INFO(dv)->chain_done_cb;
if (callback) {
pkt = TX_INFO(dv)->pkt[0];
cookie = TX_INFO(dv)->cookie;
callback(unit, (bcm_pkt_t *)pkt, cookie);
}
LOG_DEBUG(BSL_LS_BCM_TX,
(BSL_META_U(unit,
"TX Chain Done for c=%d, dv=%p\n"),
dv->dv_channel, (void *)dv));
_tx_dv_free(unit, dv);
}
/*
* Function:
* _bcm_tx_packet_done_cb
* Purpose:
* Packet done interrupt callback
* Parameters:
* unit - SOC unit number.
* dv - pointer to completed DMA chain.
* Returns:
* Nothing.
* Notes:
* Just checks to see if the packet's callback is set. If
* it is, the packet is added to the packet pending list
* and the tx thread is woken up.
*
* This will only be set up as a call back if some packet in the
* chain requires a callback.
*/
STATIC void
_bcm_tx_packet_done_cb(int unit, dv_t *dv, dcb_t *dcb)
{
bcm_pkt_t *pkt;
#if defined(BCM_CMICX_SUPPORT)
soc_stat_t *stat = &SOC_CONTROL(unit)->stat;
#endif
COMPILER_REFERENCE(dcb);
assert(dv);
assert(TX_INFO(dv));
assert(TX_INFO(dv)->pkt_count > TX_INFO(dv)->pkt_done_cnt);
pkt = (bcm_pkt_t *)TX_INFO_CUR_PKT(dv);
if (pkt) {
pkt->_dv = dv;
pkt->unit = unit;
pkt->_next = NULL;
}
#if defined(BCM_CMICX_SUPPORT)
if (soc_feature(unit, soc_feature_cmicx)) {
#if defined(BCM_CMICX_TX_PREALLOC_SUPPORT)
if (pkt) {
stat->dma_tbyt -= sizeof(pkt->_higig);
}
#else
if (pkt && pkt->tx_header) {
stat->dma_tbyt -= sizeof(pkt->_higig);
soc_cm_sfree(unit, pkt->tx_header);
pkt->tx_header = NULL;
}
#endif
}
#endif
/*
* If callback present, add to list
*/
if (BCM_SUCCESS(_bcm_tx_cb_intr_enabled())) {
TX_INFO_PKT_MARK_DONE(dv);
_bcm_tx_packet_done(pkt);
} else {
if (pkt && pkt->call_back) {
TX_SPIN_LOCK();
/* Assumes interrupt context */
if (pkt_pend_last) { /* Queue is non-empty */
pkt_pend_last->_next = pkt;
pkt_pend_last = pkt;
} else { /* Empty queue; init first and last */
pkt_pend_first = pkt;
pkt_pend_last = pkt;
}
TX_SPIN_UNLOCK();
sal_sem_give(tx_cb_sem);
}
TX_INFO_PKT_MARK_DONE(dv);
}
}
STATIC void
_bcm_tx_packet_done(bcm_pkt_t *pkt)
{
if (pkt && pkt->call_back) {
#if defined (INCLUDE_RCPU) && defined(BCM_XGS3_SWITCH_SUPPORT)
if (SOC_IS_RCPU_UNIT(pkt->unit)) {
(pkt->call_back)(pkt->unit, pkt, pkt->_dv);
} else {
(pkt->call_back)(pkt->unit, pkt,
TX_INFO((dv_t *)(pkt->_dv))->cookie);
}
#else
(pkt->call_back)(pkt->unit, pkt,
TX_INFO((dv_t *)(pkt->_dv))->cookie);
#endif /* INCLUDE_RCPU && BCM_XGS3_SWITCH_SUPPORT */
}
}
#if defined (INCLUDE_RCPU) && defined(BCM_XGS3_SWITCH_SUPPORT)
/*
* Function:
* _bcm_rcpu_tx_packet_done_cb
* Purpose:
* Packet done callback from rcpu
* Parameters:
* unit - SOC unit number.
* pkt - packet pointer
* Returns:
* Nothing.
* Notes:
* The packet is added to the packet pending list
* and the tx thread is woken up.
*
* This will only be set up as a call back if some packet in the
* chain requires a callback.
*
* This function should be only called in Task context.
*/
void
_bcm_rcpu_tx_packet_done_cb(int unit, bcm_pkt_t *pkt)
{
/*
* If callback present, add to list
*/
if (pkt->call_back) {
TX_SPIN_LOCK();
/* Assumes interrupt context */
if (pkt_pend_last) { /* Queue is non-empty */
pkt_pend_last->_next = pkt;
pkt_pend_last = pkt;
} else { /* Empty queue; init first and last */
pkt_pend_first = pkt;
pkt_pend_last = pkt;
}
TX_SPIN_UNLOCK();
sal_sem_give(tx_cb_sem);
}
}
#endif /* INCLUDE_RCPU && BCM_XGS3_SWITCH_SUPPORT */
/****************************************************************
*
* TX DV info dump routine.
*/
#if defined(BROADCOM_DEBUG)
/*
* Function:
* bcm_tx_show
* Purpose:
* Display info about tx state
* Parameters:
* unit - ignored
* Returns:
* None
* Notes:
*/
int
bcm_common_tx_show(int unit)
{
COMPILER_REFERENCE(unit);
LOG_CLI((BSL_META_U(unit,
"TX state: chain_send %d. chain_done %d. "
"chain_done_intr %d\n"),
_tx_chain_send,
_tx_chain_done,
_tx_chain_done_intr));
LOG_CLI((BSL_META_U(unit,
"TX state: chain_send %d. desc_done %d. "
"desc_done_intr %d\n"),
_tx_chain_send,
_tx_desc_done,
_tx_desc_done_intr));
LOG_CLI((BSL_META_U(unit,
"TX state: chain_send %d. rld_done %d. "
"rld_done_intr %d\n"),
_tx_chain_send,
_tx_rld_done,
_tx_rld_done_intr));
LOG_CLI((BSL_META_U(unit,
" pkt_pend_first %p. pkt_pend_last %p.\n"),
(void *)pkt_pend_first,
(void *)pkt_pend_last));
LOG_CLI((BSL_META_U(unit,
" dv_pend_first %p. dv_pend_last %p.\n"),
(void *)dv_pend_first,
(void *)dv_pend_last));
LOG_CLI((BSL_META_U(unit,
"Tx queue: size %d.\n"),
tx_queue_size));
return BCM_E_NONE;
}
/*
* Function:
* bcm_tx_dv_dump
* Purpose:
* Display info about a DV that is setup for TX.
* Parameters:
* unit - transmission unit
* dv - The DV to show info about
* Returns:
* None
* Notes:
* Mainly, dumps the tx_dv_info_t structure; then calls soc_dma_dump_dv
*/
int
bcm_common_tx_dv_dump(int unit, void *dv_p)
{
tx_dv_info_t *dv_info;
dv_t *dv = (dv_t *)dv_p;
dv_info = TX_INFO(dv);
if (dv_info != NULL) {
LOG_CLI((BSL_META_U(unit,
"TX DV info:\n DV %p. pkt count %d. done count %d.\n"),
(void *)dv, dv_info->pkt_count, dv_info->pkt_done_cnt));
#if !defined(__PEDANTIC__)
LOG_CLI((BSL_META_U(unit,
" cookie %p. cb %p\n"), (void *)dv_info->cookie,
(void *)dv_info->chain_done_cb));
#else /* !defined(__PEDANTIC__) */
LOG_CLI((BSL_META_U(unit,
" cookie %p. cb pointer unprintable\n"),
(void *)dv_info->cookie));
#endif /* !defined(__PEDANTIC__) */
} else {
LOG_CLI((BSL_META_U(unit,
"TX DV info is NULL\n")));
}
if (bsl_check(bslLayerSoc, bslSourceTx, bslSeverityVerbose, unit)) {
soc_dma_dump_dv(dv->dv_unit, "tx dv: ", dv);
}
return BCM_E_NONE;
}
#endif /* BROADCOM_DEBUG */
#endif /* defined(BCM_ESW_SUPPORT) */
#ifdef BCM_RPC_SUPPORT
/****************************************************************
*
* TX CPU tunnel support
*/
/*
* Function:
* bcm_tx_cpu_tunnel_set/get
* Purpose:
* Set/get the function used to tunnel packets to remote CPUs for TX
* Returns:
* BCM_E_NONE
* Notes:
* If set to NULL, tunneling won't happen and an error will be
* returned by bcm_tx if a remoted device is specified.
*/
static bcm_tx_cpu_tunnel_f tx_cpu_tunnel;
int
bcm_tx_cpu_tunnel_set(bcm_tx_cpu_tunnel_f f)
{
tx_cpu_tunnel = f;
return BCM_E_NONE;
}
int
bcm_tx_cpu_tunnel_get(bcm_tx_cpu_tunnel_f *f)
{
if (f != NULL) {
*f = tx_cpu_tunnel;
}
return BCM_E_NONE;
}
/*
* Function:
* bcm_tx_cpu_tunnel
* Purpose:
* Call the programmed tx tunnel function, if programmed
* Returns:
* BCM_E_INIT if tunnel function is not initialized
* Otherwise, returns the value from the tunnel call
*/
int
bcm_tx_cpu_tunnel(bcm_pkt_t *pkt,
int dest_unit,
int remote_port,
uint32 flags,
bcm_cpu_tunnel_mode_t mode)
{
if (tx_cpu_tunnel != NULL) {
return tx_cpu_tunnel(pkt, dest_unit, remote_port, flags, mode);
}
return BCM_E_INIT;
}
#endif /* BCM_RPC_SUPPORT */
| 34.141312 | 137 | 0.578854 |
88789a8506c76e0d526aed29314469c74b931f6d | 23,235 | h | C | bin/clang/astVisitor.h | deanchester/sst-macro | b590e7a5c604e38c840569de0e2b80bfc85539a0 | [
"BSD-3-Clause"
] | null | null | null | bin/clang/astVisitor.h | deanchester/sst-macro | b590e7a5c604e38c840569de0e2b80bfc85539a0 | [
"BSD-3-Clause"
] | null | null | null | bin/clang/astVisitor.h | deanchester/sst-macro | b590e7a5c604e38c840569de0e2b80bfc85539a0 | [
"BSD-3-Clause"
] | 1 | 2018-02-21T11:39:08.000Z | 2018-02-21T11:39:08.000Z | /**
Copyright 2009-2017 National Technology and Engineering Solutions of Sandia,
LLC (NTESS). Under the terms of Contract DE-NA-0003525, the U.S. Government
retains certain rights in this software.
Sandia National Laboratories is a multimission laboratory managed and operated
by National Technology and Engineering Solutions of Sandia, LLC., a wholly
owned subsidiary of Honeywell International, Inc., for the U.S. Department of
Energy's National Nuclear Security Administration under contract DE-NA0003525.
Copyright (c) 2009-2017, NTESS
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* 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.
* Neither the name of Sandia Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Questions? Contact sst-macro-help@sandia.gov
*/
#ifndef bin_clang_replAstVisitor_h
#define bin_clang_replAstVisitor_h
#include "clangHeaders.h"
#include "pragmas.h"
#include "globalVarNamespace.h"
#define visitFxn(cls) \
bool Visit##cls(clang::cls* c){ return TestStmtMacro(c); }
class FirstPassASTVistor : public clang::RecursiveASTVisitor<FirstPassASTVistor>
{
public:
FirstPassASTVistor(SSTPragmaList& prgs, clang::Rewriter& rw,
PragmaConfig& cfg);
bool VisitDecl(clang::Decl* d);
bool VisitStmt(clang::Stmt* s);
private:
SSTPragmaList& pragmas_;
PragmaConfig& pragmaConfig_;
clang::Rewriter& rewriter_;
bool noSkeletonize_;
};
/**
* @brief The SkeletonASTVisitor class
*
* Go through every node in the abstract syntax tree and perform
* certain skeletonization operations on them using the rewriter object.
* For certain nodes, we Visit. This means performing a single visit
* operation in isolation. We do not need parent or children nodes in a Visit.
* For certain nodes, we must Traverse. The means performing a pre-visit operation
* before visiting child nodes. A post-visit operation is then performed
* after visiting all child nodes. A traversal also gives the option
* to cancel all visits to child nodes.
*/
class SkeletonASTVisitor : public clang::RecursiveASTVisitor<SkeletonASTVisitor> {
private:
struct AnonRecord {
clang::RecordDecl* decl;
bool typeNameAdded;
std::string structType; //union or struct
std::string retType;
bool isFxnStatic;
//struct X_anonymous_type - gives unique typename to anonymous truct
std::string typeName;
AnonRecord() : decl(nullptr), isFxnStatic(false), typeNameAdded(false) {}
};
struct ArrayInfo {
bool needsTypedef() const {
return !typedefString.empty();
}
std::string typedefString;
std::string typedefName;
std::string retType;
bool isFxnStatic;
bool needsDeref;
ArrayInfo() : isFxnStatic(false), needsDeref(true) {}
};
public:
SkeletonASTVisitor(clang::Rewriter &R,
GlobalVarNamespace& ns,
std::set<clang::Stmt*>& deld,
PragmaConfig& cfg) :
rewriter_(R), visitingGlobal_(false), deletedStmts_(deld),
globalNs_(ns), currentNs_(&ns),
insideCxxMethod_(0),
foundCMain_(false), keepGlobals_(false), noSkeletonize_(true),
refactorMain_(true),
pragmaConfig_(cfg),
numRelocations_(0),
reconstructCount_(0)
{
initHeaders();
initReservedNames();
initMPICalls();
initConfig();
pragmaConfig_.astVisitor = this;
}
bool isGlobal(const clang::DeclRefExpr* expr) const {
return globals_.find(mainDecl(expr)) != globals_.end();
}
PragmaConfig& getPragmaConfig() {
return pragmaConfig_;
}
std::string needGlobalReplacement(clang::NamedDecl* decl) {
const clang::Decl* md = mainDecl(decl);
globalsTouched_.back().insert(md);
auto iter = globals_.find(md);
if (iter == globals_.end()){
errorAbort(decl->getLocStart(), *ci_,
"getting global replacement for non-global variable");
}
return iter->second;
}
bool noSkeletonize() const {
return noSkeletonize_;
}
void setCompilerInstance(clang::CompilerInstance& c){
ci_ = &c;
}
/**
* @brief VisitStmt Activate any pragmas associated with this statement
* This function is not called if a more specific matching function is found
* @param S
* @return
*/
bool VisitStmt(clang::Stmt* S);
/**
* @brief VisitDecl Activate any pragmas associated with this declaration
* This function is not called if a more specific matching function is found
* @param D
* @return
*/
bool VisitDecl(clang::Decl* D);
bool VisitTypedefDecl(clang::TypedefDecl* D);
/**
* @brief VisitDeclRefExpr Examine the usage of a variable to determine
* if it is either a global variable or a pragma null_variable and therefore
* requires a rewrite
* @param expr
* @return
*/
bool VisitDeclRefExpr(clang::DeclRefExpr* expr);
bool TraverseReturnStmt(clang::ReturnStmt* stmt, DataRecursionQueue* queue = nullptr);
bool TraverseMemberExpr(clang::MemberExpr* expr, DataRecursionQueue* queue = nullptr);
/**
* @brief VisitCXXNewExpr Capture all usages of operator new. Rewrite all
* operator new calls into SST-specific memory management functions.
* @param expr
* @return
*/
bool VisitCXXNewExpr(clang::CXXNewExpr* expr);
bool VisitCXXOperatorCallExpr(clang::CXXOperatorCallExpr* expr);
bool VisitArraySubscriptExpr(clang::ArraySubscriptExpr* expr);
/**
* @brief VisitCXXNewExpr Capture all usages of operator delete. Rewrite all
* operator delete calls into SST-specific memory management functions.
* @param expr
* @return
*/
bool TraverseCXXDeleteExpr(clang::CXXDeleteExpr* expr, DataRecursionQueue* = nullptr);
/**
* @brief VisitCXXMemberCallExpr Certain function calls get redirected to
* calls on member functions of SST classes. See if this is one such instance.
* Certain rewriting operations might be required. This most often occurs
* for MPI calls to convert payloads into null buffers.
* @param expr
* @return
*/
bool TraverseCXXMemberCallExpr(clang::CXXMemberCallExpr* expr, DataRecursionQueue* queue = nullptr);
/**
* @brief VisitVarDecl We only need to visit variables once down the AST.
* No pre or post operations.
* @param D
* @return Whether to skip visiting this variable's initialization
*/
bool visitVarDecl(clang::VarDecl* D);
bool TraverseVarDecl(clang::VarDecl* D);
/**
* @brief Activate any pragmas associated with this.
* In contrast to VisitStmt, call expressions can only have special replace pragmas.
* We have to push this onto the contexts list in case we have any null variables
* @param expr
* @return
*/
bool TraverseCallExpr(clang::CallExpr* expr, DataRecursionQueue* queue = nullptr);
/**
* @brief TraverseNamespaceDecl We have to traverse namespaces.
* We need pre and post operations. We have to explicitly recurse subnodes.
* @param D
* @return
*/
bool TraverseNamespaceDecl(clang::NamespaceDecl* D);
/**
* @brief TraverseCXXRecordDecl We have to traverse record declarations.
* In the pre-visit, we have to push the Decl onto a class contexts list
* In the post-visit, we pop the Decl off the list
* @param D
* @return
*/
bool TraverseCXXRecordDecl(clang::CXXRecordDecl* D);
/**
* @brief TraverseFunctionDecl We have to traverse function declarations
* In the pre-visit, we have to push the Decl onto a function contexts list
* In the post-visit, we pop the Decl off the list
* @param D
* @return
*/
bool TraverseFunctionDecl(clang::FunctionDecl* D);
/**
* @brief TraverseForStmt We have to traverse for loops.
* In the pre-visit, we have to push the ForStmt onto a context list
* In the post-visit, we have to pop the ForStmt off the list
* @param S
* @return
*/
bool TraverseForStmt(clang::ForStmt* S, DataRecursionQueue* queue = nullptr);
bool TraverseUnaryOperator(clang::UnaryOperator* op, DataRecursionQueue* queue = nullptr);
bool TraverseBinaryOperator(clang::BinaryOperator* op, DataRecursionQueue* queue = nullptr);
bool TraverseCompoundAssignOperator(clang::CompoundAssignOperator* op, DataRecursionQueue* queue = nullptr);
bool TraverseIfStmt(clang::IfStmt* S, DataRecursionQueue* queue = nullptr);
bool TraverseCompoundStmt(clang::CompoundStmt* S, DataRecursionQueue* queue = nullptr);
bool TraverseDeclStmt(clang::DeclStmt* op, DataRecursionQueue* queue = nullptr);
bool TraverseFieldDecl(clang::FieldDecl* fd, DataRecursionQueue* queue = nullptr);
bool TraverseInitListExpr(clang::InitListExpr* expr, DataRecursionQueue* queue = nullptr);
#define OPERATOR(NAME) \
bool TraverseBin##NAME(clang::BinaryOperator* op, DataRecursionQueue* queue = nullptr){ \
return TraverseBinaryOperator(op,queue); \
}
BINOP_LIST()
#undef OPERATOR
#define OPERATOR(NAME) \
bool TraverseUnary##NAME(clang::UnaryOperator* op, DataRecursionQueue* queue = nullptr){ \
return TraverseUnaryOperator(op,queue); \
}
UNARYOP_LIST()
#undef OPERATOR
#define OPERATOR(NAME) \
bool TraverseBin##NAME##Assign(clang::CompoundAssignOperator* op, DataRecursionQueue* queue = nullptr){ \
return TraverseCompoundAssignOperator(op,queue); \
}
CAO_LIST()
#undef OPERATOR
/**
* @brief TraverseFunctionTemplateDecl We have to traverse template functions
* No special pre or post visit is performed. However, there are certain SST/macro
* template functions that should be skipped. If this is a SST/macro function template,
* do not visit any of the child nodes.
* @param D
* @return
*/
bool TraverseFunctionTemplateDecl(clang::FunctionTemplateDecl* D);
/**
* @brief TraverseCXXMethodDecl We have to traverse function declarations
* In the pre-visit, we have to push the Decl onto a function contexts list
* In the post-visit, we pop the Decl off the list
* @param D
* @return
*/
bool TraverseCXXMethodDecl(clang::CXXMethodDecl *D);
/**
* @brief TraverseCXXConstructorDecl We have to traverse constructors
* If the constructor is actually a template instantation of a specific type,
* we should skip it and not visit any of the child nodes
* @param D
* @return
*/
bool TraverseCXXConstructorDecl(clang::CXXConstructorDecl* D);
/**
* @brief dataTraverseStmtPost Call after the traversal of all statements.
* Certain pragmas might have deactivate operations to be performed after traversing
* the statement. If there are any activate pragmas, deactivate them now
* @param S
* @return
*/
bool dataTraverseStmtPre(clang::Stmt* S);
/**
* @brief dataTraverseStmtPost Call after the traversal of all statements.
* Certain pragmas might have deactivate operations to be performed after traversing
* the statement. If there are any activate pragmas, deactivate them now
* @param S
* @return
*/
bool dataTraverseStmtPost(clang::Stmt* S);
SSTPragmaList& getPragmas(){
return pragmas_;
}
void setVisitingGlobal(bool flag){
visitingGlobal_ = flag;
}
void setTopLevelScope(clang::Decl* d){
currentTopLevelScope_ = d;
}
clang::Decl* getTopLevelScope() const {
return currentTopLevelScope_;
}
bool hasCStyleMain() const {
return foundCMain_;
}
const std::string& getAppName() const {
return mainName_;
}
private:
clang::NamespaceDecl* getOuterNamespace(clang::Decl* D);
bool shouldVisitDecl(clang::VarDecl* D);
void initHeaders();
void initReservedNames();
void initMPICalls();
void initConfig();
void replaceMain(clang::FunctionDecl* mainFxn);
private:
//whether we are allowed to use global variables in statements
//or if they are disallowed because they would break deglobalizer
clang::Decl* currentTopLevelScope_;
clang::Rewriter& rewriter_;
clang::CompilerInstance* ci_;
std::map<clang::RecordDecl*,clang::TypedefDecl*> typedef_structs_;
SSTPragmaList pragmas_;
bool visitingGlobal_;
std::set<clang::FunctionDecl*> templateDefinitions_;
std::set<clang::Stmt*>& deletedStmts_;
GlobalVarNamespace& globalNs_;
GlobalVarNamespace* currentNs_;
/** These should always index by the canonical decl */
std::map<const clang::Decl*,std::string> globals_;
std::map<const clang::Decl*,std::string> scopedNames_;
static inline const clang::Decl* mainDecl(const clang::Decl* d){
return d->getCanonicalDecl();
}
static inline const clang::Decl* mainDecl(const clang::DeclRefExpr* dr){
return dr->getDecl()->getCanonicalDecl();
}
std::string activeGlobalScopedName_;
bool activeGlobal() const {
return !activeGlobalScopedName_.empty();
}
void clearActiveGlobal() {
activeGlobalScopedName_.clear();
}
void setActiveGlobalScopedName(const std::string& str) {
activeGlobalScopedName_ = str;
}
const std::string& activeGlobalScopedName() const {
return activeGlobalScopedName_;
}
/**
* @brief addRelocation
* @param op The unary operator creating the pointer
* @param dr The global variable being pointed to
* @param member Optionally a specific field of the global variable being pointed to
*/
void addRelocation(clang::UnaryOperator* op, clang::DeclRefExpr* dr,
clang::ValueDecl* member = nullptr);
std::set<std::string> globalsDeclared_;
bool useAllHeaders_;
int insideCxxMethod_;
std::map<clang::FunctionDecl*, std::map<std::string, int>> static_fxn_var_counts_;
std::list<clang::FunctionDecl*> fxn_contexts_;
std::list<clang::CXXRecordDecl*> class_contexts_;
std::list<clang::ForStmt*> loop_contexts_;
std::list<clang::Stmt*> stmt_contexts_;
std::list<clang::VarDecl*> activeDecls_;
std::list<clang::Expr*> activeInits_;
int numRelocations_;
typedef enum { LHS, RHS } BinOpSide;
std::list<BinOpSide> sides_;
bool foundCMain_;
bool refactorMain_;
std::string mainName_;
bool keepGlobals_;
bool noSkeletonize_;
std::set<std::string> validHeaders_;
std::set<std::string> reservedNames_;
PragmaConfig& pragmaConfig_;
std::map<clang::Stmt*,SSTPragma*> activePragmas_;
std::set<clang::FunctionDecl*> keepWithNullArgs_;
std::set<clang::FunctionDecl*> deleteWithNullArgs_;
std::set<clang::DeclRefExpr*> alreadyReplaced_;
struct GlobalStandin {
bool fxnStatic;
std::string replText;
GlobalStandin() : fxnStatic(false){}
};
std::map<const clang::Decl*,GlobalStandin> globalStandins_;
std::list<int> initIndices_;
std::list<clang::FieldDecl*> activeFieldDecls_;
std::list<std::set<const clang::Decl*>> globalsTouched_;
typedef void (SkeletonASTVisitor::*MPI_Call)(clang::CallExpr* expr);
std::map<std::string, MPI_Call> mpiCalls_;
private:
bool isNullVariable(clang::Decl* d) const {
return pragmaConfig_.nullVariables.find(d) != pragmaConfig_.nullVariables.end();
}
SSTNullVariablePragma* getNullVariable(clang::Decl* d) const {
auto iter = pragmaConfig_.nullVariables.find(d);
if (iter != pragmaConfig_.nullVariables.end()){
return iter->second;
}
return nullptr;
}
void replaceGlobalUse(clang::DeclRefExpr* expr, clang::SourceRange rng);
clang::Expr* getUnderlyingExpr(clang::Expr *e);
void deleteNullVariableStmt(clang::Stmt* use_stmt, clang::Decl* d);
bool activatePragmasForStmt(clang::Stmt* S);
bool activatePragmasForDecl(clang::Decl* D);
void visitCollective(clang::CallExpr* expr);
void visitReduce(clang::CallExpr* expr);
void visitPt2Pt(clang::CallExpr* expr);
bool checkDeclStaticClassVar(clang::VarDecl* D);
bool checkInstanceStaticClassVar(clang::VarDecl* D);
bool checkStaticFxnVar(clang::VarDecl* D);
bool checkGlobalVar(clang::VarDecl* D);
bool checkStaticFileVar(clang::VarDecl* D);
bool checkFileVar(const std::string& filePrefix, clang::VarDecl* D);
/**
* @brief getEndLoc
* Find and return the position after the starting point where a statement ends
* i.e. find the next semi-colon after the starting point
* @param startLoc
* @return
*/
clang::SourceLocation getEndLoc(clang::SourceLocation startLoc);
bool insideClass() const {
return !class_contexts_.empty();
}
bool insideFxn() const {
return !fxn_contexts_.empty();
}
typedef enum {
Global, //regular global variable (C-style)
FileStatic,
CxxStatic, //c++ static class variable
FxnStatic
} GlobalVariable_t;
/**
* @brief replaceGlobalVar
* @param varNameScopePrefix A unique string needed for file-local or ns-local variable names
* @param clsScope A string identifying all nested class scopes, e.g. (A::B::)
* @param externVarsInsertLoc The location in the file to declare extern vars/fxns from SST/macro.
* May be invalid to indicate no insertion should be done.
* @param varSizeOfInsertLoc The location in the file to insert int size_X variable
* @param offsetInsertLoc The location to insert the 'extern int __offset_X' declaration
* May be invalid to indicate insertion just at end of var declaration
* @param insertOffsetAfter Whether to insert the offset declaration before/after the given location
* @param D The variable declaration being deglobalized
* @param staticFxnInfo For static function variables, we will want any info on anonymous records
* returned to us via this variable
* @return Whether to skip visiting this variable's initialization
*/
bool setupGlobalVar(const std::string& varNameScopeprefix,
const std::string& clsScope,
clang::SourceLocation externVarsInsertLoc,
clang::SourceLocation varSizeOfInsertLoc,
clang::SourceLocation offsetInsertLoc,
bool insertOffsetAfter,
GlobalVariable_t global_var_ty,
clang::VarDecl* D,
clang::SourceLocation declEnd = clang::SourceLocation());
/**
* @brief checkAnonStruct See if the type of the variable is an
* an anonymous union or struct. Fill in info in rec if so.
* @param D The variable being visited
* @param rec In-out paramter, info struct to fill in
* @return If D has anonymous struct type, return the passed-in rec struct
* If D is not an anonymous struct, return nullptrs
*/
AnonRecord* checkAnonStruct(clang::VarDecl* D, AnonRecord* rec);
clang::RecordDecl* checkCombinedStructVarDecl(clang::VarDecl* D);
/**
* @brief checkArray See if the type of the variable is an array
* and fill in the array info if so.
* @param D The variable being visited
* @param info In-out parameter, array info to fill in
* @return If D has array type, return the passed-in info struct.
* If D does not have array type, return nullptr
*/
ArrayInfo* checkArray(clang::VarDecl* D, ArrayInfo* info);
/**
* @brief deleteStmt Delete a statement completely in the source-to-source
* @param s
*/
void deleteStmt(clang::Stmt* s);
/**
* @brief declareSSTExternVars
* Declare all the external SST global variables we need to access
* @param insertLoc The source location where the text should go
*/
void declareSSTExternVars(clang::SourceLocation insertLoc);
bool keepWithNullArgs(clang::FunctionDecl* decl) const {
return keepWithNullArgs_.find(decl) != keepWithNullArgs_.end();
}
bool deleteWithNullArgs(clang::FunctionDecl* decl) const {
return deleteWithNullArgs_.find(decl) != keepWithNullArgs_.end();
}
struct cArrayConfig {
std::string fundamentalTypeString;
clang::QualType fundamentalType;
std::stringstream arrayIndices;
};
void traverseFunctionBody(clang::Stmt* s);
void getArrayType(const clang::Type* ty, cArrayConfig& cfg);
void setFundamentalTypes(clang::QualType qt, cArrayConfig& cfg);
struct ReconstructedType {
int typeIndex;
std::list<clang::QualType> fundamentalFieldTypes;
std::list<const clang::RecordDecl*> classFieldTypes;
std::list<const clang::RecordDecl*> newClassFieldTypes;
std::list<std::pair<std::string,std::string>> arrayTypes;
std::set<const clang::RecordDecl*> structDependencies;
};
int reconstructCount_;
void reconstructType(clang::SourceLocation typeDeclCutoff,
clang::QualType qt, ReconstructedType& rt,
std::map<const clang::RecordDecl*, ReconstructedType>& newTypes);
void reconstructType(clang::SourceLocation typeDeclCutoff,
const clang::RecordDecl* rd, ReconstructedType& rt,
std::map<const clang::RecordDecl*, ReconstructedType>& newTypes);
void addRecordField(clang::SourceLocation typeDeclCutoff,
const clang::RecordDecl* rd, ReconstructedType& rt,
std::map<const clang::RecordDecl*, ReconstructedType>& newTypes);
void addReconstructionDependency(clang::SourceLocation typeDeclCutoff,
const clang::Type* ty, ReconstructedType& rt);
void addTypeReconstructionText(const clang::RecordDecl* rd, ReconstructedType& rt,
std::map<const clang::RecordDecl*, ReconstructedType>& newTypes,
std::set<const clang::RecordDecl*>& alreadyDone,
std::ostream& os);
std::string getTypeNameForSizing(clang::SourceLocation typeDeclCutoff, clang::QualType qt,
std::map<const clang::RecordDecl*, ReconstructedType>& newTypes);
std::string getRecordTypeName(const clang::RecordDecl* rd);
void arrayFxnPointerTypedef(clang::VarDecl* D, SkeletonASTVisitor::ArrayInfo* info,
std::stringstream& sstr);
};
#endif
| 34.730942 | 110 | 0.707682 |
0022e7799ade241452be78b261e08320b9c12f64 | 3,279 | c | C | OldTownRoad/source.c | TolimanStaR/University-Tasks | aea727b0b4eae5db781f9708cb011eddcc89aa96 | [
"Unlicense"
] | 2 | 2020-01-27T23:21:38.000Z | 2020-02-01T15:04:31.000Z | OldTownRoad/source.c | TolimanStaR/University-Tasks | aea727b0b4eae5db781f9708cb011eddcc89aa96 | [
"Unlicense"
] | null | null | null | OldTownRoad/source.c | TolimanStaR/University-Tasks | aea727b0b4eae5db781f9708cb011eddcc89aa96 | [
"Unlicense"
] | null | null | null | #include <stdio.h>
#include <stdlib.h>
#include "header.h"
#define repeat(x) for(int i = 0; i < (x); ++i)
#define True 1
#define False 0
#define and &&
#define or ||
#define is ==
#define not !
Edge *new(int size) {
Edge *array;
array = (Edge *) calloc(size, sizeof(Edge));
return array;
}
int *newBoolean(int size) {
int *array;
array = (int *) calloc(size, sizeof(int));
return array;
}
int *newInt(int size) {
int *array;
array = (int*) calloc(size, sizeof(int));
return array;
}
void print(Edge *array, int size) {
repeat(size) printf("Edge between vertexes %d and %d (Cost is %d)\n",
array[i].firstVertex + 1, array[i].secondVertex + 1, array[i].cost);
puts("\n");
}
int compare(Edge firstStruct, Edge SecondStruct) {
return firstStruct.cost > SecondStruct.cost ? True : False;
}
Edge *merge(Edge *leftArray, Edge *rightArray, int leftSize, int rightSize) {
Edge *arrayToReturn = new(leftSize + rightSize);
int leftFlag, rightFlag, retIndex;
leftFlag = rightFlag = retIndex = 0;
while (leftFlag < leftSize and rightFlag < rightSize) {
if (compare(leftArray[leftFlag], rightArray[rightFlag])) {
arrayToReturn[retIndex++] = rightArray[rightFlag++];
} else {
arrayToReturn[retIndex++] = leftArray[leftFlag++];
}
}
int repeatTimes = __max(rightSize - rightFlag, leftSize - leftFlag);
if (leftSize is leftFlag) {
repeat(repeatTimes) {
arrayToReturn[retIndex++] = rightArray[rightFlag++];
}
} else {
repeat(repeatTimes) {
arrayToReturn[retIndex++] = leftArray[leftFlag++];
}
}
return arrayToReturn;
}
Edge *mergeSort(Edge *array, int size) {
if (size < 2) return array;
int middle = size / 2;
Edge *leftArray;
Edge *rightArray;
int leftSize = middle;
int rightSize = size - leftSize;
leftArray = new(leftSize);
rightArray = new(rightSize);
repeat(leftSize) leftArray[i] = array[i];
repeat(rightSize) rightArray[i] = array[leftSize + i];
leftArray = mergeSort(leftArray, leftSize);
rightArray = mergeSort(rightArray, rightSize);
return merge(leftArray, rightArray, leftSize, rightSize);
}
Edge *kruskalAlgorithm(Edge *graph, int numberOfVertexes, int numberOfEdges) {
int *used = newBoolean(numberOfVertexes);
int *parent = newInt(numberOfVertexes);
Edge *newGraph = new(numberOfVertexes - 1);
graph = mergeSort(graph, numberOfEdges);
repeat(numberOfEdges) {
graph[i].firstVertex -= 1;
graph[i].secondVertex -= 1;
}
int graphIndex, newIndex;
graphIndex = newIndex = 0;
int numberOfTrees = numberOfVertexes;
repeat(numberOfVertexes) makeSet(i, parent);
while (numberOfTrees > 1) {
if (findSet(graph[graphIndex].firstVertex, parent) != findSet(graph[graphIndex].secondVertex, parent)) {
uniteSets(graph[graphIndex].firstVertex, graph[graphIndex].secondVertex, parent);
newGraph[newIndex++] = graph[graphIndex];
--numberOfTrees;
}
++graphIndex;
}
return newGraph;
}
| 24.288889 | 114 | 0.611467 |
bb4878993e0c46b18617ed65bf50d762b6d76c33 | 7,669 | h | C | src/ModValue.h | MidflightDigital/stepmania | dbce5016978e5ab51aaa6a4fb21ef2c7ce68e52e | [
"MIT"
] | 7 | 2019-01-06T01:09:55.000Z | 2021-01-21T00:00:19.000Z | src/ModValue.h | MidflightDigital/stepmania | dbce5016978e5ab51aaa6a4fb21ef2c7ce68e52e | [
"MIT"
] | 1 | 2018-12-17T13:19:36.000Z | 2018-12-17T23:37:39.000Z | src/ModValue.h | MidflightDigital/stepmania | dbce5016978e5ab51aaa6a4fb21ef2c7ce68e52e | [
"MIT"
] | 5 | 2019-01-06T01:48:34.000Z | 2021-11-25T21:19:07.000Z | #ifndef MOD_VALUE_H
#define MOD_VALUE_H
#include <initializer_list>
#include <list>
#include <map>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include "CubicSpline.h"
#include "RageTimer.h"
#include "RageTypes.h"
#include "TimingData.h"
struct lua_State;
struct ModifiableValue;
struct mod_function;
// invalid_modfunction_time exists so that the loading code can tell when a
// start or end time was provided.
static CONSTEXPR_VARIABLE double invalid_modfunction_time= -1000.0;
struct ModManager
{
size_t column;
struct func_and_parent
{
mod_function* func;
ModifiableValue* parent;
func_and_parent() {}
func_and_parent(mod_function* f, ModifiableValue* p)
:func(f), parent(p)
{}
};
ModManager()
:m_prev_curr_second(invalid_modfunction_time)
{}
void update(double curr_beat, double curr_second);
void add_mod(mod_function* func, ModifiableValue* parent);
void remove_mod(mod_function* func);
void remove_all_mods(ModifiableValue* parent);
void dump_list_status();
void add_to_per_frame_update(mod_function* func);
void remove_from_per_frame_update(mod_function* func);
private:
void insert_into_past(mod_function* func, ModifiableValue* parent);
void insert_into_present(mod_function* func, ModifiableValue* parent);
void insert_into_future(mod_function* func, ModifiableValue* parent);
#define INSERT_FAP(time_name) \
void insert_into_##time_name(func_and_parent& fap) \
{ insert_into_##time_name(fap.func, fap.parent); }
INSERT_FAP(past);
INSERT_FAP(present);
INSERT_FAP(future);
#undef INSERT_FAP
void remove_from_present(std::list<func_and_parent>::iterator fapi);
double m_prev_curr_second;
std::list<func_and_parent> m_past_funcs;
std::list<func_and_parent> m_present_funcs;
std::list<func_and_parent> m_future_funcs;
std::unordered_set<mod_function*> m_per_frame_update_funcs;
};
struct mod_val_inputs
{
double column;
double y_offset;
double note_id_in_chart;
double note_id_in_column;
double row_id;
double eval_beat;
double eval_second;
double music_beat;
double music_second;
double dist_beat;
double dist_second;
double start_beat;
double start_second;
double end_beat;
double end_second;
double prefunres;
mod_val_inputs()
:column(0.0), y_offset(0.0),
note_id_in_chart(0.0), note_id_in_column(0.0), row_id(0.0),
eval_beat(0.0), eval_second(0.0), music_beat(0.0),
music_second(0.0), dist_beat(0.0), dist_second(0.0), prefunres(0.0)
{}
mod_val_inputs(double const mb, double const ms)
:column(0.0), y_offset(0.0),
note_id_in_chart(0.0), note_id_in_column(0.0), row_id(0.0),
eval_beat(mb), eval_second(ms), music_beat(mb),
music_second(ms), dist_beat(0.0), dist_second(0.0)
{}
mod_val_inputs(double const eb, double const es, double const mb,
double const ms)
:column(0.0), y_offset(0.0),
note_id_in_chart(0.0), note_id_in_column(0.0), row_id(0.0),
eval_beat(eb), eval_second(es), music_beat(mb),
music_second(ms), dist_beat(eb-mb), dist_second(es-ms)
{}
mod_val_inputs(double const eb, double const es, double const mb,
double const ms, double const yoff)
:column(0.0), y_offset(yoff),
note_id_in_chart(0.0), note_id_in_column(0.0), row_id(0.0),
eval_beat(eb), eval_second(es), music_beat(mb),
music_second(ms), dist_beat(eb-mb), dist_second(es-ms)
{}
void init(double const eb, double const es, double const mb,
double const ms, TapNote const* note)
{
eval_beat= eb; eval_second= es;
music_beat= mb; music_second= ms;
dist_beat= eb-mb; dist_second= es-ms;
set_note(note);
}
void change_eval_beat(double const eb)
{
eval_beat= eb;
dist_beat= eb-music_beat;
}
void change_eval_time(double const eb, double const es)
{
change_eval_beat(eb);
eval_second= es;
dist_second= es-music_second;
}
void set_time(double sb, double ss, double eb, double es)
{
start_beat= sb;
start_second= ss;
end_beat= eb;
end_second= es;
}
void set_note(TapNote const* note)
{
if(note != nullptr)
{
note_id_in_chart= note->id_in_chart;
note_id_in_column= note->id_in_column;
row_id= note->row_id;
}
}
};
struct ModifiableValue
{
ModifiableValue(ModManager* man, double value);
~ModifiableValue();
void set_timing(TimingData const* timing)
{
m_timing= timing;
}
void set_column(uint32_t col)
{
m_column= col;
}
double evaluate(mod_val_inputs& input);
std::list<mod_function*>::iterator find_mod(std::string const& name);
void add_mod(lua_State* L, int index);
void remove_mod(std::string const& name);
void clear_mods();
bool empty() { return m_mods.empty() && m_active_managed_mods.empty(); }
void add_managed_mod(lua_State* L, int index);
void remove_managed_mod(std::string const& name);
void clear_managed_mods();
void add_mod_to_active_list(mod_function* mod);
void remove_mod_from_active_list(mod_function* mod);
void add_simple_mod(std::string const& name, std::string const& input_type,
double value);
void take_over_mods(ModifiableValue& other);
bool needs_beat();
bool needs_second();
bool needs_y_offset();
virtual void PushSelf(lua_State* L);
private:
void insert_mod_internal(mod_function* new_mod);
ModManager* m_manager;
TimingData const* m_timing;
double m_column;
std::list<mod_function*> m_mods;
std::unordered_map<std::string, mod_function*> m_managed_mods;
std::multimap<int, mod_function*> m_active_managed_mods;
bool m_needs_beat;
bool m_needs_second;
bool m_needs_y_offset;
};
struct ModifiableVector3
{
ModifiableVector3(ModManager* man, double value)
:x_mod(man, value), y_mod(man, value), z_mod(man, value)
{}
ModifiableVector3(ModManager* man, double x, double y, double z)
:x_mod(man, x), y_mod(man, y), z_mod(man, z)
{}
void evaluate(mod_val_inputs& input, Rage::Vector3& out)
{
out.x = static_cast<float>(x_mod.evaluate(input));
out.y = static_cast<float>(y_mod.evaluate(input));
out.z = static_cast<float>(z_mod.evaluate(input));
}
void set_timing(TimingData const* timing)
{
x_mod.set_timing(timing);
y_mod.set_timing(timing);
z_mod.set_timing(timing);
}
void set_column(uint32_t col)
{
x_mod.set_column(col);
y_mod.set_column(col);
z_mod.set_column(col);
}
void take_over_mods(ModifiableVector3& other)
{
x_mod.take_over_mods(other.x_mod);
y_mod.take_over_mods(other.y_mod);
z_mod.take_over_mods(other.z_mod);
}
bool needs_beat();
bool needs_second();
bool needs_y_offset();
ModifiableValue x_mod;
ModifiableValue y_mod;
ModifiableValue z_mod;
};
struct ModifiableTransform
{
ModifiableTransform(ModManager* man)
:pos_mod(man, 0.0), rot_mod(man, 0.0), zoom_mod(man, 1.0)
{}
void set_timing(TimingData const* timing)
{
pos_mod.set_timing(timing);
rot_mod.set_timing(timing);
zoom_mod.set_timing(timing);
}
void set_column(uint32_t col)
{
pos_mod.set_column(col);
rot_mod.set_column(col);
zoom_mod.set_column(col);
}
void evaluate(mod_val_inputs& input, Rage::transform& out)
{
pos_mod.evaluate(input, out.pos);
rot_mod.evaluate(input, out.rot);
zoom_mod.evaluate(input, out.zoom);
}
void hold_render_eval(mod_val_inputs& input, Rage::transform& out, bool do_rot)
{
pos_mod.evaluate(input, out.pos);
if(do_rot)
{
out.rot.y = static_cast<float>(rot_mod.y_mod.evaluate(input));
}
out.zoom.x = static_cast<float>(zoom_mod.x_mod.evaluate(input));
}
void take_over_mods(ModifiableTransform& other)
{
pos_mod.take_over_mods(other.pos_mod);
rot_mod.take_over_mods(other.rot_mod);
zoom_mod.take_over_mods(other.zoom_mod);
}
bool needs_beat();
bool needs_second();
bool needs_y_offset();
ModifiableVector3 pos_mod;
ModifiableVector3 rot_mod;
ModifiableVector3 zoom_mod;
};
#endif
| 26.444828 | 80 | 0.748207 |
63ee7cd07383e6c15eefd653d8d20dd3e8305174 | 2,915 | h | C | src/elves/othello_montecarlo/OthelloUtil.h | mp13on11/dwarf_mine | e9c83e8d50d5a23670a45bfd174475f7f383a709 | [
"MIT"
] | 2 | 2015-11-06T03:18:28.000Z | 2016-06-29T07:43:10.000Z | src/elves/othello_montecarlo/OthelloUtil.h | mp13on11/dwarf_mine | e9c83e8d50d5a23670a45bfd174475f7f383a709 | [
"MIT"
] | null | null | null | src/elves/othello_montecarlo/OthelloUtil.h | mp13on11/dwarf_mine | e9c83e8d50d5a23670a45bfd174475f7f383a709 | [
"MIT"
] | null | null | null | /*****************************************************************************
* Dwarf Mine - The 13-11 Benchmark
*
* Copyright (c) 2013 Bünger, Thomas; Kieschnick, Christian; Kusber,
* Michael; Lohse, Henning; Wuttke, Nikolai; Xylander, Oliver; Yao, Gary;
* Zimmermann, Florian
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#pragma once
#include <iosfwd>
#include <vector>
#include <functional>
#include <Result.h>
#include <Move.h>
#include <Field.h>
#include <iostream>
typedef std::function<size_t(size_t)> RandomGenerator;
// shortcuts
const Field F = Field::Free;
const Field W = Field::White;
const Field B = Field::Black;
typedef std::vector<Field> Playfield;
typedef std::vector<Move> MoveList;
std::ostream& operator<<(std::ostream& stream, const Field field);
std::istream& operator>>(std::istream& stream, Field& field);
// operator overloads
inline Move operator+(const Move& first, const Move& second)
{
return Move{first.x + second.x, first.y + second.y};
}
inline void operator+=(Move& value, const Move& other)
{
value.x += other.x;
value.y += other.y;
}
inline bool operator==(const Move& first, const Move& second)
{
return first.x == second.x && first.y == second.y;
}
inline std::ostream& operator<<(std::ostream& stream, const Move& move)
{
stream << "{" << move.x << ", " << move.y << "}";
return stream;
}
// explicit helper methods
namespace OthelloHelper
{
size_t generateUniqueSeed(size_t nodeId, size_t threadId, size_t commonSeed);
void writeResultToStream(std::ostream& stream, const Result& result);
void readResultFromStream(std::istream& stream, Result& result);
void writePlayfieldToStream(std::ostream& stream, const Playfield& playfield);
void readPlayfieldFromStream(std::istream& stream, Playfield& playfield);
}
| 31.684783 | 82 | 0.690909 |
4b2cacff0f7213ab5efc9e22557eba220603c5a2 | 2,368 | h | C | libredex/ShowCFG.h | kami-lang/madex-redex | 90ae1bc46c6e20a0aed2c128183b9f289cecee34 | [
"MIT"
] | null | null | null | libredex/ShowCFG.h | kami-lang/madex-redex | 90ae1bc46c6e20a0aed2c128183b9f289cecee34 | [
"MIT"
] | null | null | null | libredex/ShowCFG.h | kami-lang/madex-redex | 90ae1bc46c6e20a0aed2c128183b9f289cecee34 | [
"MIT"
] | null | null | null | /*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "ControlFlow.h"
#include "IRList.h"
#include "Show.h"
template <typename Special>
std::string show(const cfg::Block* block, Special& special) {
std::ostringstream ss;
for (const auto& mie : *block) {
special.mie_before(ss, mie);
ss << " " << show(mie) << "\n";
special.mie_after(ss, mie);
}
return ss.str();
}
template <typename Special>
std::string show(const cfg::ControlFlowGraph& cfg, Special& special) {
const auto& blocks = cfg.blocks();
std::ostringstream ss;
ss << "CFG:\n";
for (auto* b : blocks) {
ss << " Block B" << b->id() << ":";
if (b == cfg.entry_block()) {
ss << " entry";
}
ss << "\n";
special.start_block(ss, b);
ss << " preds:";
for (const auto& p : b->preds()) {
ss << " (" << *p << " B" << p->src()->id() << ")";
}
ss << "\n";
ss << show(b, special);
ss << " succs:";
for (auto& s : b->succs()) {
ss << " (" << *s << " B" << s->target()->id() << ")";
}
ss << "\n";
special.end_block(ss, b);
}
return ss.str();
}
// Special helper interjecting fixpoint iterator data.
namespace show_impl {
template <typename Environment, typename Iterator>
struct IteratorSpecial {
Environment cur;
const Iterator& iter;
explicit IteratorSpecial(const Iterator& iter) : iter(iter) {}
void mie_before(std::ostream& os, const MethodItemEntry& mie) {
if (mie.type != MFLOW_OPCODE) {
return;
}
os << "state: " << cur << "\n";
iter.analyze_instruction(mie.insn, &cur);
}
void mie_after(std::ostream&, const MethodItemEntry&) {}
void start_block(std::ostream& os, cfg::Block* b) {
cur = iter.get_entry_state_at(b);
os << "entry state: " << cur << "\n";
}
void end_block(std::ostream& os, cfg::Block* b) {
auto exit_state = iter.get_exit_state_at(b);
os << "exit state: " << exit_state << "\n";
}
};
} // namespace show_impl
template <typename Environment, typename Iterator>
std::string show_analysis(const cfg::ControlFlowGraph& cfg,
const Iterator& iter) {
show_impl::IteratorSpecial<Environment, Iterator> special(iter);
return show(cfg, special);
}
| 26.021978 | 70 | 0.595017 |
15f06ec2104b6618f5f656b945fd67dc1c7560e4 | 852 | h | C | Shared/LLPersistentStoreNotification.h | ddeville/core-data-ipc | 446359b88f423e084c8d37c8db290932fd302bbc | [
"MIT"
] | 2 | 2016-04-27T21:38:40.000Z | 2018-06-05T20:26:37.000Z | Shared/LLPersistentStoreNotification.h | ddeville/core-data-ipc | 446359b88f423e084c8d37c8db290932fd302bbc | [
"MIT"
] | null | null | null | Shared/LLPersistentStoreNotification.h | ddeville/core-data-ipc | 446359b88f423e084c8d37c8db290932fd302bbc | [
"MIT"
] | null | null | null | //
// LLPersistentStoreNotification.h
// Application
//
// Created by Damien DeVille on 2/21/15.
// Copyright (c) 2015 Damien DeVille. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface LLPersistentStoreNotification : NSObject <NSSecureCoding>
@property (readonly, strong, nonatomic) NSDictionary *userInfo;
@property (readonly, copy, nonatomic) NSString *persistentStoreIdentifier;
@property (readonly, assign, nonatomic) pid_t senderProcessIdentifier;
@end
@interface NSManagedObjectContext (LLPersistentStoreNotification)
+ (LLPersistentStoreNotification *)createPersistentStoreNotificationFromChangeNotification:(NSNotification *)notification persistentStoreIdentifier:(NSString *)persistentStoreIdentifier;
- (void)mergeChangesFromPersistentStoreNotification:(LLPersistentStoreNotification *)persistentStoreNotification;
@end
| 31.555556 | 186 | 0.821596 |
f4cb9a558b7b5cc2f0c60a77b8f73469ee87d73c | 26,538 | c | C | .gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/src/odb_pack.c | matt1795/zkg | 1ae3ab36aac6a99beb82c284f356c89731ee9412 | [
"MIT"
] | 10 | 2020-06-13T20:15:41.000Z | 2020-06-17T05:08:34.000Z | .gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/src/odb_pack.c | matt1795/zag | c8d002b6decad7fa6917b8c9952cdddc2b0f2197 | [
"MIT"
] | 1 | 2021-11-26T16:39:10.000Z | 2021-11-26T16:39:10.000Z | .gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/src/odb_pack.c | matt1795/zag | c8d002b6decad7fa6917b8c9952cdddc2b0f2197 | [
"MIT"
] | null | null | null | /*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#include "common.h"
#include <zlib.h>
#include "git2/repository.h"
#include "git2/indexer.h"
#include "git2/sys/odb_backend.h"
#include "delta.h"
#include "futils.h"
#include "hash.h"
#include "midx.h"
#include "mwindow.h"
#include "odb.h"
#include "pack.h"
#include "git2/odb_backend.h"
/* re-freshen pack files no more than every 2 seconds */
#define FRESHEN_FREQUENCY 2
struct pack_backend {
git_odb_backend parent;
git_midx_file *midx;
git_vector midx_packs;
git_vector packs;
struct git_pack_file *last_found;
char *pack_folder;
};
struct pack_writepack {
struct git_odb_writepack parent;
git_indexer *indexer;
};
/**
* The wonderful tale of a Packed Object lookup query
* ===================================================
* A riveting and epic story of epicness and ASCII
* art, presented by yours truly,
* Sir Vicent of Marti
*
*
* Chapter 1: Once upon a time...
* Initialization of the Pack Backend
* --------------------------------------------------
*
* # git_odb_backend_pack
* | Creates the pack backend structure, initializes the
* | callback pointers to our default read() and exist() methods,
* | and tries to find the `pack` folder, if it exists. ODBs without a `pack`
* | folder are ignored altogether. If there is a `pack` folder, it tries to
* | preload all the known packfiles in the ODB.
* |
* |-# pack_backend__refresh
* | The `multi-pack-index` is loaded if it exists and is valid.
* | Then we run a `dirent` callback through every file in the pack folder,
* | even those present in `multi-pack-index`. The unindexed packfiles are
* | then sorted according to a sorting callback.
* |
* |-# refresh_multi_pack_index
* | Detect the presence of the `multi-pack-index` file. If it needs to be
* | refreshed, frees the old copy and tries to load the new one, together
* | with all the packfiles it indexes. If the process fails, fall back to
* | the old behavior, as if the `multi-pack-index` file was not there.
* |
* |-# packfile_load__cb
* | | This callback is called from `dirent` with every single file
* | | inside the pack folder. We find the packs by actually locating
* | | their index (ends in ".idx"). From that index, we verify that
* | | the corresponding packfile exists and is valid, and if so, we
* | | add it to the pack list.
* | |
* | # git_mwindow_get_pack
* | Make sure that there's a packfile to back this index, and store
* | some very basic information regarding the packfile itself,
* | such as the full path, the size, and the modification time.
* | We don't actually open the packfile to check for internal consistency.
* |
* |-# packfile_sort__cb
* Sort all the preloaded packs according to some specific criteria:
* we prioritize the "newer" packs because it's more likely they
* contain the objects we are looking for, and we prioritize local
* packs over remote ones.
*
*
*
* Chapter 2: To be, or not to be...
* A standard packed `exist` query for an OID
* --------------------------------------------------
*
* # pack_backend__exists / pack_backend__exists_prefix
* | Check if the given SHA1 oid (or a SHA1 oid prefix) exists in any of the
* | packs that have been loaded for our ODB.
* |
* |-# pack_entry_find / pack_entry_find_prefix
* | If there is a multi-pack-index present, search the SHA1 oid in that
* | index first. If it is not found there, iterate through all the unindexed
* | packs that have been preloaded (starting by the pack where the latest
* | object was found) to try to find the OID in one of them.
* |
* |-# git_midx_entry_find
* | Search for the SHA1 oid in the multi-pack-index. See
* | <https://github.com/git/git/blob/master/Documentation/technical/pack-format.txt>
* | for specifics on the multi-pack-index format and how do we find
* | entries in it.
* |
* |-# git_pack_entry_find
* | Check the index of an individual unindexed pack to see if the SHA1
* | OID can be found. If we can find the offset to that SHA1 inside of the
* | index, that means the object is contained inside of the packfile and
* | we can stop searching. Before returning, we verify that the
* | packfile behing the index we are searching still exists on disk.
* |
* |-# pack_entry_find_offset
* | Mmap the actual index file to disk if it hasn't been opened
* | yet, and run a binary search through it to find the OID.
* | See <https://github.com/git/git/blob/master/Documentation/technical/pack-format.txt>
* | for specifics on the Packfile Index format and how do we find
* | entries in it.
* |
* |-# pack_index_open
* | Guess the name of the index based on the full path to the
* | packfile, open it and verify its contents. Only if the index
* | has not been opened already.
* |
* |-# pack_index_check
* Mmap the index file and do a quick run through the header
* to guess the index version (right now we support v1 and v2),
* and to verify that the size of the index makes sense.
*
*
*
* Chapter 3: The neverending story...
* A standard packed `lookup` query for an OID
* --------------------------------------------------
*
* # pack_backend__read / pack_backend__read_prefix
* | Check if the given SHA1 oid (or a SHA1 oid prefix) exists in any of the
* | packs that have been loaded for our ODB. If it does, open the packfile and
* | read from it.
* |
* |-# git_packfile_unpack
* Armed with a packfile and the offset within it, we can finally unpack
* the object pointed at by the SHA1 oid. This involves mmapping part of
* the `.pack` file, and uncompressing the object within it (if it is
* stored in the undelfitied representation), or finding a base object and
* applying some deltas to its uncompressed representation (if it is stored
* in the deltified representation). See
* <https://github.com/git/git/blob/master/Documentation/technical/pack-format.txt>
* for specifics on the Packfile format and how do we read from it.
*
*/
/***********************************************************
*
* FORWARD DECLARATIONS
*
***********************************************************/
static int packfile_sort__cb(const void *a_, const void *b_);
static int packfile_load__cb(void *_data, git_buf *path);
static int packfile_byname_search_cmp(const void *path, const void *pack_entry);
static int pack_entry_find(struct git_pack_entry *e,
struct pack_backend *backend, const git_oid *oid);
/* Can find the offset of an object given
* a prefix of an identifier.
* Sets GIT_EAMBIGUOUS if short oid is ambiguous.
* This method assumes that len is between
* GIT_OID_MINPREFIXLEN and GIT_OID_HEXSZ.
*/
static int pack_entry_find_prefix(
struct git_pack_entry *e,
struct pack_backend *backend,
const git_oid *short_oid,
size_t len);
/***********************************************************
*
* PACK WINDOW MANAGEMENT
*
***********************************************************/
static int packfile_byname_search_cmp(const void *path_, const void *p_)
{
const git_buf *path = (const git_buf *)path_;
const struct git_pack_file *p = (const struct git_pack_file *)p_;
return strncmp(p->pack_name, git_buf_cstr(path), git_buf_len(path));
}
static int packfile_sort__cb(const void *a_, const void *b_)
{
const struct git_pack_file *a = a_;
const struct git_pack_file *b = b_;
int st;
/*
* Local packs tend to contain objects specific to our
* variant of the project than remote ones. In addition,
* remote ones could be on a network mounted filesystem.
* Favor local ones for these reasons.
*/
st = a->pack_local - b->pack_local;
if (st)
return -st;
/*
* Younger packs tend to contain more recent objects,
* and more recent objects tend to get accessed more
* often.
*/
if (a->mtime < b->mtime)
return 1;
else if (a->mtime == b->mtime)
return 0;
return -1;
}
static int packfile_load__cb(void *data, git_buf *path)
{
struct pack_backend *backend = data;
struct git_pack_file *pack;
const char *path_str = git_buf_cstr(path);
git_buf index_prefix = GIT_BUF_INIT;
size_t cmp_len = git_buf_len(path);
int error;
if (cmp_len <= strlen(".idx") || git__suffixcmp(path_str, ".idx") != 0)
return 0; /* not an index */
cmp_len -= strlen(".idx");
git_buf_attach_notowned(&index_prefix, path_str, cmp_len);
if (git_vector_search2(NULL, &backend->midx_packs, packfile_byname_search_cmp, &index_prefix) == 0)
return 0;
if (git_vector_search2(NULL, &backend->packs, packfile_byname_search_cmp, &index_prefix) == 0)
return 0;
error = git_mwindow_get_pack(&pack, path->ptr);
/* ignore missing .pack file as git does */
if (error == GIT_ENOTFOUND) {
git_error_clear();
return 0;
}
if (!error)
error = git_vector_insert(&backend->packs, pack);
return error;
}
static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backend, const git_oid *oid)
{
struct git_pack_file *last_found = backend->last_found, *p;
git_midx_entry midx_entry;
size_t i;
if (backend->midx &&
git_midx_entry_find(&midx_entry, backend->midx, oid, GIT_OID_HEXSZ) == 0 &&
midx_entry.pack_index < git_vector_length(&backend->midx_packs)) {
e->offset = midx_entry.offset;
git_oid_cpy(&e->sha1, &midx_entry.sha1);
e->p = git_vector_get(&backend->midx_packs, midx_entry.pack_index);
return 0;
}
if (last_found &&
git_pack_entry_find(e, last_found, oid, GIT_OID_HEXSZ) == 0)
return 0;
git_vector_foreach(&backend->packs, i, p) {
if (p == last_found)
continue;
if (git_pack_entry_find(e, p, oid, GIT_OID_HEXSZ) == 0) {
backend->last_found = p;
return 0;
}
}
return git_odb__error_notfound(
"failed to find pack entry", oid, GIT_OID_HEXSZ);
}
static int pack_entry_find_prefix(
struct git_pack_entry *e,
struct pack_backend *backend,
const git_oid *short_oid,
size_t len)
{
int error;
size_t i;
git_oid found_full_oid = {{0}};
bool found = false;
struct git_pack_file *last_found = backend->last_found, *p;
git_midx_entry midx_entry;
if (backend->midx) {
error = git_midx_entry_find(&midx_entry, backend->midx, short_oid, len);
if (error == GIT_EAMBIGUOUS)
return error;
if (!error && midx_entry.pack_index < git_vector_length(&backend->midx_packs)) {
e->offset = midx_entry.offset;
git_oid_cpy(&e->sha1, &midx_entry.sha1);
e->p = git_vector_get(&backend->midx_packs, midx_entry.pack_index);
git_oid_cpy(&found_full_oid, &e->sha1);
found = true;
}
}
if (last_found) {
error = git_pack_entry_find(e, last_found, short_oid, len);
if (error == GIT_EAMBIGUOUS)
return error;
if (!error) {
if (found && git_oid_cmp(&e->sha1, &found_full_oid))
return git_odb__error_ambiguous("found multiple pack entries");
git_oid_cpy(&found_full_oid, &e->sha1);
found = true;
}
}
git_vector_foreach(&backend->packs, i, p) {
if (p == last_found)
continue;
error = git_pack_entry_find(e, p, short_oid, len);
if (error == GIT_EAMBIGUOUS)
return error;
if (!error) {
if (found && git_oid_cmp(&e->sha1, &found_full_oid))
return git_odb__error_ambiguous("found multiple pack entries");
git_oid_cpy(&found_full_oid, &e->sha1);
found = true;
backend->last_found = p;
}
}
if (!found)
return git_odb__error_notfound("no matching pack entry for prefix",
short_oid, len);
else
return 0;
}
/***********************************************************
*
* MULTI-PACK-INDEX SUPPORT
*
* Functions needed to support the multi-pack-index.
*
***********************************************************/
/*
* Remove the multi-pack-index, and move all midx_packs to packs.
*/
static int remove_multi_pack_index(struct pack_backend *backend)
{
size_t i, j = git_vector_length(&backend->packs);
struct pack_backend *p;
int error = git_vector_size_hint(
&backend->packs,
j + git_vector_length(&backend->midx_packs));
if (error < 0)
return error;
git_vector_foreach(&backend->midx_packs, i, p)
git_vector_set(NULL, &backend->packs, j++, p);
git_vector_clear(&backend->midx_packs);
git_midx_free(backend->midx);
backend->midx = NULL;
return 0;
}
/*
* Loads a single .pack file referred to by the multi-pack-index. These must
* match the order in which they are declared in the multi-pack-index file,
* since these files are referred to by their index.
*/
static int process_multi_pack_index_pack(
struct pack_backend *backend,
size_t i,
const char *packfile_name)
{
int error;
struct git_pack_file *pack;
size_t found_position;
git_buf pack_path = GIT_BUF_INIT, index_prefix = GIT_BUF_INIT;
error = git_buf_joinpath(&pack_path, backend->pack_folder, packfile_name);
if (error < 0)
return error;
/* This is ensured by midx_parse_packfile_name() */
if (git_buf_len(&pack_path) <= strlen(".idx") || git__suffixcmp(git_buf_cstr(&pack_path), ".idx") != 0)
return git_odb__error_notfound("midx file contained a non-index", NULL, 0);
git_buf_attach_notowned(&index_prefix, git_buf_cstr(&pack_path), git_buf_len(&pack_path) - strlen(".idx"));
if (git_vector_search2(&found_position, &backend->packs, packfile_byname_search_cmp, &index_prefix) == 0) {
/* Pack was found in the packs list. Moving it to the midx_packs list. */
git_buf_dispose(&pack_path);
git_vector_set(NULL, &backend->midx_packs, i, git_vector_get(&backend->packs, found_position));
git_vector_remove(&backend->packs, found_position);
return 0;
}
/* Pack was not found. Allocate a new one. */
error = git_mwindow_get_pack(&pack, git_buf_cstr(&pack_path));
git_buf_dispose(&pack_path);
if (error < 0)
return error;
git_vector_set(NULL, &backend->midx_packs, i, pack);
return 0;
}
/*
* Reads the multi-pack-index. If this fails for whatever reason, the
* multi-pack-index object is freed, and all the packfiles that are related to
* it are moved to the unindexed packfiles vector.
*/
static int refresh_multi_pack_index(struct pack_backend *backend)
{
int error;
git_buf midx_path = GIT_BUF_INIT;
const char *packfile_name;
size_t i;
error = git_buf_joinpath(&midx_path, backend->pack_folder, "multi-pack-index");
if (error < 0)
return error;
/*
* Check whether the multi-pack-index has changed. If it has, close any
* old multi-pack-index and move all the packfiles to the unindexed
* packs. This is done to prevent losing any open packfiles in case
* refreshing the new multi-pack-index fails, or the file is deleted.
*/
if (backend->midx) {
if (!git_midx_needs_refresh(backend->midx, git_buf_cstr(&midx_path))) {
git_buf_dispose(&midx_path);
return 0;
}
error = remove_multi_pack_index(backend);
if (error < 0) {
git_buf_dispose(&midx_path);
return error;
}
}
error = git_midx_open(&backend->midx, git_buf_cstr(&midx_path));
git_buf_dispose(&midx_path);
if (error < 0)
return error;
git_vector_resize_to(&backend->midx_packs, git_vector_length(&backend->midx->packfile_names));
git_vector_foreach(&backend->midx->packfile_names, i, packfile_name) {
error = process_multi_pack_index_pack(backend, i, packfile_name);
if (error < 0) {
/*
* Something failed during reading multi-pack-index.
* Restore the state of backend as if the
* multi-pack-index was never there, and move all
* packfiles that have been processed so far to the
* unindexed packs.
*/
git_vector_resize_to(&backend->midx_packs, i);
remove_multi_pack_index(backend);
return error;
}
}
return 0;
}
/***********************************************************
*
* PACKED BACKEND PUBLIC API
*
* Implement the git_odb_backend API calls
*
***********************************************************/
static int pack_backend__refresh(git_odb_backend *backend_)
{
int error;
struct stat st;
git_buf path = GIT_BUF_INIT;
struct pack_backend *backend = (struct pack_backend *)backend_;
if (backend->pack_folder == NULL)
return 0;
if (p_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode))
return git_odb__error_notfound("failed to refresh packfiles", NULL, 0);
if (refresh_multi_pack_index(backend) < 0) {
/*
* It is okay if this fails. We will just not use the
* multi-pack-index in this case.
*/
git_error_clear();
}
/* reload all packs */
git_buf_sets(&path, backend->pack_folder);
error = git_path_direach(&path, 0, packfile_load__cb, backend);
git_buf_dispose(&path);
git_vector_sort(&backend->packs);
return error;
}
static int pack_backend__read_header(
size_t *len_p, git_object_t *type_p,
struct git_odb_backend *backend, const git_oid *oid)
{
struct git_pack_entry e;
int error;
GIT_ASSERT_ARG(len_p);
GIT_ASSERT_ARG(type_p);
GIT_ASSERT_ARG(backend);
GIT_ASSERT_ARG(oid);
if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0)
return error;
return git_packfile_resolve_header(len_p, type_p, e.p, e.offset);
}
static int pack_backend__freshen(
git_odb_backend *backend, const git_oid *oid)
{
struct git_pack_entry e;
time_t now;
int error;
if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0)
return error;
now = time(NULL);
if (e.p->last_freshen > now - FRESHEN_FREQUENCY)
return 0;
if ((error = git_futils_touch(e.p->pack_name, &now)) < 0)
return error;
e.p->last_freshen = now;
return 0;
}
static int pack_backend__read(
void **buffer_p, size_t *len_p, git_object_t *type_p,
git_odb_backend *backend, const git_oid *oid)
{
struct git_pack_entry e;
git_rawobj raw = {NULL};
int error;
if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0 ||
(error = git_packfile_unpack(&raw, e.p, &e.offset)) < 0)
return error;
*buffer_p = raw.data;
*len_p = raw.len;
*type_p = raw.type;
return 0;
}
static int pack_backend__read_prefix(
git_oid *out_oid,
void **buffer_p,
size_t *len_p,
git_object_t *type_p,
git_odb_backend *backend,
const git_oid *short_oid,
size_t len)
{
int error = 0;
if (len < GIT_OID_MINPREFIXLEN)
error = git_odb__error_ambiguous("prefix length too short");
else if (len >= GIT_OID_HEXSZ) {
/* We can fall back to regular read method */
error = pack_backend__read(buffer_p, len_p, type_p, backend, short_oid);
if (!error)
git_oid_cpy(out_oid, short_oid);
} else {
struct git_pack_entry e;
git_rawobj raw = {NULL};
if ((error = pack_entry_find_prefix(
&e, (struct pack_backend *)backend, short_oid, len)) == 0 &&
(error = git_packfile_unpack(&raw, e.p, &e.offset)) == 0)
{
*buffer_p = raw.data;
*len_p = raw.len;
*type_p = raw.type;
git_oid_cpy(out_oid, &e.sha1);
}
}
return error;
}
static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid)
{
struct git_pack_entry e;
return pack_entry_find(&e, (struct pack_backend *)backend, oid) == 0;
}
static int pack_backend__exists_prefix(
git_oid *out, git_odb_backend *backend, const git_oid *short_id, size_t len)
{
int error;
struct pack_backend *pb = (struct pack_backend *)backend;
struct git_pack_entry e = {0};
error = pack_entry_find_prefix(&e, pb, short_id, len);
git_oid_cpy(out, &e.sha1);
return error;
}
static int pack_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data)
{
int error;
struct git_pack_file *p;
struct pack_backend *backend;
unsigned int i;
GIT_ASSERT_ARG(_backend);
GIT_ASSERT_ARG(cb);
backend = (struct pack_backend *)_backend;
/* Make sure we know about the packfiles */
if ((error = pack_backend__refresh(_backend)) != 0)
return error;
if (backend->midx && (error = git_midx_foreach_entry(backend->midx, cb, data)) != 0)
return error;
git_vector_foreach(&backend->packs, i, p) {
if ((error = git_pack_foreach_entry(p, cb, data)) != 0)
return error;
}
return 0;
}
static int pack_backend__writepack_append(struct git_odb_writepack *_writepack, const void *data, size_t size, git_indexer_progress *stats)
{
struct pack_writepack *writepack = (struct pack_writepack *)_writepack;
GIT_ASSERT_ARG(writepack);
return git_indexer_append(writepack->indexer, data, size, stats);
}
static int pack_backend__writepack_commit(struct git_odb_writepack *_writepack, git_indexer_progress *stats)
{
struct pack_writepack *writepack = (struct pack_writepack *)_writepack;
GIT_ASSERT_ARG(writepack);
return git_indexer_commit(writepack->indexer, stats);
}
static void pack_backend__writepack_free(struct git_odb_writepack *_writepack)
{
struct pack_writepack *writepack;
if (!_writepack)
return;
writepack = (struct pack_writepack *)_writepack;
git_indexer_free(writepack->indexer);
git__free(writepack);
}
static int pack_backend__writepack(struct git_odb_writepack **out,
git_odb_backend *_backend,
git_odb *odb,
git_indexer_progress_cb progress_cb,
void *progress_payload)
{
git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT;
struct pack_backend *backend;
struct pack_writepack *writepack;
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(_backend);
*out = NULL;
opts.progress_cb = progress_cb;
opts.progress_cb_payload = progress_payload;
backend = (struct pack_backend *)_backend;
writepack = git__calloc(1, sizeof(struct pack_writepack));
GIT_ERROR_CHECK_ALLOC(writepack);
if (git_indexer_new(&writepack->indexer,
backend->pack_folder, 0, odb, &opts) < 0) {
git__free(writepack);
return -1;
}
writepack->parent.backend = _backend;
writepack->parent.append = pack_backend__writepack_append;
writepack->parent.commit = pack_backend__writepack_commit;
writepack->parent.free = pack_backend__writepack_free;
*out = (git_odb_writepack *)writepack;
return 0;
}
static int get_idx_path(
git_buf *idx_path,
struct pack_backend *backend,
struct git_pack_file *p)
{
size_t path_len;
int error;
error = git_path_prettify(idx_path, p->pack_name, backend->pack_folder);
if (error < 0)
return error;
path_len = git_buf_len(idx_path);
if (path_len <= strlen(".pack") || git__suffixcmp(git_buf_cstr(idx_path), ".pack") != 0)
return git_odb__error_notfound("packfile does not end in .pack", NULL, 0);
path_len -= strlen(".pack");
error = git_buf_splice(idx_path, path_len, strlen(".pack"), ".idx", strlen(".idx"));
if (error < 0)
return error;
return 0;
}
static int pack_backend__writemidx(git_odb_backend *_backend)
{
struct pack_backend *backend;
git_midx_writer *w = NULL;
struct git_pack_file *p;
size_t i;
int error = 0;
GIT_ASSERT_ARG(_backend);
backend = (struct pack_backend *)_backend;
error = git_midx_writer_new(&w, backend->pack_folder);
if (error < 0)
return error;
git_vector_foreach(&backend->midx_packs, i, p) {
git_buf idx_path = GIT_BUF_INIT;
error = get_idx_path(&idx_path, backend, p);
if (error < 0)
goto cleanup;
error = git_midx_writer_add(w, git_buf_cstr(&idx_path));
git_buf_dispose(&idx_path);
if (error < 0)
goto cleanup;
}
git_vector_foreach(&backend->packs, i, p) {
git_buf idx_path = GIT_BUF_INIT;
error = get_idx_path(&idx_path, backend, p);
if (error < 0)
goto cleanup;
error = git_midx_writer_add(w, git_buf_cstr(&idx_path));
git_buf_dispose(&idx_path);
if (error < 0)
goto cleanup;
}
/*
* Invalidate the previous midx before writing the new one.
*/
error = remove_multi_pack_index(backend);
if (error < 0)
goto cleanup;
error = git_midx_writer_commit(w);
if (error < 0)
goto cleanup;
error = refresh_multi_pack_index(backend);
cleanup:
git_midx_writer_free(w);
return error;
}
static void pack_backend__free(git_odb_backend *_backend)
{
struct pack_backend *backend;
struct git_pack_file *p;
size_t i;
if (!_backend)
return;
backend = (struct pack_backend *)_backend;
git_vector_foreach(&backend->midx_packs, i, p)
git_mwindow_put_pack(p);
git_vector_foreach(&backend->packs, i, p)
git_mwindow_put_pack(p);
git_midx_free(backend->midx);
git_vector_free(&backend->midx_packs);
git_vector_free(&backend->packs);
git__free(backend->pack_folder);
git__free(backend);
}
static int pack_backend__alloc(struct pack_backend **out, size_t initial_size)
{
struct pack_backend *backend = git__calloc(1, sizeof(struct pack_backend));
GIT_ERROR_CHECK_ALLOC(backend);
if (git_vector_init(&backend->midx_packs, 0, NULL) < 0) {
git__free(backend);
return -1;
}
if (git_vector_init(&backend->packs, initial_size, packfile_sort__cb) < 0) {
git_vector_free(&backend->midx_packs);
git__free(backend);
return -1;
}
backend->parent.version = GIT_ODB_BACKEND_VERSION;
backend->parent.read = &pack_backend__read;
backend->parent.read_prefix = &pack_backend__read_prefix;
backend->parent.read_header = &pack_backend__read_header;
backend->parent.exists = &pack_backend__exists;
backend->parent.exists_prefix = &pack_backend__exists_prefix;
backend->parent.refresh = &pack_backend__refresh;
backend->parent.foreach = &pack_backend__foreach;
backend->parent.writepack = &pack_backend__writepack;
backend->parent.writemidx = &pack_backend__writemidx;
backend->parent.freshen = &pack_backend__freshen;
backend->parent.free = &pack_backend__free;
*out = backend;
return 0;
}
int git_odb_backend_one_pack(git_odb_backend **backend_out, const char *idx)
{
struct pack_backend *backend = NULL;
struct git_pack_file *packfile = NULL;
if (pack_backend__alloc(&backend, 1) < 0)
return -1;
if (git_mwindow_get_pack(&packfile, idx) < 0 ||
git_vector_insert(&backend->packs, packfile) < 0)
{
pack_backend__free((git_odb_backend *)backend);
return -1;
}
*backend_out = (git_odb_backend *)backend;
return 0;
}
int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
{
int error = 0;
struct pack_backend *backend = NULL;
git_buf path = GIT_BUF_INIT;
if (pack_backend__alloc(&backend, 8) < 0)
return -1;
if (!(error = git_buf_joinpath(&path, objects_dir, "pack")) &&
git_path_isdir(git_buf_cstr(&path)))
{
backend->pack_folder = git_buf_detach(&path);
error = pack_backend__refresh((git_odb_backend *)backend);
}
if (error < 0) {
pack_backend__free((git_odb_backend *)backend);
backend = NULL;
}
*backend_out = (git_odb_backend *)backend;
git_buf_dispose(&path);
return error;
}
| 28.78308 | 139 | 0.697227 |
ebabda1d59cae80b703c91222af6462b7f8bc4df | 6,441 | h | C | src/OmXmlWriter.h | distrakt/OmEspHelpers | 4b6733dcedd5d9f24698c4cad3a6ee6a9d45acd7 | [
"MIT"
] | 22 | 2016-11-30T18:54:36.000Z | 2021-07-05T12:21:02.000Z | src/OmXmlWriter.h | distrakt/OmEspHelpers | 4b6733dcedd5d9f24698c4cad3a6ee6a9d45acd7 | [
"MIT"
] | 9 | 2020-05-25T22:56:17.000Z | 2020-12-29T23:56:01.000Z | src/OmXmlWriter.h | distrakt/OmEspHelpers | 4b6733dcedd5d9f24698c4cad3a6ee6a9d45acd7 | [
"MIT"
] | 6 | 2016-12-16T05:17:41.000Z | 2021-01-08T20:35:45.000Z | /*
* OmXmlWriter.h
* 2016-11-20
*
* This class implements an XML writer that produces
* more-or-less well-formed XML.
*
* This code is platform agnostic.
*
* It has some weakness with regard to escaping special
* characters. If you tell it produce an element named named "h1<hahaha>"
* it really won't be quoted right. But in basic use it's quite helpful.
*
* It writes into a character buffer that you provide.
*
* EXAMPLE
*
* char myBuffer[1000];
* OmXmlWriter w(myBuffer, 1000); // tell it the space limit
*
* w.beginElement("html");
* w.beginElement("head");
* w.beginElement("title");
* w.addContent("A Web Page");
* w.endElement(); // ends title
* w.endElement(); // ends head
* w.beginElement("body");
* w.beginElement("img");
* w.addAttribute("src", "http://www.omino.com/img/2016-02-24.jpg");
* w.endElement(); // ends img
* w.addContent("This is a nice picture");
* w.endElement(); // ends body
* w.endElement(); // ends html.
*
* someNetworkThingie.send(w);
*
* To produce <html><head><title>A Web Page</title></head><body>
* <img src="http://www.omino.com/img/2016-02-24.jpg" />
* This is a nice picture
* </body></html>
*/
#ifndef __OmXmlWriter__
#define __OmXmlWriter__
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
/*! Interface for streaming byte output. Can be chained together, and used as a destination by OmXmlWriter */
class OmIByteStream
{
public:
/*!
@brief emit a single byte, overridden by any implementation
*/
virtual bool put(uint8_t ch)
{
if(this->isDone)
return false;
printf("%c", ch); // simplest implementation
return true; // yup, did.
}
virtual bool done()
{
this->isDone = true;
return true;
}
/*! @brief convenience routine, same as put byte-by-byte. */
virtual bool putS(const char *s)
{
bool result = true;
while(uint8_t ch = (uint8_t)(*s++))
{
result &= this->put(ch);
}
return result;
}
bool isDone = false;
};
/*!
@class OmXmlWriter
Writes formatted XML to an OmIByteStream, streaming as it goes (mostly)
*/
class OmXmlWriter : public OmIByteStream
{
public:
static const int kOmXmlMaxDepth = 20;
OmIByteStream *consumer = 0;
int depth = 0;
int hasAnything[kOmXmlMaxDepth];
const char *elementName[kOmXmlMaxDepth];
int position = 0; // index into output
bool indenting = false;
int errorCount = 0;
unsigned int byteCount = 0;
const char *attributeName = 0; // current open attribute if any, streaming into it
/*! @brief Instantiate an XML writer to write into the specified buffer */
OmXmlWriter(OmIByteStream *consumer);
/*! @brief Begins a new XML element, like <elementName> */
void beginElement(const char *elementName);
/*! @brief Begins a new XML element with one attribute already in it, like <elementName attr="value"> */
void beginElement(const char *elementName, const char *attribute1, const char *value1);
/*! @brief Adds text to an element, like <element>content</element> */
void addContent(const char *content);
/*! @brief Adds text to the document ignoring XML rules
But also needed things like rendering DOCTYPE at the start. Caution.
*/
void addContentRaw(const char *content);
/*! @brief Adds text to an element, using printf semantics */
void addContentF(const char *fmt,...);
/*! @brief Adds an attribute to an element, like <element attr="value"> */
void addAttribute(const char *attribute, const char *value);
/*! @brief Adds an attribute to an element, using printf semantics */
void addAttributeF(const char *attribute, const char *fmt,...);
/*! @brief Handle oversized attribute. :-/ */
void addAttributeFBig(int reserve, const char *attribute, const char *fmt,...);
/*! @brief Adds an attribute to an element, using printf semantics, and %20 escapes. */
void addAttributeUrlF(const char *attribute, const char *fmt,...);
/*! @brief Adds an attribute to an element from an integer */
void addAttribute(const char *attribute, long long int value);
/*! @brief Adds an element with no attributes or content (no need for endElement()) like <hr/> */
void addElement(const char *elementName);
/*! @brief Adds an element with content (no need for endElement()) like <h1>Content</h1> */
void addElement(const char *elementName, const char *content);
/*! @brief Adds an element with content (no need for endElement()) like <h1>Content</h1> */
void addElementF(const char *elementName, const char *fmt,...);
/*! @brief Ends the most recent beginElement(). Caps them with either <element/> or </element>. */
void endElement();
/*! @brief Ends most recent beginElement, and prints error message if element name does not match. */
void endElement(const char *elementName);
/*! @brief Ends any remaining elements. */
void endElements();
/*! @brief Add content directly to the output stream, no escaping or element balancing.
You can definitely break your XML output with this! Use wisely.
*/
void addRawContent(const char *rawContent);
/*! @brief Enables primitive formatting. Uses more bytes of buffer. */
void setIndenting(int onOff);
/*! @brief Returns nonzero of any errors occurred, usually buffer overruns leading to missing portions. */
int getErrorCount();
/*! @brief Bytes written. */
unsigned int getByteCount();
/*! Our own put.
OmXmlWriter needs to know what context it's in, to manage escapes correctly.
also relies upon some new concepts like beginAttribute, <stream a big attribute value>, endAttribute. */
bool put(uint8_t ch) override;
bool done() override;
void beginAttribute(const char *attributeName);
void endAttribute();
void putf(const char *fmt,...);
bool puts(const char *stuff, bool contentEscapes = false);
private:
void indent();
void cr();
void addingToElement(bool addContent);
bool inElementContentWithEscapes = false; // triggered by addContent, halted by beginElement and endElement. But not inside <script> for example.
};
#endif /* defined(__OmXmlWriter__) */
| 33.546875 | 149 | 0.658593 |
8d9b3fe6ad772033a874f634bb7ade8cedd68edf | 394 | h | C | DisqusService.h | hlung/DisqusService | 7041f38ec620b351e69010f772cc9085bc996be4 | [
"MIT"
] | 9 | 2016-09-20T12:49:23.000Z | 2020-12-28T11:11:59.000Z | DisqusService.h | hlung/DisqusService | 7041f38ec620b351e69010f772cc9085bc996be4 | [
"MIT"
] | 2 | 2018-11-07T09:18:18.000Z | 2018-11-08T06:12:24.000Z | DisqusService.h | hlung/DisqusService | 7041f38ec620b351e69010f772cc9085bc996be4 | [
"MIT"
] | 1 | 2018-11-05T10:33:53.000Z | 2018-11-05T10:33:53.000Z | //
// DisqusService.h
// DisqusService
//
// Created by Matteo Riva on 18/09/2016.
// Copyright © 2016 Matteo Riva. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>
#import <SafariServices/SafariServices.h>
FOUNDATION_EXPORT double DisqusServiceVersionNumber;
FOUNDATION_EXPORT const unsigned char DisqusServiceVersionString[];
| 23.176471 | 67 | 0.769036 |
cbc9b8955666349bfa16ebdf280fdbea64995645 | 279 | h | C | ChX3DTouchDemo/ChX3DTouchDemo/ChXDemoViewController.h | sunrisechen007/ChX3DTouchDemo | 92279e7dcae95c7b54240437efeafd377fb9eb69 | [
"MIT"
] | 2 | 2018-09-06T11:03:53.000Z | 2018-09-06T11:04:39.000Z | ChX3DTouchDemo/ChX3DTouchDemo/ChXDemoViewController.h | sunrisechen007/ChX3DTouchDemo | 92279e7dcae95c7b54240437efeafd377fb9eb69 | [
"MIT"
] | null | null | null | ChX3DTouchDemo/ChX3DTouchDemo/ChXDemoViewController.h | sunrisechen007/ChX3DTouchDemo | 92279e7dcae95c7b54240437efeafd377fb9eb69 | [
"MIT"
] | null | null | null | //
// ChXDemoViewController.h
// ChX3DTouchDemo
//
// Created by Xu Chen on 2018/8/11.
// Copyright © 2018年 xu.yzl. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ChXDemoViewController : UIViewController
@property (nonatomic, strong) NSString *titleName;
@end
| 18.6 | 51 | 0.724014 |
c4f693e45afffc2c4f68a8c8e5fafc29d32dac79 | 4,070 | c | C | deps/GraphBLAS/Source/GB_AxB_alloc.c | The-Alchemist/RedisGraph | 3dca151464d915f3a4a1e57bbc04ad0ae0b1388d | [
"Ruby",
"ISC",
"MIT"
] | 1 | 2021-01-13T07:08:07.000Z | 2021-01-13T07:08:07.000Z | deps/GraphBLAS/Source/GB_AxB_alloc.c | The-Alchemist/RedisGraph | 3dca151464d915f3a4a1e57bbc04ad0ae0b1388d | [
"Ruby",
"ISC",
"MIT"
] | 1 | 2019-06-02T15:09:59.000Z | 2019-06-02T15:09:59.000Z | Source/GB_AxB_alloc.c | sntran/GraphBLAS | ce36e9bb1bb4962111ac969804a995ff1c3ce396 | [
"DOC"
] | null | null | null | //------------------------------------------------------------------------------
// GB_AxB_alloc: estimate nnz(C) and allocate C for C=A*B or C=A'*B
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2019, All Rights Reserved.
// http://suitesparse.com See GraphBLAS/Doc/License.txt for license.
//------------------------------------------------------------------------------
// parallel: this function will remain sequential.
// parallelism will be done in GB_AxB_parallel.
// Does not log an error; returns GrB_SUCCESS, GrB_OUT_OF_MEMORY, or GrB_PANIC.
#include "GB.h"
GrB_Info GB_AxB_alloc // estimate nnz(C) and allocate C for C=A*B
(
GrB_Matrix *Chandle, // output matrix
const GrB_Type ctype, // type of C
const GrB_Index cvlen, // vector length of C
const GrB_Index cvdim, // # of vectors of C
const GrB_Matrix M, // optional mask
const GrB_Matrix A, // input matrix A (transposed for dot product)
const GrB_Matrix B, // input matrix B
const bool numeric, // if true, allocate A->x, else A->x is NULL
const int64_t rough_guess // rough estimate of nnz(C)
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
GB_Context Context = NULL ;
ASSERT (Chandle != NULL) ;
ASSERT (*Chandle == NULL) ;
ASSERT_OK_OR_NULL (GB_check (M, "M for alloc C=A*B", GB0)) ;
ASSERT_OK (GB_check (A, "A for alloc C=A*B", GB0)) ;
ASSERT_OK (GB_check (B, "B for alloc C=A*B", GB0)) ;
GrB_Info info ;
//--------------------------------------------------------------------------
// determine hypersparsity
//--------------------------------------------------------------------------
// C is hypersparse if any of A, B, and/or M are hypersparse
bool C_is_hyper = (cvdim > 1) &&
(A->is_hyper || B->is_hyper || (M != NULL && M->is_hyper)) ;
//--------------------------------------------------------------------------
// estimate nnz(C)
//--------------------------------------------------------------------------
int64_t cnz_guess ;
if (M == NULL)
{
// estimate the number of nonzeros for C=A*B (or C=A'*B for dot
// product method)
cnz_guess = rough_guess ;
// abnzmax = cvlen * cvdim, but check for overflow
GrB_Index abnzmax ;
if (GB_Index_multiply (&abnzmax, cvlen, cvdim))
{
// only do this if cvlen * cvdim does not overflow
cnz_guess = GB_IMIN (cnz_guess, abnzmax) ;
}
}
else
{
// the pattern of C is a subset of the mask
cnz_guess = GB_NNZ (M) ;
}
// add one to ensure cnz_guess > 0, and (cnz < C->nzmax) will always hold
// if cnz_guess is exact.
cnz_guess++ ;
//--------------------------------------------------------------------------
// allocate C
//--------------------------------------------------------------------------
// Use CSC format but this is ignored for now. If hypersparse, assume C or
// as many non-empty columns of B (compute it if it has not already been
// computed). This is an upper bound. If nnz(B(:,j)) is zero, this
// implies nnz(C(:,j)) will be zero, but not the other way around. That
// is, nnz(B(:,j)) can be > 0, but if nnz(A(k,j)) == 0 for all k for
// entries B(k,j), then nnz(C(:,j)) will be zero.
// C->p and C->h are allocated but not initialized.
int64_t cplen = -1 ;
if (C_is_hyper)
{
if (B->nvec_nonempty < 0)
{
B->nvec_nonempty = GB_nvec_nonempty (B, NULL) ;
}
cplen = B->nvec_nonempty ;
}
GB_CREATE (Chandle, ctype, cvlen, cvdim, GB_Ap_malloc, true,
GB_SAME_HYPER_AS (C_is_hyper), B->hyper_ratio, cplen,
cnz_guess, numeric, NULL) ;
return (info) ;
}
| 35.701754 | 80 | 0.466339 |
8f5aeef8b19c15d4a59c3b19a16ae1d840566aa9 | 1,665 | h | C | Applications/PineBoard/PBAXFeatureManager.h | lechium/tvOS124Headers | 11d1b56dd4c0ffd88b9eac43f87a5fd6f7228475 | [
"MIT"
] | 4 | 2019-08-27T18:03:47.000Z | 2021-09-18T06:29:00.000Z | Applications/PineBoard/PBAXFeatureManager.h | lechium/tvOS124Headers | 11d1b56dd4c0ffd88b9eac43f87a5fd6f7228475 | [
"MIT"
] | null | null | null | Applications/PineBoard/PBAXFeatureManager.h | lechium/tvOS124Headers | 11d1b56dd4c0ffd88b9eac43f87a5fd6f7228475 | [
"MIT"
] | null | null | null | //
// Generated by class-dump 3.5 (64 bit).
//
// class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2013 by Steve Nygard.
//
#import "NSObject.h"
@class NSArray, NSTimer, TVSStateMachine;
@interface PBAXFeatureManager : NSObject
{
NSArray *_pendingUpdates; // 8 = 0x8
CDUnknownBlockType _updateCompletion; // 16 = 0x10
NSTimer *_updateTimer; // 24 = 0x18
TVSStateMachine *_stateMachine; // 32 = 0x20
}
+ (id)sharedInstance; // IMP=0x00000001000bc0e0
@property(retain, nonatomic) TVSStateMachine *stateMachine; // @synthesize stateMachine=_stateMachine;
@property(copy, nonatomic) NSTimer *updateTimer; // @synthesize updateTimer=_updateTimer;
@property(copy, nonatomic) CDUnknownBlockType updateCompletion; // @synthesize updateCompletion=_updateCompletion;
@property(copy, nonatomic) NSArray *pendingUpdates; // @synthesize pendingUpdates=_pendingUpdates;
- (void).cxx_destruct; // IMP=0x00000001000bf5d8
- (void)_cancelPendingUpdates; // IMP=0x00000001000bf490
- (void)_servicePendingUpdates; // IMP=0x00000001000bf160
- (void)_applyUpdatesWithOptions:(id)arg1 completion:(CDUnknownBlockType)arg2; // IMP=0x00000001000bf088
- (id)_updatesForConfigurationOptions:(id)arg1; // IMP=0x00000001000be164
- (id)_currentConfigOptions; // IMP=0x00000001000bdb4c
- (id)_handleSetDefaultConfiguration:(id)arg1; // IMP=0x00000001000bd878
- (id)_handleSetSingleAppConfiguration:(id)arg1; // IMP=0x00000001000bd564
- (void)_initialzeStateMachine; // IMP=0x00000001000bcfc0
- (void)updateWithConfiguration:(id)arg1; // IMP=0x00000001000bcec8
- (_Bool)handleAXShortcutEvent; // IMP=0x00000001000bc1ec
- (id)init; // IMP=0x00000001000bc194
@end
| 42.692308 | 114 | 0.772973 |
eb0e0a19acb37cd841fdb68d352b888671ca1205 | 1,844 | h | C | System/Library/Frameworks/HealthKit.framework/HKTaskServerProxyProvider.h | lechium/tvOS144Headers | e22dcf52662ae03002e3a6d57273f54e74013cb0 | [
"MIT"
] | 2 | 2021-04-15T10:50:21.000Z | 2021-08-19T19:00:09.000Z | System/Library/Frameworks/HealthKit.framework/HKTaskServerProxyProvider.h | lechium/tvOS144Headers | e22dcf52662ae03002e3a6d57273f54e74013cb0 | [
"MIT"
] | null | null | null | System/Library/Frameworks/HealthKit.framework/HKTaskServerProxyProvider.h | lechium/tvOS144Headers | e22dcf52662ae03002e3a6d57273f54e74013cb0 | [
"MIT"
] | null | null | null | /*
* This header is generated by classdump-dyld 1.5
* on Wednesday, April 14, 2021 at 2:26:13 PM Mountain Standard Time
* Operating System: Version 14.4 (Build 18K802)
* Image Source: /System/Library/Frameworks/HealthKit.framework/HealthKit
* classdump-dyld is licensed under GPLv3, Copyright © 2013-2016 by Elias Limneos. Updated by Kevin Bradley.
*/
#import <HealthKit/HKProxyProvider.h>
@class NSUUID, NSURL, HKTaskConfiguration, NSString;
@interface HKTaskServerProxyProvider : HKProxyProvider {
NSUUID* _taskUUID;
NSURL* _pluginURL;
HKTaskConfiguration* _taskConfiguration;
}
@property (nonatomic,copy,readonly) NSUUID * taskUUID; //@synthesize taskUUID=_taskUUID - In the implementation block
@property (nonatomic,copy,readonly) NSString * taskIdentifier;
@property (nonatomic,copy) NSURL * pluginURL; //@synthesize pluginURL=_pluginURL - In the implementation block
@property (copy) HKTaskConfiguration * taskConfiguration; //@synthesize taskConfiguration=_taskConfiguration - In the implementation block
-(NSString *)taskIdentifier;
-(NSUUID *)taskUUID;
-(id)initWithHealthStore:(id)arg1 taskIdentifier:(id)arg2 exportedObject:(id)arg3 taskUUID:(id)arg4 ;
-(void)setTaskConfiguration:(HKTaskConfiguration *)arg1 ;
-(HKTaskConfiguration *)taskConfiguration;
-(void)fetchProxyServiceEndpointForIdentifier:(id)arg1 healthStore:(id)arg2 endpointHandler:(/*^block*/id)arg3 errorHandler:(/*^block*/id)arg4 ;
-(id)initWithHealthStore:(id)arg1 taskIdentifier:(id)arg2 exportedObject:(id)arg3 exportedInterface:(id)arg4 remoteInterface:(id)arg5 taskUUID:(id)arg6 ;
-(NSURL *)pluginURL;
-(void)setPluginURL:(NSURL *)arg1 ;
@end
| 51.222222 | 156 | 0.700651 |
5bc264e5b684166c1b4033a3e7009c410323fbcc | 285 | h | C | mlfe/optimizers/impl/cuda/kernel/adadelta.h | shi510/mlfe | aec8d52ddb54ce6f6e00a6515d7023ffba9d02f0 | [
"MIT"
] | 13 | 2019-01-23T11:21:01.000Z | 2021-06-20T18:25:11.000Z | mlfe/optimizers/impl/cuda/kernel/adadelta.h | shi510/mlfe | aec8d52ddb54ce6f6e00a6515d7023ffba9d02f0 | [
"MIT"
] | null | null | null | mlfe/optimizers/impl/cuda/kernel/adadelta.h | shi510/mlfe | aec8d52ddb54ce6f6e00a6515d7023ffba9d02f0 | [
"MIT"
] | 4 | 2018-01-08T12:40:22.000Z | 2021-12-02T05:23:36.000Z | #pragma once
#include <cctype>
#include <cstddef>
namespace mlfe{
namespace cuda_kernel{
template <typename T>
void adadelta(const int size, T *w, const T *dw, T *grad_hist,
T *acc_hist, const T lr, const T momentum, const T eps);
} // namespace cuda_kernel
} // namespace mlfe
| 20.357143 | 62 | 0.715789 |
df3ba3c6f176cb13cbfd7bda61acfadb25ec5594 | 2,058 | c | C | d/azha/rift/hell1.c | guille-valencia/shadowgate | a5c63b535e50020b58435d6fbb5b4f60d8f25639 | [
"MIT"
] | 1 | 2021-06-10T00:35:51.000Z | 2021-06-10T00:35:51.000Z | d/azha/rift/hell1.c | guille-valencia/shadowgate | a5c63b535e50020b58435d6fbb5b4f60d8f25639 | [
"MIT"
] | null | null | null | d/azha/rift/hell1.c | guille-valencia/shadowgate | a5c63b535e50020b58435d6fbb5b4f60d8f25639 | [
"MIT"
] | null | null | null | // This area is to be DEATH to anyone that enters it. there is NO way out.
// if you are a wiz reading this... LET THEM DIE
// Love. G.
#include <std.h>
inherit ROOM;
string *exts;
void create(){
::create();
set_name("The flames of hell");
set_short("%^RED%^Your own personal corner of HELL%^RESET%^");
set_long(
"%^BOLD%^%^RED%^All around you all you see are the endless flames of the pits of hell as the reach for you, tauntingly floating away never burning you just slowly roasting you alive.%^RESET%^"
);
set_smell("default", "you smell %^RED%^FIRE AND BRIMSTONE%^RESET%^");
set_listen("default", "You hear the eternal %^RED%^FLAMES%^RESET%^");
set_property("indoors", 1);
set_property("no teleport", 1);
set_property("light", 2);
set_property("night light", 2);
set_exits( ([
"north" : "/d/azha/rift/hell2.c",
"south" : "/d/azha/rift/hell2.c",
"east" : "/d/azha/rift/hell2.c",
"west" : "/d/azha/rift/hell2.c",
"northwest" : "/d/azha/rift/hell2.c",
"southwest" : "/d/azha/rift/hell2.c",
"southeast" : "/d/azha/rift/hell2.c",
"northeast" : "/d/azha/rift/hell2.c",
]) );
set_heart_beat(8);
}
void init(){
::init();
add_action("peer", "peer");
add_action("peer", "lpeer");
exts = ETP->query_exits();
if(member_array("rift",exts) != -1){
TO->remove_exit("rift");
tell_room(ETP, "%^RED%^%^BOLD%^As you step through the portal, you realize that somthing has gone very wrong as the portal closes before you leaving you in this corner of hell.");
}
}
int peer(){
write("%^RED%^All you see is FLAME");
return 1;
}
void heart_beat(){
object *starved;
int i,j;
starved = all_living(TO);
j = sizeof(starved);
for(i=0;i<j;i++){
tell_object(starved[i],"%^BOLD%^%^RED%^The flames lick at your flesh torturing you endlessly.");
if(!wizardp(starved[i])){
starved[i]->do_damage(starved[i]->return_target_limb(),roll_dice(5,5));
starved[i]->add_attacker(TO);
starved[i]->continue_attack();
}
}
}
| 31.661538 | 198 | 0.621963 |
8a1e684f493cd67190de7abeec09fa7ef6b6bbbd | 604 | c | C | tests/2.c | yali4/fantasy | 055b033f277f43a412ffdf7180a1142939376361 | [
"MIT"
] | 2 | 2016-11-02T05:19:43.000Z | 2016-11-02T16:43:10.000Z | tests/2.c | yali4/fantasy | 055b033f277f43a412ffdf7180a1142939376361 | [
"MIT"
] | null | null | null | tests/2.c | yali4/fantasy | 055b033f277f43a412ffdf7180a1142939376361 | [
"MIT"
] | null | null | null | int yali = 1;
int nbr = 2;
/*
func plus(int first = 1, int second = 5)
{
if ( first > 1 && second > 5 )
{
//return -1;
}
if ( first > 1 )
{
if ( second > 5 )
{
return 31;
}
}
return 1;
}
arr data = [1,3,5,7,9];
data.reverse();
data.isOnline;
data.userCount = 10;
int result = plus(2, 6);
func sum(arg1 = 10, arg2 = 10)
{
if ( arg1 > 250 )
{
return arg1 * arg1;
}
return arg1 + arg2 + arg1;
}
int first = sum();
int second = sum(100, 100);
int third = sum(250, 250);
int fourth = sum(500, 500);
*/ | 12.583333 | 40 | 0.471854 |
3d788dfce6f25f5d8c5293c693b3d0fbd6b77f02 | 1,370 | h | C | deps/exokit-bindings/leapmotion/include/leapmotion.h | Fierent/exokit | 59bc83e122b9b9b6a210987d7a21832253adc5b5 | [
"MIT"
] | 2 | 2018-10-15T18:32:39.000Z | 2019-04-10T09:06:03.000Z | deps/exokit-bindings/leapmotion/include/leapmotion.h | Fierent/exokit | 59bc83e122b9b9b6a210987d7a21832253adc5b5 | [
"MIT"
] | 1 | 2019-03-19T10:04:14.000Z | 2019-03-20T19:14:20.000Z | deps/exokit-bindings/leapmotion/include/leapmotion.h | Fierent/exokit | 59bc83e122b9b9b6a210987d7a21832253adc5b5 | [
"MIT"
] | 1 | 2019-03-18T05:07:07.000Z | 2019-03-18T05:07:07.000Z | #ifndef _LEAPMOTION_H_
#define _LEAPMOTION_H_
#include <v8.h>
#include <node.h>
#include <nan/nan.h>
#include <defines.h>
#include <Leap.h>
#include <LeapMath.h>
#include <cstring>
using namespace v8;
using namespace node;
namespace lm {
class ListenerImpl : public Leap::Listener {
public:
virtual void onInit(const Leap::Controller&);
virtual void onConnect(const Leap::Controller&);
virtual void onDisconnect(const Leap::Controller&);
virtual void onExit(const Leap::Controller&);
virtual void onFrame(const Leap::Controller&);
virtual void onFocusGained(const Leap::Controller&);
virtual void onFocusLost(const Leap::Controller&);
virtual void onDeviceChange(const Leap::Controller&);
virtual void onServiceConnect(const Leap::Controller&);
virtual void onServiceDisconnect(const Leap::Controller&);
virtual void onServiceChange(const Leap::Controller&);
virtual void onDeviceFailure(const Leap::Controller&);
virtual void onLogMessage(const Leap::Controller&, Leap::MessageSeverity severity, int64_t timestamp, const char* msg);
};
class LMContext : public ObjectWrap {
public:
static Handle<Object> Initialize(Isolate *isolate);
protected:
LMContext();
~LMContext();
static NAN_METHOD(New);
static NAN_METHOD(WaitGetPoses);
ListenerImpl listener;
Leap::Controller controller;
};
}
Handle<Object> makeLm();
#endif
| 25.37037 | 121 | 0.757664 |
3da233ac63e0888690180a6338b6111436b7b628 | 3,658 | h | C | include/sharded_cache.h | moeing-chain/MoeingKV | 3fa2bc3ef7e94a8abaa1b0bb0f3d372f231401c3 | [
"Apache-2.0"
] | 1 | 2021-03-18T18:01:43.000Z | 2021-03-18T18:01:43.000Z | include/sharded_cache.h | moeing-chain/MoeingKV | 3fa2bc3ef7e94a8abaa1b0bb0f3d372f231401c3 | [
"Apache-2.0"
] | null | null | null | include/sharded_cache.h | moeing-chain/MoeingKV | 3fa2bc3ef7e94a8abaa1b0bb0f3d372f231401c3 | [
"Apache-2.0"
] | 2 | 2021-11-10T05:01:17.000Z | 2021-12-25T02:21:25.000Z | #pragma once
#include <mutex>
#include <atomic>
#include "xxhash64.h"
#include "common.h"
#include "cpp-btree-1.0.1/btree_map.h"
namespace moeingkv {
// A cache with N shards. Each shard has its own mutex and allows one accessor for one time.
// With N shards, this cache can have many accessors who are accessing different shard.
// It caches the KV pairs contained in the on-disk and in-mem vaults. Each cache entry has a
// timestamp to indicate its age. When a cache shard is full, we try to find an old enough
// entry to evict.
template<int N>
class sharded_cache {
enum {
EVICT_TRY_DIST = 10,
};
struct dstr_id_time {
std::string kstr;
std::string vstr;
int64_t id;
int64_t timestamp;
};
typedef btree::btree_multimap<uint64_t, dstr_id_time> i2str_map;
struct map {
i2str_map m;
std::mutex mtx;
void lock() {
//since each access to map would not take a long time, we keep waiting here
while(!mtx.try_lock()) {/*do nothing*/}
}
void unlock() {
mtx.unlock();
}
size_t size() {
return m.size();
}
// Look up the corresponding 'str_with_id' for 'kstr'. 'key' must be short hash of 'key_str'
// Returns whether a valid 'out' is found.
bool lookup(uint64_t key, const std::string& kstr, str_with_id* out_ptr) {
lock();
bool res = false;
for(auto iter = m.find(key); iter != m.end(); iter++) {
if(iter->second.kstr == kstr) {
out_ptr->str = iter->second.vstr;
out_ptr->id = iter->second.id;
res = true;
break;
}
}
unlock();
return res;
}
// Insert a new entry to the cache or change the cached value, to keep sync with the vaults.
void add(uint64_t key, const dstr_id_time& value) {
lock();
bool found_it = false;
for(auto iter = m.find(key); iter != m.end(); iter++) {
if(iter->second.kstr == value.kstr) {
iter->second = value;
found_it = true;
break;
}
}
if(!found_it) {
m.insert(std::make_pair(key, value));
}
unlock();
}
// Start iterating from rand_key for EVICT_TRY_DIST steps to find an oldest entry and evict it
void evict_oldest(uint64_t rand_key) {
lock();
auto del_pos = m.end(); //pointing to the position for eviction
int64_t smallest_time = -1;
int dist = 0;
for(auto iter = m.lower_bound(rand_key); iter != m.end(); iter++) {
if(dist++ > EVICT_TRY_DIST) break;
if(smallest_time == -1 || smallest_time > iter->second.timestamp) {
del_pos = iter;
smallest_time = iter->second.timestamp;
}
}
if(del_pos != m.end()) {
m.erase(del_pos);
}
unlock();
}
};
public:
map map_arr[N];
int64_t timestamp;
std::atomic_ullong rand_key;
size_t shard_max_size;
void set_timestamp(int64_t t) {
timestamp = t;
}
void set_shard_max_size(size_t sz) {
shard_max_size = sz;
}
// lookup a cache entry. 'key' must be short hash of 'key_str'
bool lookup(uint64_t key, const std::string& key_str, str_with_id* out_ptr) {
rand_key.fetch_xor(key);
return map_arr[key%N].lookup(key, key_str, out_ptr);
}
// Add a new cache entry and if the shard is full, evict the oldest
void add(uint64_t key, const std::string& kstr, const std::string& vstr, int64_t id) {
auto value = dstr_id_time{.kstr=kstr, .vstr=vstr, .id=id, .timestamp=timestamp};
auto idx = key%N;
if(map_arr[idx].size() > shard_max_size) {
rand_key.store(hash(rand_key.load(), key));
map_arr[idx].evict_oldest(rand_key.load());
}
map_arr[idx].add(key, value);
}
};
//unsigned long milliseconds_since_epoch =
// std::chrono::system_clock::now().time_since_epoch() /
// std::chrono::milliseconds(1);
}
| 29.264 | 96 | 0.653089 |
38550a91375126852c57ecf534389e1ce23764f3 | 2,255 | c | C | src/util.c | Colortear/elf-packer | 7850e080388acc4b4176f802504b5b0e02300228 | [
"MIT"
] | 28 | 2018-03-22T02:49:33.000Z | 2022-03-30T00:55:33.000Z | src/util.c | Colortear/elf-packer | 7850e080388acc4b4176f802504b5b0e02300228 | [
"MIT"
] | null | null | null | src/util.c | Colortear/elf-packer | 7850e080388acc4b4176f802504b5b0e02300228 | [
"MIT"
] | 7 | 2019-12-29T15:05:35.000Z | 2021-11-28T04:51:06.000Z | #include "../include/packer.h"
int print_error_return(int e_flag)
{
switch(e_flag) {
case e_bad_args:
fprintf(stderr, "Incorrect number of args.\n");
break;
case e_stat_fail:
fprintf(stderr, "Stat failed.\n");
break;
case e_regfile_fail:
fprintf(stderr, "Argument not a file.\n");
break;
case e_open_fail:
fprintf(stderr, "Couldn't open file provided as argument.\n");
break;
case e_mmap_fail:
fprintf(stderr, "Couldn't map file to memory,\n");
break;
default:
fprintf(stderr, "ERROR.\n");
}
return (1);
}
void print_error(int e_flag)
{
switch(e_flag) {
case e_elf64_fail:
fprintf(stderr, "File not a 64 bit ELF format executable.\n");
break;
case e_malloc_fail:
fprintf(stderr, "Malloc failure.\n");
break;
case e_modify_fail:
fprintf(stderr, "Could not modify source file for some reason.\n");
break;
case e_write_fail:
fprintf(stderr, "Could not write to new file.\n");
break;
default:
fprintf(stderr, "ERROR.\n");
}
}
t_elf *init_t_elf(char *file, struct stat *statbuf)
{
t_elf *ret;
srand(time(0));
ret = malloc(sizeof(t_elf));
ret->e_hdr = (void *)file;
ret->p_hdr = (ret->e_hdr->e_phoff > 0) ?
((void *)(file + ret->e_hdr->e_phoff)) : NULL;
ret->s_hdr = (ret->e_hdr->e_shoff > 0) ?
((void *)(file + ret->e_hdr->e_shoff)) : NULL;
ret->new_entry = 0;
ret->encrypt_addr = 0;
ret->encrypt_off = 0;
ret->enc_key = gen_key();
ret->section_size = 0;
ret->file_size = statbuf->st_size;
ret->in_file = 0;
ret->payload = NULL;
ret->payload_size = load_size;
ret->file_ptr = file;
return ret;
}
int write_file(t_elf *bin)
{
int fd;
int flags;
int ret;
ret = 1;
if (bin->in_file == 1)
flags = (O_RDWR | O_CREAT);
else
flags = (O_WRONLY | O_CREAT | O_APPEND);
if ((fd = open(NEW_FILE, flags, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) == -1)
ret = 0;
else if (ret) {
if (bin->in_file == 1 && write(fd, bin->file_ptr, bin->file_size) == -1)
ret = 0;
else if (write(fd, bin->file_ptr, bin->file_size) == -1 ||
write(fd, bin->payload, bin->payload_size) == -1)
ret = 0;
}
if (ret)
close(fd);
return (ret);
}
void destruct(t_elf *bin)
{
if (bin) {
free(bin->payload);
free(bin);
}
}
| 21.893204 | 89 | 0.627938 |
e1b76cc244578911698a9ab94eeb8e8d44bc0ba9 | 1,658 | c | C | 83-deleteDuplicates/83-deleteDuplicates/main.c | SmallElephant/leetcode_Swift | 995c0989950bd1fdb1414355ee4c7c31bd9abac0 | [
"MIT"
] | 3 | 2018-09-22T11:38:23.000Z | 2019-01-03T11:44:37.000Z | 83-deleteDuplicates/83-deleteDuplicates/main.c | SmallElephant/leetcode_Swift | 995c0989950bd1fdb1414355ee4c7c31bd9abac0 | [
"MIT"
] | null | null | null | 83-deleteDuplicates/83-deleteDuplicates/main.c | SmallElephant/leetcode_Swift | 995c0989950bd1fdb1414355ee4c7c31bd9abac0 | [
"MIT"
] | null | null | null | //
// main.c
// 83-deleteDuplicates
//
// Created by FlyElephant on 2017/9/11.
// Copyright © 2017年 FlyElephant. All rights reserved.
//
#include <stdio.h>
#include <stdbool.h>
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode {
int val;
struct ListNode *next;
};
struct ListNode* deleteDuplicates(struct ListNode* head) {
struct ListNode *node = NULL;
struct ListNode **tail = &node;
while (head != NULL) {
*tail = head;
while (head != NULL && head->next != NULL && head->val == (head->next)->val) {
head = head->next;
}
head = head->next;
tail = &((*tail)->next);
if (head == NULL) {
*tail = NULL;
}
}
return node;
}
int main(int argc, const char * argv[]) {
// insert code here...
printf("Hello, World!\n");
struct ListNode node1 = { .val = 3, .next = NULL};
struct ListNode node2 = { .val = 2, .next = &node1};
struct ListNode node3 = { .val = 2, .next = &node2};
struct ListNode node4 = { .val = 1, .next = &node3};
struct ListNode node5 = { .val = 1, .next = &node4};
struct ListNode *head = deleteDuplicates(&node5);
while (head != NULL) {
printf("当前的head的值:%d\n",head->val);
head = head->next;
}
// struct ListNode node4 = { .val = 1, .next = NULL};
// struct ListNode node5 = { .val = 1, .next = &node4};
// struct ListNode *head = deleteDuplicates(&node5);
// while (head != NULL) {
// printf("当前的head的值:%d\n",head->val);
// head = head->next;
// }
return 0;
}
| 25.90625 | 86 | 0.548854 |
071320d3f7f5e617b26520119d0c6f207d152835 | 6,592 | h | C | getic/UiEnhancer.h | circinusX1/getic3d | a9c54c977f2f4fef8bc3a5f91f9d8e99684e5eb5 | [
"BSD-4-Clause"
] | null | null | null | getic/UiEnhancer.h | circinusX1/getic3d | a9c54c977f2f4fef8bc3a5f91f9d8e99684e5eb5 | [
"BSD-4-Clause"
] | 1 | 2020-09-01T15:02:02.000Z | 2020-09-01T16:11:07.000Z | getic/UiEnhancer.h | circinusX1/getic3d | a9c54c977f2f4fef8bc3a5f91f9d8e99684e5eb5 | [
"BSD-4-Clause"
] | 1 | 2020-09-08T19:14:57.000Z | 2020-09-08T19:14:57.000Z | // UiEnhancer.h: interface for the UiEnhancer class.
//
//////////////////////////////////////////////////////////////////////
#ifndef __UIENHANCER_H__
#define __UIENHANCER_H__
#include "ColorButon.h"
#include <set>
using namespace std;
#define WM_REDRAW_DLG (WM_USER+1238)
#define WM_POST_WM_INITDIALOG (WM_USER+1239)
class C_Rebar : public CReBar
{
// Construction
public:
C_Rebar(){};
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(C_Rebar)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~C_Rebar(){
TRACE("~C_Rebar()");
};
// Generated message map functions
protected:
//{{AFX_MSG(C_Rebar)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
class C_ToolBar : public CToolBar
{
// Construction
public:
C_ToolBar(){};
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(C_ToolBar)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~C_ToolBar(){};
// Generated message map functions
protected:
//{{AFX_MSG(C_ToolBar)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
class C_HeaderCtrl : public CHeaderCtrl
{
// Construction
public:
C_HeaderCtrl(){};
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(C_HeaderCtrl)
protected:
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~C_HeaderCtrl(){};
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
// Generated message map functions
protected:
//{{AFX_MSG(C_HeaderCtrl)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
class TabDlgSel;
class C_TabCtrl : public CTabCtrl
{
// Construction
public:
friend class TabDlgSel;// for vc7
C_TabCtrl(){};
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(C_TabCtrl)
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~C_TabCtrl(){};
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
// Generated message map functions
protected:
//{{AFX_MSG(C_TabCtrl)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnNcPaint();
//}}AFX_MSG
public:
DECLARE_MESSAGE_MAP()
};
class C_Menu : public CMenu
{
// Construction
public:
C_Menu(){};
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(C_Menu)
//}}AFX_VIRTUAL
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
// virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
// Implementation
public:
virtual ~C_Menu(){
TRACE("~C_Menu()");
};
// Generated message map functions
protected:
//{{AFX_MSG(C_Menu)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
};
class C_Static : public CStatic
{
// Construction
public:
C_Static();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(C_Static)
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~C_Static();
// Generated message map functions
protected:
//{{AFX_MSG(C_Static)
afx_msg HBRUSH CtlColor(CDC* pDC, size_t nCtlColor);
afx_msg void OnPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
// for VC Stupid stupid 7------------------------------------------------------------
class DlgGameItem;
class CDlgCompilerPath;
class DlgTriggerItem;
class SceItem;
//-----------------------------------------------------------------------------------
class CBaseDlg : public CDialog
{
// Construction
public:
friend class DlgGameItem;
friend class CDlgCompilerPath;
CBaseDlg(const char* lpszTemplateName, CWnd* pParentWnd = NULL):CDialog(lpszTemplateName, pParentWnd),_dirty(0),_updatingCtrls(1),_itmType(0),_pCurItem(0){};
CBaseDlg(size_t nIDTemplate, CWnd* pParentWnd = NULL):CDialog(nIDTemplate, pParentWnd ),_dirty(0),_updatingCtrls(0),_itmType(0),_pCurItem(0){};
void DisableAllCtrls();
// Dialog Data
//{{AFX_DATA(CBaseDlg)
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
virtual BOOL OnInitDialog();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CBaseDlg)
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
// Generated message map functions
//{{AFX_MSG(CBaseDlg)
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, size_t nCtlColor);
afx_msg void OnNcPaint();
afx_msg void OnShowWindow(BOOL bShow, size_t nStatus);
//}}AFX_MSG
LRESULT OnRedraw(WPARAM, LPARAM);
LRESULT OnPostInitDialog(WPARAM, LPARAM);
virtual void Dirty();
virtual void OnAction(){};
virtual BOOL IsRetreiveBlocked();
BOOL OnCmdMsg(size_t nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
void SetItmType(size_t iType){_itmType=iType;}
size_t ItemType(){return _itmType;}
virtual void Update(SceItem* pItem,int selCount=1){
};
virtual void Retreive(SceItem* pItem,int selCount=1){
};
virtual void BlockBarUpdate(){_updatingCtrls=TRUE;};
virtual BOOL IsDlgVisible(){return FALSE;}
virtual void Show(BOOL){};
virtual BOOL CanShowDetDlg(){return 1;};
BOOL _dirty;
public:
void ClearDirtyIDs(){_touchedIDs.clear();};
DECLARE_MESSAGE_MAP()
C_Static _allstats;
set<size_t> _touchedIDs;
BOOL _updatingCtrls;
size_t _itmType;
SceItem* _pCurItem;
};
#ifdef _SKINNY
typedef C_TabCtrl C_TABCTRL;
typedef C_HeaderCtrl C_HEADERCTRL;
typedef C_ToolBar C_TOOLBAR;
typedef C_Rebar C_REBAR;
typedef CBaseDlg CBASEDLG;
#else
typedef CTabCtrl C_TABCTRL;
typedef CHeaderCtrl C_HEADERCTRL;
typedef CToolBar C_TOOLBAR;
typedef CReBar C_REBAR;
typedef CBaseDlg CBASEDLG ;
#endif
#endif // !__UIENHANCER_H__
| 21.973333 | 162 | 0.645176 |
fd22ce5a52c3bdf0ce842e1b01b868b3e8a53b1f | 1,021 | h | C | src/config/utils.h | odeke-em/bud | 3b468213f392b52251d9ea238e27f4e118fc65ce | [
"MIT",
"Unlicense"
] | 310 | 2015-01-01T17:20:54.000Z | 2021-08-23T14:38:26.000Z | src/config/utils.h | odeke-em/bud | 3b468213f392b52251d9ea238e27f4e118fc65ce | [
"MIT",
"Unlicense"
] | 52 | 2015-01-01T17:05:03.000Z | 2018-12-10T07:15:51.000Z | src/config/utils.h | odeke-em/bud | 3b468213f392b52251d9ea238e27f4e118fc65ce | [
"MIT",
"Unlicense"
] | 23 | 2015-03-15T06:32:13.000Z | 2018-10-29T20:28:32.000Z | #ifndef SRC_CONFIG_UTILS_H_
#define SRC_CONFIG_UTILS_H_
#include "openssl/bio.h"
#include "openssl/x509.h"
#include "parson.h"
#include "src/config.h"
#include "src/common.h"
int bud_context_use_certificate_chain(bud_context_t* ctx, BIO *in);
int bud_config_verify_cert(int status, X509_STORE_CTX* s);
bud_config_balance_t bud_config_balance_to_enum(const char* balance);
bud_error_t bud_config_load_file(bud_config_t* config,
const char* path,
const char** out);
void bud_config_load_addr(JSON_Object* obj,
bud_config_addr_t* addr);
bud_error_t bud_config_load_ca_arr(X509_STORE** store,
const JSON_Array* ca);
bud_error_t bud_config_load_ca_file(X509_STORE** store,
const char* filename);
bud_error_t bud_config_verify_all_strings(const JSON_Array* npn,
const char* name);
#endif /* SRC_CONFIG_UTILS_H_ */
| 34.033333 | 69 | 0.648384 |
b85ddb18092239077213937066005fba7e30e7d1 | 232 | h | C | Demos/Braintree-Demo/Demo Use Case View Controllers/One Touch/BraintreeDemoOneTouchDemoViewController.h | mickeyreiss/braintree_ios | 773d6c90dd8a9f2230bfc5e0ffe10d64de09d52f | [
"MIT"
] | 1 | 2015-09-21T01:11:03.000Z | 2015-09-21T01:11:03.000Z | Demos/Braintree-Demo/Demo Use Case View Controllers/One Touch/BraintreeDemoOneTouchDemoViewController.h | Pretz/braintree_ios | d105da3bce798098ac1d90b43004b25f07fcbda9 | [
"MIT"
] | 2 | 2021-05-20T20:02:28.000Z | 2021-11-04T21:44:30.000Z | Demos/Braintree-Demo/Demo Use Case View Controllers/One Touch/BraintreeDemoOneTouchDemoViewController.h | Pretz/braintree_ios | d105da3bce798098ac1d90b43004b25f07fcbda9 | [
"MIT"
] | null | null | null | #import <UIKit/UIKit.h>
@class Braintree;
@interface BraintreeDemoOneTouchDemoViewController : UIViewController
- (instancetype)initWithBraintree:(Braintree *)braintree completion:(void (^)(NSString *nonce))completionBlock;
@end
| 25.777778 | 111 | 0.806034 |
fc0ba8af8ad71baf0c809c34ec4366bc0d53f4b1 | 137,445 | h | C | win-client/include/ProtocolBuffer/IM.Message.pb.h | playbar/TeamTalk | 0c04a1bf4ba0a0884666addf360f10460d1f44a7 | [
"Apache-2.0"
] | null | null | null | win-client/include/ProtocolBuffer/IM.Message.pb.h | playbar/TeamTalk | 0c04a1bf4ba0a0884666addf360f10460d1f44a7 | [
"Apache-2.0"
] | null | null | null | win-client/include/ProtocolBuffer/IM.Message.pb.h | playbar/TeamTalk | 0c04a1bf4ba0a0884666addf360f10460d1f44a7 | [
"Apache-2.0"
] | null | null | null | // Generated by the protocol buffer compiler. DO NOT EDIT!
// source: IM.Message.proto
#ifndef PROTOBUF_IM_2eMessage_2eproto__INCLUDED
#define PROTOBUF_IM_2eMessage_2eproto__INCLUDED
#include <string>
#include <google/protobuf/stubs/common.h>
#if GOOGLE_PROTOBUF_VERSION < 2006000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 2006001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/message_lite.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include "IM.BaseDefine.pb.h"
// @@protoc_insertion_point(includes)
namespace IM {
namespace Message {
// Internal implementation detail -- do not call these.
void protobuf_AddDesc_IM_2eMessage_2eproto();
void protobuf_AssignDesc_IM_2eMessage_2eproto();
void protobuf_ShutdownFile_IM_2eMessage_2eproto();
class IMMsgData;
class IMMsgDataAck;
class IMMsgDataReadAck;
class IMMsgDataReadNotify;
class IMClientTimeReq;
class IMClientTimeRsp;
class IMUnreadMsgCntReq;
class IMUnreadMsgCntRsp;
class IMGetMsgListReq;
class IMGetMsgListRsp;
class IMGetLatestMsgIdReq;
class IMGetLatestMsgIdRsp;
class IMGetMsgByIdReq;
class IMGetMsgByIdRsp;
// ===================================================================
class IMMsgData : public ::google::protobuf::MessageLite {
public:
IMMsgData();
virtual ~IMMsgData();
IMMsgData(const IMMsgData& from);
inline IMMsgData& operator=(const IMMsgData& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMMsgData& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMMsgData* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMMsgData* other);
// implements Message ----------------------------------------------
IMMsgData* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMMsgData& from);
void MergeFrom(const IMMsgData& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required uint32 from_user_id = 1;
inline bool has_from_user_id() const;
inline void clear_from_user_id();
static const int kFromUserIdFieldNumber = 1;
inline ::google::protobuf::uint32 from_user_id() const;
inline void set_from_user_id(::google::protobuf::uint32 value);
// required uint32 to_session_id = 2;
inline bool has_to_session_id() const;
inline void clear_to_session_id();
static const int kToSessionIdFieldNumber = 2;
inline ::google::protobuf::uint32 to_session_id() const;
inline void set_to_session_id(::google::protobuf::uint32 value);
// required uint32 msg_id = 3;
inline bool has_msg_id() const;
inline void clear_msg_id();
static const int kMsgIdFieldNumber = 3;
inline ::google::protobuf::uint32 msg_id() const;
inline void set_msg_id(::google::protobuf::uint32 value);
// required uint32 create_time = 4;
inline bool has_create_time() const;
inline void clear_create_time();
static const int kCreateTimeFieldNumber = 4;
inline ::google::protobuf::uint32 create_time() const;
inline void set_create_time(::google::protobuf::uint32 value);
// required .IM.BaseDefine.MsgType msg_type = 5;
inline bool has_msg_type() const;
inline void clear_msg_type();
static const int kMsgTypeFieldNumber = 5;
inline ::IM::BaseDefine::MsgType msg_type() const;
inline void set_msg_type(::IM::BaseDefine::MsgType value);
// required bytes msg_data = 6;
inline bool has_msg_data() const;
inline void clear_msg_data();
static const int kMsgDataFieldNumber = 6;
inline const ::std::string& msg_data() const;
inline void set_msg_data(const ::std::string& value);
inline void set_msg_data(const char* value);
inline void set_msg_data(const void* value, size_t size);
inline ::std::string* mutable_msg_data();
inline ::std::string* release_msg_data();
inline void set_allocated_msg_data(::std::string* msg_data);
// optional bytes attach_data = 20;
inline bool has_attach_data() const;
inline void clear_attach_data();
static const int kAttachDataFieldNumber = 20;
inline const ::std::string& attach_data() const;
inline void set_attach_data(const ::std::string& value);
inline void set_attach_data(const char* value);
inline void set_attach_data(const void* value, size_t size);
inline ::std::string* mutable_attach_data();
inline ::std::string* release_attach_data();
inline void set_allocated_attach_data(::std::string* attach_data);
// @@protoc_insertion_point(class_scope:IM.Message.IMMsgData)
private:
inline void set_has_from_user_id();
inline void clear_has_from_user_id();
inline void set_has_to_session_id();
inline void clear_has_to_session_id();
inline void set_has_msg_id();
inline void clear_has_msg_id();
inline void set_has_create_time();
inline void clear_has_create_time();
inline void set_has_msg_type();
inline void clear_has_msg_type();
inline void set_has_msg_data();
inline void clear_has_msg_data();
inline void set_has_attach_data();
inline void clear_has_attach_data();
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
::google::protobuf::uint32 from_user_id_;
::google::protobuf::uint32 to_session_id_;
::google::protobuf::uint32 msg_id_;
::google::protobuf::uint32 create_time_;
::std::string* msg_data_;
::std::string* attach_data_;
int msg_type_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMMsgData* default_instance_;
};
// -------------------------------------------------------------------
class IMMsgDataAck : public ::google::protobuf::MessageLite {
public:
IMMsgDataAck();
virtual ~IMMsgDataAck();
IMMsgDataAck(const IMMsgDataAck& from);
inline IMMsgDataAck& operator=(const IMMsgDataAck& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMMsgDataAck& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMMsgDataAck* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMMsgDataAck* other);
// implements Message ----------------------------------------------
IMMsgDataAck* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMMsgDataAck& from);
void MergeFrom(const IMMsgDataAck& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required uint32 user_id = 1;
inline bool has_user_id() const;
inline void clear_user_id();
static const int kUserIdFieldNumber = 1;
inline ::google::protobuf::uint32 user_id() const;
inline void set_user_id(::google::protobuf::uint32 value);
// required uint32 session_id = 2;
inline bool has_session_id() const;
inline void clear_session_id();
static const int kSessionIdFieldNumber = 2;
inline ::google::protobuf::uint32 session_id() const;
inline void set_session_id(::google::protobuf::uint32 value);
// required uint32 msg_id = 3;
inline bool has_msg_id() const;
inline void clear_msg_id();
static const int kMsgIdFieldNumber = 3;
inline ::google::protobuf::uint32 msg_id() const;
inline void set_msg_id(::google::protobuf::uint32 value);
// required .IM.BaseDefine.SessionType session_type = 4;
inline bool has_session_type() const;
inline void clear_session_type();
static const int kSessionTypeFieldNumber = 4;
inline ::IM::BaseDefine::SessionType session_type() const;
inline void set_session_type(::IM::BaseDefine::SessionType value);
// @@protoc_insertion_point(class_scope:IM.Message.IMMsgDataAck)
private:
inline void set_has_user_id();
inline void clear_has_user_id();
inline void set_has_session_id();
inline void clear_has_session_id();
inline void set_has_msg_id();
inline void clear_has_msg_id();
inline void set_has_session_type();
inline void clear_has_session_type();
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
::google::protobuf::uint32 user_id_;
::google::protobuf::uint32 session_id_;
::google::protobuf::uint32 msg_id_;
int session_type_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMMsgDataAck* default_instance_;
};
// -------------------------------------------------------------------
class IMMsgDataReadAck : public ::google::protobuf::MessageLite {
public:
IMMsgDataReadAck();
virtual ~IMMsgDataReadAck();
IMMsgDataReadAck(const IMMsgDataReadAck& from);
inline IMMsgDataReadAck& operator=(const IMMsgDataReadAck& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMMsgDataReadAck& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMMsgDataReadAck* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMMsgDataReadAck* other);
// implements Message ----------------------------------------------
IMMsgDataReadAck* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMMsgDataReadAck& from);
void MergeFrom(const IMMsgDataReadAck& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required uint32 user_id = 1;
inline bool has_user_id() const;
inline void clear_user_id();
static const int kUserIdFieldNumber = 1;
inline ::google::protobuf::uint32 user_id() const;
inline void set_user_id(::google::protobuf::uint32 value);
// required uint32 session_id = 2;
inline bool has_session_id() const;
inline void clear_session_id();
static const int kSessionIdFieldNumber = 2;
inline ::google::protobuf::uint32 session_id() const;
inline void set_session_id(::google::protobuf::uint32 value);
// required uint32 msg_id = 3;
inline bool has_msg_id() const;
inline void clear_msg_id();
static const int kMsgIdFieldNumber = 3;
inline ::google::protobuf::uint32 msg_id() const;
inline void set_msg_id(::google::protobuf::uint32 value);
// required .IM.BaseDefine.SessionType session_type = 4;
inline bool has_session_type() const;
inline void clear_session_type();
static const int kSessionTypeFieldNumber = 4;
inline ::IM::BaseDefine::SessionType session_type() const;
inline void set_session_type(::IM::BaseDefine::SessionType value);
// @@protoc_insertion_point(class_scope:IM.Message.IMMsgDataReadAck)
private:
inline void set_has_user_id();
inline void clear_has_user_id();
inline void set_has_session_id();
inline void clear_has_session_id();
inline void set_has_msg_id();
inline void clear_has_msg_id();
inline void set_has_session_type();
inline void clear_has_session_type();
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
::google::protobuf::uint32 user_id_;
::google::protobuf::uint32 session_id_;
::google::protobuf::uint32 msg_id_;
int session_type_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMMsgDataReadAck* default_instance_;
};
// -------------------------------------------------------------------
class IMMsgDataReadNotify : public ::google::protobuf::MessageLite {
public:
IMMsgDataReadNotify();
virtual ~IMMsgDataReadNotify();
IMMsgDataReadNotify(const IMMsgDataReadNotify& from);
inline IMMsgDataReadNotify& operator=(const IMMsgDataReadNotify& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMMsgDataReadNotify& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMMsgDataReadNotify* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMMsgDataReadNotify* other);
// implements Message ----------------------------------------------
IMMsgDataReadNotify* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMMsgDataReadNotify& from);
void MergeFrom(const IMMsgDataReadNotify& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required uint32 user_id = 1;
inline bool has_user_id() const;
inline void clear_user_id();
static const int kUserIdFieldNumber = 1;
inline ::google::protobuf::uint32 user_id() const;
inline void set_user_id(::google::protobuf::uint32 value);
// required uint32 session_id = 2;
inline bool has_session_id() const;
inline void clear_session_id();
static const int kSessionIdFieldNumber = 2;
inline ::google::protobuf::uint32 session_id() const;
inline void set_session_id(::google::protobuf::uint32 value);
// required uint32 msg_id = 3;
inline bool has_msg_id() const;
inline void clear_msg_id();
static const int kMsgIdFieldNumber = 3;
inline ::google::protobuf::uint32 msg_id() const;
inline void set_msg_id(::google::protobuf::uint32 value);
// required .IM.BaseDefine.SessionType session_type = 4;
inline bool has_session_type() const;
inline void clear_session_type();
static const int kSessionTypeFieldNumber = 4;
inline ::IM::BaseDefine::SessionType session_type() const;
inline void set_session_type(::IM::BaseDefine::SessionType value);
// @@protoc_insertion_point(class_scope:IM.Message.IMMsgDataReadNotify)
private:
inline void set_has_user_id();
inline void clear_has_user_id();
inline void set_has_session_id();
inline void clear_has_session_id();
inline void set_has_msg_id();
inline void clear_has_msg_id();
inline void set_has_session_type();
inline void clear_has_session_type();
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
::google::protobuf::uint32 user_id_;
::google::protobuf::uint32 session_id_;
::google::protobuf::uint32 msg_id_;
int session_type_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMMsgDataReadNotify* default_instance_;
};
// -------------------------------------------------------------------
class IMClientTimeReq : public ::google::protobuf::MessageLite {
public:
IMClientTimeReq();
virtual ~IMClientTimeReq();
IMClientTimeReq(const IMClientTimeReq& from);
inline IMClientTimeReq& operator=(const IMClientTimeReq& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMClientTimeReq& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMClientTimeReq* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMClientTimeReq* other);
// implements Message ----------------------------------------------
IMClientTimeReq* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMClientTimeReq& from);
void MergeFrom(const IMClientTimeReq& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// @@protoc_insertion_point(class_scope:IM.Message.IMClientTimeReq)
private:
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMClientTimeReq* default_instance_;
};
// -------------------------------------------------------------------
class IMClientTimeRsp : public ::google::protobuf::MessageLite {
public:
IMClientTimeRsp();
virtual ~IMClientTimeRsp();
IMClientTimeRsp(const IMClientTimeRsp& from);
inline IMClientTimeRsp& operator=(const IMClientTimeRsp& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMClientTimeRsp& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMClientTimeRsp* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMClientTimeRsp* other);
// implements Message ----------------------------------------------
IMClientTimeRsp* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMClientTimeRsp& from);
void MergeFrom(const IMClientTimeRsp& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required uint32 server_time = 1;
inline bool has_server_time() const;
inline void clear_server_time();
static const int kServerTimeFieldNumber = 1;
inline ::google::protobuf::uint32 server_time() const;
inline void set_server_time(::google::protobuf::uint32 value);
// @@protoc_insertion_point(class_scope:IM.Message.IMClientTimeRsp)
private:
inline void set_has_server_time();
inline void clear_has_server_time();
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
::google::protobuf::uint32 server_time_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMClientTimeRsp* default_instance_;
};
// -------------------------------------------------------------------
class IMUnreadMsgCntReq : public ::google::protobuf::MessageLite {
public:
IMUnreadMsgCntReq();
virtual ~IMUnreadMsgCntReq();
IMUnreadMsgCntReq(const IMUnreadMsgCntReq& from);
inline IMUnreadMsgCntReq& operator=(const IMUnreadMsgCntReq& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMUnreadMsgCntReq& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMUnreadMsgCntReq* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMUnreadMsgCntReq* other);
// implements Message ----------------------------------------------
IMUnreadMsgCntReq* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMUnreadMsgCntReq& from);
void MergeFrom(const IMUnreadMsgCntReq& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required uint32 user_id = 1;
inline bool has_user_id() const;
inline void clear_user_id();
static const int kUserIdFieldNumber = 1;
inline ::google::protobuf::uint32 user_id() const;
inline void set_user_id(::google::protobuf::uint32 value);
// optional bytes attach_data = 20;
inline bool has_attach_data() const;
inline void clear_attach_data();
static const int kAttachDataFieldNumber = 20;
inline const ::std::string& attach_data() const;
inline void set_attach_data(const ::std::string& value);
inline void set_attach_data(const char* value);
inline void set_attach_data(const void* value, size_t size);
inline ::std::string* mutable_attach_data();
inline ::std::string* release_attach_data();
inline void set_allocated_attach_data(::std::string* attach_data);
// @@protoc_insertion_point(class_scope:IM.Message.IMUnreadMsgCntReq)
private:
inline void set_has_user_id();
inline void clear_has_user_id();
inline void set_has_attach_data();
inline void clear_has_attach_data();
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
::std::string* attach_data_;
::google::protobuf::uint32 user_id_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMUnreadMsgCntReq* default_instance_;
};
// -------------------------------------------------------------------
class IMUnreadMsgCntRsp : public ::google::protobuf::MessageLite {
public:
IMUnreadMsgCntRsp();
virtual ~IMUnreadMsgCntRsp();
IMUnreadMsgCntRsp(const IMUnreadMsgCntRsp& from);
inline IMUnreadMsgCntRsp& operator=(const IMUnreadMsgCntRsp& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMUnreadMsgCntRsp& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMUnreadMsgCntRsp* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMUnreadMsgCntRsp* other);
// implements Message ----------------------------------------------
IMUnreadMsgCntRsp* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMUnreadMsgCntRsp& from);
void MergeFrom(const IMUnreadMsgCntRsp& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required uint32 user_id = 1;
inline bool has_user_id() const;
inline void clear_user_id();
static const int kUserIdFieldNumber = 1;
inline ::google::protobuf::uint32 user_id() const;
inline void set_user_id(::google::protobuf::uint32 value);
// required uint32 total_cnt = 2;
inline bool has_total_cnt() const;
inline void clear_total_cnt();
static const int kTotalCntFieldNumber = 2;
inline ::google::protobuf::uint32 total_cnt() const;
inline void set_total_cnt(::google::protobuf::uint32 value);
// repeated .IM.BaseDefine.UnreadInfo unreadinfo_list = 3;
inline int unreadinfo_list_size() const;
inline void clear_unreadinfo_list();
static const int kUnreadinfoListFieldNumber = 3;
inline const ::IM::BaseDefine::UnreadInfo& unreadinfo_list(int index) const;
inline ::IM::BaseDefine::UnreadInfo* mutable_unreadinfo_list(int index);
inline ::IM::BaseDefine::UnreadInfo* add_unreadinfo_list();
inline const ::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::UnreadInfo >&
unreadinfo_list() const;
inline ::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::UnreadInfo >*
mutable_unreadinfo_list();
// optional bytes attach_data = 20;
inline bool has_attach_data() const;
inline void clear_attach_data();
static const int kAttachDataFieldNumber = 20;
inline const ::std::string& attach_data() const;
inline void set_attach_data(const ::std::string& value);
inline void set_attach_data(const char* value);
inline void set_attach_data(const void* value, size_t size);
inline ::std::string* mutable_attach_data();
inline ::std::string* release_attach_data();
inline void set_allocated_attach_data(::std::string* attach_data);
// @@protoc_insertion_point(class_scope:IM.Message.IMUnreadMsgCntRsp)
private:
inline void set_has_user_id();
inline void clear_has_user_id();
inline void set_has_total_cnt();
inline void clear_has_total_cnt();
inline void set_has_attach_data();
inline void clear_has_attach_data();
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
::google::protobuf::uint32 user_id_;
::google::protobuf::uint32 total_cnt_;
::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::UnreadInfo > unreadinfo_list_;
::std::string* attach_data_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMUnreadMsgCntRsp* default_instance_;
};
// -------------------------------------------------------------------
class IMGetMsgListReq : public ::google::protobuf::MessageLite {
public:
IMGetMsgListReq();
virtual ~IMGetMsgListReq();
IMGetMsgListReq(const IMGetMsgListReq& from);
inline IMGetMsgListReq& operator=(const IMGetMsgListReq& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMGetMsgListReq& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMGetMsgListReq* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMGetMsgListReq* other);
// implements Message ----------------------------------------------
IMGetMsgListReq* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMGetMsgListReq& from);
void MergeFrom(const IMGetMsgListReq& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required uint32 user_id = 1;
inline bool has_user_id() const;
inline void clear_user_id();
static const int kUserIdFieldNumber = 1;
inline ::google::protobuf::uint32 user_id() const;
inline void set_user_id(::google::protobuf::uint32 value);
// required .IM.BaseDefine.SessionType session_type = 2;
inline bool has_session_type() const;
inline void clear_session_type();
static const int kSessionTypeFieldNumber = 2;
inline ::IM::BaseDefine::SessionType session_type() const;
inline void set_session_type(::IM::BaseDefine::SessionType value);
// required uint32 session_id = 3;
inline bool has_session_id() const;
inline void clear_session_id();
static const int kSessionIdFieldNumber = 3;
inline ::google::protobuf::uint32 session_id() const;
inline void set_session_id(::google::protobuf::uint32 value);
// required uint32 msg_id_begin = 4;
inline bool has_msg_id_begin() const;
inline void clear_msg_id_begin();
static const int kMsgIdBeginFieldNumber = 4;
inline ::google::protobuf::uint32 msg_id_begin() const;
inline void set_msg_id_begin(::google::protobuf::uint32 value);
// required uint32 msg_cnt = 5;
inline bool has_msg_cnt() const;
inline void clear_msg_cnt();
static const int kMsgCntFieldNumber = 5;
inline ::google::protobuf::uint32 msg_cnt() const;
inline void set_msg_cnt(::google::protobuf::uint32 value);
// optional bytes attach_data = 20;
inline bool has_attach_data() const;
inline void clear_attach_data();
static const int kAttachDataFieldNumber = 20;
inline const ::std::string& attach_data() const;
inline void set_attach_data(const ::std::string& value);
inline void set_attach_data(const char* value);
inline void set_attach_data(const void* value, size_t size);
inline ::std::string* mutable_attach_data();
inline ::std::string* release_attach_data();
inline void set_allocated_attach_data(::std::string* attach_data);
// @@protoc_insertion_point(class_scope:IM.Message.IMGetMsgListReq)
private:
inline void set_has_user_id();
inline void clear_has_user_id();
inline void set_has_session_type();
inline void clear_has_session_type();
inline void set_has_session_id();
inline void clear_has_session_id();
inline void set_has_msg_id_begin();
inline void clear_has_msg_id_begin();
inline void set_has_msg_cnt();
inline void clear_has_msg_cnt();
inline void set_has_attach_data();
inline void clear_has_attach_data();
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
::google::protobuf::uint32 user_id_;
int session_type_;
::google::protobuf::uint32 session_id_;
::google::protobuf::uint32 msg_id_begin_;
::std::string* attach_data_;
::google::protobuf::uint32 msg_cnt_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMGetMsgListReq* default_instance_;
};
// -------------------------------------------------------------------
class IMGetMsgListRsp : public ::google::protobuf::MessageLite {
public:
IMGetMsgListRsp();
virtual ~IMGetMsgListRsp();
IMGetMsgListRsp(const IMGetMsgListRsp& from);
inline IMGetMsgListRsp& operator=(const IMGetMsgListRsp& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMGetMsgListRsp& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMGetMsgListRsp* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMGetMsgListRsp* other);
// implements Message ----------------------------------------------
IMGetMsgListRsp* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMGetMsgListRsp& from);
void MergeFrom(const IMGetMsgListRsp& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required uint32 user_id = 1;
inline bool has_user_id() const;
inline void clear_user_id();
static const int kUserIdFieldNumber = 1;
inline ::google::protobuf::uint32 user_id() const;
inline void set_user_id(::google::protobuf::uint32 value);
// required .IM.BaseDefine.SessionType session_type = 2;
inline bool has_session_type() const;
inline void clear_session_type();
static const int kSessionTypeFieldNumber = 2;
inline ::IM::BaseDefine::SessionType session_type() const;
inline void set_session_type(::IM::BaseDefine::SessionType value);
// required uint32 session_id = 3;
inline bool has_session_id() const;
inline void clear_session_id();
static const int kSessionIdFieldNumber = 3;
inline ::google::protobuf::uint32 session_id() const;
inline void set_session_id(::google::protobuf::uint32 value);
// required uint32 msg_id_begin = 4;
inline bool has_msg_id_begin() const;
inline void clear_msg_id_begin();
static const int kMsgIdBeginFieldNumber = 4;
inline ::google::protobuf::uint32 msg_id_begin() const;
inline void set_msg_id_begin(::google::protobuf::uint32 value);
// repeated .IM.BaseDefine.MsgInfo msg_list = 5;
inline int msg_list_size() const;
inline void clear_msg_list();
static const int kMsgListFieldNumber = 5;
inline const ::IM::BaseDefine::MsgInfo& msg_list(int index) const;
inline ::IM::BaseDefine::MsgInfo* mutable_msg_list(int index);
inline ::IM::BaseDefine::MsgInfo* add_msg_list();
inline const ::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::MsgInfo >&
msg_list() const;
inline ::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::MsgInfo >*
mutable_msg_list();
// optional bytes attach_data = 20;
inline bool has_attach_data() const;
inline void clear_attach_data();
static const int kAttachDataFieldNumber = 20;
inline const ::std::string& attach_data() const;
inline void set_attach_data(const ::std::string& value);
inline void set_attach_data(const char* value);
inline void set_attach_data(const void* value, size_t size);
inline ::std::string* mutable_attach_data();
inline ::std::string* release_attach_data();
inline void set_allocated_attach_data(::std::string* attach_data);
// @@protoc_insertion_point(class_scope:IM.Message.IMGetMsgListRsp)
private:
inline void set_has_user_id();
inline void clear_has_user_id();
inline void set_has_session_type();
inline void clear_has_session_type();
inline void set_has_session_id();
inline void clear_has_session_id();
inline void set_has_msg_id_begin();
inline void clear_has_msg_id_begin();
inline void set_has_attach_data();
inline void clear_has_attach_data();
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
::google::protobuf::uint32 user_id_;
int session_type_;
::google::protobuf::uint32 session_id_;
::google::protobuf::uint32 msg_id_begin_;
::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::MsgInfo > msg_list_;
::std::string* attach_data_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMGetMsgListRsp* default_instance_;
};
// -------------------------------------------------------------------
class IMGetLatestMsgIdReq : public ::google::protobuf::MessageLite {
public:
IMGetLatestMsgIdReq();
virtual ~IMGetLatestMsgIdReq();
IMGetLatestMsgIdReq(const IMGetLatestMsgIdReq& from);
inline IMGetLatestMsgIdReq& operator=(const IMGetLatestMsgIdReq& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMGetLatestMsgIdReq& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMGetLatestMsgIdReq* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMGetLatestMsgIdReq* other);
// implements Message ----------------------------------------------
IMGetLatestMsgIdReq* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMGetLatestMsgIdReq& from);
void MergeFrom(const IMGetLatestMsgIdReq& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required uint32 user_id = 1;
inline bool has_user_id() const;
inline void clear_user_id();
static const int kUserIdFieldNumber = 1;
inline ::google::protobuf::uint32 user_id() const;
inline void set_user_id(::google::protobuf::uint32 value);
// required .IM.BaseDefine.SessionType session_type = 2;
inline bool has_session_type() const;
inline void clear_session_type();
static const int kSessionTypeFieldNumber = 2;
inline ::IM::BaseDefine::SessionType session_type() const;
inline void set_session_type(::IM::BaseDefine::SessionType value);
// required uint32 session_id = 3;
inline bool has_session_id() const;
inline void clear_session_id();
static const int kSessionIdFieldNumber = 3;
inline ::google::protobuf::uint32 session_id() const;
inline void set_session_id(::google::protobuf::uint32 value);
// optional bytes attach_data = 20;
inline bool has_attach_data() const;
inline void clear_attach_data();
static const int kAttachDataFieldNumber = 20;
inline const ::std::string& attach_data() const;
inline void set_attach_data(const ::std::string& value);
inline void set_attach_data(const char* value);
inline void set_attach_data(const void* value, size_t size);
inline ::std::string* mutable_attach_data();
inline ::std::string* release_attach_data();
inline void set_allocated_attach_data(::std::string* attach_data);
// @@protoc_insertion_point(class_scope:IM.Message.IMGetLatestMsgIdReq)
private:
inline void set_has_user_id();
inline void clear_has_user_id();
inline void set_has_session_type();
inline void clear_has_session_type();
inline void set_has_session_id();
inline void clear_has_session_id();
inline void set_has_attach_data();
inline void clear_has_attach_data();
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
::google::protobuf::uint32 user_id_;
int session_type_;
::std::string* attach_data_;
::google::protobuf::uint32 session_id_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMGetLatestMsgIdReq* default_instance_;
};
// -------------------------------------------------------------------
class IMGetLatestMsgIdRsp : public ::google::protobuf::MessageLite {
public:
IMGetLatestMsgIdRsp();
virtual ~IMGetLatestMsgIdRsp();
IMGetLatestMsgIdRsp(const IMGetLatestMsgIdRsp& from);
inline IMGetLatestMsgIdRsp& operator=(const IMGetLatestMsgIdRsp& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMGetLatestMsgIdRsp& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMGetLatestMsgIdRsp* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMGetLatestMsgIdRsp* other);
// implements Message ----------------------------------------------
IMGetLatestMsgIdRsp* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMGetLatestMsgIdRsp& from);
void MergeFrom(const IMGetLatestMsgIdRsp& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required uint32 user_id = 1;
inline bool has_user_id() const;
inline void clear_user_id();
static const int kUserIdFieldNumber = 1;
inline ::google::protobuf::uint32 user_id() const;
inline void set_user_id(::google::protobuf::uint32 value);
// required .IM.BaseDefine.SessionType session_type = 2;
inline bool has_session_type() const;
inline void clear_session_type();
static const int kSessionTypeFieldNumber = 2;
inline ::IM::BaseDefine::SessionType session_type() const;
inline void set_session_type(::IM::BaseDefine::SessionType value);
// required uint32 session_id = 3;
inline bool has_session_id() const;
inline void clear_session_id();
static const int kSessionIdFieldNumber = 3;
inline ::google::protobuf::uint32 session_id() const;
inline void set_session_id(::google::protobuf::uint32 value);
// required uint32 latest_msg_id = 4;
inline bool has_latest_msg_id() const;
inline void clear_latest_msg_id();
static const int kLatestMsgIdFieldNumber = 4;
inline ::google::protobuf::uint32 latest_msg_id() const;
inline void set_latest_msg_id(::google::protobuf::uint32 value);
// optional bytes attach_data = 20;
inline bool has_attach_data() const;
inline void clear_attach_data();
static const int kAttachDataFieldNumber = 20;
inline const ::std::string& attach_data() const;
inline void set_attach_data(const ::std::string& value);
inline void set_attach_data(const char* value);
inline void set_attach_data(const void* value, size_t size);
inline ::std::string* mutable_attach_data();
inline ::std::string* release_attach_data();
inline void set_allocated_attach_data(::std::string* attach_data);
// @@protoc_insertion_point(class_scope:IM.Message.IMGetLatestMsgIdRsp)
private:
inline void set_has_user_id();
inline void clear_has_user_id();
inline void set_has_session_type();
inline void clear_has_session_type();
inline void set_has_session_id();
inline void clear_has_session_id();
inline void set_has_latest_msg_id();
inline void clear_has_latest_msg_id();
inline void set_has_attach_data();
inline void clear_has_attach_data();
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
::google::protobuf::uint32 user_id_;
int session_type_;
::google::protobuf::uint32 session_id_;
::google::protobuf::uint32 latest_msg_id_;
::std::string* attach_data_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMGetLatestMsgIdRsp* default_instance_;
};
// -------------------------------------------------------------------
class IMGetMsgByIdReq : public ::google::protobuf::MessageLite {
public:
IMGetMsgByIdReq();
virtual ~IMGetMsgByIdReq();
IMGetMsgByIdReq(const IMGetMsgByIdReq& from);
inline IMGetMsgByIdReq& operator=(const IMGetMsgByIdReq& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMGetMsgByIdReq& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMGetMsgByIdReq* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMGetMsgByIdReq* other);
// implements Message ----------------------------------------------
IMGetMsgByIdReq* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMGetMsgByIdReq& from);
void MergeFrom(const IMGetMsgByIdReq& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required uint32 user_id = 1;
inline bool has_user_id() const;
inline void clear_user_id();
static const int kUserIdFieldNumber = 1;
inline ::google::protobuf::uint32 user_id() const;
inline void set_user_id(::google::protobuf::uint32 value);
// required .IM.BaseDefine.SessionType session_type = 2;
inline bool has_session_type() const;
inline void clear_session_type();
static const int kSessionTypeFieldNumber = 2;
inline ::IM::BaseDefine::SessionType session_type() const;
inline void set_session_type(::IM::BaseDefine::SessionType value);
// required uint32 session_id = 3;
inline bool has_session_id() const;
inline void clear_session_id();
static const int kSessionIdFieldNumber = 3;
inline ::google::protobuf::uint32 session_id() const;
inline void set_session_id(::google::protobuf::uint32 value);
// repeated uint32 msg_id_list = 4;
inline int msg_id_list_size() const;
inline void clear_msg_id_list();
static const int kMsgIdListFieldNumber = 4;
inline ::google::protobuf::uint32 msg_id_list(int index) const;
inline void set_msg_id_list(int index, ::google::protobuf::uint32 value);
inline void add_msg_id_list(::google::protobuf::uint32 value);
inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >&
msg_id_list() const;
inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >*
mutable_msg_id_list();
// optional bytes attach_data = 20;
inline bool has_attach_data() const;
inline void clear_attach_data();
static const int kAttachDataFieldNumber = 20;
inline const ::std::string& attach_data() const;
inline void set_attach_data(const ::std::string& value);
inline void set_attach_data(const char* value);
inline void set_attach_data(const void* value, size_t size);
inline ::std::string* mutable_attach_data();
inline ::std::string* release_attach_data();
inline void set_allocated_attach_data(::std::string* attach_data);
// @@protoc_insertion_point(class_scope:IM.Message.IMGetMsgByIdReq)
private:
inline void set_has_user_id();
inline void clear_has_user_id();
inline void set_has_session_type();
inline void clear_has_session_type();
inline void set_has_session_id();
inline void clear_has_session_id();
inline void set_has_attach_data();
inline void clear_has_attach_data();
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
::google::protobuf::uint32 user_id_;
int session_type_;
::google::protobuf::RepeatedField< ::google::protobuf::uint32 > msg_id_list_;
::std::string* attach_data_;
::google::protobuf::uint32 session_id_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMGetMsgByIdReq* default_instance_;
};
// -------------------------------------------------------------------
class IMGetMsgByIdRsp : public ::google::protobuf::MessageLite {
public:
IMGetMsgByIdRsp();
virtual ~IMGetMsgByIdRsp();
IMGetMsgByIdRsp(const IMGetMsgByIdRsp& from);
inline IMGetMsgByIdRsp& operator=(const IMGetMsgByIdRsp& from) {
CopyFrom(from);
return *this;
}
inline const ::std::string& unknown_fields() const {
return _unknown_fields_;
}
inline ::std::string* mutable_unknown_fields() {
return &_unknown_fields_;
}
static const IMGetMsgByIdRsp& default_instance();
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
// Returns the internal default instance pointer. This function can
// return NULL thus should not be used by the user. This is intended
// for Protobuf internal code. Please use default_instance() declared
// above instead.
static inline const IMGetMsgByIdRsp* internal_default_instance() {
return default_instance_;
}
#endif
void Swap(IMGetMsgByIdRsp* other);
// implements Message ----------------------------------------------
IMGetMsgByIdRsp* New() const;
void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);
void CopyFrom(const IMGetMsgByIdRsp& from);
void MergeFrom(const IMGetMsgByIdRsp& from);
void Clear();
bool IsInitialized() const;
int ByteSize() const;
bool MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
void DiscardUnknownFields();
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
void SetCachedSize(int size) const;
public:
::std::string GetTypeName() const;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
// required uint32 user_id = 1;
inline bool has_user_id() const;
inline void clear_user_id();
static const int kUserIdFieldNumber = 1;
inline ::google::protobuf::uint32 user_id() const;
inline void set_user_id(::google::protobuf::uint32 value);
// required .IM.BaseDefine.SessionType session_type = 2;
inline bool has_session_type() const;
inline void clear_session_type();
static const int kSessionTypeFieldNumber = 2;
inline ::IM::BaseDefine::SessionType session_type() const;
inline void set_session_type(::IM::BaseDefine::SessionType value);
// required uint32 session_id = 3;
inline bool has_session_id() const;
inline void clear_session_id();
static const int kSessionIdFieldNumber = 3;
inline ::google::protobuf::uint32 session_id() const;
inline void set_session_id(::google::protobuf::uint32 value);
// repeated .IM.BaseDefine.MsgInfo msg_list = 4;
inline int msg_list_size() const;
inline void clear_msg_list();
static const int kMsgListFieldNumber = 4;
inline const ::IM::BaseDefine::MsgInfo& msg_list(int index) const;
inline ::IM::BaseDefine::MsgInfo* mutable_msg_list(int index);
inline ::IM::BaseDefine::MsgInfo* add_msg_list();
inline const ::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::MsgInfo >&
msg_list() const;
inline ::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::MsgInfo >*
mutable_msg_list();
// optional bytes attach_data = 20;
inline bool has_attach_data() const;
inline void clear_attach_data();
static const int kAttachDataFieldNumber = 20;
inline const ::std::string& attach_data() const;
inline void set_attach_data(const ::std::string& value);
inline void set_attach_data(const char* value);
inline void set_attach_data(const void* value, size_t size);
inline ::std::string* mutable_attach_data();
inline ::std::string* release_attach_data();
inline void set_allocated_attach_data(::std::string* attach_data);
// @@protoc_insertion_point(class_scope:IM.Message.IMGetMsgByIdRsp)
private:
inline void set_has_user_id();
inline void clear_has_user_id();
inline void set_has_session_type();
inline void clear_has_session_type();
inline void set_has_session_id();
inline void clear_has_session_id();
inline void set_has_attach_data();
inline void clear_has_attach_data();
::std::string _unknown_fields_;
::google::protobuf::uint32 _has_bits_[1];
mutable int _cached_size_;
::google::protobuf::uint32 user_id_;
int session_type_;
::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::MsgInfo > msg_list_;
::std::string* attach_data_;
::google::protobuf::uint32 session_id_;
#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
friend void protobuf_AddDesc_IM_2eMessage_2eproto_impl();
#else
friend void protobuf_AddDesc_IM_2eMessage_2eproto();
#endif
friend void protobuf_AssignDesc_IM_2eMessage_2eproto();
friend void protobuf_ShutdownFile_IM_2eMessage_2eproto();
void InitAsDefaultInstance();
static IMGetMsgByIdRsp* default_instance_;
};
// ===================================================================
// ===================================================================
// IMMsgData
// required uint32 from_user_id = 1;
inline bool IMMsgData::has_from_user_id() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void IMMsgData::set_has_from_user_id() {
_has_bits_[0] |= 0x00000001u;
}
inline void IMMsgData::clear_has_from_user_id() {
_has_bits_[0] &= ~0x00000001u;
}
inline void IMMsgData::clear_from_user_id() {
from_user_id_ = 0u;
clear_has_from_user_id();
}
inline ::google::protobuf::uint32 IMMsgData::from_user_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgData.from_user_id)
return from_user_id_;
}
inline void IMMsgData::set_from_user_id(::google::protobuf::uint32 value) {
set_has_from_user_id();
from_user_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgData.from_user_id)
}
// required uint32 to_session_id = 2;
inline bool IMMsgData::has_to_session_id() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void IMMsgData::set_has_to_session_id() {
_has_bits_[0] |= 0x00000002u;
}
inline void IMMsgData::clear_has_to_session_id() {
_has_bits_[0] &= ~0x00000002u;
}
inline void IMMsgData::clear_to_session_id() {
to_session_id_ = 0u;
clear_has_to_session_id();
}
inline ::google::protobuf::uint32 IMMsgData::to_session_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgData.to_session_id)
return to_session_id_;
}
inline void IMMsgData::set_to_session_id(::google::protobuf::uint32 value) {
set_has_to_session_id();
to_session_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgData.to_session_id)
}
// required uint32 msg_id = 3;
inline bool IMMsgData::has_msg_id() const {
return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void IMMsgData::set_has_msg_id() {
_has_bits_[0] |= 0x00000004u;
}
inline void IMMsgData::clear_has_msg_id() {
_has_bits_[0] &= ~0x00000004u;
}
inline void IMMsgData::clear_msg_id() {
msg_id_ = 0u;
clear_has_msg_id();
}
inline ::google::protobuf::uint32 IMMsgData::msg_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgData.msg_id)
return msg_id_;
}
inline void IMMsgData::set_msg_id(::google::protobuf::uint32 value) {
set_has_msg_id();
msg_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgData.msg_id)
}
// required uint32 create_time = 4;
inline bool IMMsgData::has_create_time() const {
return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void IMMsgData::set_has_create_time() {
_has_bits_[0] |= 0x00000008u;
}
inline void IMMsgData::clear_has_create_time() {
_has_bits_[0] &= ~0x00000008u;
}
inline void IMMsgData::clear_create_time() {
create_time_ = 0u;
clear_has_create_time();
}
inline ::google::protobuf::uint32 IMMsgData::create_time() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgData.create_time)
return create_time_;
}
inline void IMMsgData::set_create_time(::google::protobuf::uint32 value) {
set_has_create_time();
create_time_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgData.create_time)
}
// required .IM.BaseDefine.MsgType msg_type = 5;
inline bool IMMsgData::has_msg_type() const {
return (_has_bits_[0] & 0x00000010u) != 0;
}
inline void IMMsgData::set_has_msg_type() {
_has_bits_[0] |= 0x00000010u;
}
inline void IMMsgData::clear_has_msg_type() {
_has_bits_[0] &= ~0x00000010u;
}
inline void IMMsgData::clear_msg_type() {
msg_type_ = 1;
clear_has_msg_type();
}
inline ::IM::BaseDefine::MsgType IMMsgData::msg_type() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgData.msg_type)
return static_cast< ::IM::BaseDefine::MsgType >(msg_type_);
}
inline void IMMsgData::set_msg_type(::IM::BaseDefine::MsgType value) {
assert(::IM::BaseDefine::MsgType_IsValid(value));
set_has_msg_type();
msg_type_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgData.msg_type)
}
// required bytes msg_data = 6;
inline bool IMMsgData::has_msg_data() const {
return (_has_bits_[0] & 0x00000020u) != 0;
}
inline void IMMsgData::set_has_msg_data() {
_has_bits_[0] |= 0x00000020u;
}
inline void IMMsgData::clear_has_msg_data() {
_has_bits_[0] &= ~0x00000020u;
}
inline void IMMsgData::clear_msg_data() {
if (msg_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
msg_data_->clear();
}
clear_has_msg_data();
}
inline const ::std::string& IMMsgData::msg_data() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgData.msg_data)
return *msg_data_;
}
inline void IMMsgData::set_msg_data(const ::std::string& value) {
set_has_msg_data();
if (msg_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
msg_data_ = new ::std::string;
}
msg_data_->assign(value);
// @@protoc_insertion_point(field_set:IM.Message.IMMsgData.msg_data)
}
inline void IMMsgData::set_msg_data(const char* value) {
set_has_msg_data();
if (msg_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
msg_data_ = new ::std::string;
}
msg_data_->assign(value);
// @@protoc_insertion_point(field_set_char:IM.Message.IMMsgData.msg_data)
}
inline void IMMsgData::set_msg_data(const void* value, size_t size) {
set_has_msg_data();
if (msg_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
msg_data_ = new ::std::string;
}
msg_data_->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:IM.Message.IMMsgData.msg_data)
}
inline ::std::string* IMMsgData::mutable_msg_data() {
set_has_msg_data();
if (msg_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
msg_data_ = new ::std::string;
}
// @@protoc_insertion_point(field_mutable:IM.Message.IMMsgData.msg_data)
return msg_data_;
}
inline ::std::string* IMMsgData::release_msg_data() {
clear_has_msg_data();
if (msg_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
return NULL;
} else {
::std::string* temp = msg_data_;
msg_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return temp;
}
}
inline void IMMsgData::set_allocated_msg_data(::std::string* msg_data) {
if (msg_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
delete msg_data_;
}
if (msg_data) {
set_has_msg_data();
msg_data_ = msg_data;
} else {
clear_has_msg_data();
msg_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
// @@protoc_insertion_point(field_set_allocated:IM.Message.IMMsgData.msg_data)
}
// optional bytes attach_data = 20;
inline bool IMMsgData::has_attach_data() const {
return (_has_bits_[0] & 0x00000040u) != 0;
}
inline void IMMsgData::set_has_attach_data() {
_has_bits_[0] |= 0x00000040u;
}
inline void IMMsgData::clear_has_attach_data() {
_has_bits_[0] &= ~0x00000040u;
}
inline void IMMsgData::clear_attach_data() {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_->clear();
}
clear_has_attach_data();
}
inline const ::std::string& IMMsgData::attach_data() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgData.attach_data)
return *attach_data_;
}
inline void IMMsgData::set_attach_data(const ::std::string& value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set:IM.Message.IMMsgData.attach_data)
}
inline void IMMsgData::set_attach_data(const char* value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set_char:IM.Message.IMMsgData.attach_data)
}
inline void IMMsgData::set_attach_data(const void* value, size_t size) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:IM.Message.IMMsgData.attach_data)
}
inline ::std::string* IMMsgData::mutable_attach_data() {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
// @@protoc_insertion_point(field_mutable:IM.Message.IMMsgData.attach_data)
return attach_data_;
}
inline ::std::string* IMMsgData::release_attach_data() {
clear_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
return NULL;
} else {
::std::string* temp = attach_data_;
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return temp;
}
}
inline void IMMsgData::set_allocated_attach_data(::std::string* attach_data) {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
delete attach_data_;
}
if (attach_data) {
set_has_attach_data();
attach_data_ = attach_data;
} else {
clear_has_attach_data();
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
// @@protoc_insertion_point(field_set_allocated:IM.Message.IMMsgData.attach_data)
}
// -------------------------------------------------------------------
// IMMsgDataAck
// required uint32 user_id = 1;
inline bool IMMsgDataAck::has_user_id() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void IMMsgDataAck::set_has_user_id() {
_has_bits_[0] |= 0x00000001u;
}
inline void IMMsgDataAck::clear_has_user_id() {
_has_bits_[0] &= ~0x00000001u;
}
inline void IMMsgDataAck::clear_user_id() {
user_id_ = 0u;
clear_has_user_id();
}
inline ::google::protobuf::uint32 IMMsgDataAck::user_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgDataAck.user_id)
return user_id_;
}
inline void IMMsgDataAck::set_user_id(::google::protobuf::uint32 value) {
set_has_user_id();
user_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgDataAck.user_id)
}
// required uint32 session_id = 2;
inline bool IMMsgDataAck::has_session_id() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void IMMsgDataAck::set_has_session_id() {
_has_bits_[0] |= 0x00000002u;
}
inline void IMMsgDataAck::clear_has_session_id() {
_has_bits_[0] &= ~0x00000002u;
}
inline void IMMsgDataAck::clear_session_id() {
session_id_ = 0u;
clear_has_session_id();
}
inline ::google::protobuf::uint32 IMMsgDataAck::session_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgDataAck.session_id)
return session_id_;
}
inline void IMMsgDataAck::set_session_id(::google::protobuf::uint32 value) {
set_has_session_id();
session_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgDataAck.session_id)
}
// required uint32 msg_id = 3;
inline bool IMMsgDataAck::has_msg_id() const {
return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void IMMsgDataAck::set_has_msg_id() {
_has_bits_[0] |= 0x00000004u;
}
inline void IMMsgDataAck::clear_has_msg_id() {
_has_bits_[0] &= ~0x00000004u;
}
inline void IMMsgDataAck::clear_msg_id() {
msg_id_ = 0u;
clear_has_msg_id();
}
inline ::google::protobuf::uint32 IMMsgDataAck::msg_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgDataAck.msg_id)
return msg_id_;
}
inline void IMMsgDataAck::set_msg_id(::google::protobuf::uint32 value) {
set_has_msg_id();
msg_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgDataAck.msg_id)
}
// required .IM.BaseDefine.SessionType session_type = 4;
inline bool IMMsgDataAck::has_session_type() const {
return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void IMMsgDataAck::set_has_session_type() {
_has_bits_[0] |= 0x00000008u;
}
inline void IMMsgDataAck::clear_has_session_type() {
_has_bits_[0] &= ~0x00000008u;
}
inline void IMMsgDataAck::clear_session_type() {
session_type_ = 1;
clear_has_session_type();
}
inline ::IM::BaseDefine::SessionType IMMsgDataAck::session_type() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgDataAck.session_type)
return static_cast< ::IM::BaseDefine::SessionType >(session_type_);
}
inline void IMMsgDataAck::set_session_type(::IM::BaseDefine::SessionType value) {
assert(::IM::BaseDefine::SessionType_IsValid(value));
set_has_session_type();
session_type_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgDataAck.session_type)
}
// -------------------------------------------------------------------
// IMMsgDataReadAck
// required uint32 user_id = 1;
inline bool IMMsgDataReadAck::has_user_id() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void IMMsgDataReadAck::set_has_user_id() {
_has_bits_[0] |= 0x00000001u;
}
inline void IMMsgDataReadAck::clear_has_user_id() {
_has_bits_[0] &= ~0x00000001u;
}
inline void IMMsgDataReadAck::clear_user_id() {
user_id_ = 0u;
clear_has_user_id();
}
inline ::google::protobuf::uint32 IMMsgDataReadAck::user_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgDataReadAck.user_id)
return user_id_;
}
inline void IMMsgDataReadAck::set_user_id(::google::protobuf::uint32 value) {
set_has_user_id();
user_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgDataReadAck.user_id)
}
// required uint32 session_id = 2;
inline bool IMMsgDataReadAck::has_session_id() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void IMMsgDataReadAck::set_has_session_id() {
_has_bits_[0] |= 0x00000002u;
}
inline void IMMsgDataReadAck::clear_has_session_id() {
_has_bits_[0] &= ~0x00000002u;
}
inline void IMMsgDataReadAck::clear_session_id() {
session_id_ = 0u;
clear_has_session_id();
}
inline ::google::protobuf::uint32 IMMsgDataReadAck::session_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgDataReadAck.session_id)
return session_id_;
}
inline void IMMsgDataReadAck::set_session_id(::google::protobuf::uint32 value) {
set_has_session_id();
session_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgDataReadAck.session_id)
}
// required uint32 msg_id = 3;
inline bool IMMsgDataReadAck::has_msg_id() const {
return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void IMMsgDataReadAck::set_has_msg_id() {
_has_bits_[0] |= 0x00000004u;
}
inline void IMMsgDataReadAck::clear_has_msg_id() {
_has_bits_[0] &= ~0x00000004u;
}
inline void IMMsgDataReadAck::clear_msg_id() {
msg_id_ = 0u;
clear_has_msg_id();
}
inline ::google::protobuf::uint32 IMMsgDataReadAck::msg_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgDataReadAck.msg_id)
return msg_id_;
}
inline void IMMsgDataReadAck::set_msg_id(::google::protobuf::uint32 value) {
set_has_msg_id();
msg_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgDataReadAck.msg_id)
}
// required .IM.BaseDefine.SessionType session_type = 4;
inline bool IMMsgDataReadAck::has_session_type() const {
return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void IMMsgDataReadAck::set_has_session_type() {
_has_bits_[0] |= 0x00000008u;
}
inline void IMMsgDataReadAck::clear_has_session_type() {
_has_bits_[0] &= ~0x00000008u;
}
inline void IMMsgDataReadAck::clear_session_type() {
session_type_ = 1;
clear_has_session_type();
}
inline ::IM::BaseDefine::SessionType IMMsgDataReadAck::session_type() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgDataReadAck.session_type)
return static_cast< ::IM::BaseDefine::SessionType >(session_type_);
}
inline void IMMsgDataReadAck::set_session_type(::IM::BaseDefine::SessionType value) {
assert(::IM::BaseDefine::SessionType_IsValid(value));
set_has_session_type();
session_type_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgDataReadAck.session_type)
}
// -------------------------------------------------------------------
// IMMsgDataReadNotify
// required uint32 user_id = 1;
inline bool IMMsgDataReadNotify::has_user_id() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void IMMsgDataReadNotify::set_has_user_id() {
_has_bits_[0] |= 0x00000001u;
}
inline void IMMsgDataReadNotify::clear_has_user_id() {
_has_bits_[0] &= ~0x00000001u;
}
inline void IMMsgDataReadNotify::clear_user_id() {
user_id_ = 0u;
clear_has_user_id();
}
inline ::google::protobuf::uint32 IMMsgDataReadNotify::user_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgDataReadNotify.user_id)
return user_id_;
}
inline void IMMsgDataReadNotify::set_user_id(::google::protobuf::uint32 value) {
set_has_user_id();
user_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgDataReadNotify.user_id)
}
// required uint32 session_id = 2;
inline bool IMMsgDataReadNotify::has_session_id() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void IMMsgDataReadNotify::set_has_session_id() {
_has_bits_[0] |= 0x00000002u;
}
inline void IMMsgDataReadNotify::clear_has_session_id() {
_has_bits_[0] &= ~0x00000002u;
}
inline void IMMsgDataReadNotify::clear_session_id() {
session_id_ = 0u;
clear_has_session_id();
}
inline ::google::protobuf::uint32 IMMsgDataReadNotify::session_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgDataReadNotify.session_id)
return session_id_;
}
inline void IMMsgDataReadNotify::set_session_id(::google::protobuf::uint32 value) {
set_has_session_id();
session_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgDataReadNotify.session_id)
}
// required uint32 msg_id = 3;
inline bool IMMsgDataReadNotify::has_msg_id() const {
return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void IMMsgDataReadNotify::set_has_msg_id() {
_has_bits_[0] |= 0x00000004u;
}
inline void IMMsgDataReadNotify::clear_has_msg_id() {
_has_bits_[0] &= ~0x00000004u;
}
inline void IMMsgDataReadNotify::clear_msg_id() {
msg_id_ = 0u;
clear_has_msg_id();
}
inline ::google::protobuf::uint32 IMMsgDataReadNotify::msg_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgDataReadNotify.msg_id)
return msg_id_;
}
inline void IMMsgDataReadNotify::set_msg_id(::google::protobuf::uint32 value) {
set_has_msg_id();
msg_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgDataReadNotify.msg_id)
}
// required .IM.BaseDefine.SessionType session_type = 4;
inline bool IMMsgDataReadNotify::has_session_type() const {
return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void IMMsgDataReadNotify::set_has_session_type() {
_has_bits_[0] |= 0x00000008u;
}
inline void IMMsgDataReadNotify::clear_has_session_type() {
_has_bits_[0] &= ~0x00000008u;
}
inline void IMMsgDataReadNotify::clear_session_type() {
session_type_ = 1;
clear_has_session_type();
}
inline ::IM::BaseDefine::SessionType IMMsgDataReadNotify::session_type() const {
// @@protoc_insertion_point(field_get:IM.Message.IMMsgDataReadNotify.session_type)
return static_cast< ::IM::BaseDefine::SessionType >(session_type_);
}
inline void IMMsgDataReadNotify::set_session_type(::IM::BaseDefine::SessionType value) {
assert(::IM::BaseDefine::SessionType_IsValid(value));
set_has_session_type();
session_type_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMMsgDataReadNotify.session_type)
}
// -------------------------------------------------------------------
// IMClientTimeReq
// -------------------------------------------------------------------
// IMClientTimeRsp
// required uint32 server_time = 1;
inline bool IMClientTimeRsp::has_server_time() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void IMClientTimeRsp::set_has_server_time() {
_has_bits_[0] |= 0x00000001u;
}
inline void IMClientTimeRsp::clear_has_server_time() {
_has_bits_[0] &= ~0x00000001u;
}
inline void IMClientTimeRsp::clear_server_time() {
server_time_ = 0u;
clear_has_server_time();
}
inline ::google::protobuf::uint32 IMClientTimeRsp::server_time() const {
// @@protoc_insertion_point(field_get:IM.Message.IMClientTimeRsp.server_time)
return server_time_;
}
inline void IMClientTimeRsp::set_server_time(::google::protobuf::uint32 value) {
set_has_server_time();
server_time_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMClientTimeRsp.server_time)
}
// -------------------------------------------------------------------
// IMUnreadMsgCntReq
// required uint32 user_id = 1;
inline bool IMUnreadMsgCntReq::has_user_id() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void IMUnreadMsgCntReq::set_has_user_id() {
_has_bits_[0] |= 0x00000001u;
}
inline void IMUnreadMsgCntReq::clear_has_user_id() {
_has_bits_[0] &= ~0x00000001u;
}
inline void IMUnreadMsgCntReq::clear_user_id() {
user_id_ = 0u;
clear_has_user_id();
}
inline ::google::protobuf::uint32 IMUnreadMsgCntReq::user_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMUnreadMsgCntReq.user_id)
return user_id_;
}
inline void IMUnreadMsgCntReq::set_user_id(::google::protobuf::uint32 value) {
set_has_user_id();
user_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMUnreadMsgCntReq.user_id)
}
// optional bytes attach_data = 20;
inline bool IMUnreadMsgCntReq::has_attach_data() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void IMUnreadMsgCntReq::set_has_attach_data() {
_has_bits_[0] |= 0x00000002u;
}
inline void IMUnreadMsgCntReq::clear_has_attach_data() {
_has_bits_[0] &= ~0x00000002u;
}
inline void IMUnreadMsgCntReq::clear_attach_data() {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_->clear();
}
clear_has_attach_data();
}
inline const ::std::string& IMUnreadMsgCntReq::attach_data() const {
// @@protoc_insertion_point(field_get:IM.Message.IMUnreadMsgCntReq.attach_data)
return *attach_data_;
}
inline void IMUnreadMsgCntReq::set_attach_data(const ::std::string& value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set:IM.Message.IMUnreadMsgCntReq.attach_data)
}
inline void IMUnreadMsgCntReq::set_attach_data(const char* value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set_char:IM.Message.IMUnreadMsgCntReq.attach_data)
}
inline void IMUnreadMsgCntReq::set_attach_data(const void* value, size_t size) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:IM.Message.IMUnreadMsgCntReq.attach_data)
}
inline ::std::string* IMUnreadMsgCntReq::mutable_attach_data() {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
// @@protoc_insertion_point(field_mutable:IM.Message.IMUnreadMsgCntReq.attach_data)
return attach_data_;
}
inline ::std::string* IMUnreadMsgCntReq::release_attach_data() {
clear_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
return NULL;
} else {
::std::string* temp = attach_data_;
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return temp;
}
}
inline void IMUnreadMsgCntReq::set_allocated_attach_data(::std::string* attach_data) {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
delete attach_data_;
}
if (attach_data) {
set_has_attach_data();
attach_data_ = attach_data;
} else {
clear_has_attach_data();
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
// @@protoc_insertion_point(field_set_allocated:IM.Message.IMUnreadMsgCntReq.attach_data)
}
// -------------------------------------------------------------------
// IMUnreadMsgCntRsp
// required uint32 user_id = 1;
inline bool IMUnreadMsgCntRsp::has_user_id() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void IMUnreadMsgCntRsp::set_has_user_id() {
_has_bits_[0] |= 0x00000001u;
}
inline void IMUnreadMsgCntRsp::clear_has_user_id() {
_has_bits_[0] &= ~0x00000001u;
}
inline void IMUnreadMsgCntRsp::clear_user_id() {
user_id_ = 0u;
clear_has_user_id();
}
inline ::google::protobuf::uint32 IMUnreadMsgCntRsp::user_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMUnreadMsgCntRsp.user_id)
return user_id_;
}
inline void IMUnreadMsgCntRsp::set_user_id(::google::protobuf::uint32 value) {
set_has_user_id();
user_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMUnreadMsgCntRsp.user_id)
}
// required uint32 total_cnt = 2;
inline bool IMUnreadMsgCntRsp::has_total_cnt() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void IMUnreadMsgCntRsp::set_has_total_cnt() {
_has_bits_[0] |= 0x00000002u;
}
inline void IMUnreadMsgCntRsp::clear_has_total_cnt() {
_has_bits_[0] &= ~0x00000002u;
}
inline void IMUnreadMsgCntRsp::clear_total_cnt() {
total_cnt_ = 0u;
clear_has_total_cnt();
}
inline ::google::protobuf::uint32 IMUnreadMsgCntRsp::total_cnt() const {
// @@protoc_insertion_point(field_get:IM.Message.IMUnreadMsgCntRsp.total_cnt)
return total_cnt_;
}
inline void IMUnreadMsgCntRsp::set_total_cnt(::google::protobuf::uint32 value) {
set_has_total_cnt();
total_cnt_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMUnreadMsgCntRsp.total_cnt)
}
// repeated .IM.BaseDefine.UnreadInfo unreadinfo_list = 3;
inline int IMUnreadMsgCntRsp::unreadinfo_list_size() const {
return unreadinfo_list_.size();
}
inline void IMUnreadMsgCntRsp::clear_unreadinfo_list() {
unreadinfo_list_.Clear();
}
inline const ::IM::BaseDefine::UnreadInfo& IMUnreadMsgCntRsp::unreadinfo_list(int index) const {
// @@protoc_insertion_point(field_get:IM.Message.IMUnreadMsgCntRsp.unreadinfo_list)
return unreadinfo_list_.Get(index);
}
inline ::IM::BaseDefine::UnreadInfo* IMUnreadMsgCntRsp::mutable_unreadinfo_list(int index) {
// @@protoc_insertion_point(field_mutable:IM.Message.IMUnreadMsgCntRsp.unreadinfo_list)
return unreadinfo_list_.Mutable(index);
}
inline ::IM::BaseDefine::UnreadInfo* IMUnreadMsgCntRsp::add_unreadinfo_list() {
// @@protoc_insertion_point(field_add:IM.Message.IMUnreadMsgCntRsp.unreadinfo_list)
return unreadinfo_list_.Add();
}
inline const ::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::UnreadInfo >&
IMUnreadMsgCntRsp::unreadinfo_list() const {
// @@protoc_insertion_point(field_list:IM.Message.IMUnreadMsgCntRsp.unreadinfo_list)
return unreadinfo_list_;
}
inline ::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::UnreadInfo >*
IMUnreadMsgCntRsp::mutable_unreadinfo_list() {
// @@protoc_insertion_point(field_mutable_list:IM.Message.IMUnreadMsgCntRsp.unreadinfo_list)
return &unreadinfo_list_;
}
// optional bytes attach_data = 20;
inline bool IMUnreadMsgCntRsp::has_attach_data() const {
return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void IMUnreadMsgCntRsp::set_has_attach_data() {
_has_bits_[0] |= 0x00000008u;
}
inline void IMUnreadMsgCntRsp::clear_has_attach_data() {
_has_bits_[0] &= ~0x00000008u;
}
inline void IMUnreadMsgCntRsp::clear_attach_data() {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_->clear();
}
clear_has_attach_data();
}
inline const ::std::string& IMUnreadMsgCntRsp::attach_data() const {
// @@protoc_insertion_point(field_get:IM.Message.IMUnreadMsgCntRsp.attach_data)
return *attach_data_;
}
inline void IMUnreadMsgCntRsp::set_attach_data(const ::std::string& value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set:IM.Message.IMUnreadMsgCntRsp.attach_data)
}
inline void IMUnreadMsgCntRsp::set_attach_data(const char* value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set_char:IM.Message.IMUnreadMsgCntRsp.attach_data)
}
inline void IMUnreadMsgCntRsp::set_attach_data(const void* value, size_t size) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:IM.Message.IMUnreadMsgCntRsp.attach_data)
}
inline ::std::string* IMUnreadMsgCntRsp::mutable_attach_data() {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
// @@protoc_insertion_point(field_mutable:IM.Message.IMUnreadMsgCntRsp.attach_data)
return attach_data_;
}
inline ::std::string* IMUnreadMsgCntRsp::release_attach_data() {
clear_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
return NULL;
} else {
::std::string* temp = attach_data_;
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return temp;
}
}
inline void IMUnreadMsgCntRsp::set_allocated_attach_data(::std::string* attach_data) {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
delete attach_data_;
}
if (attach_data) {
set_has_attach_data();
attach_data_ = attach_data;
} else {
clear_has_attach_data();
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
// @@protoc_insertion_point(field_set_allocated:IM.Message.IMUnreadMsgCntRsp.attach_data)
}
// -------------------------------------------------------------------
// IMGetMsgListReq
// required uint32 user_id = 1;
inline bool IMGetMsgListReq::has_user_id() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void IMGetMsgListReq::set_has_user_id() {
_has_bits_[0] |= 0x00000001u;
}
inline void IMGetMsgListReq::clear_has_user_id() {
_has_bits_[0] &= ~0x00000001u;
}
inline void IMGetMsgListReq::clear_user_id() {
user_id_ = 0u;
clear_has_user_id();
}
inline ::google::protobuf::uint32 IMGetMsgListReq::user_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgListReq.user_id)
return user_id_;
}
inline void IMGetMsgListReq::set_user_id(::google::protobuf::uint32 value) {
set_has_user_id();
user_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgListReq.user_id)
}
// required .IM.BaseDefine.SessionType session_type = 2;
inline bool IMGetMsgListReq::has_session_type() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void IMGetMsgListReq::set_has_session_type() {
_has_bits_[0] |= 0x00000002u;
}
inline void IMGetMsgListReq::clear_has_session_type() {
_has_bits_[0] &= ~0x00000002u;
}
inline void IMGetMsgListReq::clear_session_type() {
session_type_ = 1;
clear_has_session_type();
}
inline ::IM::BaseDefine::SessionType IMGetMsgListReq::session_type() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgListReq.session_type)
return static_cast< ::IM::BaseDefine::SessionType >(session_type_);
}
inline void IMGetMsgListReq::set_session_type(::IM::BaseDefine::SessionType value) {
assert(::IM::BaseDefine::SessionType_IsValid(value));
set_has_session_type();
session_type_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgListReq.session_type)
}
// required uint32 session_id = 3;
inline bool IMGetMsgListReq::has_session_id() const {
return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void IMGetMsgListReq::set_has_session_id() {
_has_bits_[0] |= 0x00000004u;
}
inline void IMGetMsgListReq::clear_has_session_id() {
_has_bits_[0] &= ~0x00000004u;
}
inline void IMGetMsgListReq::clear_session_id() {
session_id_ = 0u;
clear_has_session_id();
}
inline ::google::protobuf::uint32 IMGetMsgListReq::session_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgListReq.session_id)
return session_id_;
}
inline void IMGetMsgListReq::set_session_id(::google::protobuf::uint32 value) {
set_has_session_id();
session_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgListReq.session_id)
}
// required uint32 msg_id_begin = 4;
inline bool IMGetMsgListReq::has_msg_id_begin() const {
return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void IMGetMsgListReq::set_has_msg_id_begin() {
_has_bits_[0] |= 0x00000008u;
}
inline void IMGetMsgListReq::clear_has_msg_id_begin() {
_has_bits_[0] &= ~0x00000008u;
}
inline void IMGetMsgListReq::clear_msg_id_begin() {
msg_id_begin_ = 0u;
clear_has_msg_id_begin();
}
inline ::google::protobuf::uint32 IMGetMsgListReq::msg_id_begin() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgListReq.msg_id_begin)
return msg_id_begin_;
}
inline void IMGetMsgListReq::set_msg_id_begin(::google::protobuf::uint32 value) {
set_has_msg_id_begin();
msg_id_begin_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgListReq.msg_id_begin)
}
// required uint32 msg_cnt = 5;
inline bool IMGetMsgListReq::has_msg_cnt() const {
return (_has_bits_[0] & 0x00000010u) != 0;
}
inline void IMGetMsgListReq::set_has_msg_cnt() {
_has_bits_[0] |= 0x00000010u;
}
inline void IMGetMsgListReq::clear_has_msg_cnt() {
_has_bits_[0] &= ~0x00000010u;
}
inline void IMGetMsgListReq::clear_msg_cnt() {
msg_cnt_ = 0u;
clear_has_msg_cnt();
}
inline ::google::protobuf::uint32 IMGetMsgListReq::msg_cnt() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgListReq.msg_cnt)
return msg_cnt_;
}
inline void IMGetMsgListReq::set_msg_cnt(::google::protobuf::uint32 value) {
set_has_msg_cnt();
msg_cnt_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgListReq.msg_cnt)
}
// optional bytes attach_data = 20;
inline bool IMGetMsgListReq::has_attach_data() const {
return (_has_bits_[0] & 0x00000020u) != 0;
}
inline void IMGetMsgListReq::set_has_attach_data() {
_has_bits_[0] |= 0x00000020u;
}
inline void IMGetMsgListReq::clear_has_attach_data() {
_has_bits_[0] &= ~0x00000020u;
}
inline void IMGetMsgListReq::clear_attach_data() {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_->clear();
}
clear_has_attach_data();
}
inline const ::std::string& IMGetMsgListReq::attach_data() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgListReq.attach_data)
return *attach_data_;
}
inline void IMGetMsgListReq::set_attach_data(const ::std::string& value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgListReq.attach_data)
}
inline void IMGetMsgListReq::set_attach_data(const char* value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set_char:IM.Message.IMGetMsgListReq.attach_data)
}
inline void IMGetMsgListReq::set_attach_data(const void* value, size_t size) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:IM.Message.IMGetMsgListReq.attach_data)
}
inline ::std::string* IMGetMsgListReq::mutable_attach_data() {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
// @@protoc_insertion_point(field_mutable:IM.Message.IMGetMsgListReq.attach_data)
return attach_data_;
}
inline ::std::string* IMGetMsgListReq::release_attach_data() {
clear_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
return NULL;
} else {
::std::string* temp = attach_data_;
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return temp;
}
}
inline void IMGetMsgListReq::set_allocated_attach_data(::std::string* attach_data) {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
delete attach_data_;
}
if (attach_data) {
set_has_attach_data();
attach_data_ = attach_data;
} else {
clear_has_attach_data();
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
// @@protoc_insertion_point(field_set_allocated:IM.Message.IMGetMsgListReq.attach_data)
}
// -------------------------------------------------------------------
// IMGetMsgListRsp
// required uint32 user_id = 1;
inline bool IMGetMsgListRsp::has_user_id() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void IMGetMsgListRsp::set_has_user_id() {
_has_bits_[0] |= 0x00000001u;
}
inline void IMGetMsgListRsp::clear_has_user_id() {
_has_bits_[0] &= ~0x00000001u;
}
inline void IMGetMsgListRsp::clear_user_id() {
user_id_ = 0u;
clear_has_user_id();
}
inline ::google::protobuf::uint32 IMGetMsgListRsp::user_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgListRsp.user_id)
return user_id_;
}
inline void IMGetMsgListRsp::set_user_id(::google::protobuf::uint32 value) {
set_has_user_id();
user_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgListRsp.user_id)
}
// required .IM.BaseDefine.SessionType session_type = 2;
inline bool IMGetMsgListRsp::has_session_type() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void IMGetMsgListRsp::set_has_session_type() {
_has_bits_[0] |= 0x00000002u;
}
inline void IMGetMsgListRsp::clear_has_session_type() {
_has_bits_[0] &= ~0x00000002u;
}
inline void IMGetMsgListRsp::clear_session_type() {
session_type_ = 1;
clear_has_session_type();
}
inline ::IM::BaseDefine::SessionType IMGetMsgListRsp::session_type() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgListRsp.session_type)
return static_cast< ::IM::BaseDefine::SessionType >(session_type_);
}
inline void IMGetMsgListRsp::set_session_type(::IM::BaseDefine::SessionType value) {
assert(::IM::BaseDefine::SessionType_IsValid(value));
set_has_session_type();
session_type_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgListRsp.session_type)
}
// required uint32 session_id = 3;
inline bool IMGetMsgListRsp::has_session_id() const {
return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void IMGetMsgListRsp::set_has_session_id() {
_has_bits_[0] |= 0x00000004u;
}
inline void IMGetMsgListRsp::clear_has_session_id() {
_has_bits_[0] &= ~0x00000004u;
}
inline void IMGetMsgListRsp::clear_session_id() {
session_id_ = 0u;
clear_has_session_id();
}
inline ::google::protobuf::uint32 IMGetMsgListRsp::session_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgListRsp.session_id)
return session_id_;
}
inline void IMGetMsgListRsp::set_session_id(::google::protobuf::uint32 value) {
set_has_session_id();
session_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgListRsp.session_id)
}
// required uint32 msg_id_begin = 4;
inline bool IMGetMsgListRsp::has_msg_id_begin() const {
return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void IMGetMsgListRsp::set_has_msg_id_begin() {
_has_bits_[0] |= 0x00000008u;
}
inline void IMGetMsgListRsp::clear_has_msg_id_begin() {
_has_bits_[0] &= ~0x00000008u;
}
inline void IMGetMsgListRsp::clear_msg_id_begin() {
msg_id_begin_ = 0u;
clear_has_msg_id_begin();
}
inline ::google::protobuf::uint32 IMGetMsgListRsp::msg_id_begin() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgListRsp.msg_id_begin)
return msg_id_begin_;
}
inline void IMGetMsgListRsp::set_msg_id_begin(::google::protobuf::uint32 value) {
set_has_msg_id_begin();
msg_id_begin_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgListRsp.msg_id_begin)
}
// repeated .IM.BaseDefine.MsgInfo msg_list = 5;
inline int IMGetMsgListRsp::msg_list_size() const {
return msg_list_.size();
}
inline void IMGetMsgListRsp::clear_msg_list() {
msg_list_.Clear();
}
inline const ::IM::BaseDefine::MsgInfo& IMGetMsgListRsp::msg_list(int index) const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgListRsp.msg_list)
return msg_list_.Get(index);
}
inline ::IM::BaseDefine::MsgInfo* IMGetMsgListRsp::mutable_msg_list(int index) {
// @@protoc_insertion_point(field_mutable:IM.Message.IMGetMsgListRsp.msg_list)
return msg_list_.Mutable(index);
}
inline ::IM::BaseDefine::MsgInfo* IMGetMsgListRsp::add_msg_list() {
// @@protoc_insertion_point(field_add:IM.Message.IMGetMsgListRsp.msg_list)
return msg_list_.Add();
}
inline const ::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::MsgInfo >&
IMGetMsgListRsp::msg_list() const {
// @@protoc_insertion_point(field_list:IM.Message.IMGetMsgListRsp.msg_list)
return msg_list_;
}
inline ::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::MsgInfo >*
IMGetMsgListRsp::mutable_msg_list() {
// @@protoc_insertion_point(field_mutable_list:IM.Message.IMGetMsgListRsp.msg_list)
return &msg_list_;
}
// optional bytes attach_data = 20;
inline bool IMGetMsgListRsp::has_attach_data() const {
return (_has_bits_[0] & 0x00000020u) != 0;
}
inline void IMGetMsgListRsp::set_has_attach_data() {
_has_bits_[0] |= 0x00000020u;
}
inline void IMGetMsgListRsp::clear_has_attach_data() {
_has_bits_[0] &= ~0x00000020u;
}
inline void IMGetMsgListRsp::clear_attach_data() {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_->clear();
}
clear_has_attach_data();
}
inline const ::std::string& IMGetMsgListRsp::attach_data() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgListRsp.attach_data)
return *attach_data_;
}
inline void IMGetMsgListRsp::set_attach_data(const ::std::string& value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgListRsp.attach_data)
}
inline void IMGetMsgListRsp::set_attach_data(const char* value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set_char:IM.Message.IMGetMsgListRsp.attach_data)
}
inline void IMGetMsgListRsp::set_attach_data(const void* value, size_t size) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:IM.Message.IMGetMsgListRsp.attach_data)
}
inline ::std::string* IMGetMsgListRsp::mutable_attach_data() {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
// @@protoc_insertion_point(field_mutable:IM.Message.IMGetMsgListRsp.attach_data)
return attach_data_;
}
inline ::std::string* IMGetMsgListRsp::release_attach_data() {
clear_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
return NULL;
} else {
::std::string* temp = attach_data_;
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return temp;
}
}
inline void IMGetMsgListRsp::set_allocated_attach_data(::std::string* attach_data) {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
delete attach_data_;
}
if (attach_data) {
set_has_attach_data();
attach_data_ = attach_data;
} else {
clear_has_attach_data();
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
// @@protoc_insertion_point(field_set_allocated:IM.Message.IMGetMsgListRsp.attach_data)
}
// -------------------------------------------------------------------
// IMGetLatestMsgIdReq
// required uint32 user_id = 1;
inline bool IMGetLatestMsgIdReq::has_user_id() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void IMGetLatestMsgIdReq::set_has_user_id() {
_has_bits_[0] |= 0x00000001u;
}
inline void IMGetLatestMsgIdReq::clear_has_user_id() {
_has_bits_[0] &= ~0x00000001u;
}
inline void IMGetLatestMsgIdReq::clear_user_id() {
user_id_ = 0u;
clear_has_user_id();
}
inline ::google::protobuf::uint32 IMGetLatestMsgIdReq::user_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetLatestMsgIdReq.user_id)
return user_id_;
}
inline void IMGetLatestMsgIdReq::set_user_id(::google::protobuf::uint32 value) {
set_has_user_id();
user_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetLatestMsgIdReq.user_id)
}
// required .IM.BaseDefine.SessionType session_type = 2;
inline bool IMGetLatestMsgIdReq::has_session_type() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void IMGetLatestMsgIdReq::set_has_session_type() {
_has_bits_[0] |= 0x00000002u;
}
inline void IMGetLatestMsgIdReq::clear_has_session_type() {
_has_bits_[0] &= ~0x00000002u;
}
inline void IMGetLatestMsgIdReq::clear_session_type() {
session_type_ = 1;
clear_has_session_type();
}
inline ::IM::BaseDefine::SessionType IMGetLatestMsgIdReq::session_type() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetLatestMsgIdReq.session_type)
return static_cast< ::IM::BaseDefine::SessionType >(session_type_);
}
inline void IMGetLatestMsgIdReq::set_session_type(::IM::BaseDefine::SessionType value) {
assert(::IM::BaseDefine::SessionType_IsValid(value));
set_has_session_type();
session_type_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetLatestMsgIdReq.session_type)
}
// required uint32 session_id = 3;
inline bool IMGetLatestMsgIdReq::has_session_id() const {
return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void IMGetLatestMsgIdReq::set_has_session_id() {
_has_bits_[0] |= 0x00000004u;
}
inline void IMGetLatestMsgIdReq::clear_has_session_id() {
_has_bits_[0] &= ~0x00000004u;
}
inline void IMGetLatestMsgIdReq::clear_session_id() {
session_id_ = 0u;
clear_has_session_id();
}
inline ::google::protobuf::uint32 IMGetLatestMsgIdReq::session_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetLatestMsgIdReq.session_id)
return session_id_;
}
inline void IMGetLatestMsgIdReq::set_session_id(::google::protobuf::uint32 value) {
set_has_session_id();
session_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetLatestMsgIdReq.session_id)
}
// optional bytes attach_data = 20;
inline bool IMGetLatestMsgIdReq::has_attach_data() const {
return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void IMGetLatestMsgIdReq::set_has_attach_data() {
_has_bits_[0] |= 0x00000008u;
}
inline void IMGetLatestMsgIdReq::clear_has_attach_data() {
_has_bits_[0] &= ~0x00000008u;
}
inline void IMGetLatestMsgIdReq::clear_attach_data() {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_->clear();
}
clear_has_attach_data();
}
inline const ::std::string& IMGetLatestMsgIdReq::attach_data() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetLatestMsgIdReq.attach_data)
return *attach_data_;
}
inline void IMGetLatestMsgIdReq::set_attach_data(const ::std::string& value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set:IM.Message.IMGetLatestMsgIdReq.attach_data)
}
inline void IMGetLatestMsgIdReq::set_attach_data(const char* value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set_char:IM.Message.IMGetLatestMsgIdReq.attach_data)
}
inline void IMGetLatestMsgIdReq::set_attach_data(const void* value, size_t size) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:IM.Message.IMGetLatestMsgIdReq.attach_data)
}
inline ::std::string* IMGetLatestMsgIdReq::mutable_attach_data() {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
// @@protoc_insertion_point(field_mutable:IM.Message.IMGetLatestMsgIdReq.attach_data)
return attach_data_;
}
inline ::std::string* IMGetLatestMsgIdReq::release_attach_data() {
clear_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
return NULL;
} else {
::std::string* temp = attach_data_;
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return temp;
}
}
inline void IMGetLatestMsgIdReq::set_allocated_attach_data(::std::string* attach_data) {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
delete attach_data_;
}
if (attach_data) {
set_has_attach_data();
attach_data_ = attach_data;
} else {
clear_has_attach_data();
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
// @@protoc_insertion_point(field_set_allocated:IM.Message.IMGetLatestMsgIdReq.attach_data)
}
// -------------------------------------------------------------------
// IMGetLatestMsgIdRsp
// required uint32 user_id = 1;
inline bool IMGetLatestMsgIdRsp::has_user_id() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void IMGetLatestMsgIdRsp::set_has_user_id() {
_has_bits_[0] |= 0x00000001u;
}
inline void IMGetLatestMsgIdRsp::clear_has_user_id() {
_has_bits_[0] &= ~0x00000001u;
}
inline void IMGetLatestMsgIdRsp::clear_user_id() {
user_id_ = 0u;
clear_has_user_id();
}
inline ::google::protobuf::uint32 IMGetLatestMsgIdRsp::user_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetLatestMsgIdRsp.user_id)
return user_id_;
}
inline void IMGetLatestMsgIdRsp::set_user_id(::google::protobuf::uint32 value) {
set_has_user_id();
user_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetLatestMsgIdRsp.user_id)
}
// required .IM.BaseDefine.SessionType session_type = 2;
inline bool IMGetLatestMsgIdRsp::has_session_type() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void IMGetLatestMsgIdRsp::set_has_session_type() {
_has_bits_[0] |= 0x00000002u;
}
inline void IMGetLatestMsgIdRsp::clear_has_session_type() {
_has_bits_[0] &= ~0x00000002u;
}
inline void IMGetLatestMsgIdRsp::clear_session_type() {
session_type_ = 1;
clear_has_session_type();
}
inline ::IM::BaseDefine::SessionType IMGetLatestMsgIdRsp::session_type() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetLatestMsgIdRsp.session_type)
return static_cast< ::IM::BaseDefine::SessionType >(session_type_);
}
inline void IMGetLatestMsgIdRsp::set_session_type(::IM::BaseDefine::SessionType value) {
assert(::IM::BaseDefine::SessionType_IsValid(value));
set_has_session_type();
session_type_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetLatestMsgIdRsp.session_type)
}
// required uint32 session_id = 3;
inline bool IMGetLatestMsgIdRsp::has_session_id() const {
return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void IMGetLatestMsgIdRsp::set_has_session_id() {
_has_bits_[0] |= 0x00000004u;
}
inline void IMGetLatestMsgIdRsp::clear_has_session_id() {
_has_bits_[0] &= ~0x00000004u;
}
inline void IMGetLatestMsgIdRsp::clear_session_id() {
session_id_ = 0u;
clear_has_session_id();
}
inline ::google::protobuf::uint32 IMGetLatestMsgIdRsp::session_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetLatestMsgIdRsp.session_id)
return session_id_;
}
inline void IMGetLatestMsgIdRsp::set_session_id(::google::protobuf::uint32 value) {
set_has_session_id();
session_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetLatestMsgIdRsp.session_id)
}
// required uint32 latest_msg_id = 4;
inline bool IMGetLatestMsgIdRsp::has_latest_msg_id() const {
return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void IMGetLatestMsgIdRsp::set_has_latest_msg_id() {
_has_bits_[0] |= 0x00000008u;
}
inline void IMGetLatestMsgIdRsp::clear_has_latest_msg_id() {
_has_bits_[0] &= ~0x00000008u;
}
inline void IMGetLatestMsgIdRsp::clear_latest_msg_id() {
latest_msg_id_ = 0u;
clear_has_latest_msg_id();
}
inline ::google::protobuf::uint32 IMGetLatestMsgIdRsp::latest_msg_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetLatestMsgIdRsp.latest_msg_id)
return latest_msg_id_;
}
inline void IMGetLatestMsgIdRsp::set_latest_msg_id(::google::protobuf::uint32 value) {
set_has_latest_msg_id();
latest_msg_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetLatestMsgIdRsp.latest_msg_id)
}
// optional bytes attach_data = 20;
inline bool IMGetLatestMsgIdRsp::has_attach_data() const {
return (_has_bits_[0] & 0x00000010u) != 0;
}
inline void IMGetLatestMsgIdRsp::set_has_attach_data() {
_has_bits_[0] |= 0x00000010u;
}
inline void IMGetLatestMsgIdRsp::clear_has_attach_data() {
_has_bits_[0] &= ~0x00000010u;
}
inline void IMGetLatestMsgIdRsp::clear_attach_data() {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_->clear();
}
clear_has_attach_data();
}
inline const ::std::string& IMGetLatestMsgIdRsp::attach_data() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetLatestMsgIdRsp.attach_data)
return *attach_data_;
}
inline void IMGetLatestMsgIdRsp::set_attach_data(const ::std::string& value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set:IM.Message.IMGetLatestMsgIdRsp.attach_data)
}
inline void IMGetLatestMsgIdRsp::set_attach_data(const char* value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set_char:IM.Message.IMGetLatestMsgIdRsp.attach_data)
}
inline void IMGetLatestMsgIdRsp::set_attach_data(const void* value, size_t size) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:IM.Message.IMGetLatestMsgIdRsp.attach_data)
}
inline ::std::string* IMGetLatestMsgIdRsp::mutable_attach_data() {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
// @@protoc_insertion_point(field_mutable:IM.Message.IMGetLatestMsgIdRsp.attach_data)
return attach_data_;
}
inline ::std::string* IMGetLatestMsgIdRsp::release_attach_data() {
clear_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
return NULL;
} else {
::std::string* temp = attach_data_;
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return temp;
}
}
inline void IMGetLatestMsgIdRsp::set_allocated_attach_data(::std::string* attach_data) {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
delete attach_data_;
}
if (attach_data) {
set_has_attach_data();
attach_data_ = attach_data;
} else {
clear_has_attach_data();
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
// @@protoc_insertion_point(field_set_allocated:IM.Message.IMGetLatestMsgIdRsp.attach_data)
}
// -------------------------------------------------------------------
// IMGetMsgByIdReq
// required uint32 user_id = 1;
inline bool IMGetMsgByIdReq::has_user_id() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void IMGetMsgByIdReq::set_has_user_id() {
_has_bits_[0] |= 0x00000001u;
}
inline void IMGetMsgByIdReq::clear_has_user_id() {
_has_bits_[0] &= ~0x00000001u;
}
inline void IMGetMsgByIdReq::clear_user_id() {
user_id_ = 0u;
clear_has_user_id();
}
inline ::google::protobuf::uint32 IMGetMsgByIdReq::user_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgByIdReq.user_id)
return user_id_;
}
inline void IMGetMsgByIdReq::set_user_id(::google::protobuf::uint32 value) {
set_has_user_id();
user_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgByIdReq.user_id)
}
// required .IM.BaseDefine.SessionType session_type = 2;
inline bool IMGetMsgByIdReq::has_session_type() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void IMGetMsgByIdReq::set_has_session_type() {
_has_bits_[0] |= 0x00000002u;
}
inline void IMGetMsgByIdReq::clear_has_session_type() {
_has_bits_[0] &= ~0x00000002u;
}
inline void IMGetMsgByIdReq::clear_session_type() {
session_type_ = 1;
clear_has_session_type();
}
inline ::IM::BaseDefine::SessionType IMGetMsgByIdReq::session_type() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgByIdReq.session_type)
return static_cast< ::IM::BaseDefine::SessionType >(session_type_);
}
inline void IMGetMsgByIdReq::set_session_type(::IM::BaseDefine::SessionType value) {
assert(::IM::BaseDefine::SessionType_IsValid(value));
set_has_session_type();
session_type_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgByIdReq.session_type)
}
// required uint32 session_id = 3;
inline bool IMGetMsgByIdReq::has_session_id() const {
return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void IMGetMsgByIdReq::set_has_session_id() {
_has_bits_[0] |= 0x00000004u;
}
inline void IMGetMsgByIdReq::clear_has_session_id() {
_has_bits_[0] &= ~0x00000004u;
}
inline void IMGetMsgByIdReq::clear_session_id() {
session_id_ = 0u;
clear_has_session_id();
}
inline ::google::protobuf::uint32 IMGetMsgByIdReq::session_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgByIdReq.session_id)
return session_id_;
}
inline void IMGetMsgByIdReq::set_session_id(::google::protobuf::uint32 value) {
set_has_session_id();
session_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgByIdReq.session_id)
}
// repeated uint32 msg_id_list = 4;
inline int IMGetMsgByIdReq::msg_id_list_size() const {
return msg_id_list_.size();
}
inline void IMGetMsgByIdReq::clear_msg_id_list() {
msg_id_list_.Clear();
}
inline ::google::protobuf::uint32 IMGetMsgByIdReq::msg_id_list(int index) const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgByIdReq.msg_id_list)
return msg_id_list_.Get(index);
}
inline void IMGetMsgByIdReq::set_msg_id_list(int index, ::google::protobuf::uint32 value) {
msg_id_list_.Set(index, value);
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgByIdReq.msg_id_list)
}
inline void IMGetMsgByIdReq::add_msg_id_list(::google::protobuf::uint32 value) {
msg_id_list_.Add(value);
// @@protoc_insertion_point(field_add:IM.Message.IMGetMsgByIdReq.msg_id_list)
}
inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >&
IMGetMsgByIdReq::msg_id_list() const {
// @@protoc_insertion_point(field_list:IM.Message.IMGetMsgByIdReq.msg_id_list)
return msg_id_list_;
}
inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >*
IMGetMsgByIdReq::mutable_msg_id_list() {
// @@protoc_insertion_point(field_mutable_list:IM.Message.IMGetMsgByIdReq.msg_id_list)
return &msg_id_list_;
}
// optional bytes attach_data = 20;
inline bool IMGetMsgByIdReq::has_attach_data() const {
return (_has_bits_[0] & 0x00000010u) != 0;
}
inline void IMGetMsgByIdReq::set_has_attach_data() {
_has_bits_[0] |= 0x00000010u;
}
inline void IMGetMsgByIdReq::clear_has_attach_data() {
_has_bits_[0] &= ~0x00000010u;
}
inline void IMGetMsgByIdReq::clear_attach_data() {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_->clear();
}
clear_has_attach_data();
}
inline const ::std::string& IMGetMsgByIdReq::attach_data() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgByIdReq.attach_data)
return *attach_data_;
}
inline void IMGetMsgByIdReq::set_attach_data(const ::std::string& value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgByIdReq.attach_data)
}
inline void IMGetMsgByIdReq::set_attach_data(const char* value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set_char:IM.Message.IMGetMsgByIdReq.attach_data)
}
inline void IMGetMsgByIdReq::set_attach_data(const void* value, size_t size) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:IM.Message.IMGetMsgByIdReq.attach_data)
}
inline ::std::string* IMGetMsgByIdReq::mutable_attach_data() {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
// @@protoc_insertion_point(field_mutable:IM.Message.IMGetMsgByIdReq.attach_data)
return attach_data_;
}
inline ::std::string* IMGetMsgByIdReq::release_attach_data() {
clear_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
return NULL;
} else {
::std::string* temp = attach_data_;
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return temp;
}
}
inline void IMGetMsgByIdReq::set_allocated_attach_data(::std::string* attach_data) {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
delete attach_data_;
}
if (attach_data) {
set_has_attach_data();
attach_data_ = attach_data;
} else {
clear_has_attach_data();
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
// @@protoc_insertion_point(field_set_allocated:IM.Message.IMGetMsgByIdReq.attach_data)
}
// -------------------------------------------------------------------
// IMGetMsgByIdRsp
// required uint32 user_id = 1;
inline bool IMGetMsgByIdRsp::has_user_id() const {
return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void IMGetMsgByIdRsp::set_has_user_id() {
_has_bits_[0] |= 0x00000001u;
}
inline void IMGetMsgByIdRsp::clear_has_user_id() {
_has_bits_[0] &= ~0x00000001u;
}
inline void IMGetMsgByIdRsp::clear_user_id() {
user_id_ = 0u;
clear_has_user_id();
}
inline ::google::protobuf::uint32 IMGetMsgByIdRsp::user_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgByIdRsp.user_id)
return user_id_;
}
inline void IMGetMsgByIdRsp::set_user_id(::google::protobuf::uint32 value) {
set_has_user_id();
user_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgByIdRsp.user_id)
}
// required .IM.BaseDefine.SessionType session_type = 2;
inline bool IMGetMsgByIdRsp::has_session_type() const {
return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void IMGetMsgByIdRsp::set_has_session_type() {
_has_bits_[0] |= 0x00000002u;
}
inline void IMGetMsgByIdRsp::clear_has_session_type() {
_has_bits_[0] &= ~0x00000002u;
}
inline void IMGetMsgByIdRsp::clear_session_type() {
session_type_ = 1;
clear_has_session_type();
}
inline ::IM::BaseDefine::SessionType IMGetMsgByIdRsp::session_type() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgByIdRsp.session_type)
return static_cast< ::IM::BaseDefine::SessionType >(session_type_);
}
inline void IMGetMsgByIdRsp::set_session_type(::IM::BaseDefine::SessionType value) {
assert(::IM::BaseDefine::SessionType_IsValid(value));
set_has_session_type();
session_type_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgByIdRsp.session_type)
}
// required uint32 session_id = 3;
inline bool IMGetMsgByIdRsp::has_session_id() const {
return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void IMGetMsgByIdRsp::set_has_session_id() {
_has_bits_[0] |= 0x00000004u;
}
inline void IMGetMsgByIdRsp::clear_has_session_id() {
_has_bits_[0] &= ~0x00000004u;
}
inline void IMGetMsgByIdRsp::clear_session_id() {
session_id_ = 0u;
clear_has_session_id();
}
inline ::google::protobuf::uint32 IMGetMsgByIdRsp::session_id() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgByIdRsp.session_id)
return session_id_;
}
inline void IMGetMsgByIdRsp::set_session_id(::google::protobuf::uint32 value) {
set_has_session_id();
session_id_ = value;
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgByIdRsp.session_id)
}
// repeated .IM.BaseDefine.MsgInfo msg_list = 4;
inline int IMGetMsgByIdRsp::msg_list_size() const {
return msg_list_.size();
}
inline void IMGetMsgByIdRsp::clear_msg_list() {
msg_list_.Clear();
}
inline const ::IM::BaseDefine::MsgInfo& IMGetMsgByIdRsp::msg_list(int index) const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgByIdRsp.msg_list)
return msg_list_.Get(index);
}
inline ::IM::BaseDefine::MsgInfo* IMGetMsgByIdRsp::mutable_msg_list(int index) {
// @@protoc_insertion_point(field_mutable:IM.Message.IMGetMsgByIdRsp.msg_list)
return msg_list_.Mutable(index);
}
inline ::IM::BaseDefine::MsgInfo* IMGetMsgByIdRsp::add_msg_list() {
// @@protoc_insertion_point(field_add:IM.Message.IMGetMsgByIdRsp.msg_list)
return msg_list_.Add();
}
inline const ::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::MsgInfo >&
IMGetMsgByIdRsp::msg_list() const {
// @@protoc_insertion_point(field_list:IM.Message.IMGetMsgByIdRsp.msg_list)
return msg_list_;
}
inline ::google::protobuf::RepeatedPtrField< ::IM::BaseDefine::MsgInfo >*
IMGetMsgByIdRsp::mutable_msg_list() {
// @@protoc_insertion_point(field_mutable_list:IM.Message.IMGetMsgByIdRsp.msg_list)
return &msg_list_;
}
// optional bytes attach_data = 20;
inline bool IMGetMsgByIdRsp::has_attach_data() const {
return (_has_bits_[0] & 0x00000010u) != 0;
}
inline void IMGetMsgByIdRsp::set_has_attach_data() {
_has_bits_[0] |= 0x00000010u;
}
inline void IMGetMsgByIdRsp::clear_has_attach_data() {
_has_bits_[0] &= ~0x00000010u;
}
inline void IMGetMsgByIdRsp::clear_attach_data() {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_->clear();
}
clear_has_attach_data();
}
inline const ::std::string& IMGetMsgByIdRsp::attach_data() const {
// @@protoc_insertion_point(field_get:IM.Message.IMGetMsgByIdRsp.attach_data)
return *attach_data_;
}
inline void IMGetMsgByIdRsp::set_attach_data(const ::std::string& value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set:IM.Message.IMGetMsgByIdRsp.attach_data)
}
inline void IMGetMsgByIdRsp::set_attach_data(const char* value) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(value);
// @@protoc_insertion_point(field_set_char:IM.Message.IMGetMsgByIdRsp.attach_data)
}
inline void IMGetMsgByIdRsp::set_attach_data(const void* value, size_t size) {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
attach_data_->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_set_pointer:IM.Message.IMGetMsgByIdRsp.attach_data)
}
inline ::std::string* IMGetMsgByIdRsp::mutable_attach_data() {
set_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
attach_data_ = new ::std::string;
}
// @@protoc_insertion_point(field_mutable:IM.Message.IMGetMsgByIdRsp.attach_data)
return attach_data_;
}
inline ::std::string* IMGetMsgByIdRsp::release_attach_data() {
clear_has_attach_data();
if (attach_data_ == &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
return NULL;
} else {
::std::string* temp = attach_data_;
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
return temp;
}
}
inline void IMGetMsgByIdRsp::set_allocated_attach_data(::std::string* attach_data) {
if (attach_data_ != &::google::protobuf::internal::GetEmptyStringAlreadyInited()) {
delete attach_data_;
}
if (attach_data) {
set_has_attach_data();
attach_data_ = attach_data;
} else {
clear_has_attach_data();
attach_data_ = const_cast< ::std::string*>(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
// @@protoc_insertion_point(field_set_allocated:IM.Message.IMGetMsgByIdRsp.attach_data)
}
// @@protoc_insertion_point(namespace_scope)
} // namespace Message
} // namespace IM
// @@protoc_insertion_point(global_scope)
#endif // PROTOBUF_IM_2eMessage_2eproto__INCLUDED
| 36.09375 | 110 | 0.709193 |
0a72b59136fad40faba8676da4d13440fafa2b40 | 7,842 | c | C | terrain.c | HenryDane/Asterisk | 27f960ab4ef9552a376deb678624731e09b42f09 | [
"MIT"
] | 2 | 2017-12-19T01:14:53.000Z | 2018-01-13T23:24:08.000Z | terrain.c | HenryDane/Asterisk | 27f960ab4ef9552a376deb678624731e09b42f09 | [
"MIT"
] | 48 | 2017-12-19T22:42:26.000Z | 2018-06-11T00:41:35.000Z | terrain.c | HenryDane/Asterisk | 27f960ab4ef9552a376deb678624731e09b42f09 | [
"MIT"
] | 4 | 2017-12-19T01:15:05.000Z | 2021-05-01T13:22:30.000Z | #include "main.h"
#include "display.h"
#include "levels.h"
#include <stdio.h>
void load_map(int index){
master_index = index;
cached_map = rogue_map_master[index].mapdat;
character_x = rogue_map_master[index].coord.x;
character_y = rogue_map_master[index].coord.y;
cached_map.num_entities = rogue_map_master[index].mapdat.num_entities;
num_entities = rogue_map_master[index].mapdat.num_entities;
printf("Loading map %d with start of (%d, %d) and %d entities \n", index, rogue_map_master[index].coord.x, rogue_map_master[index].coord.y, rogue_map_master[index].mapdat.num_entities);
int i = 0;
printf("Found %d entities \n", rogue_map_master[index].mapdat.num_entities);
for ( ; i < rogue_map_master[index].mapdat.num_entities; i++){
//entities[i] = rogue_map_master[index].mapdat.entities[i];
entity_t entity_tmp;
rogue_enemy_master[index](&entity_tmp, i);
if (entity_tmp.id >= 0){
entities[i] = entity_tmp;
} else {
printf("Breaking out of entity loading at index %d \n", i);
break;
}
}
if (num_entities - 1 > i) {
printf("WARN: num_entities - 1 > i! (%d - 1> %d) Resolving . . . \n", num_entities, i);
num_entities = i + 1;
}
}
void load_teleport(int index, int x, int y){
master_index = index;
cached_map = rogue_map_master[index].mapdat;
character_x = x;
character_y = y;
cached_map.num_entities = rogue_map_master[index].mapdat.num_entities;
num_entities = rogue_map_master[index].mapdat.num_entities;
printf("Loading map %d with start of (%d, %d) and %d entities \n", index, rogue_map_master[index].coord.x, rogue_map_master[index].coord.y, rogue_map_master[index].mapdat.num_entities);
int i = 0;
for ( ; i < rogue_map_master[index].mapdat.num_entities; i++){
//entities[i] = rogue_map_master[index].mapdat.entities[i];
entity_t entity_tmp;
rogue_enemy_master[index](&entity_tmp, i);
if (entity_tmp.id >= 0){
entities[i] = entity_tmp;
} else {
printf("Breaking out of entity loading at index %d \n", i);
break;
}
}
if (num_entities - 1 > i) {
printf("WARN: num_entities - 1 > i! (%d - 1> %d) Resolving . . . \n", num_entities, i);
num_entities = i;
}
}
void build_terrain(int sector_x, int sector_y, int sector_s){
// reset all lists (asteroids, enemies, etc)
num_entities = 0;
search_and_build(level_master[level + (sector_s % 4)].tile_dat);
}
void search_and_build(const tile_data * tiledata){
printf("SECTOR: %d \n", sector_s);
// init vairables
bool exists = false;
int i = 0;
// search
for ( ; i < 10; i++){
printf("Testing %d, %d with %d, %d \n", tiledata[i].x, tiledata[i].y, sector_x, sector_y);
if (tiledata[i].x == sector_x && tiledata[i].y == sector_y){
exists = true;
printf("FOUND W DESC %d I: %d \n" , tiledata[i].data, i);
break;
}
}
printf("EXITST: %d \n", ((exists) ? 1 : 0) );
// create entities
if (exists){
printf("EXISTS!! NUM: %d I: %d \n", tiledata[i].num_level_data, i);
for(int j = 0; j < tiledata[i].num_level_data; j++){
printf("LOOKING AT J: %d \n", j);
switch(tiledata[i].flight_data[j].type){
case 0: // station
printf("SPAWN STATION AT X: %d Y: %d \n", tiledata[i].flight_data[j].x, tiledata[i].flight_data[j].y);
// create entity listing
entities_o[num_entities_o].id = id_entity_last;
entities_o[num_entities_o].x = tiledata[i].flight_data[j].x;
entities_o[num_entities_o].y = tiledata[i].flight_data[j].y;
entities_o[num_entities_o].type = 0;
for (int k = 0; k < 16; k++){
entities_o[num_entities_o].data[i] = tiledata[i].flight_data[j].data[i];
}
entities_o[num_entities_o].vx = tiledata[i].flight_data[j].num; // encodes which map
entities_o[num_entities_o].vy = 0;
if (num_entities_o < MAX_ENTITIES) num_entities_o++;
id_entity_last++;
break;
case 1: //asteroid
printf("SPAWN ASTEROID AT X: %d Y: %d \n", tiledata[i].flight_data[j].x, tiledata[i].flight_data[j].y);
for (int m = 0; m < tiledata[i].flight_data[j].num; m++){
entities_o[num_entities_o].id = id_entity_last;
entities_o[num_entities_o].x = rand() % WIDTH;
entities_o[num_entities_o].y = rand() % HEIGHT;
entities_o[num_entities_o].type = 1;
for (int k = 0; k < 16; k++){
entities_o[num_entities_o].data[i] = tiledata[i].flight_data[j].data[i];
}
entities_o[num_entities_o].vx = (rand() % 5) - 2;
entities_o[num_entities_o].vy = (rand() % 5) - 2;
if (num_entities_o < MAX_ENTITIES) {
num_entities_o++;
}
id_entity_last++;
}
break;
case 2: // enemy
printf("SPAWN ENEMY AT X: %d Y: %d \n", tiledata[i].flight_data[j].x, tiledata[i].flight_data[j].y);
for (int m = 0; m < tiledata[i].flight_data[j].num; m++){
entities_o[num_entities_o].id = id_entity_last;
entities_o[num_entities_o].x = tiledata[i].flight_data[j].x;
entities_o[num_entities_o].y = tiledata[i].flight_data[j].y;
entities_o[num_entities_o].type = 2;
for (int k = 0; k < 16; k++){
entities_o[num_entities_o].data[i] = tiledata[i].flight_data[j].data[i];
}
entities_o[num_entities_o].vx = (rand() % 10 > 5) ? -1 : 1;
entities_o[num_entities_o].vy = (rand() % 10 > 5) ? -1 : 1;
if (num_entities < MAX_ENTITIES) num_entities_o++;
}
break;
case 3: // debris
printf("SPAWN DEBRIS AT X: %d Y: %d \n", tiledata[i].flight_data[j].x, tiledata[i].flight_data[j].y);
for (int m = 0; m < tiledata[i].flight_data[j].num; m++){
entities_o[num_entities_o].id = id_entity_last;
entities_o[num_entities_o].x = rand() % WIDTH;
entities_o[num_entities_o].y = rand() % HEIGHT;
entities_o[num_entities_o].type = 3;
for (int k = 0; k < 16; k++){
entities_o[num_entities_o].data[i] = tiledata[i].flight_data[j].data[i];
}
entities_o[num_entities_o].vx = 0;
entities_o[num_entities_o].vy = 0;
if (num_entities_o < MAX_ENTITIES) num_entities_o++;
id_entity_last++;
}
break;
default:
printf("FAILED WITH: %d \n" , tiledata[i].flight_data[j].type);
}
}
} else {
printf("SPAWINING NOTHING \n");
}
}
bool searchQuest(int quest_id){
bool found = false;
for (int i = 0; i < num_active_quests; i++){
if (quest_a_registry[i].quest.id == quest_id){
found = true;
break;
}
}
return found;
}
| 43.810056 | 189 | 0.522061 |
f8ba5423d09ee6d924a07ada98215d884adec4a4 | 1,022 | c | C | src/daemontools-extras/s6-setuidgid.c | Kevin6000/s6 | 19ecbe91d2ef699f3d2a063c50cbff4d7e46eb1e | [
"ISC"
] | null | null | null | src/daemontools-extras/s6-setuidgid.c | Kevin6000/s6 | 19ecbe91d2ef699f3d2a063c50cbff4d7e46eb1e | [
"ISC"
] | null | null | null | src/daemontools-extras/s6-setuidgid.c | Kevin6000/s6 | 19ecbe91d2ef699f3d2a063c50cbff4d7e46eb1e | [
"ISC"
] | null | null | null | /* ISC license. */
#include <string.h>
#include <skalibs/strerr2.h>
#include <skalibs/djbunix.h>
#include <s6/config.h>
#define USAGE "s6-setuidgid username prog..."
#define dieusage() strerr_dieusage(100, USAGE)
int main (int argc, char *const *argv, char const *const *envp)
{
char const *newargv[argc + 7] ;
char *colon ;
unsigned int m = 0 ;
PROG = "s6-setuidgid" ;
if (argc < 3) dieusage() ;
argv++ ;
colon = strchr(argv[0], ':') ;
if (colon)
{
*colon = 0 ;
newargv[m++] = S6_BINPREFIX "s6-applyuidgid" ;
newargv[m++] = "-u" ;
newargv[m++] = argv[0] ;
newargv[m++] = "-g" ;
newargv[m++] = colon + 1 ;
newargv[m++] = "-G" ;
newargv[m++] = "" ;
argv++ ;
}
else
{
newargv[m++] = S6_BINPREFIX "s6-envuidgid" ;
newargv[m++] = *argv++ ;
newargv[m++] = S6_BINPREFIX "s6-applyuidgid" ;
newargv[m++] = "-Uz" ;
}
newargv[m++] = "--" ;
while (*argv) newargv[m++] = *argv++ ;
newargv[m++] = 0 ;
xpathexec_run(newargv[0], newargv, envp) ;
}
| 23.227273 | 63 | 0.552838 |
f8bce644a1b4ee269b33cceb28549038e4c7f170 | 1,428 | h | C | Engine/Classes/MovableBrushEntity_tables.h | openlastchaos/lastchaos-source-client | 3d88594dba7347b1bb45378136605e31f73a8555 | [
"Apache-2.0"
] | 1 | 2022-02-14T15:46:44.000Z | 2022-02-14T15:46:44.000Z | Engine/Classes/MovableBrushEntity_tables.h | openlastchaos/lastchaos-source-client | 3d88594dba7347b1bb45378136605e31f73a8555 | [
"Apache-2.0"
] | null | null | null | Engine/Classes/MovableBrushEntity_tables.h | openlastchaos/lastchaos-source-client | 3d88594dba7347b1bb45378136605e31f73a8555 | [
"Apache-2.0"
] | 2 | 2022-01-10T22:17:06.000Z | 2022-01-17T09:34:08.000Z | /*
* This file is generated by Entity Class Compiler, (c) CroTeam 1997-98
*/
CDLLEntityEvent *CMovableBrushEntity_events[] = {NULL};
#define CMovableBrushEntity_eventsct 0
#define ENTITYCLASS CMovableBrushEntity
CEntityProperty CMovableBrushEntity_properties[] = {
CEntityProperty()
};
#define CMovableBrushEntity_propertiesct 0
CEntityComponent CMovableBrushEntity_components[] = {
CEntityComponent()
};
#define CMovableBrushEntity_componentsct 0
CEventHandlerEntry CMovableBrushEntity_handlers[] = {
{0x00030000, -1, CEntity::pEventHandler(&CMovableBrushEntity::
#line 46 "C:/Users/pwesty/Desktop/SD-Source/nov-source/Reco_Csrc/Engine/Classes/MovableBrushEntity.es"
Dummy),DEBUGSTRING("CMovableBrushEntity::Dummy")},
};
#define CMovableBrushEntity_handlersct ARRAYCOUNT(CMovableBrushEntity_handlers)
CEntity *CMovableBrushEntity_New(void) { return new CMovableBrushEntity; };
void CMovableBrushEntity_OnInitClass(void) {};
void CMovableBrushEntity_OnEndClass(void) {};
void CMovableBrushEntity_OnPrecache(CDLLEntityClass *pdec, INDEX iUser) {};
void CMovableBrushEntity_OnWorldEnd(CWorld *pwo) {};
void CMovableBrushEntity_OnWorldInit(CWorld *pwo) {};
void CMovableBrushEntity_OnWorldTick(CWorld *pwo) {};
void CMovableBrushEntity_OnWorldRender(CWorld *pwo) {};
ENTITY_CLASSDEFINITION(CMovableBrushEntity, CMovableEntity, "MovableBrushEntity", "", 0x00000003);
DECLARE_CTFILENAME(_fnmCMovableBrushEntity_tbn, "");
| 37.578947 | 102 | 0.820028 |
f8c186f25451475854ddbfd7d566e83e6b41c40f | 978 | h | C | System/Library/PrivateFrameworks/ManagedConfiguration.framework/MCEDUModeUtilities.h | lechium/iOS1351Headers | 6bed3dada5ffc20366b27f7f2300a24a48a6284e | [
"MIT"
] | 2 | 2021-11-02T09:23:27.000Z | 2022-03-28T08:21:57.000Z | System/Library/PrivateFrameworks/ManagedConfiguration.framework/MCEDUModeUtilities.h | lechium/iOS1351Headers | 6bed3dada5ffc20366b27f7f2300a24a48a6284e | [
"MIT"
] | null | null | null | System/Library/PrivateFrameworks/ManagedConfiguration.framework/MCEDUModeUtilities.h | lechium/iOS1351Headers | 6bed3dada5ffc20366b27f7f2300a24a48a6284e | [
"MIT"
] | 1 | 2022-03-28T08:21:59.000Z | 2022-03-28T08:21:59.000Z | /*
* This header is generated by classdump-dyld 1.5
* on Friday, April 30, 2021 at 11:34:24 AM Mountain Standard Time
* Operating System: Version 13.5.1 (Build 17F80)
* Image Source: /System/Library/PrivateFrameworks/ManagedConfiguration.framework/ManagedConfiguration
* classdump-dyld is licensed under GPLv3, Copyright © 2013-2016 by Elias Limneos. Updated by Kevin Bradley.
*/
@interface MCEDUModeUtilities : NSObject
+(BOOL)isEphemeralMultiUser;
+(id)_configureQuotaSizeForSharedDeviceImmediately:(id)arg1 ;
+(id)_configureResidentUsersNumberForSharedDeviceImmediately:(id)arg1 ;
+(BOOL)isFirstSetupBuddyDone;
+(unsigned long long)_getDiskSize;
+(unsigned long long)getDiskAvailableSize;
+(id)configureToSharedDevice;
+(id)configureQuotaSizeForSharedDevice:(id)arg1 ;
+(id)configureResidentUsersNumberForSharedDevice:(id)arg1 ;
@end
| 44.454545 | 130 | 0.697342 |
fd672f4b3e212df01aa83c5442cb728f9c33844b | 9,081 | h | C | Translator_file/deal.II/fe/fe_poly_face.h | jiaqiwang969/deal.ii-course-practice | 0da5ad1537d8152549d8a0e4de5872efe7619c8a | [
"MIT"
] | null | null | null | Translator_file/deal.II/fe/fe_poly_face.h | jiaqiwang969/deal.ii-course-practice | 0da5ad1537d8152549d8a0e4de5872efe7619c8a | [
"MIT"
] | null | null | null | Translator_file/deal.II/fe/fe_poly_face.h | jiaqiwang969/deal.ii-course-practice | 0da5ad1537d8152549d8a0e4de5872efe7619c8a | [
"MIT"
] | null | null | null | //include/deal.II-translator/fe/fe_poly_face_0.txt
// ---------------------------------------------------------------------
//
// Copyright (C) 2009 - 2021 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE.md at
// the top level directory of deal.II.
//
// ---------------------------------------------------------------------
#ifndef dealii_fe_poly_face_h
#define dealii_fe_poly_face_h
#include <deal.II/base/config.h>
#include <deal.II/base/qprojector.h>
#include <deal.II/fe/fe.h>
#include <memory>
DEAL_II_NAMESPACE_OPEN
/*!@addtogroup febase */
/*@{*/
/**
* @warning 这个类还没有得到充分的测试!
* 这个类给出了一个统一的框架来实现只位于网格面上的FiniteElement类。它们是基于多项式空间,如TensorProductPolynomials或PolynomialSpace类。
* 每个实现以下功能的类都可以作为模板参数PolynomialType。
*
*
* @code
* double compute_value (const unsigned int i,
* const Point<dim> &p) const;
* @endcode
* 示例类是TensorProductPolynomials、PolynomialSpace或PolynomialsP。
* 这个类不是一个完全实现的FiniteElement类。相反,有几个在FiniteElement类中声明的纯虚拟函数不能由这个类来实现,而是留给派生类来实现。
*
*
*/
template <class PolynomialType,
int dim = PolynomialType::dimension + 1,
int spacedim = dim>
class FE_PolyFace : public FiniteElement<dim, spacedim>
{
public:
/**
* 构造函数。
*
*/
FE_PolyFace(const PolynomialType & poly_space,
const FiniteElementData<dim> &fe_data,
const std::vector<bool> & restriction_is_additive_flags);
/**
* 返回该有限元的多项式程度,即传递给构造函数的值。
*
*/
unsigned int
get_degree() const;
// for documentation, see the FiniteElement base class
virtual UpdateFlags
requires_update_flags(const UpdateFlags update_flags) const override;
protected:
/*注意:以下函数的定义被内联到类的声明中,因为我们在MS Visual Studio中否则会遇到编译器错误。
*
*/
virtual std::unique_ptr<
typename FiniteElement<dim, spacedim>::InternalDataBase>
get_data(
const UpdateFlags update_flags,
const Mapping<dim, spacedim> &mapping,
const Quadrature<dim> & quadrature,
dealii::internal::FEValuesImplementation::FiniteElementRelatedData<dim,
spacedim>
&output_data) const override
{
(void)update_flags;
(void)mapping;
(void)quadrature;
(void)output_data;
return std::make_unique<InternalData>();
}
using FiniteElement<dim, spacedim>::get_face_data;
std::unique_ptr<typename FiniteElement<dim, spacedim>::InternalDataBase>
get_face_data(
const UpdateFlags update_flags,
const Mapping<dim, spacedim> & mapping,
const hp::QCollection<dim - 1> &quadrature,
dealii::internal::FEValuesImplementation::FiniteElementRelatedData<dim,
spacedim>
&output_data) const override
{
(void)mapping;
(void)output_data;
AssertDimension(quadrature.size(), 1);
// generate a new data object and
// initialize some fields
std::unique_ptr<typename FiniteElement<dim, spacedim>::InternalDataBase>
data_ptr = std::make_unique<InternalData>();
auto &data = dynamic_cast<InternalData &>(*data_ptr);
data.update_each = requires_update_flags(update_flags);
const unsigned int n_q_points = quadrature[0].size();
// some scratch arrays
std::vector<double> values(0);
std::vector<Tensor<1, dim - 1>> grads(0);
std::vector<Tensor<2, dim - 1>> grad_grads(0);
std::vector<Tensor<3, dim - 1>> empty_vector_of_3rd_order_tensors;
std::vector<Tensor<4, dim - 1>> empty_vector_of_4th_order_tensors;
// initialize fields only if really
// necessary. otherwise, don't
// allocate memory
if (data.update_each & update_values)
{
values.resize(poly_space.n());
data.shape_values.resize(poly_space.n(),
std::vector<double>(n_q_points));
for (unsigned int i = 0; i < n_q_points; ++i)
{
poly_space.evaluate(quadrature[0].point(i),
values,
grads,
grad_grads,
empty_vector_of_3rd_order_tensors,
empty_vector_of_4th_order_tensors);
for (unsigned int k = 0; k < poly_space.n(); ++k)
data.shape_values[k][i] = values[k];
}
}
// No derivatives of this element
// are implemented.
if (data.update_each & update_gradients ||
data.update_each & update_hessians)
{
Assert(false, ExcNotImplemented());
}
return data_ptr;
}
std::unique_ptr<typename FiniteElement<dim, spacedim>::InternalDataBase>
get_subface_data(
const UpdateFlags update_flags,
const Mapping<dim, spacedim> &mapping,
const Quadrature<dim - 1> & quadrature,
dealii::internal::FEValuesImplementation::FiniteElementRelatedData<dim,
spacedim>
&output_data) const override
{
return get_face_data(
update_flags,
mapping,
hp::QCollection<dim - 1>(QProjector<dim - 1>::project_to_all_children(
ReferenceCells::get_hypercube<dim - 1>(), quadrature)),
output_data);
}
virtual void
fill_fe_values(
const typename Triangulation<dim, spacedim>::cell_iterator &cell,
const CellSimilarity::Similarity cell_similarity,
const Quadrature<dim> & quadrature,
const Mapping<dim, spacedim> & mapping,
const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
const dealii::internal::FEValuesImplementation::MappingRelatedData<dim,
spacedim>
& mapping_data,
const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
dealii::internal::FEValuesImplementation::FiniteElementRelatedData<dim,
spacedim>
&output_data) const override;
using FiniteElement<dim, spacedim>::fill_fe_face_values;
virtual void
fill_fe_face_values(
const typename Triangulation<dim, spacedim>::cell_iterator &cell,
const unsigned int face_no,
const hp::QCollection<dim - 1> & quadrature,
const Mapping<dim, spacedim> & mapping,
const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
const dealii::internal::FEValuesImplementation::MappingRelatedData<dim,
spacedim>
& mapping_data,
const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
dealii::internal::FEValuesImplementation::FiniteElementRelatedData<dim,
spacedim>
&output_data) const override;
virtual void
fill_fe_subface_values(
const typename Triangulation<dim, spacedim>::cell_iterator &cell,
const unsigned int face_no,
const unsigned int sub_no,
const Quadrature<dim - 1> & quadrature,
const Mapping<dim, spacedim> & mapping,
const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
const dealii::internal::FEValuesImplementation::MappingRelatedData<dim,
spacedim>
& mapping_data,
const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
dealii::internal::FEValuesImplementation::FiniteElementRelatedData<dim,
spacedim>
&output_data) const override;
/**
* 独立于细胞的数据字段。
* 关于这个类的一般用途的信息,请看基类的文档。
*
*/
class InternalData : public FiniteElement<dim, spacedim>::InternalDataBase
{
public:
/**
* 包含一个面上的正交点的形状函数值的数组。
* 每个形状函数都有一行,包含每个正交点的值。
* 在这个数组中,我们将形状函数的值存储在单元格一个面上的正交点。由于这些值在转换到实际单元时不会改变,我们只需要在访问具体单元时将它们复制过来。
* 特别是,我们可以简单地将同一组数值复制到每个面。
*
*/
std::vector<std::vector<double>> shape_values;
};
/**
* 多项式空间。其类型由模板参数PolynomialType给出。
*
*/
PolynomialType poly_space;
};
/*@}*/
DEAL_II_NAMESPACE_CLOSE
#endif
| 35.33463 | 96 | 0.58727 |
745dc342f84bbb65974f7f284dc5f29a5afa4d7e | 421 | c | C | lib/ctype/tolower.c | aglotoff/osdev-pbx-a9 | d053020da451e6c25f8b6668bf042044e4902fc6 | [
"MIT"
] | 1 | 2022-02-13T11:37:53.000Z | 2022-02-13T11:37:53.000Z | lib/ctype/tolower.c | aglotoff/osdev-pbx-a9 | d053020da451e6c25f8b6668bf042044e4902fc6 | [
"MIT"
] | null | null | null | lib/ctype/tolower.c | aglotoff/osdev-pbx-a9 | d053020da451e6c25f8b6668bf042044e4902fc6 | [
"MIT"
] | null | null | null | #include <ctype.h>
/**
* Transliterate uppercase characters to lowercase.
*
* @param c The value to be converted, representable as an unsigned char or
* equal to the value of the macro EOF.
*
* @return The lowercase letter corresponding to c, if such value exists; or c
* (unchanged) otherwise.
*
* @sa toupper
*/
int
(tolower)(int c)
{
return c < 0 ? c : __tolower[(unsigned char) c];
}
| 22.157895 | 78 | 0.650831 |
ddecad0a6435c7bcc48194bea62f827b82dbce1c | 1,107 | h | C | Drone/Drone/Modules/SerialCOM/SerialCOM.h | lorki97/drone-atmega | bf2fbe2f1b753530ab1d90c1e9098dedf56fe68d | [
"Unlicense"
] | 1 | 2020-01-27T11:07:06.000Z | 2020-01-27T11:07:06.000Z | Drone/Drone/Modules/SerialCOM/SerialCOM.h | florianL21/drone-atsam | bf2fbe2f1b753530ab1d90c1e9098dedf56fe68d | [
"Unlicense"
] | null | null | null | Drone/Drone/Modules/SerialCOM/SerialCOM.h | florianL21/drone-atsam | bf2fbe2f1b753530ab1d90c1e9098dedf56fe68d | [
"Unlicense"
] | null | null | null | /*
* SerialCOM.h
*
* Created: 12.02.2018 08:59:14
* Author: flola
*/
#ifndef SERIALCOM_H_
#define SERIALCOM_H_
#include "sam.h"
#include <stdlib.h>
#include <stdarg.h>
#include "../../config.h"
#include "../UART/uart0.h"
#include "../ErrorHandling/ErrorHandling.h"
/*
* Transmission Types:
* 0x01 - Debug message
* 0x10 - Error
*/
typedef void (*SerialCOM_RECV_CALLBACK)(uint8_t* message, uint8_t Type);
ErrorCode SerialCOM_init();
ErrorCode SerialCOM_put_debug(char Text[]);
ErrorCode SerialCOM_put_debug_n(char Text[], uint8_t Length);
ErrorCode SerialCOM_register_call_back(SerialCOM_RECV_CALLBACK callback);
ErrorCode SerialCOM_put_error(char Text[]);
ErrorCode SerialCOM_force_put_error(char Text[]);
uint8_t SerialCOM_get_free_space();
ErrorCode SerialCOM_put_message(uint8_t message[], uint8_t Type, uint8_t Length);
ErrorCode SerialCOM_put_Command(char CommandChar, uint8_t Type);
ErrorCode SerialCOM_print_error(const char *fmt, ...);
ErrorCode SerialCOM_print_debug(const char *fmt, ...);
void SerialCOM_serializeFloat(float* Value, uint8_t* startptr);
#endif /* SERIALCOM_H_ */ | 27 | 81 | 0.766034 |
de298db4090d8d25ab4e2a3936929dc72d65c628 | 1,909 | h | C | Plugins/SGMessaging/Source/Public/Core/Message/SGAny.h | crazytuzi/SGMessagingDemo | ffe9d4a5fb47742de2f0e753fbfe68eb9d289ab8 | [
"MIT"
] | 1 | 2022-03-01T04:03:03.000Z | 2022-03-01T04:03:03.000Z | Plugins/SGMessaging/Source/Public/Core/Message/SGAny.h | crazytuzi/SGMessagingDemo | ffe9d4a5fb47742de2f0e753fbfe68eb9d289ab8 | [
"MIT"
] | null | null | null | Plugins/SGMessaging/Source/Public/Core/Message/SGAny.h | crazytuzi/SGMessagingDemo | ffe9d4a5fb47742de2f0e753fbfe68eb9d289ab8 | [
"MIT"
] | 1 | 2022-03-01T03:17:53.000Z | 2022-03-01T03:17:53.000Z | #pragma once
#include "CoreMinimal.h"
#include "SGAnyType.h"
struct FSGAny
{
FSGAny()
: ScriptArray(nullptr)
{
}
FSGAny(const FSGAny& That)
: ScriptArray(That.ScriptArray),
Pointer(That.Clone()),
AnyType(That.AnyType)
{
}
FSGAny(FSGAny&& That) noexcept
: ScriptArray(MoveTemp(That.ScriptArray)),
Pointer(MoveTemp(That.Pointer)),
AnyType(MoveTemp(That.AnyType))
{
}
template <typename T, class = TEnableIf<TNot<TIsSame<TDecay<T>, FSGAny>>::Value, T>>
explicit FSGAny(T&& Value)
: ScriptArray(nullptr),
Pointer(new TDerived<typename TDecay<T>::Type>(Forward<T>(Value))),
AnyType(TSGAnyTraits<typename TRemoveReference<decltype(Value)>::Type>::GetType())
{
}
bool IsValid() const
{
return Pointer.IsValid();
}
FSGAnyType GetType() const
{
return AnyType;
}
template <class T>
bool IsA() const
{
return AnyType == TSGAnyTraits<T>::GetType();
}
template <class T>
T& Cast() const
{
auto Derived = static_cast<TDerived<T>*>(Pointer.Get());
return Derived->Value;
}
FSGAny& operator=(const FSGAny& Other)
{
if (Pointer == Other.Pointer)
{
return *this;
}
Pointer = Other.Clone();
AnyType = Other.AnyType;
return *this;
}
private:
struct FBase;
using FBasePtr = TUniquePtr<FBase>;
struct FBase
{
virtual ~FBase()
{
}
virtual FBasePtr Clone() const = 0;
};
template <typename T>
struct TDerived final : FBase
{
template <typename U>
explicit TDerived(U&& InValue)
: Value(Forward<U>(InValue))
{
}
virtual FBasePtr Clone() const override
{
return MakeUnique<TDerived<T>>(Value);
}
T Value;
};
private:
FBasePtr Clone() const
{
return Pointer != nullptr ? Pointer->Clone() : nullptr;
}
public:
union
{
FScriptArray* ScriptArray;
FScriptMap* ScriptMap;
FScriptSet* ScriptSet;
void* ScriptStruct;
};
private:
FBasePtr Pointer;
FSGAnyType AnyType;
};
| 15.031496 | 86 | 0.663174 |
ea2bd9b1fcbf40446779693370d4eeaa6b86d6ba | 2,629 | c | C | sorc/ssmi/seaice_ssmibufr.fd/binary.c | rgrumbine/seaice-concentration | 80449bb23028c8a211fd050ff694b52eb5fc6bde | [
"Apache-2.0"
] | null | null | null | sorc/ssmi/seaice_ssmibufr.fd/binary.c | rgrumbine/seaice-concentration | 80449bb23028c8a211fd050ff694b52eb5fc6bde | [
"Apache-2.0"
] | 1 | 2021-04-09T13:50:58.000Z | 2021-04-09T13:50:58.000Z | sorc/ssmi/seaice_ssmibufr.fd/binary.c | rgrumbine/seaice-concentration | 80449bb23028c8a211fd050ff694b52eb5fc6bde | [
"Apache-2.0"
] | 1 | 2022-03-14T19:00:41.000Z | 2022-03-14T19:00:41.000Z | #include <stdio.h>
/* Perform the unformatted binary output for ssmibufr */
/* Robert Grumbine 12 Mar 2004 */
FILE *fout;
#ifdef IBM
int openout(int *unit) {
#elif LINUX
int openout_(int *unit) {
#else
int openout_(int *unit) {
#endif
char fname[80];
sprintf(fname,"fort.%02d\0",*unit);
fout = fopen(fname, "w");
if (fout == (FILE *) NULL) {
printf("Failed to open output unit %d\n",*unit);
return 1;
}
return 0;
}
#ifdef IBM
int shortout(int *satno, int *iy, int *im, int *id, int *ihr, int *imins, int *isec, int *iscan) {
#elif LINUX
int shortout_(int *satno, int *iy, int *im, int *id, int *ihr, int *imins, int *isec, int *iscan) {
#else
int shortout_(int *satno, int *iy, int *im, int *id, int *ihr, int *imins, int *isec, int *iscan) {
#endif
fwrite(satno, sizeof(int), 1, fout);
fwrite(iy, sizeof(int), 1, fout);
fwrite(im, sizeof(int), 1, fout);
fwrite(id, sizeof(int), 1, fout);
fwrite(ihr, sizeof(int), 1, fout);
fwrite(imins, sizeof(int), 1, fout);
fwrite(isec, sizeof(int), 1, fout);
fwrite(iscan, sizeof(int), 1, fout);
return 0;
}
#ifdef IBM
int longout(int *kscan, float *xlat, float *xlon, int *sftg, int *posn, float *tmp1, float *tmp2, float *tmp3, float *tmp4, float *tmp5, float *tmp6, float *tmp7) {
#elif LINUX
int longout_(int *kscan, float *xlat, float *xlon, int *sftg, int *posn, float *tmp1, float *tmp2, float *tmp3, float *tmp4, float *tmp5, float *tmp6, float *tmp7) {
#else
int longout_(int *kscan, float *xlat, float *xlon, int *sftg, int *posn, float *tmp1, float *tmp2, float *tmp3, float *tmp4, float *tmp5, float *tmp6, float *tmp7) {
#endif
fwrite(kscan, sizeof(int), 1, fout);
fwrite(xlat, sizeof(float), 1, fout);
fwrite(xlon, sizeof(float), 1, fout);
fwrite(sftg, sizeof(int), 1, fout);
fwrite(posn, sizeof(int), 1, fout);
fwrite(tmp1, sizeof(float), 1, fout);
fwrite(tmp2, sizeof(float), 1, fout);
fwrite(tmp3, sizeof(float), 1, fout);
fwrite(tmp4, sizeof(float), 1, fout);
fwrite(tmp5, sizeof(float), 1, fout);
fwrite(tmp6, sizeof(float), 1, fout);
fwrite(tmp7, sizeof(float), 1, fout);
return 0;
}
#ifdef IBM
int hiresout(int *kwrit, float *xlat, float *xlon, int *sftg, int*posn, float *tmp1, float*tmp2) {
#else
int hiresout_(int *kwrit, float *xlat, float *xlon, int *sftg, int*posn, float *tmp1, float*tmp2) {
#endif
fwrite(kwrit, sizeof(int), 1, fout);
fwrite(xlat, sizeof(float), 1, fout);
fwrite(xlon, sizeof(float), 1, fout);
fwrite(sftg, sizeof(int), 1, fout);
fwrite(posn, sizeof(int), 1, fout);
fwrite(tmp1, sizeof(float), 1, fout);
fwrite(tmp2, sizeof(float), 1, fout);
return 0;
}
| 32.45679 | 165 | 0.651198 |
ea730334df991320d6b00a9530a7805c4786c932 | 933 | h | C | System/Library/PrivateFrameworks/MapsSync.framework/MapsSync.MapsSyncMutableHistoryDirectionsItem.h | zhangkn/iOS14Header | 4323e9459ed6f6f5504ecbea2710bfd6c3d7c946 | [
"MIT"
] | 1 | 2020-11-04T15:43:01.000Z | 2020-11-04T15:43:01.000Z | System/Library/PrivateFrameworks/MapsSync.framework/MapsSync.MapsSyncMutableHistoryDirectionsItem.h | zhangkn/iOS14Header | 4323e9459ed6f6f5504ecbea2710bfd6c3d7c946 | [
"MIT"
] | null | null | null | System/Library/PrivateFrameworks/MapsSync.framework/MapsSync.MapsSyncMutableHistoryDirectionsItem.h | zhangkn/iOS14Header | 4323e9459ed6f6f5504ecbea2710bfd6c3d7c946 | [
"MIT"
] | null | null | null | /*
* This header is generated by classdump-dyld 1.0
* on Sunday, September 27, 2020 at 11:41:36 AM Mountain Standard Time
* Operating System: Version 14.0 (Build 18A373)
* Image Source: /System/Library/PrivateFrameworks/MapsSync.framework/MapsSync
* classdump-dyld is licensed under GPLv3, Copyright © 2013-2016 by Elias Limneos.
*/
#import <MapsSync/MapsSync.MapsSyncMutableHistoryItem.h>
@class GEOStorageRouteRequestStorage;
@interface MapsSync.MapsSyncMutableHistoryDirectionsItem : MapsSync.MapsSyncMutableHistoryItem {
_proxyHistory;
}
@property (assign,nonatomic) BOOL navigationInterrupted;
@property (retain,nonatomic) GEOStorageRouteRequestStorage * routeRequestStorage;
-(id)initWithProxyObject:(id)arg1 ;
-(BOOL)navigationInterrupted;
-(GEOStorageRouteRequestStorage *)routeRequestStorage;
-(void)setNavigationInterrupted:(BOOL)arg1 ;
-(void)setRouteRequestStorage:(GEOStorageRouteRequestStorage *)arg1 ;
@end
| 33.321429 | 96 | 0.811361 |
8ce4a06f6c97611f835a2f4fd30e5fad900ad9b5 | 6,618 | h | C | common/include/opae/cxx/core/shared_buffer.h | trixirt/opae-sdk | 71ac5d4a7923826bc3b6c8e971b5b3b48a08044d | [
"BSD-3-Clause"
] | null | null | null | common/include/opae/cxx/core/shared_buffer.h | trixirt/opae-sdk | 71ac5d4a7923826bc3b6c8e971b5b3b48a08044d | [
"BSD-3-Clause"
] | null | null | null | common/include/opae/cxx/core/shared_buffer.h | trixirt/opae-sdk | 71ac5d4a7923826bc3b6c8e971b5b3b48a08044d | [
"BSD-3-Clause"
] | null | null | null | // Copyright(c) 2018, Intel Corporation
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * 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.
// * Neither the name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <chrono>
#include <cstdint>
#include <initializer_list>
#include <memory>
#include <thread>
#include <vector>
#include <opae/buffer.h>
#include <opae/cxx/core/except.h>
#include <opae/cxx/core/handle.h>
namespace opae {
namespace fpga {
namespace types {
/** Host/AFU shared memory blocks
*
* shared_buffer abstracts a memory block that may be shared
* between the host cpu and an accelerator. The block may
* be allocated by the shared_buffer class itself (see allocate),
* or it may be allocated elsewhere and then attached to
* a shared_buffer object via attach.
*/
class shared_buffer {
public:
typedef std::size_t size_t;
typedef std::shared_ptr<shared_buffer> ptr_t;
shared_buffer(const shared_buffer &) = delete;
shared_buffer &operator=(const shared_buffer &) = delete;
/** shared_buffer destructor.
*/
virtual ~shared_buffer();
/** shared_buffer factory method - allocate a shared_buffer.
* @param[in] handle The handle used to allocate the buffer.
* @param[in] len The length in bytes of the requested buffer.
* @return A valid shared_buffer smart pointer on success, or an
* empty smart pointer on failure.
*/
static shared_buffer::ptr_t allocate(handle::ptr_t handle, size_t len,
bool read_only = false);
/** Attach a pre-allocated buffer to a shared_buffer object.
*
* @param[in] handle The handle used to attach the buffer.
* @param[in] base The base of the pre-allocated memory.
* @param[in] len The size of the pre-allocated memory,
* which must be a multiple of the page size.
* @return A valid shared_buffer smart pointer on success, or an
* empty smart pointer on failure.
*/
static shared_buffer::ptr_t attach(handle::ptr_t handle, uint8_t *base,
size_t len, bool read_only = false);
/**
* @brief Disassociate the shared_buffer object from the resource used to
* create it. If the buffer was allocated using the allocate function then
* the buffer is freed.
*/
void release();
/** Retrieve the virtual address of the buffer base.
*
* @note Instances of a shared buffer can only be created using either
* 'allocate' or 'attach' static factory function. Because these
* functions return a shared pointer (std::shared_ptr) to the instance,
* references to an instance are counted automatically by design of the
* shared_ptr class. Calling 'c_type()' function is provided to get access
* to the raw data but isn't used in tracking its reference count.
* Assigning this to a variable should be done in limited scopes as this
* variable can be defined in an outer scope and may outlive the
* shared_buffer object. Once the reference count in the shared_ptr reaches
* zero, the shared_buffer object will be released and deallocated, turning
* any variables assigned from a call to 'c_type()' into dangling pointers.
*/
volatile uint8_t *c_type() const { return virt_; }
/** Retrieve the handle smart pointer associated with
* this buffer.
*/
handle::ptr_t owner() const { return handle_; }
/** Retrieve the length of the buffer in bytes.
*/
size_t size() const { return len_; }
/** Retrieve the underlying buffer's workspace id.
*/
uint64_t wsid() const { return wsid_; }
/** Retrieve the address of the buffer suitable for
* programming into the accelerator device.
*/
uint64_t io_address() const { return io_address_; }
/** Write c to each byte location in the buffer.
*/
void fill(int c);
/** Compare this shared_buffer (the first len bytes)
* to that held in other, using memcmp().
*/
int compare(ptr_t other, size_t len) const;
/** Read a T-sized block of memory at the given location.
* @param[in] offset The byte offset from the start of the buffer.
* @return A T from buffer base + offset.
*/
template <typename T>
T read(size_t offset) const {
if ((offset < len_) && (virt_ != nullptr)) {
return *reinterpret_cast<T *>(virt_ + offset);
} else if (offset >= len_) {
throw except(OPAECXX_HERE);
} else {
throw except(OPAECXX_HERE);
}
return T();
}
/** Write a T-sized block of memory to the given location.
* @param[in] value The value to write.
* @param[in] offset The byte offset from the start of the buffer.
*/
template <typename T>
void write(const T &value, size_t offset) {
if ((offset < len_) && (virt_ != nullptr)) {
*reinterpret_cast<T *>(virt_ + offset) = value;
} else if (offset >= len_) {
throw except(OPAECXX_HERE);
} else {
throw except(OPAECXX_HERE);
}
}
protected:
shared_buffer(handle::ptr_t handle, size_t len, uint8_t *virt, uint64_t wsid,
uint64_t io_address);
handle::ptr_t handle_;
size_t len_;
uint8_t *virt_;
uint64_t wsid_;
uint64_t io_address_;
};
} // end of namespace types
} // end of namespace fpga
} // end of namespace opae
| 37.179775 | 79 | 0.697492 |
734947a16c022f91580a5cb3f016bdc902f37833 | 3,063 | c | C | c/esami/2019/10-luglio-2019/main.c | unimoreinginfo/sistemi-operativi | db07fa1f5b7180b0806ae0d3c18582c3ba3feeb0 | [
"MIT"
] | 2 | 2021-04-23T08:43:59.000Z | 2021-04-23T11:42:30.000Z | c/esami/2019/10-luglio-2019/main.c | unimoreinginfo/sistemi-operativi | db07fa1f5b7180b0806ae0d3c18582c3ba3feeb0 | [
"MIT"
] | null | null | null | c/esami/2019/10-luglio-2019/main.c | unimoreinginfo/sistemi-operativi | db07fa1f5b7180b0806ae0d3c18582c3ba3feeb0 | [
"MIT"
] | 3 | 2021-04-09T11:49:44.000Z | 2021-06-03T20:51:40.000Z | #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/wait.h>
#include <stdbool.h>
#include <string.h>
typedef int piped_t[2];
int main(int argc, char** argv){
// vengono passati N + 1 parametri
int N = argc - 2;
long int start = 0;
if(N < 2){
printf("errore nel numero dei parametri");
exit(1);
}
char c = argv[N + 1][0];
printf("c: %c\n", c);
printf("numero figli: %d * 2 = %d\n", N, N * 2);
piped_t* pipes = malloc(sizeof(piped_t) * (N * 2));
for(int i = 0; i < N * 2; i++){
// printf("pipe n° %d\n", i);
if(pipe(pipes[i]) != 0){
printf("errore in pipe");
exit(2);
}
}
for(int i = 0; i < N * 2; i++){
int P;
if((P = (fork())) < 0){
exit(2);
}
if(P == 0){
// printf("spawned %d\n", getpid());
int read_channel = pipes[i][0],
write_channel = pipes[(2 * N) - (i + 1)][1];
if(i < N){
write(pipes[i][1], &start, sizeof(long int));
printf("%d viene fatto partire subito\n", i);
}
int file_index;
if(i < N) file_index = i;
else {
file_index = 2 * N - (i + 1);
}
char* F = argv[file_index + 1];
// printf("%d scrive su pipes[%d][1] con file %s\n", i, (2 * N) - (i + 1), F);
int file = open(F, O_RDONLY);
if(file < 0) exit(-1);
for(int j = 0; j < 2 * N; j++){
if(j != i) close(pipes[j][0]);
if(j != (2 * N) - (i + 1)) close(pipes[j][1]);
}
char buf;
long int position = 0;
int occ = 0;
// if(i < N)
read(read_channel, &position, sizeof(long int));
lseek(file, position, SEEK_SET);
printf("figlio %d inizia alla posizione %ld\n", i, position);
while(read(file, &buf, sizeof(char)) > 0){
position++;
if(buf == c){
occ++;
write(write_channel, &position, sizeof(long int));
printf("figlio %d si blocca in posizione %ld\n", i, position);
read(read_channel, &position, sizeof(long int));
printf("figlio %d ricomincia alla posizione %ld\n", i, position + 1);
lseek(file, position + 1, SEEK_SET);
}
}
// printf("%d termina\n", i);
write(write_channel, &position, sizeof(long int));
exit(occ);
}else{
}
}
for(int i = 0; i < 2*N; i++){
int p, status;
if((p = wait(&status)) < 0){
exit(2);
}
status = WEXITSTATUS(status);
printf("%d ha trovato il carattere '%c' %d volta/e\n", i, c, status);
}
} | 24.309524 | 90 | 0.418544 |
21d79b375f3aa2b410a4935fc9666e37e80b9b0e | 435 | h | C | ZZOperationExtension/Classes/ZZOperationConditionEvaluator.h | sablib/ZZOperationExtension | e6b97d3568e6d3025a690131c953fae9feddd520 | [
"MIT"
] | null | null | null | ZZOperationExtension/Classes/ZZOperationConditionEvaluator.h | sablib/ZZOperationExtension | e6b97d3568e6d3025a690131c953fae9feddd520 | [
"MIT"
] | null | null | null | ZZOperationExtension/Classes/ZZOperationConditionEvaluator.h | sablib/ZZOperationExtension | e6b97d3568e6d3025a690131c953fae9feddd520 | [
"MIT"
] | null | null | null | //
// ZZOperationConditionEvaluator.h
// aaa
//
// Created by 张凯 on 15/11/23.
// Copyright © 2015年 sablib. All rights reserved.
//
#import <Foundation/Foundation.h>
@class ZZOperation;
@interface ZZOperationConditionEvaluator : NSObject
+ (void)evaluateWithConditions:(NSArray *)conditions
operation:(ZZOperation *)operation
completion:(void (^)(NSArray<NSError *> *))completion;
@end
| 21.75 | 74 | 0.668966 |
73a486458c74813bec913bc3cfbde9eca28f83e6 | 7,469 | h | C | lib/definition.h | cpereida/acvpproxy | 3df0b8cebd97f4f37b36fa26ab68a2670de567e7 | [
"BSD-3-Clause"
] | 9 | 2019-01-03T00:48:10.000Z | 2022-03-31T21:36:06.000Z | lib/definition.h | cpereida/acvpproxy | 3df0b8cebd97f4f37b36fa26ab68a2670de567e7 | [
"BSD-3-Clause"
] | 44 | 2018-12-10T20:53:04.000Z | 2022-02-20T18:30:55.000Z | lib/definition.h | cpereida/acvpproxy | 3df0b8cebd97f4f37b36fa26ab68a2670de567e7 | [
"BSD-3-Clause"
] | 7 | 2019-06-25T15:52:14.000Z | 2022-03-07T10:14:59.000Z | /* API for ACVP Proxy definition implementations
*
* Copyright (C) 2018 - 2021, Stephan Mueller <smueller@chronox.de>
*
* License: see LICENSE file in root directory
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
* WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
#ifndef DEFINITION_H
#define DEFINITION_H
#include "aux_helper.h"
#include "constructor.h"
#include "definition_cipher_drbg.h"
#include "definition_cipher_hash.h"
#include "definition_cipher_mac.h"
#include "definition_cipher_sym.h"
#include "definition_cipher_rsa.h"
#include "definition_cipher_ecdsa.h"
#include "definition_cipher_eddsa.h"
#include "definition_cipher_dsa.h"
#include "definition_cipher_kas_ecc.h"
#include "definition_cipher_kas_ecc_r3.h"
#include "definition_cipher_kas_ffc.h"
#include "definition_cipher_kas_ffc_r3.h"
#include "definition_cipher_kdf_ssh.h"
#include "definition_cipher_kdf_tpm.h"
#include "definition_cipher_kdf_ikev1.h"
#include "definition_cipher_kdf_ikev2.h"
#include "definition_cipher_kdf_tls.h"
#include "definition_cipher_kdf_tls13.h"
#include "definition_cipher_kdf_108.h"
#include "definition_cipher_hkdf.h"
#include "definition_cipher_pbkdf.h"
#include "definition_cipher_kas_ifc.h"
#include "definition_cipher_safeprimes.h"
#include "definition_cipher_conditioning_components.h"
#include "definition_cipher_kdf_onestep.h"
#include "definition_cipher_kdf_twostep.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief This data structure defines a particular cipher algorithm
* definition.
*
* @var type Specify the cipher type.
* @var algo Fill in the data structure corresponding to the @param type
* selection.
*/
struct def_algo {
enum def_algo_type {
/** symmetric ciphers, incl. AEAD */
DEF_ALG_TYPE_SYM,
/** SHA hashes */
DEF_ALG_TYPE_SHA,
/** SHAKE cipher */
DEF_ALG_TYPE_SHAKE,
/** HMAC ciphers */
DEF_ALG_TYPE_HMAC,
/** CMAC ciphers */
DEF_ALG_TYPE_CMAC,
/** SP800-90A DRBG cipher */
DEF_ALG_TYPE_DRBG,
/** FIPS 186-4 RSA cipher */
DEF_ALG_TYPE_RSA,
/** FIPS 186-4 ECDSA cipher */
DEF_ALG_TYPE_ECDSA,
/** Bernstein EDDSA cipher */
DEF_ALG_TYPE_EDDSA,
/** FIPS 186-4 DSA cipher */
DEF_ALG_TYPE_DSA,
/** KAS_ECC (ECDH, ECMQV) cipher */
DEF_ALG_TYPE_KAS_ECC,
/** KAS_ECC (Finite Field DH, Finite Field MQV) cipher */
DEF_ALG_TYPE_KAS_FFC,
/** SP800-135 KDF: SSH */
DEF_ALG_TYPE_KDF_SSH,
/** SP800-135 KDF: IKE v1 */
DEF_ALG_TYPE_KDF_IKEV1,
/** SP800-135 KDF: IKE v2 */
DEF_ALG_TYPE_KDF_IKEV2,
/** SP800-135 KDF: TLS */
DEF_ALG_TYPE_KDF_TLS,
/** SP800-135 / RFC7627 KDF: TLS */
DEF_ALG_TYPE_KDF_TLS12,
/** RFC8446 KDF: TLS 1.3 */
DEF_ALG_TYPE_KDF_TLS13,
/** SP800-108 KDF */
DEF_ALG_TYPE_KDF_108,
/** SP800-132 PBKDF */
DEF_ALG_TYPE_PBKDF,
/** SP800-56A rev3 FFC */
DEF_ALG_TYPE_KAS_FFC_R3,
/** SP800-56A rev3 KAS ECC */
DEF_ALG_TYPE_KAS_ECC_R3,
/** SP800-56A rev 3 Safe Primes */
DEF_ALG_TYPE_SAFEPRIMES,
/** SP800-56B rev2 KAS IFC (RSA) */
DEF_ALG_TYPE_KAS_IFC,
/** SP800-56C rev 1 HKDF (RFC 5869) */
DEF_ALG_TYPE_HKDF,
/** SP800-90B conditioning components */
DEF_ALG_TYPE_COND_COMP,
/** SP800-56C rev 1 onestep KDF */
DEF_ALG_TYPE_KDF_ONESTEP,
/** SP800-56C rev 1 twostep KDF */
DEF_ALG_TYPE_KDF_TWOSTEP,
/** SP800-135 TPM KDF */
DEF_ALG_TYPE_KDF_TPM,
} type;
union {
/** DEF_ALG_TYPE_SYM */
struct def_algo_sym sym;
/** DEF_ALG_TYPE_SHA */
struct def_algo_sha sha;
/** DEF_ALG_TYPE_SHAKE */
struct def_algo_shake shake;
/** DEF_ALG_TYPE_HMAC */
struct def_algo_hmac hmac;
/** DEF_ALG_TYPE_CMAC */
struct def_algo_cmac cmac;
/** DEF_ALG_TYPE_DRBG */
struct def_algo_drbg drbg;
/** DEF_ALG_TYPE_RSA */
struct def_algo_rsa rsa;
/** DEF_ALG_TYPE_ECDSA */
struct def_algo_ecdsa ecdsa;
/** DEF_ALG_TYPE_EDDSA */
struct def_algo_eddsa eddsa;
/** DEF_ALG_TYPE_DSA */
struct def_algo_dsa dsa;
/** DEF_ALG_TYPE_KAS_ECC */
struct def_algo_kas_ecc kas_ecc;
/** DEF_ALG_TYPE_KAS_FFC */
struct def_algo_kas_ffc kas_ffc;
/** DEF_ALG_TYPE_KDF_SSH */
struct def_algo_kdf_ssh kdf_ssh;
/** DEF_ALG_TYPE_KDF_IKEV1 */
struct def_algo_kdf_ikev1 kdf_ikev1;
/** DEF_ALG_TYPE_KDF_IKEV2 */
struct def_algo_kdf_ikev2 kdf_ikev2;
/** DEF_ALG_TYPE_KDF_TLS / DEF_ALG_TYPE_KDF_TLS12 */
struct def_algo_kdf_tls kdf_tls;
/** DEF_ALG_TYPE_KDF_TLS 1.3 */
struct def_algo_kdf_tls13 kdf_tls13;
/** DEF_ALG_TYPE_KDF_108 */
struct def_algo_kdf_108 kdf_108;
/** DEF_ALG_TYPE_PBKDF */
struct def_algo_pbkdf pbkdf;
/** DEF_ALG_TYPE_KAS_FFC_R3 */
struct def_algo_kas_ffc_r3 kas_ffc_r3;
/** DEF_ALG_TYPE_KAS_ECC_R3 */
struct def_algo_kas_ecc_r3 kas_ecc_r3;
/** DEF_ALG_TYPE_SAFEPRIMES */
struct def_algo_safeprimes safeprimes;
/** DEF_ALG_TYPE_KAS_IFC */
struct def_algo_kas_ifc kas_ifc;
/** DEF_ALG_TYPE_HKDF */
struct def_algo_hkdf hkdf;
/** DEF_ALG_TYPE_COND_COMP */
struct def_algo_cond_comp cond_comp;
/** DEF_ALG_TYPE_KDF_ONESTEP */
struct def_algo_kdf_onestep kdf_onestep;
/** DEF_ALG_TYPE_KDF_TWOSTEP */
struct def_algo_kdf_twostep kdf_twostep;
/** DEF_ALG_TYPE_KDF_TPM */
struct def_algo_kdf_tpm kdf_tpm;
} algo;
};
struct def_algo_map {
const struct def_algo *algos;
unsigned int num_algos;
const char *algo_name;
const char *processor;
const char *impl_name;
const char *impl_description;
struct def_algo_map *next;
};
/**
* @brief Data structure to for registering out-of-tree module implementation
* definitions. This structure should only be used with the
* ACVP_EXTENSION macro.
*/
struct acvp_extension {
struct def_algo_map *curr_map;
unsigned int nrmaps;
};
#define SET_IMPLEMENTATION(impl) .algos = impl, .num_algos = ARRAY_SIZE(impl)
#define IMPLEMENTATION(imp, alg_name, proc, imple_name, imple_description)\
{ \
SET_IMPLEMENTATION(imp), \
.algo_name = alg_name, \
.processor = proc, \
.impl_name = imple_name, \
.impl_description = imple_description \
}
#if defined(ACVPPROXY_EXTENSION)
#define ACVP_EXTENSION(map) \
__attribute__((visibility( \
"default"))) struct acvp_extension acvp_extension = { \
map, ARRAY_SIZE(map) \
};
#else
#define ACVP_EXTENSION(map)
#endif
/**
* @brief Register uninstantiated algorithm definitions (i.e. definitions
* without meta data of module information, operational environment,
* and vendor information).
*
* @param curr_map Pointer to the uninstantiated algorithm definition.
* @param nrmaps Number of map definitions pointed to by curr_map
*/
void acvp_register_algo_map(struct def_algo_map *curr_map,
const unsigned int nrmaps);
#ifdef __cplusplus
}
#endif
#endif /* DEFINITION_H */
| 30.610656 | 80 | 0.726469 |
34a549bc083f335d56022ee4774c9678ea03b4cf | 380 | h | C | Projects/Honeycomb/Honeycomb/Drawers/TagComponentDrawer.h | dSyncro/Honey | 571862e56d2a977d319779be751e5c0ef79de5a1 | [
"MIT"
] | null | null | null | Projects/Honeycomb/Honeycomb/Drawers/TagComponentDrawer.h | dSyncro/Honey | 571862e56d2a977d319779be751e5c0ef79de5a1 | [
"MIT"
] | null | null | null | Projects/Honeycomb/Honeycomb/Drawers/TagComponentDrawer.h | dSyncro/Honey | 571862e56d2a977d319779be751e5c0ef79de5a1 | [
"MIT"
] | null | null | null | #pragma once
#include "ComponentDrawing.h"
#include <Honeycomb/Editor/EditorGUI.h>
namespace Honey {
REGISTER_COMPONENT_DRAWER(TagComponentDrawer, entity)
{
std::string& tag = entity.getComponent<TagComponent>().tag;
static char buffer[256];
memset(buffer, 0, sizeof(buffer));
strcpy_s(buffer, sizeof(buffer), tag.c_str());
EditorGUI::textField("Tag", tag);
}
}
| 20 | 61 | 0.726316 |
90644f1c05d611ec5010ac6eb3a90f583083bdf6 | 846 | h | C | src/base/Creator.h | webOS-ports/appinstalld2 | 4b8fe91a1334460ebc8c960fa78a2dfc6e8b999f | [
"Apache-2.0"
] | 2 | 2018-03-22T19:10:56.000Z | 2019-05-06T05:13:52.000Z | src/base/Creator.h | webosose/appinstalld2 | 4d35a10c9687675a6a458bd03d660984d50ff749 | [
"Apache-2.0"
] | 1 | 2022-01-27T11:02:16.000Z | 2022-02-02T13:51:02.000Z | src/base/Creator.h | webosose/appinstalld2 | 4d35a10c9687675a6a458bd03d660984d50ff749 | [
"Apache-2.0"
] | 4 | 2018-03-22T19:10:58.000Z | 2019-06-21T17:30:03.000Z | // Copyright (c) 2015-2019 LG Electronics, Inc.
//
// 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.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef __CREATOR_H__
#define __CREATOR_H__
//! Creator template class using new operator
template <typename T>
class CreatorUsingNew {
public:
T * operator()() const { return new T; }
};
#endif
| 30.214286 | 75 | 0.738771 |
f11acfb4f977708c76008fc7742010753a2da406 | 277 | h | C | src/akerd.h | JuliaPackageMirrors/RobustStats.jl | e1cb6d9d0fba718b1e496907971381c183148328 | [
"MIT"
] | null | null | null | src/akerd.h | JuliaPackageMirrors/RobustStats.jl | e1cb6d9d0fba718b1e496907971381c183148328 | [
"MIT"
] | null | null | null | src/akerd.h | JuliaPackageMirrors/RobustStats.jl | e1cb6d9d0fba718b1e496907971381c183148328 | [
"MIT"
] | null | null | null | #ifndef __AKERD__
#define __AKERD__
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void akerd_C(double *pts, int npts, double *x, int n, double *alam, double hval, double *output) ;
void alam_C(double *fhat, int n, double gm, double aval, double *output) ;
#endif | 27.7 | 98 | 0.714801 |
52e69172314a8e2f312c61a052af4b7e958f0fc1 | 1,056 | c | C | kernel/kernel.c | namansood/clay | 3aa4bcd7cc92898307c12331928923512992e967 | [
"MIT"
] | 1 | 2020-08-27T07:02:29.000Z | 2020-08-27T07:02:29.000Z | kernel/kernel.c | namansood/clay | 3aa4bcd7cc92898307c12331928923512992e967 | [
"MIT"
] | 1 | 2020-10-05T03:56:15.000Z | 2020-10-05T03:56:15.000Z | kernel/kernel.c | namansood/clay | 3aa4bcd7cc92898307c12331928923512992e967 | [
"MIT"
] | null | null | null | /*
these headers are not part of the C
standard library but provided by the
compiler itself. stdbool provides booleans,
stddef provides stuff like size_t and NULL,
and stdint provides intX_t and uintX_t types.
*/
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "vga/include/vga.h"
void kernel_main(void) {
terminalInit();
terminalPrintf("Hello, world!\n");
terminalPrintf("This is ");
terminalColorPrintf(vgaEntryColor(VGA_CYAN, VGA_BLACK), "Clay");
terminalPrintf(".\n\n");
terminalPrintf("Testing string and character output, \"%s\" and \'%c\'\n", "lmao", '*');
terminalPrintf("Testing literal percent sign, %%\n");
terminalPrintf("Testing binary number, 0b%b\n", 42);
terminalPrintf("Testing octal number, 0%o\n", 69);
terminalPrintf("Testing unsigned decimal number, %u\n", 2147483648);
terminalPrintf("Testing signed decimal number, %d or %i\n", -100, 100);
terminalPrintf("Testing hex number, 0x%x\n", 0xf00dcafe);
terminalPrintf("Testing invalid formatter %P\n");
}
| 34.064516 | 92 | 0.698864 |
135370002473fc28af40f6795b19abc3a08327da | 1,019 | h | C | System/Library/PrivateFrameworks/RelevanceEngine.framework/REShortcutFilter.h | lechium/tvOS145Headers | 9940da19adb0017f8037853e9cfccbe01b290dd5 | [
"MIT"
] | 5 | 2021-04-29T04:31:43.000Z | 2021-08-19T18:59:58.000Z | System/Library/PrivateFrameworks/RelevanceEngine.framework/REShortcutFilter.h | lechium/tvOS145Headers | 9940da19adb0017f8037853e9cfccbe01b290dd5 | [
"MIT"
] | null | null | null | System/Library/PrivateFrameworks/RelevanceEngine.framework/REShortcutFilter.h | lechium/tvOS145Headers | 9940da19adb0017f8037853e9cfccbe01b290dd5 | [
"MIT"
] | 1 | 2022-03-19T11:16:23.000Z | 2022-03-19T11:16:23.000Z | /*
* This header is generated by classdump-dyld 1.5
* on Wednesday, April 28, 2021 at 9:12:16 PM Mountain Standard Time
* Operating System: Version 14.5 (Build 18L204)
* Image Source: /System/Library/PrivateFrameworks/RelevanceEngine.framework/RelevanceEngine
* classdump-dyld is licensed under GPLv3, Copyright © 2013-2016 by Elias Limneos. Updated by Kevin Bradley.
*/
@interface REShortcutFilter : NSObject
+(unsigned long long)filterVersion;
-(id)init;
-(unsigned long long)_actionIdentifierForIntent:(id)arg1 ;
-(unsigned long long)_actionIdentifierForUserActivity:(id)arg1 ;
-(id)intentByFilteringIntent:(id)arg1 withLevel:(unsigned long long)arg2 ;
-(id)userActivityByFilteringUserActivity:(id)arg1 withLevel:(unsigned long long)arg2 ;
-(id)identifierForIntent:(id)arg1 bundleIdentifier:(id)arg2 ;
-(id)identifierForUserActivity:(id)arg1 bundleIdentifier:(id)arg2 ;
@end
| 48.52381 | 130 | 0.685967 |
fb029207557631485eb814a29cd26420c77e92d2 | 545 | c | C | forks/fork-thread.c | stivenramireza/colfax-HPC | 46f2e0cd475d698b35bb2296ddc036f5de19c48b | [
"MIT"
] | 1 | 2019-06-21T22:18:28.000Z | 2019-06-21T22:18:28.000Z | forks/fork-thread.c | stivenramireza/colfax-HPC | 46f2e0cd475d698b35bb2296ddc036f5de19c48b | [
"MIT"
] | null | null | null | forks/fork-thread.c | stivenramireza/colfax-HPC | 46f2e0cd475d698b35bb2296ddc036f5de19c48b | [
"MIT"
] | null | null | null | #include <stdio.h>
#include <unistd.h>
#include <pthread.h>
char msg[100] = "uninitialized";
void *Child_Thread(void *tid) {
printf("In child thread at %p: '%s':\n", &msg, msg);
sleep(2);
printf("In child thread at %p: '%s':\n", &msg, msg);
}
void Parent_Thread() {
sleep(1);
strcpy(msg, "I'm a little teapot, short and stout");
printf("In parent thread at %p: '%s':\n", &msg, msg);
}
int main() {
pthread_t thr;
pthread_create(&thr, NULL, Child_Thread, NULL); // Spawn thread
Parent_Thread();
pthread_exit(NULL);
}
| 19.464286 | 65 | 0.625688 |
1f5c429a5823e934035b424bd458b910b2dc7ecc | 2,294 | h | C | include/stm32_config.h | tyler-gilbert/StratifyOS-mcu-stm32 | faa3234fb89e976e20e3bde03f15abf6a1875251 | [
"MIT"
] | null | null | null | include/stm32_config.h | tyler-gilbert/StratifyOS-mcu-stm32 | faa3234fb89e976e20e3bde03f15abf6a1875251 | [
"MIT"
] | null | null | null | include/stm32_config.h | tyler-gilbert/StratifyOS-mcu-stm32 | faa3234fb89e976e20e3bde03f15abf6a1875251 | [
"MIT"
] | null | null | null | //Copyright (c) 2011-2022 Tyler Gilbert and Stratify Labs, Inc. See LICENSE.md for details
#ifndef STM32_CONFIG_H
#define STM32_CONFIG_H
#include <sdk/types.h>
#include <mcu/uart.h>
#include <sos/dev/pio.h>
void stm32_initialize();
void stm32_initialize_systick();
void stm32_get_serial_number(mcu_sn_t *serial_number);
// mcu
int stm32_mcu_set_pin_function(
const mcu_pin_t *pin,
int periph,
int periph_port);
// clock
void stm32_clock_initialize(
int (*handle_match_channel0)(void *, const mcu_event_t *),
int (*handle_match_channel1)(void *, const mcu_event_t *),
int (*handle_overflow)(void *, const mcu_event_t *));
void stm32_clock_enable();
u32 stm32_clock_disable();
void stm32_clock_set_channel(const mcu_channel_t *channel);
void stm32_clock_get_channel(mcu_channel_t *channel);
u32 stm32_clock_microseconds();
u32 stm32_clock_nanoseconds();
// debug
void stm32_debug_initialize();
void stm32_debug_write(const void *buf, int nbyte);
// pio
void stm32_pio_set_attributes(int port, const pio_attr_t *attr);
void stm32_pio_write(int port, u32 mask, int value);
u32 stm32_pio_read(int port, u32 mask);
// usb
int stm32_usb_set_attributes(const devfs_handle_t *handle, void *ctl);
int stm32_usb_set_action(const devfs_handle_t *handle, mcu_action_t *action);
void stm32_usb_write_endpoint(
const devfs_handle_t *handle,
u32 endpoint_num,
const void *src,
u32 size);
int stm32_usb_read_endpoint(
const devfs_handle_t *handle,
u32 endpoint_num,
void *dest);
enum {
STM32_CONFIG_FLAG_IS_CACHE_ENABLED = (1 << 0),
STM32_CONFIG_FLAG_IS_DEBUG_LED_ACTIVE_HIGH = (1 << 1)
};
#define USB_TX_FIFO_WORD_SIZE_COUNT 9
typedef struct {
void *rx_buffer;
u16 rx_buffer_size;
u16 rx_fifo_word_size /*! RX FIFO word size for all endpoints (STM32) */;
u8 tx_fifo_word_size
[USB_TX_FIFO_WORD_SIZE_COUNT] /*! TX FIFO word size (used on STM32) */;
} stm32_usb_config_t;
typedef struct MCU_PACK {
u16 flash_program_millivolts;
u16 flags;
u32 oscillator_frequency;
stm32_usb_config_t usb;
} stm32_config_t;
// must be defined and provided by board support package
extern const stm32_config_t stm32_config;
typedef struct {
const char *git_hash;
} stm32_git_hash_t;
extern const stm32_git_hash_t stm32_config_git_hash;
#endif // STM32_CONFIG_H
| 26.367816 | 90 | 0.776809 |
1c809e187cd93530e85861080878b79b5e99a2ec | 460 | h | C | ShinobiEngine/Engine/GlobalObjects/Graphix/RenderObject.h | denevcoding/ShinobiEngine2D | 3d29adc18cd4ccbb975969d1ccf348401c715fa4 | [
"Apache-2.0"
] | 1 | 2020-07-22T12:41:02.000Z | 2020-07-22T12:41:02.000Z | ShinobiEngine/Engine/GlobalObjects/Graphix/RenderObject.h | denevcoding/ShinobiEngine2D | 3d29adc18cd4ccbb975969d1ccf348401c715fa4 | [
"Apache-2.0"
] | null | null | null | ShinobiEngine/Engine/GlobalObjects/Graphix/RenderObject.h | denevcoding/ShinobiEngine2D | 3d29adc18cd4ccbb975969d1ccf348401c715fa4 | [
"Apache-2.0"
] | null | null | null | #pragma once
#ifndef _RENDER_OBJECT_H_
#define _RENDER_OBJECT_H_
#include "../../../Global/MathTools/Vec2.h"
#include "../../GameObjectx/Components/Transform2D.h"
//Struct Color for color rendering
struct Color { int R; int G; int B; int A; };
class RenderObject
{
public://Variables
Transform2D* m_transform_2d;
Vec2 pivot;
public://Constructor
RenderObject(): m_transform_2d(nullptr), pivot(Vec2(0,0)) {};
virtual void Render() = 0;
};
#endif
| 19.166667 | 62 | 0.713043 |
46ed041a2e26faaa5e0e00178c8953b23034bf97 | 678 | h | C | include/routingkit/timestamp_flag.h | TheMarex/RoutingKit | 92ad3dd90a82b687a8a9a7468054f2449ff7c67f | [
"BSD-2-Clause"
] | 1 | 2021-04-13T05:54:28.000Z | 2021-04-13T05:54:28.000Z | include/routingkit/timestamp_flag.h | TheMarex/RoutingKit | 92ad3dd90a82b687a8a9a7468054f2449ff7c67f | [
"BSD-2-Clause"
] | null | null | null | include/routingkit/timestamp_flag.h | TheMarex/RoutingKit | 92ad3dd90a82b687a8a9a7468054f2449ff7c67f | [
"BSD-2-Clause"
] | null | null | null | #ifndef ROUTING_KIT_TIMESTAMP_FLAG_H
#define ROUTING_KIT_TIMESTAMP_FLAG_H
#include <vector>
namespace RoutingKit{
class TimestampFlags{
public:
TimestampFlags(){}
explicit TimestampFlags(unsigned id_count):last_seen(id_count, 0), current_timestamp(1){}
bool is_set(unsigned id)const{
return last_seen[id] == current_timestamp;
}
void set(unsigned id){
last_seen[id] = current_timestamp;
}
void reset_all(){
++current_timestamp;
if(current_timestamp == 0){
std::fill(last_seen.begin(), last_seen.end(), 0);
current_timestamp = 1;
}
}
private:
std::vector<unsigned short>last_seen;
unsigned short current_timestamp;
};
} // RoutingKit
#endif
| 17.384615 | 90 | 0.740413 |
2d724885b9909ea6620cb86625b58e5ab59640b8 | 10,808 | h | C | kmd/include/nvdla_interface.h | Miskina/nvdla_sw | 3b6dcaa27bafe9725898bd1c87a966bdbf5a8f7c | [
"Apache-2.0"
] | null | null | null | kmd/include/nvdla_interface.h | Miskina/nvdla_sw | 3b6dcaa27bafe9725898bd1c87a966bdbf5a8f7c | [
"Apache-2.0"
] | null | null | null | kmd/include/nvdla_interface.h | Miskina/nvdla_sw | 3b6dcaa27bafe9725898bd1c87a966bdbf5a8f7c | [
"Apache-2.0"
] | null | null | null | /*
* Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __NVDLA_INTERFACE_H_
#define __NVDLA_INTERFACE_H_
#include <stdint.h>
#include <stdbool.h>
/**
* @brief Register driver to firmware
*
* Implementation in firmware, called by portability layer
*
* This function must be called once during boot to initialize DLA
* engine scheduler and register driver with firmware before submitting
* any task. Pass pointer to driver context in @param driver_context
* which is passed as param when firmware calls any function
* of portability layer. It also updates pointer to engine context
* which must be passed in any function call to firmware after this point.
*
* @param engine_context Pointer to engine specific data
* @param driver_context Pointer to driver specific data
*
* @return 0 on success and negative on error
*/
int32_t dla_register_driver(void **engine_context, void *driver_context);
/**
* @brief Interrupt handler
*
* Implementation in firmware, called by portability layer
*
* This function is called when DLA interrupt is received. Portability layer
* should register it's own handler using the mechanism supported by that platform
* and call this function from the handler. Call to this function must be
* protected by lock to prevent handling interrupt when firmware is programming
* layers in process context.
*
* @param engine_context Engine specific data received in dla_register_driver
*
* @return 0 on success and negative on error
*/
int32_t dla_isr_handler(void *engine_context);
/**
* @brief Process events recorded in interrupt handler
*
* Implementation in firmware, called by portability layer
*
* Interrupt handler just records events and does not process those events.
* Portability layer must call this function in thread/process context after
* interrupt handler is done.
*
* @param engine_context Engine specific data received in dla_register_driver
* @param task_complete Pointer to parameter to indicate task complete,
firmare writes 1 to it if all layers are processed.
*
* @return 0 on success and negative on error
*
*/
int32_t dla_process_events(void *engine_context, uint32_t *task_complete);
/**
* @brief Clear task from firmware
*
* Implementation in firmware, called by portability layer
*
* This function resets engine scheduler state including op descriptor cache,
* error values, sub-engine status, events etc and clears previous task state
* from firmware. This function can be called by portability layer after
* task completion. It is not mandatory to call it but calling it will
* ensure clean state before next task execution.
*
* @param engine_context Engine specific data received in dla_register_driver
*
* @return 0 on success and negative on error
*
*/
void dla_clear_task(void *engine_context);
/**
* @brief Execute task
*
* Implementation in firmware, called by portability layer
*
* This function initializes sub-engines and starts task execution. Further
* programming and layer scheduling is triggered by events received from
* hardware.
*
* @param engine_context Engine specific data received in dla_register_driver
* @param task_data Task specific data to be passed when reading task info
* @param config_data Configuration data to be passed
*
* @return 0 on success and negative on error
*
*/
int32_t dla_execute_task(void *engine_context, void *task_data, void *config_data);
/**
* @brief Register read
*
* Implementation in portability layer, called by firmware
*
* Read DLA HW register. Portability layer is responsible to use correct
* base address and for any IO mapping if required.
*
* @param engine_context Driver specific data received in dla_register_driver
* @param addr Register offset
*
* @return Register value
*
*/
uint32_t dla_reg_read(void *driver_context, uint32_t addr);
/**
* @brief Register write
*
* Implementation in portability layer, called by firmware
*
* Write DLA HW registr. Portability layer is responsible to use correct
* base address and for any IO mapping if required.
*
* @param driver_context Driver specific data received in dla_register_driver
* @param addr Register offset
* @param reg Value to write
*
*/
void dla_reg_write(void *driver_context, uint32_t addr, uint32_t reg);
/**
* @brief Read data from DMA mapped memory in local buffer
*
* Implementation in portability layer, called by firmware
*
* This function reads data from buffers passed by UMD in local memory.
* Addresses for buffers passed by are shared in address list and network
* descriptor contains index in address list for those buffers. Firmware
* reads this data from buffer shared by UMD into local buffer to consume
* the information.
*
* @param driver_context Driver specific data received in dla_register_driver
* @param task_data Task specific data received in dla_execute_task
* @param src Index in address list
* @param dst Pointer to local memory
* @param size Size of data to copy
* @param offset Offset from start of UMD buffer
*
* @return 0 on success and negative on error
*
*/
int32_t dla_data_read(void *driver_context, void *task_data,
uint64_t src, void *dst,
uint32_t size, uint64_t offset);
/**
* @brief Write data to DMA mapped memory from local buffer
*
* Implementation in portability layer, called by firmware
*
* This function writes data from local buffer to buffer passed by UMD.
* Addresses for buffers passed by are shared in address list and network
* descriptor contains index in address list for those buffers. Firmware
* writes this data to buffer shared by UMD from local buffer to update
* the information.
*
* @param driver_context Driver specific data received in dla_register_driver
* @param task_data Task specific data received in dla_execute_task
* @param src Pointer to local memory
* @param dst Index in address list
* @param size Size of data to copy
* @param offset Offset from start of UMD buffer
*
* @return 0 on success and negative on error
*
*/
int32_t dla_data_write(void *driver_context, void *task_data,
void *src, uint64_t dst,
uint32_t size, uint64_t offset);
/* Destination for DMA buffer */
#define DESTINATION_PROCESSOR 0
#define DESTINATION_DMA 1
/**
* @brief Read DMA address
*
* Implementation in portability layer, called by firmware
*
* Some buffers shared by UMD are accessed by processor responsible for
* programming DLA HW. It would be companion micro-controller in case of
* headed config while main CPU in case of headless config. Also, some
* buffers are accessed by DLA DMA engines inside sub-engines. This function
* should return proper address accessible by destination user depending
* on config.
*
* @param driver_context Driver specific data received in dla_register_driver
* @param task_data Task specific data received in dla_execute_task
* @param index Index in address list
* @param dst_ptr Pointer to update address
* @param destination Destination user for DMA address
*
* @return 0 on success and negative on error
*
*/
int32_t dla_get_dma_address(void *driver_context, void *task_data,
int16_t index, void *dst_ptr,
uint32_t destination);
/**
* @brief Read time value in micro-seconds
*
* Implementation in portability layer, called by firmware
*
* Read system time in micro-seconds
*
* @return Time value in micro-seconds
*
*/
int64_t dla_get_time_us(void);
/**
* @brief Print debug message
*
* Implementation in portability layer, called by firmware
*
* Print debug message to console
*
* @param str Format string and variable arguments
*
*/
void dla_debug(const char *str, ...);
/**
* @brief Print information message
*
* Implementation in portability layer, called by firmware
*
* Print information message to console
*
* @param str Format string and variable arguments
*
*/
void dla_info(const char *str, ...);
/**
* @brief Print warning message
*
* Implementation in portability layer, called by firmware
*
* Print warning message to console
*
* @param str Format string and variable arguments
*
*/
void dla_warn(const char *str, ...);
/**
* @brief Print error message
*
* Implementation in portability layer, called by firmware
*
* Print error message to console
*
* @param str Format string and variable arguments
*
*/
void dla_error(const char *str, ...);
/**
* @brief Fill memory region
*
* Implementation in portability layer, called by firmware
*
* Fills the first len bytes of the memory area pointed to by src
* with the constant byte ch.
*
* @param src Memory area address
* @param ch Byte to fill
* @param len Length of memory area to fill
*
* @return Memory area address
*
*/
void *dla_memset(void *src, int ch, uint64_t len);
/**
* @brief Copy memory
*
* Implementation in portability layer, called by firmware
*
* Copies len bytes from memory area src to memory area dest.
*
* @param dest Destination memory area address
* @param src Source memory area address
* @param len Length of memory area to copy
*
* @return Destination memory area address
*
*/
void *dla_memcpy(void *dest, const void *src, uint64_t len);
#endif
| 32.851064 | 83 | 0.745744 |
bff9b31def2c4b3b3c7d9c342c0a5f5d968e7e18 | 468 | h | C | include/entities/me.h | nickbedner/dad-n-me-server | 380ca474b9a5faf162c16901ca3ac0914a1657c3 | [
"MIT"
] | null | null | null | include/entities/me.h | nickbedner/dad-n-me-server | 380ca474b9a5faf162c16901ca3ac0914a1657c3 | [
"MIT"
] | null | null | null | include/entities/me.h | nickbedner/dad-n-me-server | 380ca474b9a5faf162c16901ca3ac0914a1657c3 | [
"MIT"
] | null | null | null | /*#pragma once
#ifndef ME_H
#define ME_H
#include "memoryallocator.h"
//
#include "entities/entity.h"
#include "gamestate.h"
enum MeState {
ME_IDLE_STATE = 0,
ME_WALKING_STATE
};
struct Me {
struct Entity entity;
enum MeState state;
};
struct GameState;
int me_init(struct Me* me, struct GameState* game_state);
void me_delete(struct Me* me, void* other);
void me_update(struct Me* me, struct GameState* game_state, float delta_time);
#endif // ME_H*/
| 16.714286 | 78 | 0.724359 |
f54c121dca66e497d36519386901c4f43535b633 | 6,572 | h | C | gui/main_window/LoginPage.h | mail-ru-im/im-desktop | d6bb606650ad84b31046fe39b81db1fec4e6050b | [
"Apache-2.0"
] | 81 | 2019-09-18T13:53:17.000Z | 2022-03-19T00:44:20.000Z | gui/main_window/LoginPage.h | mail-ru-im/im-desktop | d6bb606650ad84b31046fe39b81db1fec4e6050b | [
"Apache-2.0"
] | 4 | 2019-10-03T15:17:00.000Z | 2019-11-03T01:05:41.000Z | gui/main_window/LoginPage.h | mail-ru-im/im-desktop | d6bb606650ad84b31046fe39b81db1fec4e6050b | [
"Apache-2.0"
] | 25 | 2019-09-27T16:56:02.000Z | 2022-03-14T07:11:14.000Z | #pragma once
#include "../types/common_phone.h"
#include "../controls/TextUnit.h"
#include "accessibility/LinkAccessibleWidget.h"
namespace core
{
namespace stats
{
enum class stats_event_names;
}
}
namespace Ui
{
class LabelEx;
class LineEditEx;
class CommonInputContainer;
class PhoneInputContainer;
class CodeInputContainer;
class TextEditEx;
class CountrySearchCombobox;
class CustomButton;
class DialogButton;
class TermsPrivacyWidget;
class IntroduceYourself;
class TextWidget;
class ContextMenu;
class ContactUsWidget;
class EntryHintWidget : public LinkAccessibleWidget
{
Q_OBJECT
Q_SIGNALS:
void changeClicked();
private:
TextRendering::TextUnitPtr textUnit_;
bool explained_;
private:
void updateSize();
protected:
void paintEvent(QPaintEvent* _event) override;
void mouseReleaseEvent(QMouseEvent* _event) override;
void mouseMoveEvent(QMouseEvent* _event) override;
public:
explicit EntryHintWidget(QWidget* _parent, const QString& _initialText);
void setText(const QString& _text);
void appendPhone(const QString& _text);
void appendLink(const QString& _text, const QString& _link, bool _forceShowLink = false);
const TextRendering::TextUnitPtr& getTextUnit() const override { return textUnit_; }
};
class LoginPage : public QWidget
{
Q_OBJECT
Q_SIGNALS:
void country(const QString&);
void loggedIn();
void attached();
private Q_SLOTS:
void nextPage();
void updateTimer();
void resendCode();
void sendCode();
void callPhone();
void getSmsResult(int64_t, int, int, const QString& _ivrUrl, const QString& _checks);
void loginResult(int64_t, int, bool);
void loginResultAttachPhone(int64_t, int);
void clearErrors(bool ignorePhoneInfo = false);
void codeEditChanged(const QString&);
void stats_edit_phone();
void postSmsSendStats();
void phoneInfoResult(qint64, const Data::PhoneInfo&);
void phoneTextChanged();
void authError(const int _result);
void onUrlConfigError(const int _error);
public Q_SLOTS:
void prevPage();
void switchLoginType();
void openProxySettings();
private Q_SLOTS:
void openOAuth2Dialog();
void onAuthCodeReceived(const QString& _token);
void onAuthDialogResult(int _result);
public:
LoginPage(QWidget* _parent);
~LoginPage() = default;
static bool isCallCheck(const QString& _checks);
protected:
void keyPressEvent(QKeyEvent* _event) override;
void paintEvent(QPaintEvent* _event) override;
void resizeEvent(QResizeEvent* _event) override;
bool eventFilter(QObject* _obj, QEvent* _event) override;
private:
enum class LoginSubpage
{
SUBPAGE_PHONE_LOGIN_INDEX = 0,
SUBPAGE_PHONE_CONF_INDEX = 1,
SUBPAGE_UIN_LOGIN_INDEX = 2,
SUBPAGE_INTRODUCEYOURSELF = 3,
SUBPAGE_REPORT = 4,
SUBPAGE_OAUTH2_LOGIN_INDEX = 5
};
void init();
void login();
void initLoginSubPage(const LoginSubpage _index);
void initGDPR();
bool needGDPRPage() const;
void connectGDPR();
void setGDPRacceptedThisSession(bool _accepted);
bool gdprAcceptedThisSession() const;
void setErrorText(int _result);
void setErrorText(const QString& _customError);
void updateErrors(int _result);
static void updateKeedLoggedInSetting(bool _keep_logged_in);
void prepareLoginByPhone();
void updateBackButton();
void updateNextButton();
void updateInputFocus();
enum class UpdateMode
{
Delayed,
Instant
};
void updatePage(UpdateMode _mode = UpdateMode::Delayed);
void updateButtonsWidgetHeight();
void resizeSpacers();
void setLoginPageFocus() const;
enum class OTPAuthState
{
Email,
Password
};
LoginSubpage currentPage() const;
void updateOTPState(OTPAuthState _state);
std::string statType(const LoginSubpage _page) const;
void showUrlConfigHostDialog();
private:
QStackedWidget* mainStakedWidget_;
TermsPrivacyWidget* termsWidget_;
QTimer* timer_;
LineEditEx* countryCode_;
PhoneInputContainer* phone_;
unsigned int remainingSeconds_;
QStackedWidget* loginStakedWidget_;
QWidget* controlsWidget_;
QWidget* hintsWidget_;
CustomButton* loginButton_;
DialogButton* nextButton_;
CustomButton* changePageButton_;
CustomButton* proxySettingsButton_;
CustomButton* reportButton_;
QPushButton* resendButton_;
CommonInputContainer* uinInput_;
CommonInputContainer* passwordInput_;
QWidget* keepLoggedWidget_;
QWidget* errorWidget_;
QWidget* buttonsWidget_;
QCheckBox* keepLogged_;
CodeInputContainer* codeInput_;
LabelEx* errorLabel_;
TextWidget* titleLabel_;
EntryHintWidget* entryHint_;
QWidget* forgotPasswordWidget_;
LabelEx* forgotPasswordLabel_;
bool isLogin_;
int64_t sendSeq_;
int codeLength_;
bool phoneChangedAuto_;
bool gdprAccepted_;
bool loggedIn_;
Data::PhoneInfo receivedPhoneInfo_;
QString checks_;
QString ivrUrl_;
IntroduceYourself* introduceMyselfWidget_;
ContactUsWidget* contactUsWidget_;
std::optional<OTPAuthState> otpState_;
LoginSubpage lastPage_;
int smsCodeSendCount_;
QSpacerItem* topSpacer_;
QSpacerItem* bottomSpacer_;
ContextMenu* resendMenu_;
QString lastEnteredCode_;
};
}
| 31 | 101 | 0.597535 |
40b3829c078cc0e38cc705be3e397f3e23772a58 | 728 | h | C | cnn_card_embedded_code.X/model/model_weights.h | PaulKlinger/cnn_card | 2e4b5c4947a5a38b841f1dd2b3bad1d89c03fe8b | [
"MIT"
] | 77 | 2020-11-22T17:55:31.000Z | 2022-01-16T23:31:46.000Z | cnn_card_embedded_code.X/model/model_weights.h | PaulKlinger/cnn_card | 2e4b5c4947a5a38b841f1dd2b3bad1d89c03fe8b | [
"MIT"
] | null | null | null | cnn_card_embedded_code.X/model/model_weights.h | PaulKlinger/cnn_card | 2e4b5c4947a5a38b841f1dd2b3bad1d89c03fe8b | [
"MIT"
] | 3 | 2020-11-23T23:06:56.000Z | 2021-05-14T11:17:51.000Z | /*
* File: model_weights.h
* Author: kling
*
* Created on 26 September 2020, 23:02
*/
#ifndef MODEL_WEIGHTS_H
#define MODEL_WEIGHTS_H
#ifdef __cplusplus
extern "C" {
#endif
struct float_4tensor conv0_kernel;
struct float_4tensor conv0_bias;
const float conv0_activation_99per;
struct float_4tensor conv1_kernel;
struct float_4tensor conv1_bias;
const float conv1_activation_99per;
struct float_4tensor conv2_kernel;
struct float_4tensor conv2_bias;
const float conv2_activation_99per;
struct float_4tensor dense_kernel;
struct float_4tensor dense_bias;
#ifdef __cplusplus
}
#endif
#endif /* MODEL_WEIGHTS_H */
| 19.675676 | 40 | 0.692308 |
09d871f0f60f4abe27fa345c5434b2c5ac2a467f | 676 | h | C | src/JPKit/JPModels/JPModelMap.h | jpmcglone/JPKit | a172955051d21c9c83f703a04c9d7c3ec8c90137 | [
"MIT"
] | 2 | 2015-07-04T17:52:24.000Z | 2015-09-02T05:09:06.000Z | src/JPKit/JPModels/JPModelMap.h | jpmcglone/JPKit | a172955051d21c9c83f703a04c9d7c3ec8c90137 | [
"MIT"
] | null | null | null | src/JPKit/JPModels/JPModelMap.h | jpmcglone/JPKit | a172955051d21c9c83f703a04c9d7c3ec8c90137 | [
"MIT"
] | null | null | null | //
// Created by JP McGlone on 4/23/14.
// Copyright (c) 2014 JP McGlone. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface JPModelMap : NSObject
+ (NSArray *)mapsWithSingularKey:(NSString *)singularKey
pluralKey:(NSString *)pluralKey
class:(Class)aClass;
@property (nonatomic, copy) NSString *key;
// YES is an array of aClass objects, NO is just an aClass object
@property (nonatomic, assign) BOOL isPlural;
@property (nonatomic, assign) Class aClass;
- (id)initWithJSON:(NSDictionary *)JSON;
- (id)initWithKey:(NSString *)key
class:(Class)aClass
isPlural:(BOOL)isPlural;
@end | 26 | 65 | 0.664201 |
6777880ff2d81f14baff3e169a5c60f4024e066f | 40,644 | c | C | kernel/drivers/devkit/tpkit/3_0/panel/gt1x/gt1x_test.c | wonderful666/marx-10.1.0 | a8be8880fe31bff4f94d6e3fad17c455666ff60f | [
"MIT"
] | null | null | null | kernel/drivers/devkit/tpkit/3_0/panel/gt1x/gt1x_test.c | wonderful666/marx-10.1.0 | a8be8880fe31bff4f94d6e3fad17c455666ff60f | [
"MIT"
] | null | null | null | kernel/drivers/devkit/tpkit/3_0/panel/gt1x/gt1x_test.c | wonderful666/marx-10.1.0 | a8be8880fe31bff4f94d6e3fad17c455666ff60f | [
"MIT"
] | null | null | null | /*
* gt1x_ts_test.c - TP test
*
* Copyright (C) 2015 - 2016 gt1x Technology Incorporated
* Copyright (C) 2015 - 2016 Yulong Cai <caiyulong@gt1x.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be a reference
* to you, when you are integrating the gt1x's CTP IC into your system,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
*/
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/firmware.h>
#include "gt1x.h"
#include "../../huawei_ts_kit.h"
#define SHORT_TO_GND_RESISTER(sig) (div_s64(5266285, (sig) & (~0x8000)) - 40 * 100) /* 52662.85/code-40 */
#define SHORT_TO_VDD_RESISTER(sig, value) (div_s64((s64)(36864 * ((value) - 9)) * 100, (((sig) & (~0x8000)) * 7)) - 40 * 100)
#define FLOAT_AMPLIFIER 1000
#define MAX_U16_VALUE 65535
#define RAWDATA_TEST_TIMES 10
#define MAX_ACCEPT_FAILE_CNT 2
#define STATISTICS_DATA_LEN 32
#define MAX_TEST_ITEMS 10 /* 0P-1P-2P-3P-5P total test items */
#define GTP_CAP_TEST 1
#define GTP_DELTA_TEST 2
#define GTP_NOISE_TEST 3
#define GTP_SHORT_TEST 5
#define GTP_TEST_PASS 1
#define GTP_PANEL_REASON 2
#define SYS_SOFTWARE_REASON 3
#define CSV_TP_UNIFIED_LIMIT "unified_raw_limit"
#define CSV_TP_NOISE_LIMIT "noise_data_limit"
#define CSV_TP_SPECIAL_RAW_MIN "specail_raw_min"
#define CSV_TP_SPECIAL_RAW_MAX "specail_raw_max"
#define CSV_TP_SPECIAL_RAW_DELTA "special_raw_delta"
#define CSV_TP_SHORT_THRESHOLD "shortciurt_threshold"
char *gt1x_strncat(char *dest, char *src, size_t dest_size);
/**
* struct ts_test_params - test parameters
* drv_num: touch panel tx(driver) number
* sen_num: touch panel tx(sensor) number
* max_limits: max limits of rawdata
* min_limits: min limits of rawdata
* deviation_limits: channel deviation limits
* short_threshold: short resistance threshold
* r_drv_drv_threshold: resistance threshold between drv and drv
* r_drv_sen_threshold: resistance threshold between drv and sen
* r_sen_sen_threshold: resistance threshold between sen and sen
* r_drv_gnd_threshold: resistance threshold between drv and gnd
* r_sen_gnd_threshold: resistance threshold between sen and gnd
* avdd_value: avdd voltage value
*/
struct ts_test_params {
u32 drv_num;
u32 sen_num;
u32 max_limits[MAX_DRV_NUM * MAX_SEN_NUM];
u32 min_limits[MAX_DRV_NUM * MAX_SEN_NUM];
u32 deviation_limits[MAX_DRV_NUM * MAX_SEN_NUM];
u32 noise_threshold;
u32 short_threshold;
u32 r_drv_drv_threshold;
u32 r_drv_sen_threshold;
u32 r_sen_sen_threshold;
u32 r_drv_gnd_threshold;
u32 r_sen_gnd_threshold;
u32 avdd_value;
};
/**
* struct ts_test_rawdata - rawdata structure
* data: rawdata buffer
* size: rawdata size
*/
struct ts_test_rawdata {
u16 data[MAX_SEN_NUM * MAX_DRV_NUM];
u32 size;
};
/**
* struct gt1x_ts_test - main data structrue
* ts: gt1x touch screen data
* test_config: test mode config data
* orig_config: original config data
* test_param: test parameters
* rawdata: raw data structure
* test_result: test result string
*/
struct gt1x_ts_test {
struct gt1x_ts_data *ts;
struct gt1x_ts_config test_config;
struct gt1x_ts_config orig_config;
struct ts_test_params test_params;
struct ts_test_rawdata rawdata;
struct ts_test_rawdata noisedata;
/*[0][0][0][0][0].. 0 without test; 1 pass, 2 panel failed; 3 software failed */
char test_result[MAX_TEST_ITEMS];
char test_info[TS_RAWDATA_RESULT_MAX];
};
struct gt1x_ts_test *gts_test = NULL;
static int gt1x_init_testlimits(struct gt1x_ts_test *ts_test)
{
int ret = 0, i;
char file_path[100] = {0};
char file_name[GT1X_FW_NAME_LEN] = {0};
u32 data_buf[MAX_DRV_NUM] = {0};
struct gt1x_ts_data *ts = ts_test->ts;
struct ts_test_params *test_params = NULL;
snprintf(file_name, GT1X_FW_NAME_LEN, "%s_%s_%s_%s_limits.csv",
ts->dev_data->ts_platform_data->product_name, GT1X_OF_NAME,
ts->project_id, ts->dev_data->module_name);
#ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
snprintf(file_path, sizeof(file_path), "/product/etc/firmware/ts/%s", file_name);
#else
snprintf(file_path, sizeof(file_path), "/odm/etc/firmware/ts/%s", file_name);
#endif
TS_LOG_INFO("%s: csv_file_path =%s\n", __func__, file_path);
test_params = &ts_test->test_params;
/* <max_threshold, min_threshold, delta_threshold> */
ret = ts_kit_parse_csvfile(file_path, CSV_TP_UNIFIED_LIMIT, data_buf, 1, 3);
if (ret) {
TS_LOG_INFO("%s: Failed get %s \n", __func__, CSV_TP_UNIFIED_LIMIT);
return ret;
}
/* store data to test_parms */
for(i = 0; i < MAX_DRV_NUM * MAX_SEN_NUM; i++) {
test_params->max_limits[i] = data_buf[0];
test_params->min_limits[i] = data_buf[1];
test_params->deviation_limits[i] = data_buf[2];
}
ret = ts_kit_parse_csvfile(file_path, CSV_TP_NOISE_LIMIT, data_buf, 1, 1);
if (ret) {
TS_LOG_INFO("%s: Failed get %s \n", __func__, CSV_TP_NOISE_LIMIT);
return ret;
}
test_params->noise_threshold = data_buf[0];
/* shortciurt_threshold <short_threshold,drv_to_drv,
drv_to_sen,sen_to_sen, drv_to_gnd, sen_to_gnd, avdd_r> */
ret = ts_kit_parse_csvfile(file_path, CSV_TP_SHORT_THRESHOLD, data_buf, 1, 7);
if (ret) {
TS_LOG_INFO("%s: Failed get %s \n", __func__, CSV_TP_SHORT_THRESHOLD);
return ret;
}
test_params->short_threshold = data_buf[0];
test_params->r_drv_drv_threshold = data_buf[1];
test_params->r_drv_sen_threshold = data_buf[2];
test_params->r_sen_sen_threshold = data_buf[3];
test_params->r_drv_gnd_threshold = data_buf[4];
test_params->r_sen_gnd_threshold = data_buf[5];
test_params->avdd_value = data_buf[6];
ret = ts_kit_parse_csvfile(file_path, CSV_TP_SPECIAL_RAW_MAX, test_params->max_limits,
test_params->drv_num, test_params->sen_num);
if (ret) {
TS_LOG_INFO("%s: Failed get %s \n", __func__, CSV_TP_SPECIAL_RAW_MAX);
ret = 0; /* if does not specialed the node value, we will use unified limits setting */
}
ret = ts_kit_parse_csvfile(file_path, CSV_TP_SPECIAL_RAW_MIN, test_params->min_limits,
test_params->drv_num, test_params->sen_num);
if (ret) {
TS_LOG_INFO("%s: Failed get %s \n", __func__, CSV_TP_SPECIAL_RAW_MIN);
ret = 0;
}
ret = ts_kit_parse_csvfile(file_path, CSV_TP_SPECIAL_RAW_DELTA, test_params->deviation_limits,
test_params->drv_num, test_params->sen_num);
if (ret) {
TS_LOG_INFO("%s: Failed get %s \n", __func__, CSV_TP_SPECIAL_RAW_DELTA);
ret = 0;
}
return ret;
}
/* gt1x_read_origconfig
*
* read original config data
*/
static int gt1x_cache_origconfig(struct gt1x_ts_test *ts_test)
{
int ret = -ENODEV;
int cfg_size = 0;
cfg_size = GTP_CONFIG_ORG_LENGTH;
if (ts_test->ts->ops.i2c_read) {
ret = ts_test->ts->ops.i2c_read(GTP_REG_CONFIG_DATA,&ts_test->orig_config.data[0], cfg_size);
if (ret < 0) {
TS_LOG_ERR("Failed to read original config data\n");
return ret;
}
if (ts_test->orig_config.data[EXTERN_CFG_OFFSET] & 0x40) {
ret = ts_test->ts->ops.i2c_read(GTP_REG_EXT_CONFIG,&ts_test->orig_config.data[cfg_size],
GTP_CONFIG_EXT_LENGTH);
if (ret < 0) {
TS_LOG_ERR("Failed to read external config data\n");
return ret;
}
cfg_size += GTP_CONFIG_EXT_LENGTH;
}
ts_test->orig_config.size = cfg_size;
ts_test->orig_config.delay_ms = SEND_CFG_FLASH;
strncpy(ts_test->orig_config.name, "original_config", MAX_STR_LEN);
ts_test->orig_config.initialized = true;
}
return ret;
}
/* gt1x_tptest_prepare
*
* preparation before tp test
*/
static int gt1x_tptest_prepare(struct gt1x_ts_test *ts_test)
{
int ret = 0;
TS_LOG_INFO("TP test preparation\n");
ret = gt1x_cache_origconfig(ts_test);
if (ret) {
TS_LOG_ERR("Failed cache origin config\n");
return ret;
}
/*same config version, ensure firmware will accept this test config data */
ts_test->ts->test_config.data[0] = ts_test->orig_config.data[0];
ret = gt1x_get_channel_num(
&ts_test->test_params.sen_num,
&ts_test->test_params.drv_num);
if (ret) {
TS_LOG_ERR("Failed get channel num:%d\n", ret);
ts_test->test_params.sen_num = MAX_DRV_NUM;
ts_test->test_params.drv_num = MAX_SEN_NUM;
return ret;
}
if (true == ts_test->ts->open_threshold_status){
/* parse test limits from csv */
ret = gt1x_init_testlimits(ts_test);
if (ret) {
TS_LOG_ERR("Failed to init testlimits from csv:%d\n", ret);
return ret;
}
if (ts_test->ts->only_open_once_captest_threshold) {
ts_test->ts->open_threshold_status = false;
}
}
if (ts_test->ts->ops.send_cfg) {
ts_test->ts->noise_test_config.data[6] |=0x80;
ret = ts_test->ts->ops.send_cfg(&ts_test->ts->noise_test_config);
if (ret) {
ts_test->ts->noise_test_config.data[6] &=0x7f;
TS_LOG_ERR("Failed to send noise test config config:%d\n", ret);
return ret;
}
ts_test->ts->noise_test_config.data[6] &=0x7f;
TS_LOG_INFO("send noise test config success :%d\n", ret);
}
return ret;
}
/* gt1x_tptest_finish
*
* finish test
*/
static int gt1x_tptest_finish(struct gt1x_ts_test *ts_test)
{
int ret = RESULT_ERR;
TS_LOG_INFO("TP test finish\n");
ret = gt1x_chip_reset();
if (ret < 0)
TS_LOG_ERR("%s: chip reset failed\n", __func__);
if (ts_test->ts->ops.send_cfg) {
ret = ts_test->ts->ops.send_cfg(&ts_test->orig_config);
if (ret) {
TS_LOG_ERR("Failed to send normal config:%d\n", ret);
return ret;
}
} else
TS_LOG_ERR("%s: send_cfg is NULL, recover origin cfg failed\n", __func__);
return ret;
}
/**
* gt1x_cache_rawdata - cache rawdata
*/
static int gt1x_cache_rawdata(struct gt1x_ts_test *ts_test)
{
int i=0, j;
int retry;
int ret = -EINVAL;
u8 buf[1] = {0x00};
u32 rawdata_size=0;
u16 rawdata_addr = 0;
TS_LOG_DEBUG("Cache rawdata\n");
rawdata_size = ts_test->test_params.sen_num *
ts_test->test_params.drv_num;
if (rawdata_size > MAX_DRV_NUM * MAX_SEN_NUM || rawdata_size <= 0) {
TS_LOG_ERR("Invalid rawdata size(%u)\n", rawdata_size);
return ret;
}
ts_test->rawdata.size = rawdata_size;
if (IC_TYPE_9P == ts_test->ts->ic_type)
rawdata_addr = GTP_RAWDATA_ADDR_9P;
else
rawdata_addr = GTP_RAWDATA_ADDR_9PT;
TS_LOG_INFO("Rawdata address=0x%x\n", rawdata_addr);
for(j = 0; j< GT1X_RETRY_NUM -1; j++){
ret = ts_test->ts->ops.send_cmd(GTP_CMD_RAWDATA, 0x00, GT1X_NEED_SLEEP);
if (ret){
TS_LOG_ERR("%s:Failed send rawdata cmd:ret%d\n", __func__, ret);
goto cache_exit;
}else{
TS_LOG_INFO("%s: Success change to rawdata mode\n", __func__);
}
for (retry = 0;retry < GT1X_RETRY_NUM; retry++) {
ret = ts_test->ts->ops.i2c_read(GTP_READ_COOR_ADDR, &buf[0], 1);
if ((ret== 0) && (buf[0] & 0x80) == 0x80) {
TS_LOG_INFO("Success read rawdata\n");
break;
}
TS_LOG_INFO("Rawdata in not ready:ret=%d, buf[0]=0x%x\n", ret, buf[0]);
msleep(15);
}
if (retry < GT1X_RETRY_NUM) {
/* read rawdata */
ret = ts_test->ts->ops.i2c_read(
rawdata_addr,
(u8 *)&ts_test->rawdata.data[0],
rawdata_size * 2);
if (ret < 0) {
TS_LOG_ERR("Failed to read rawdata:%d\n", ret);
goto cache_exit;
}
for (i = 0; i < rawdata_size; i++)
ts_test->rawdata.data[i] =be16_to_cpu(ts_test->rawdata.data[i]);
TS_LOG_INFO("Rawdata ready\n");
break;
} else {
TS_LOG_ERR("%s : Read rawdata timeout, retry[%d] send command\n", __func__, j);
ret = -EFAULT;
}
}
cache_exit:
/* clear data ready flag */
buf[0] = 0x00;
ts_test->ts->ops.i2c_write(GTP_READ_COOR_ADDR, &buf[0], 1);
return ret;
}
/* test noise data */
static void gt1x_test_noisedata(struct gt1x_ts_test *ts_test)
{
int ret = 0, i = 0;
u32 data_size;
int test_cnt;
int fail_cnt;
u32 find_bad_node = 0;
u8 buf[1] = {0x00};
u8 *data_buf;
u32 noisedata_addr = 0;
ts_test->noisedata.size = 0;
data_size = ts_test->test_params.sen_num *
ts_test->test_params.drv_num;
if (IC_TYPE_9P == ts_test->ts->ic_type)
noisedata_addr = GTP_REG_NOISEDATA_9P;
else
noisedata_addr = GTP_REG_NOISEDATA_9PT;
if (data_size <= 0 || data_size > MAX_DRV_NUM * MAX_SEN_NUM) {
TS_LOG_ERR("%s: Bad data_size[%d]\n", __func__, data_size);
ts_test->test_result[GTP_NOISE_TEST] = SYS_SOFTWARE_REASON;
return;
}
data_buf = (u8*) kzalloc(data_size, GFP_KERNEL);
if (!data_buf) {
TS_LOG_ERR("%s:Failed alloc memory\n", __func__);
ts_test->test_result[GTP_NOISE_TEST] = SYS_SOFTWARE_REASON;
return;
}
/* change to rawdata mode */
ret = ts_test->ts->ops.send_cmd(GTP_CMD_RAWDATA, 0x00 ,GT1X_NEED_SLEEP);
if (ret) {
TS_LOG_ERR("%s: Failed send rawdata command:ret%d\n", __func__, ret);
ts_test->test_result[GTP_NOISE_TEST] = SYS_SOFTWARE_REASON;
goto exit;
}
TS_LOG_INFO("%s: Enter rawdata mode\n", __func__);
fail_cnt = 0;
for (test_cnt = 0; test_cnt < RAWDATA_TEST_TIMES; test_cnt++) {
for (i = 0; i < GT1X_RETRY_NUM; i++) {
ret = ts_test->ts->ops.i2c_read(GTP_READ_COOR_ADDR, &buf[0], 1);
if ((ret == 0) && (buf[0] & 0x80))
break;
else if (ret) {
TS_LOG_ERR("%s: failed read noise data status\n", __func__);
goto soft_err_out;
}
msleep(15); /* waiting for noise data ready */
}
if (i >= GT1X_RETRY_NUM) {
fail_cnt++;
TS_LOG_INFO("%s: wait for noise data timeout, retry[%d] send command\n", __func__, fail_cnt);
ret = ts_test->ts->ops.send_cmd(GTP_CMD_RAWDATA, 0x00 ,GT1X_NEED_SLEEP);
if (ret) {
TS_LOG_ERR("%s: Failed send rawdata command, fail_cnt[%d]\n", __func__, fail_cnt);
goto soft_err_out;
}
continue;
}
/* read noise data */
ret = ts_test->ts->ops.i2c_read(noisedata_addr,
data_buf, data_size);
if (!ret) {
/* check noise data */
find_bad_node = 0;
for (i = 0; i < data_size; i++) {
if (data_buf[i] > ts_test->test_params.noise_threshold) {
find_bad_node++;
TS_LOG_ERR("noise check failed: niose[%d][%d]:%u, > %u\n",
(u32)div_s64(i, ts_test->test_params.sen_num),
i % ts_test->test_params.sen_num, data_buf[i],
ts_test->test_params.noise_threshold);
}
}
if (find_bad_node) {
TS_LOG_INFO("%s:noise test find bad node, test times=%d\n",__func__, test_cnt );
fail_cnt++;
}
} else {
TS_LOG_INFO("%s:Failed read noise data\n", __func__);
goto soft_err_out;
}
/* clear data ready flag */
buf[0] = 0x00;
ret = ts_test->ts->ops.i2c_write(GTP_READ_COOR_ADDR, &buf[0], 1);
if (ret) {
TS_LOG_ERR("%s:failed clear noise data ready register\n", __func__);
goto soft_err_out;
}
}
if (fail_cnt <= MAX_ACCEPT_FAILE_CNT) {
ts_test->test_result[GTP_NOISE_TEST] = GTP_TEST_PASS;
} else {
TS_LOG_ERR("%s :Noise test failed\n", __func__);
ts_test->test_result[GTP_NOISE_TEST] = GTP_PANEL_REASON;
}
/* cache noise data */
for (i = 0; i < data_size; i++) {
ts_test->noisedata.data[i] = (u16)data_buf[i];
ts_test->noisedata.size = data_size;
}
TS_LOG_INFO("%s:Noise test fail_cnt =%d\n", __func__, fail_cnt);
ret = ts_test->ts->ops.send_cmd(GTP_CMD_NORMAL, 0x00, GT1X_NEED_SLEEP);
if (ret)
TS_LOG_ERR("Failed send normal mode cmd:ret%d\n", ret);
goto exit;
soft_err_out:
buf[0] = 0x00;
ts_test->ts->ops.i2c_write(GTP_READ_COOR_ADDR, &buf[0], 1);
ts_test->noisedata.size = 0;
ts_test->test_result[GTP_NOISE_TEST] = SYS_SOFTWARE_REASON;
exit:
if(data_buf){
TS_LOG_INFO("%s: kfree data_buf.\n", __func__);
kfree(data_buf);
data_buf = NULL;
}
return;
}
static int gt1x_rawcapacitance_test(struct ts_test_rawdata *rawdata,
struct ts_test_params *test_params)
{
int i =0;
int ret = NO_ERR;
for (i = 0; i < rawdata->size; i++) {
if (rawdata->data[i] > test_params->max_limits[i]) {
TS_LOG_ERR("rawdata[%d][%d]:%u > max_limit:%u, NG\n",
(u32)div_s64(i, test_params->sen_num), i % test_params->sen_num,
rawdata->data[i], test_params->max_limits[i]);
ret = RESULT_ERR;
}
if (rawdata->data[i] < test_params->min_limits[i]) {
TS_LOG_ERR("rawdata[%d][%d]:%u < min_limit:%u, NG\n",
(u32)div_s64(i, test_params->sen_num), i % test_params->sen_num,
rawdata->data[i], test_params->min_limits[i]);
ret = RESULT_ERR;
}
}
return ret;
}
static int gt1x_deltacapacitance_test(struct ts_test_rawdata *rawdata,
struct ts_test_params *test_params)
{
int i=0;
int ret;
int cols = 0;
u32 max_val = 0;
u32 rawdata_val=0;
u32 sc_data_num=0;
u32 up = 0, down = 0, left = 0, right = 0;
ret = NO_ERR;
cols = test_params->sen_num;
sc_data_num = test_params->drv_num * test_params->sen_num;
if (cols <= 0) {
TS_LOG_ERR("%s: parmas invalid\n", __func__);
return RESULT_ERR;
}
for (i = 0; i < sc_data_num; i++) {
rawdata_val = rawdata->data[i];
max_val = 0;
/* calculate deltacpacitance with above node */
if (i - cols >= 0) {
up = rawdata->data[i - cols];
up = abs(rawdata_val - up);
if (up > max_val)
max_val = up;
}
/* calculate deltacpacitance with bellow node */
if (i + cols < sc_data_num) {
down = rawdata->data[i + cols];
down = abs(rawdata_val - down);
if (down > max_val)
max_val = down;
}
/* calculate deltacpacitance with left node */
if (i % cols) {
left = rawdata->data[i - 1];
left = abs(rawdata_val - left);
if (left > max_val)
max_val = left;
}
/* calculate deltacpacitance with right node */
if ((i + 1) % cols) {
right = rawdata->data[i + 1];
right = abs(rawdata_val - right);
if (right > max_val)
max_val = right;
}
/* float to integer */
if (rawdata_val) {
max_val *= FLOAT_AMPLIFIER;
max_val = (u32)div_s64(max_val, rawdata_val);
if (max_val > test_params->deviation_limits[i]) {
TS_LOG_ERR("deviation[%d][%d]:%u > delta_limit:%u, NG\n",
(u32)div_s64(i, cols), i % cols, max_val,
test_params->deviation_limits[i]);
ret = RESULT_ERR;
}
} else {
TS_LOG_ERR("Find rawdata=0 when calculate deltacapacitance:[%d][%d]\n",
(u32)div_s64(i, cols), i % cols);
ret = RESULT_ERR;
}
}
return ret;
}
/* gt1x_captest_prepare
*
* parse test peremeters from dt
*/
static int gt1x_captest_prepare(struct gt1x_ts_test *ts_test)
{
int ret = -EINVAL;
if (ts_test->ts->ops.send_cfg) {
ret = ts_test->ts->ops.send_cfg(&ts_test->ts->test_config);
if (ret)
TS_LOG_ERR("Failed to send test config:%d\n", ret);
else {
TS_LOG_INFO("Success send test config");
}
} else
TS_LOG_ERR("Ops.send_cfg is NULL\n");
return ret;
}
static void gt1x_capacitance_test(struct gt1x_ts_test *ts_test)
{
int ret=0;
ret = gt1x_captest_prepare(ts_test);
if (ret) {
TS_LOG_ERR("Captest prepare failed\n");
ts_test->test_result[GTP_CAP_TEST] = SYS_SOFTWARE_REASON;
ts_test->test_result[GTP_DELTA_TEST] = SYS_SOFTWARE_REASON;
return;
}
/* read rawdata and calculate result, statistics fail times */
ret = gt1x_cache_rawdata(ts_test);
if (ret < 0) {
/* Failed read rawdata */
TS_LOG_ERR("Read rawdata failed\n");
ts_test->test_result[GTP_CAP_TEST] = SYS_SOFTWARE_REASON;
ts_test->test_result[GTP_DELTA_TEST] = SYS_SOFTWARE_REASON;
return;
}
ret = gt1x_rawcapacitance_test(&ts_test->rawdata,&ts_test->test_params);
if (!ret) {
ts_test->test_result[GTP_CAP_TEST] = GTP_TEST_PASS;
TS_LOG_INFO("Rawdata test pass\n");
} else {
ts_test->test_result[GTP_CAP_TEST] = GTP_PANEL_REASON;
TS_LOG_ERR("RawCap test failed\n");
}
ret = gt1x_deltacapacitance_test(&ts_test->rawdata,&ts_test->test_params);
if (!ret) {
ts_test->test_result[GTP_DELTA_TEST] = GTP_TEST_PASS;
TS_LOG_INFO("DeltaCap test pass\n");
} else {
ts_test->test_result[GTP_DELTA_TEST] = GTP_PANEL_REASON;
TS_LOG_ERR("DeltaCap test failed\n");
}
return;
}
static void gt1x_shortcircut_test(struct gt1x_ts_test *ts_test);
static void gt1x_put_test_result(struct ts_rawdata_info *info, struct gt1x_ts_test *ts_test);
/** gt1x_put_test_failed_prepare_newformat *
* i2c prepare Abnormal failed */
static void gt1x_put_test_failed_prepare_newformat(struct ts_rawdata_info_new *info)
{
int ret = 0;
ret = gt1x_strncat(info->i2cinfo, "0F", sizeof(info->i2cinfo));
if(!ret){
TS_LOG_ERR("%s: strncat 0F failed.\n", __func__);
}
ret = gt1x_strncat(info->i2cerrinfo, "software reason", sizeof(info->i2cerrinfo));
if(!ret){
TS_LOG_ERR("%s: strncat software reason failed.\n", __func__);
}
return;
}
int gt1x_get_rawdata(struct ts_rawdata_info *info,struct ts_cmd_node *out_cmd)
{
int ret = 0;
if (!gt1x_ts || !info){
TS_LOG_ERR("%s: gt1x_ts is NULL\n", __func__);
return -ENODEV;
}
if (!gts_test) {
gts_test = kzalloc(sizeof(struct gt1x_ts_test),GFP_KERNEL);
if (!gts_test) {
TS_LOG_ERR("%s: Failed to alloc mem\n", __func__);
return -ENOMEM;
}
gts_test->ts = gt1x_ts;
} else {
memset(gts_test->test_result, 0, MAX_TEST_ITEMS);
memset(gts_test->test_info, 0, TS_RAWDATA_RESULT_MAX);
memset(&(gts_test->rawdata), 0, sizeof(struct ts_test_rawdata));
memset(&(gts_test->noisedata), 0, sizeof(struct ts_test_rawdata));
}
ret = gt1x_tptest_prepare(gts_test);
if (ret) {
TS_LOG_ERR("%s: Failed parse test peremeters, exit test\n", __func__);
if (gt1x_ts->dev_data->ts_platform_data->chip_data->rawdata_newformatflag == TS_RAWDATA_NEWFORMAT) {
gt1x_put_test_failed_prepare_newformat((struct ts_rawdata_info_new *)info);
} else {
strncpy(info->result, "0F-software reason", TS_RAWDATA_RESULT_MAX -1);
}
goto exit_finish;
}
TS_LOG_INFO("%s: TP test prepare OK\n", __func__);
gt1x_test_noisedata(gts_test); /*3F test*/
gt1x_capacitance_test(gts_test); /* 1F 2F test*/
gt1x_shortcircut_test(gts_test); /* 5F test */
gt1x_put_test_result(info, gts_test);
gt1x_tptest_finish(gts_test);
return ret;
exit_finish:
if(gts_test)
kfree(gts_test);
gts_test = NULL;
gt1x_ts->open_threshold_status = true;
return ret;
}
char *gt1x_strncat(char *dest, char *src, size_t dest_size)
{
size_t dest_len = 0;
dest_len = strnlen(dest, dest_size);
return strncat(&dest[dest_len], src, (dest_size > dest_len ? (dest_size - dest_len - 1) : 0));
}
char *gt1x_strncatint(char * dest, int src, char * format, size_t dest_size)
{
char src_str[MAX_STR_LEN] = {0};
snprintf(src_str, MAX_STR_LEN, format, src);
return gt1x_strncat(dest, src_str, dest_size);
}
/** gt1x_data_statistics
*
* catlculate Avg Min Max value of data
*/
static void gt1x_data_statistics(u16 *data, size_t data_size, char *result, size_t res_size)
{
u16 i=0;
u16 avg = 0;
u16 min = 0;
u16 max = 0;
long long sum = 0;
if (!data || !result) {
TS_LOG_ERR("parameters error please check *data and *result value\n");
return;
}
if (data_size <= 0 || res_size <= 0) {
TS_LOG_ERR("input parameter is illegva:data_size=%ld, res_size=%ld\n",
data_size, res_size);
return;
}
min=data[0];
max=data[0];
for (i = 0; i < data_size; i++) {
sum += data[i];
if (max < data[i])
max = data[i];
if (min > data[i])
min=data[i];
}
avg=div_s64(sum, data_size);
memset(result, 0, res_size);
snprintf(result, res_size, "[%d,%d,%d]", avg, max, min);
return;
}
static void gt1x_put_test_result_newformat(
struct ts_rawdata_info_new *info,
struct gt1x_ts_test *ts_test)
{
int i = 0;
int have_bus_error = 0;
int have_panel_error = 0;
char statistics_data[STATISTICS_DATA_LEN] = {0};
struct ts_rawdata_newnodeinfo * pts_node = NULL;
char testresut[]={' ','P','F','F'};
TS_LOG_INFO("%s :\n",__func__);
info->tx = ts_test->test_params.sen_num;
info->rx = ts_test->test_params.drv_num;
/* i2c info */
for (i = 0; i < MAX_TEST_ITEMS; i++) {
if (ts_test->test_result[i] == SYS_SOFTWARE_REASON)
have_bus_error = 1;
else if (ts_test->test_result[i] == GTP_PANEL_REASON)
have_panel_error = 1;
}
if (have_bus_error)
gt1x_strncat(info->i2cinfo, "0F", sizeof(info->i2cinfo));
else
gt1x_strncat(info->i2cinfo, "0P", sizeof(info->i2cinfo));
/********************************************************************/
/* enum ts_raw_data_type
/* {
/* RAW_DATA_TYPE_IC = 0,
/* #define GTP_CAP_TEST 1 RAW_DATA_TYPE_CAPRAWDATA,
/* #define GTP_DELTA_TEST 2 RAW_DATA_TYPE_TrxDelta,
/* #define GTP_NOISE_TEST 3 RAW_DATA_TYPE_Noise,
/* RAW_DATA_TYPE_FreShift,
/* #define GTP_SHORT_TEST 5 RAW_DATA_TYPE_OpenShort,
/* RAW_DATA_TYPE_SelfCap,
/* RAW_DATA_TYPE_CbCctest,
/* RAW_DATA_TYPE_highResistance,
/* RAW_DATA_TYPE_SelfNoisetest,
/* RAW_DATA_END,
/* };
/* value is same
**********************************************************************/
/* CAP data info */
pts_node = (struct ts_rawdata_newnodeinfo *)kzalloc(sizeof(struct ts_rawdata_newnodeinfo), GFP_KERNEL);
if (!pts_node) {
TS_LOG_ERR("malloc failed\n");
return;
}
if (ts_test->rawdata.size) {
pts_node->values = kzalloc(ts_test->rawdata.size*sizeof(int), GFP_KERNEL);
if (!pts_node->values) {
TS_LOG_ERR("malloc failed for values\n");
kfree(pts_node);
pts_node = NULL;
return;
}
for (i = 0; i < ts_test->rawdata.size; i++)
pts_node->values[i] = ts_test->rawdata.data[i];
/* calculate rawdata min avg max vale*/
gt1x_data_statistics(&ts_test->rawdata.data[0],ts_test->rawdata.size,statistics_data,STATISTICS_DATA_LEN-1);
strncpy(pts_node->statistics_data,statistics_data,sizeof(pts_node->statistics_data)-1);
}
pts_node->size = ts_test->rawdata.size;
pts_node->testresult = testresut[ts_test->test_result[GTP_CAP_TEST]];
pts_node->typeindex = GTP_CAP_TEST;
strncpy(pts_node->test_name,"Cap_Rawdata",sizeof(pts_node->test_name)-1);
list_add_tail(&pts_node->node, &info->rawdata_head);
/* DELTA */
pts_node = (struct ts_rawdata_newnodeinfo *)kzalloc(sizeof(struct ts_rawdata_newnodeinfo), GFP_KERNEL);
if (!pts_node) {
TS_LOG_ERR("malloc failed\n");
return;
}
pts_node->size = 0;
pts_node->testresult = testresut[ts_test->test_result[GTP_DELTA_TEST]];
pts_node->typeindex = GTP_DELTA_TEST;
strncpy(pts_node->test_name,"Trx_delta",sizeof(pts_node->test_name)-1);
list_add_tail(&pts_node->node, &info->rawdata_head);
/* save noise data to info->buff */
pts_node = (struct ts_rawdata_newnodeinfo *)kzalloc(sizeof(struct ts_rawdata_newnodeinfo), GFP_KERNEL);
if (!pts_node) {
TS_LOG_ERR("malloc failed\n");
return;
}
if (ts_test->noisedata.size) {
pts_node->values = kzalloc(ts_test->noisedata.size*sizeof(int), GFP_KERNEL);
if (!pts_node->values) {
TS_LOG_ERR("malloc failed for values\n");
kfree(pts_node);
pts_node = NULL;
return;
}
for (i = 0; i < ts_test->noisedata.size; i++)
pts_node->values[i] = ts_test->noisedata.data[i];
/* calculate rawdata min avg max vale*/
gt1x_data_statistics(&ts_test->noisedata.data[0],ts_test->noisedata.size,statistics_data,STATISTICS_DATA_LEN-1);
strncpy(pts_node->statistics_data,statistics_data,sizeof(pts_node->statistics_data)-1);
}
pts_node->size = ts_test->noisedata.size;
pts_node->testresult = testresut[ts_test->test_result[GTP_NOISE_TEST]];
pts_node->typeindex = GTP_NOISE_TEST;
strncpy(pts_node->test_name,"noise_delta",sizeof(pts_node->test_name)-1);
list_add_tail(&pts_node->node, &info->rawdata_head);
/* shortcircut */
pts_node = (struct ts_rawdata_newnodeinfo *)kzalloc(sizeof(struct ts_rawdata_newnodeinfo), GFP_KERNEL);
if (!pts_node) {
TS_LOG_ERR("malloc failed\n");
return;
}
pts_node->size = 0;
pts_node->testresult = testresut[ts_test->test_result[GTP_SHORT_TEST]];
pts_node->typeindex = GTP_SHORT_TEST;
strncpy(pts_node->test_name,"open_test",sizeof(pts_node->test_name)-1);
list_add_tail(&pts_node->node, &info->rawdata_head);
/* dev info */
gt1x_strncat(info->deviceinfo, "-GT", sizeof(info->deviceinfo));
gt1x_strncat(info->deviceinfo, ts_test->ts->hw_info.product_id, sizeof(info->deviceinfo)-strlen(info->deviceinfo));
gt1x_strncat(info->deviceinfo, "-", sizeof(info->deviceinfo)-strlen(info->deviceinfo));
gt1x_strncatint(info->deviceinfo, ts_test->ts->dev_data->ts_platform_data->panel_id,"%d;",sizeof(info->deviceinfo)-strlen(info->deviceinfo));
return;
}
static void gt1x_put_test_result(
struct ts_rawdata_info *info,
struct gt1x_ts_test *ts_test)
{
int i = 0;
int have_bus_error = 0;
int have_panel_error = 0;
char statistics_data[STATISTICS_DATA_LEN] = {0};
if (gt1x_ts->dev_data->ts_platform_data->chip_data->rawdata_newformatflag == TS_RAWDATA_NEWFORMAT){
gt1x_put_test_result_newformat((struct ts_rawdata_info_new *)info,ts_test);
}else{
TS_LOG_ERR("%s: Not support old capacitance data format\n",
__func__);
}
return ;
}
/* short test */
static int gt1x_short_test_prepare(struct gt1x_ts_test *ts_test)
{
u8 chksum = 0x00;
int ret=0, i=0, retry = GT1X_RETRY_NUM;
u16 drv_offest=0, sen_offest=0;
u8 data[MAX_DRV_NUM + MAX_SEN_NUM];
TS_LOG_INFO("Short test prepare+\n");
while (--retry) {
/* switch to shrot test system */
ret = ts_test->ts->ops.send_cmd(0x42, 0x0, GT1X_NEED_SLEEP); /*bagan test command*/
if (ret) {
TS_LOG_ERR("Can not switch to short test system\n");
return ret;
}
/* check firmware running */
for (i = 0; i < GT1X_RETRY_FIVE; i++) {
TS_LOG_INFO("Check firmware running..");
ret = ts_test->ts->ops.i2c_read(SHORT_STATUS_REG, &data[0], 1); //SHORT_STATUS_REG is 0x5095
if (ret) {
TS_LOG_ERR("Check firmware running failed\n");
return ret;
} else if (data[0] == 0xaa) {
TS_LOG_INFO("Short firmware is running\n");
break;
}
msleep(50);
}
if (i < GT1X_RETRY_FIVE)
break;
else
ts_test->ts->ops.chip_reset();
}
if (retry <= 0) {
ret = -EINVAL;
TS_LOG_ERR("Switch to short test mode timeout\n");
return ret;
}
TS_LOG_INFO("Firmware in short test mode\n");
data[0] = (ts_test->test_params.short_threshold >> 8) & 0xff;
data[1] = ts_test->test_params.short_threshold & 0xff;
ret = ts_test->ts->ops.i2c_write(SHORT_THRESHOLD_REG, data, 2); /* SHORT THRESHOLD_REG 0X8808 */
if (ret < 0)
return ret;
/* ADC Read Delay */
data[0] = (ADC_RDAD_VALUE >> 8) & 0xff;
data[1] = ADC_RDAD_VALUE & 0xff;
ret = ts_test->ts->ops.i2c_write(ADC_READ_DELAY_REG, data, 2);
if (ret < 0)
return ret;
/* DiffCode Short Threshold */
data[0] = (DIFFCODE_SHORT_VALUE >> 8) & 0xff;
data[1] = DIFFCODE_SHORT_VALUE & 0xff;
ret = ts_test->ts->ops.i2c_write(DIFFCODE_SHORT_THRESHOLD, data, 2);
if (ret) {
TS_LOG_ERR("Failed writ diff short threshold\n");
return ret;
}
memset(data, 0xFF, sizeof(data));
if (IC_TYPE_9P == ts_test->ts->ic_type) {
drv_offest = DRIVER_CH0_REG_9P - GTP_REG_CONFIG_DATA;
sen_offest = SENSE_CH0_REG_9P - GTP_REG_CONFIG_DATA;
} else {
drv_offest = DRIVER_CH0_REG_9PT - GTP_REG_CONFIG_DATA;
sen_offest = SENSE_CH0_REG_9PT - GTP_REG_CONFIG_DATA;
}
for(i = 0; i < ts_test->test_params.sen_num; i++)
data[i] = ts_test->ts->test_config.data[sen_offest + i];
for(i = 0; i < ts_test->test_params.drv_num; i++)
data[32 + i] = ts_test->ts->test_config.data[drv_offest + i];
for (i = 0; i < sizeof(data); i++)
chksum += data[i];
chksum = 0 - chksum;
ret = ts_test->ts->ops.i2c_write(DRV_CONFIG_REG, &data[MAX_DRV_NUM], MAX_DRV_NUM);
if (ret) {
TS_LOG_ERR("Failed writ tp driver config\n");
return ret;
}
ret = ts_test->ts->ops.i2c_write(SENSE_CONFIG_REG, &data[0], MAX_SEN_NUM);
if (ret) {
TS_LOG_ERR("Failed writ tp sensor config\n");
return ret;
}
ret = ts_test->ts->ops.i2c_write( DRVSEN_CHECKSUM_REG, &chksum, 1); /* DRVSEN_CHECKSUM_REG 0x884E */
if (ret) {
TS_LOG_ERR("Failed write drv checksum\n");
return ret;
}
data[0] = 0x01;
ret = ts_test->ts->ops.i2c_write(CONFIG_REFRESH_REG, data, 1); /* CONFIG_REFRESH_REG 0x813E */
if (ret) {
TS_LOG_ERR("Failed write config refresh reg\n");
return ret;
}
/* clr 5095, runing dsp */
data[0] = 0x00;
ret = ts_test->ts->ops.i2c_write(SHORT_STATUS_REG, data, 1); /* SHORT_STATUS_REG 0X5095 */
if (ret) {
TS_LOG_ERR("Failed write running dsp reg\n");
return ret;
}
TS_LOG_INFO("Short test prepare-\n");
return 0;
}
/**
* gt1x_calc_resisitance - calculate resistance
* @self_capdata: self-capacitance value
* @adc_signal: ADC signal value
* return: resistance value
*/
static inline long gt1x_calc_resisitance(u16 self_capdata, u16 adc_signal)
{
long ret;
ret = div_s64(self_capdata * 81 * FLOAT_AMPLIFIER, adc_signal) ;
ret -= (81 * FLOAT_AMPLIFIER);
return ret;
}
static int gt1x_check_resistance_to_gnd(struct ts_test_params *test_params,
u16 adc_signal, u8 pos)
{
long r=0;
u16 r_th=0, avdd_value=0;
avdd_value = test_params->avdd_value;
if (adc_signal == 0 || adc_signal == 0x8000)
adc_signal |= 1;
if ((adc_signal & 0x8000) == 0) /* short to GND */
r = SHORT_TO_GND_RESISTER(adc_signal);
else /* short to VDD */
r = SHORT_TO_VDD_RESISTER(adc_signal, avdd_value);
r *= 2;
r = (long)div_s64(r, 100);
r = r > MAX_U16_VALUE ? MAX_U16_VALUE : r;
r = r < 0 ? 0 : r;
if (pos < MAX_DRV_NUM)
r_th = test_params->r_drv_gnd_threshold;
else
r_th = test_params->r_sen_gnd_threshold;
if (r < r_th) {
if ((adc_signal & (0x8000)) == 0) {
if (pos < MAX_DRV_NUM)
TS_LOG_ERR("Tx%d shortcircut to GND,R=%ldK,R_Threshold=%dK\n",
pos, r, r_th);
else
TS_LOG_ERR("Rx%d shortcircut to GND,R=%ldK,R_Threshold=%dK\n",
pos - MAX_DRV_NUM, r, r_th);
} else {
if (pos < MAX_DRV_NUM)
TS_LOG_ERR("Tx%d shortcircut to VDD,R=%ldK,R_Threshold=%dK\n",
pos, r, r_th);
else
TS_LOG_ERR("Rx%d shortcircut to VDD,R=%ldK,R_Threshold=%dK\n",
pos - MAX_DRV_NUM, r, r_th);
}
return RESULT_ERR;
}
return NO_ERR;
}
static int gt1x_check_short_resistance(u16 self_capdata, u16 adc_signal,
u32 short_r_th)
{
long r;
int ret = 0;
unsigned short short_val;
if (self_capdata == 0xffff || self_capdata == 0)
return 0;
r = gt1x_calc_resisitance(self_capdata, adc_signal);
r = (long)div_s64(r, FLOAT_AMPLIFIER);
r = r > MAX_U16_VALUE ? MAX_U16_VALUE : r;
short_val = (r >= 0 ? r : 0);
if (short_val < short_r_th) {
TS_LOG_ERR("Short circut:R=%dK,R_Threshold=%dK\n",
short_val, short_r_th);
ret = -EINVAL;
}
return ret;
}
static int gt1x_shortcircut_analysis(struct gt1x_ts_test *ts_test)
{
int ret = 0, err = 0;
u32 r_threshold=0;
int size=0, i=0, j=0;
u16 adc_signal=0, data_addr=0;
u8 short_flag, *data_buf = NULL, short_status[3]={0};
u16 self_capdata[MAX_DRV_NUM + MAX_SEN_NUM]={0}, short_pin_num=0;
ret = ts_test->ts->ops.i2c_read(TEST_RESTLT_REG, &short_flag, 1); /* TEST_RESTLT_REG 0x8801 */
if (ret < 0) {
TS_LOG_ERR("Read TEST_TESULT_REG falied\n");
goto shortcircut_analysis_error;
} else if ((short_flag & 0x0F) == 0x00) {
TS_LOG_INFO("No shortcircut\n");
return NO_ERR;
}
data_buf = kzalloc((MAX_DRV_NUM + MAX_SEN_NUM) * 2, GFP_KERNEL);
if (!data_buf) {
TS_LOG_ERR("Failed to alloc memory\n");
goto shortcircut_analysis_error;
}
/* shortcircut to gnd */
if (short_flag & 0x08) {
/* read diff code, diff code will be used to calculate
* resistance between channel and GND */
size = (MAX_DRV_NUM + MAX_SEN_NUM) * 2;
ret = ts_test->ts->ops.i2c_read(DIFF_CODE_REG, data_buf, size); /* DIFF_CODE_REG 0xA322 */
if (ret < 0) {
TS_LOG_ERR("Failed read to-gnd rawdata\n");
goto shortcircut_analysis_error;
}
for (i = 0; i < size; i += 2) {
adc_signal = be16_to_cpup((__be16*)&data_buf[i]);
ret = gt1x_check_resistance_to_gnd(&ts_test->test_params,
adc_signal, i >> 1); /* i >> 1 = i / 2 */
if (ret) {
TS_LOG_ERR("Resistance to-gnd test failed\n");
err |= ret;
}
}
}
/* read self-capdata+ */
size = (MAX_DRV_NUM + MAX_SEN_NUM) * 2;
ret = ts_test->ts->ops.i2c_read(DRV_SELF_CODE_REG, data_buf, size); /* DRV_SELF_CODE_REG 0xA2A0 */
if (ret) {
TS_LOG_ERR("Failed read selfcap rawdata\n");
goto shortcircut_analysis_error;
}
for (i = 0; i < MAX_DRV_NUM + MAX_SEN_NUM; i++)
self_capdata[i] = be16_to_cpup((__be16*)&data_buf[i * 2]) & 0x7fff;
/* read self-capdata- */
/* read tx tx short number */
ret = ts_test->ts->ops.i2c_read(TX_SHORT_NUM, &short_status[0], 3); /* TX_SHORT_NUM 0x8802 */
if (ret) {
TS_LOG_ERR("Failed read tx-to-tx short rawdata\n");
goto shortcircut_analysis_error;
}
/* short_status[0]: tr tx
** short_status[1]: tr rx
** short_status[2]: rx rx
*/
TS_LOG_INFO("Tx&Tx:%d,Rx&Rx:%d,Tx&Rx:%d\n",short_status[0],short_status[1],short_status[2]);
/* drv&drv shortcircut check */
data_addr = 0x8800 + 0x60;
for (i = 0; i < short_status[0]; i++) {
size = SHORT_CAL_SIZE(MAX_DRV_NUM ); // 4 + MAX_DRV_NUM * 2 + 2;
ret = ts_test->ts->ops.i2c_read(data_addr, data_buf, size);
if (ret) {
TS_LOG_ERR("Failed read drv-to-drv short rawdata\n");
goto shortcircut_analysis_error;
}
r_threshold = ts_test->test_params.r_drv_drv_threshold;
short_pin_num = be16_to_cpup((__be16 *)&data_buf[0]);
if (short_pin_num > (MAX_DRV_NUM + MAX_SEN_NUM - 1))
continue;
for (j = i + 1; j < MAX_DRV_NUM; j++) {
adc_signal = be16_to_cpup((__be16 *)&data_buf[4 + j * 2]);
if (adc_signal > ts_test->test_params.short_threshold) {
ret = gt1x_check_short_resistance(
self_capdata[short_pin_num], adc_signal,
r_threshold);
if (ret < 0) {
err |= ret;
TS_LOG_ERR("Tx%d-Tx%d shortcircut\n", short_pin_num, j);
}
}
}
data_addr += size;
}
/* sen&sen shortcircut check */
data_addr = 0x9120;
for (i = 0; i < short_status[1]; i++) {
size = SHORT_CAL_SIZE(MAX_SEN_NUM); // 4 + MAX_SEN_NUM * 2 + 2;
ret = ts_test->ts->ops.i2c_read(data_addr, data_buf, size);
if (ret) {
TS_LOG_ERR("Failed read sen-to-sen short rawdata\n");
goto shortcircut_analysis_error;
}
r_threshold = ts_test->test_params.r_sen_sen_threshold;
short_pin_num = be16_to_cpup((__be16 *)&data_buf[0]) + MAX_DRV_NUM;
if (short_pin_num > (MAX_DRV_NUM + MAX_SEN_NUM -1))
continue;
for (j = 0; j < MAX_SEN_NUM; j++) {
if(j == i || (j < i && (j & 0x01) == 0))
continue;
adc_signal = be16_to_cpup((__be16 *)&data_buf[4 + j * 2]);
if (adc_signal > ts_test->test_params.short_threshold) {
ret = gt1x_check_short_resistance(
self_capdata[short_pin_num], adc_signal,
r_threshold);
if (ret < 0) {
err |= (u32)ret;
TS_LOG_ERR("Rx%d-Rx%d shortcircut\n",
short_pin_num - MAX_DRV_NUM, j);
}
}
}
data_addr += size;
}
/* sen&drv shortcircut check */
data_addr = 0x99e0;
for (i = 0; i < short_status[2]; i++) {
size = SHORT_CAL_SIZE(MAX_SEN_NUM); //size = 4 + MAX_SEN_NUM * 2 + 2;
ret = ts_test->ts->ops.i2c_read(data_addr, data_buf, size);
if (ret) {
TS_LOG_ERR("Failed read sen-to-drv short rawdata\n");
goto shortcircut_analysis_error;
}
r_threshold = ts_test->test_params.r_drv_sen_threshold;
short_pin_num = be16_to_cpup((__be16 *)&data_buf[0]) + MAX_DRV_NUM;
if (short_pin_num > (MAX_DRV_NUM + MAX_SEN_NUM - 1))
continue;
for (j = 0; j < MAX_DRV_NUM; j++) {
adc_signal = be16_to_cpup((__be16 *)&data_buf[4 + j * 2]);
if (adc_signal > ts_test->test_params.short_threshold) {
ret = gt1x_check_short_resistance(
self_capdata[short_pin_num], adc_signal,
r_threshold);
if (ret < 0) {
err |= ret;
TS_LOG_ERR("Rx%d-Tx%d shortcircut\n",
short_pin_num - MAX_DRV_NUM, j);
}
}
}
data_addr += size;
}
if(data_buf){
kfree(data_buf);
data_buf = NULL;
}
return err | (u32)ret ? -EFAULT : NO_ERR;
shortcircut_analysis_error:
if(data_buf!=NULL){
kfree(data_buf);
data_buf = NULL;
}
return -EINVAL;
}
static void gt1x_shortcircut_test(struct gt1x_ts_test *ts_test)
{
int i = 0;
int ret=0;
u8 data[2]={0};
ts_test->test_result[GTP_SHORT_TEST] = GTP_TEST_PASS;
ret = gt1x_short_test_prepare(ts_test);
if (ret < 0){
TS_LOG_ERR("Failed enter short test mode\n");
ts_test->test_result[GTP_SHORT_TEST] = SYS_SOFTWARE_REASON;
return;
}
for (i = 0; i < GT1X_RETRY_FIVE; i++) {
msleep(300);
TS_LOG_INFO("waitting for short test end...:retry=%d\n", i);
ret = ts_test->ts->ops.i2c_read(TEST_SHORT_STATUS_REG, data, 1); /* Test_SHORT_STATUS_REG 0x8800 */
if (ret)
TS_LOG_ERR("Failed get short test result: retry%d\n", i);
else if (data[0] == 0x88) /* test ok*/
break;
}
if (i < GT1X_RETRY_FIVE) {
ret = gt1x_shortcircut_analysis(ts_test);
if (ret){
ts_test->test_result[GTP_SHORT_TEST] = GTP_PANEL_REASON;
TS_LOG_ERR("Short test failed\n");
} else
TS_LOG_ERR("Short test success\n");
} else {
TS_LOG_ERR("Wait short test finish timeout\n");
ts_test->test_result[GTP_SHORT_TEST] = SYS_SOFTWARE_REASON;
}
return;
}
void gt1x_test_free(void)
{
if(NULL != gts_test){
kfree(gts_test);
gts_test = NULL;
}
}
| 29.580786 | 142 | 0.688244 |
1bee7c6f6fcab42ee9429fa543300b1154cd9573 | 2,555 | h | C | hicn-light/src/hicn/socket/ops.h | muscariello/hicn-test | dba9cb958219d042e0a01f6758feb2c1ffabbf05 | [
"Apache-2.0"
] | 47 | 2019-02-18T13:54:34.000Z | 2022-03-03T04:46:50.000Z | hicn-light/src/hicn/socket/ops.h | icn-team/hicn | 72a9acca4500a9c07a4661fe112a1a212567fc9f | [
"Apache-2.0"
] | 1 | 2019-09-09T09:14:43.000Z | 2019-09-09T09:14:43.000Z | hicn-light/src/hicn/socket/ops.h | icn-team/hicn | 72a9acca4500a9c07a4661fe112a1a212567fc9f | [
"Apache-2.0"
] | 28 | 2019-02-22T17:40:03.000Z | 2021-08-18T02:39:40.000Z | #ifndef HICN_SOCKET_OPS_H
#define HICN_SOCKET_OPS_H
#include <hicn/hicn.h>
#include <stdint.h>
typedef struct {
char *arch;
int (*tun_create)(char *name);
int (*get_tun_name)(const char *prefix, const char *identifier,
char *tun_name);
int (*enable_v6_forwarding)(char *interface_name);
int (*enable_v4_forwarding)();
int (*enable_ndp_proxy)();
uint32_t (*get_ifid)(const char *ifname);
int (*get_output_ifid)(const char *ip_address, uint8_t address_family,
uint32_t *interface_id);
int (*get_ip_addr)(uint32_t interface_id, uint8_t address_family,
ip_prefix_t *ip_address);
int (*set_ip_addr)(uint32_t interface_id, ip_prefix_t *ip_address);
int (*up_if)(uint32_t interface_id);
int (*add_in_route_table)(const ip_prefix_t *prefix,
const uint32_t interface_id,
const uint8_t table_id);
int (*add_in_route_table_s)(const char *prefix, const uint32_t interface_id,
const uint8_t table_id);
int (*add_in_route_s)(const char *prefix, const uint32_t interface_id);
int (*add_out_route)(const char *gateway, const uint8_t address_family,
const uint8_t table_id, int default_route);
int (*del_out_route)(const char *gateway, const uint8_t address_family,
const uint8_t table_id);
int (*del_lo_route)(const ip_prefix_t *ip_address);
int (*add_rule)(const char *interface_name, const uint8_t address_family,
const uint8_t table_id);
int (*del_rule)(const char *interface_name, const uint8_t address_family,
const uint8_t table_id);
int (*add_neigh_proxy)(const ip_prefix_t *ip_address,
const uint32_t interface_id);
int (*add_prio_rule)(const ip_prefix_t *ip_address,
const uint8_t address_family, const uint32_t priority,
const uint8_t table_id);
int (*add_lo_prio_rule)(const ip_prefix_t *ip_address,
const uint8_t address_family,
const uint32_t priority);
int (*del_prio_rule)(const ip_prefix_t *ip_address,
const uint8_t address_family, const uint32_t priority,
const uint8_t table_id);
int (*del_lo_prio_rule)(const ip_prefix_t *ip_address,
const uint8_t address_family,
const uint32_t priority);
} hicn_socket_ops_t;
#endif /* HICN_SOCKET_OPS_H */
| 46.454545 | 78 | 0.64227 |
f40090389ea8fe590cdbfcf057689b9635e183cc | 807 | h | C | memory/memory.h | doriandekoning/functional-cache-simulator | bc68f1935a762b0b7b7d69e3ac5fb13ea457fd41 | [
"Apache-2.0"
] | 1 | 2020-12-09T05:36:07.000Z | 2020-12-09T05:36:07.000Z | memory/memory.h | doriandekoning/functional-cache-simulator | bc68f1935a762b0b7b7d69e3ac5fb13ea457fd41 | [
"Apache-2.0"
] | null | null | null | memory/memory.h | doriandekoning/functional-cache-simulator | bc68f1935a762b0b7b7d69e3ac5fb13ea457fd41 | [
"Apache-2.0"
] | null | null | null | #ifndef __MEMORY_H
#define __MEMORY_H
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
typedef __int128 int128_t;
typedef unsigned __int128 uint128_t;
struct Memory{
struct Memory** table;
uint64_t addr_start, addr_end;
FILE* backing_file;
};
struct Memory* init_memory(FILE* backing_file, uint64_t addr_start, uint64_t addr_end);
void free_memory();
void convert_to_little_endian(size_t size, void* value);
void* get_memory_pointer(int amount_memories, struct Memory* memories, uint64_t address);
int write_sim_memory(int amount_memories, struct Memory* memories, uint64_t address, size_t size, void* value);
int read_sim_memory(int amount_memories, struct Memory* memories, uint64_t address, size_t size, void* value);
uint64_t get_size(struct Memory* mem);
#endif /* __MEMORY_H */
| 26.032258 | 111 | 0.788104 |
0b05310183f7439f18c2427804e19c1fce758e24 | 90 | h | C | ios/Classes/BsGridSystemPlugin.h | kholifanalfon/bs_grid_system | 66f64c6ac47ee30f4d295c4833cd04f1e1f975f1 | [
"MIT"
] | 1 | 2021-08-12T09:49:50.000Z | 2021-08-12T09:49:50.000Z | ios/Classes/BsGridSystemPlugin.h | kholifanalfon/bs_grid_system | 66f64c6ac47ee30f4d295c4833cd04f1e1f975f1 | [
"MIT"
] | null | null | null | ios/Classes/BsGridSystemPlugin.h | kholifanalfon/bs_grid_system | 66f64c6ac47ee30f4d295c4833cd04f1e1f975f1 | [
"MIT"
] | null | null | null | #import <Flutter/Flutter.h>
@interface BsGridSystemPlugin : NSObject<FlutterPlugin>
@end
| 18 | 55 | 0.8 |
73aa4bb0f3f1b609e9d89709d77af58e80158108 | 1,256 | h | C | src/blst_evm384.h | sean-sn/blst_evm384 | 5333351c32b662240a43947d9998231fa389be38 | [
"Apache-2.0"
] | 1 | 2020-11-05T21:39:14.000Z | 2020-11-05T21:39:14.000Z | src/blst_evm384.h | sean-sn/blst_evm384 | 5333351c32b662240a43947d9998231fa389be38 | [
"Apache-2.0"
] | null | null | null | src/blst_evm384.h | sean-sn/blst_evm384 | 5333351c32b662240a43947d9998231fa389be38 | [
"Apache-2.0"
] | 1 | 2020-11-20T06:02:22.000Z | 2020-11-20T06:02:22.000Z | // Copyright Supranational LLC
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
#ifndef __BLST_EVM384_H__
#define __BLST_EVM384_H__
#if defined(__ADX__) /* e.g. -march=broadwell */ && !defined(__BLST_PORTABLE__)
# define mul_mont_384 mulx_mont_384
#endif
typedef uint64_t vec384[6];
extern "C" {
void add_mod_384(vec384 ret, const vec384 a, const vec384 b, const vec384 p);
void sub_mod_384(vec384 ret, const vec384 a, const vec384 b, const vec384 p);
void mul_mont_384(vec384 ret, const vec384 a, const vec384 b,
const vec384 p, uint64_t n0);
}
// BLS12-381 Modulus
const uint64_t BLS12_381_P[6] = {
0xb9feffffffffaaab, 0x1eabfffeb153ffff,
0x6730d2a0f6b0f624, 0x64774b84f38512bf,
0x4b1ba7b6434bacd7, 0x1a0111ea397fe69a
};
const uint64_t BLS12_381_p0 = (uint64_t)0x89f3fffcfffcfffd; /* -1/P */
void add_mod_384_no_asm(vec384 ret, const vec384 a, const vec384 b,
const vec384 p);
void sub_mod_384_no_asm(vec384 ret, const vec384 a, const vec384 b,
const vec384 p);
void mul_mont_384_no_asm(vec384 ret, const vec384 a, const vec384 b,
const vec384 p, uint64_t n0);
#endif
| 33.052632 | 79 | 0.707006 |
5d99690c4174eb8d2c8eb55bbe16deb6b3b0f8e9 | 453 | h | C | usr/libexec/coreidvd/_TtC8coreidvd12NonceRequest.h | lechium/iOS1351Headers | 6bed3dada5ffc20366b27f7f2300a24a48a6284e | [
"MIT"
] | 2 | 2021-11-02T09:23:27.000Z | 2022-03-28T08:21:57.000Z | usr/libexec/coreidvd/_TtC8coreidvd12NonceRequest.h | zhangkn/iOS14Header | 4323e9459ed6f6f5504ecbea2710bfd6c3d7c946 | [
"MIT"
] | null | null | null | usr/libexec/coreidvd/_TtC8coreidvd12NonceRequest.h | zhangkn/iOS14Header | 4323e9459ed6f6f5504ecbea2710bfd6c3d7c946 | [
"MIT"
] | 1 | 2022-03-28T08:21:59.000Z | 2022-03-28T08:21:59.000Z | //
// Generated by classdumpios 1.0.1 (64 bit) (iOS port by DreamDevLost)(Debug version compiled Sep 26 2020 13:48:20).
//
// Copyright (C) 1997-2019 Steve Nygard.
//
#import "_TtC8coreidvd13DIPWebRequest.h"
@class MISSING_TYPE;
@interface _TtC8coreidvd12NonceRequest : _TtC8coreidvd13DIPWebRequest
{
MISSING_TYPE *nonceCount; // 24 = 0x18
MISSING_TYPE *providerId; // 32 = 0x20
MISSING_TYPE *appleCredentials; // 48 = 0x30
}
@end
| 22.65 | 120 | 0.717439 |
951c9147d2a5ba59a923b2beef6bd16638df1311 | 507 | h | C | catboost/libs/options/enum_helpers.h | avant1/catboost | 36e301b4167e3fe371f254474b1561a8acc3851d | [
"Apache-2.0"
] | null | null | null | catboost/libs/options/enum_helpers.h | avant1/catboost | 36e301b4167e3fe371f254474b1561a8acc3851d | [
"Apache-2.0"
] | null | null | null | catboost/libs/options/enum_helpers.h | avant1/catboost | 36e301b4167e3fe371f254474b1561a8acc3851d | [
"Apache-2.0"
] | null | null | null | #pragma once
#include "enums.h"
#include <util/generic/string.h>
bool IsClassificationLoss(ELossFunction lossFunction);
bool IsClassificationLoss(const TString& lossDescription);
bool IsMultiClassError(ELossFunction lossFunction);
bool IsQuerywiseError(ELossFunction lossFunction);
bool IsPairwiseError(ELossFunction lossFunction);
bool IsPlainMode(EBoostingType boostingType);
bool IsSecondOrderScoreFunction(EScoreFunction scoreFunction);
bool AreZeroWeightsAfterBootstrap(EBootstrapType type);
| 23.045455 | 62 | 0.848126 |
4eb281555b33665cc62eb6d0e0e4632aeffeed73 | 268 | h | C | JLKit/Additions/Foundation/NSData+JLKit.h | jangsy/JLCategorys | 9b227e990088ad90da6b0b6419e05ab10453e8c5 | [
"MIT"
] | 3 | 2015-10-17T08:08:38.000Z | 2016-02-18T01:16:02.000Z | JLKit/Additions/Foundation/NSData+JLKit.h | jangsy7883/JLCategorys | 9b227e990088ad90da6b0b6419e05ab10453e8c5 | [
"MIT"
] | null | null | null | JLKit/Additions/Foundation/NSData+JLKit.h | jangsy7883/JLCategorys | 9b227e990088ad90da6b0b6419e05ab10453e8c5 | [
"MIT"
] | null | null | null | //
// NSData+JLKit.h
// JLKit
//
// Created by Jangsy7883 on 2015. 12. 31..
// Copyright © 2015년 Dalkomm. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSData (JLKit)
@property (nonatomic, readonly) NSString * _Nullable UTF8String;
@end
| 16.75 | 64 | 0.69403 |
b67370476d821e0fd951d194b2e40f3f87abcf84 | 224 | h | C | RunTime/Six/RunTimeExample/RunTimeExample/Module/RunTimeCoder/Controller/RunTimeCoderController.h | CainRun/iOS-Project-Example | a02b669a14b5ade94456924c41421d511ffd12f7 | [
"MIT"
] | 10 | 2017-08-12T03:14:39.000Z | 2017-11-26T04:08:22.000Z | RunTime/Six/RunTimeExample/RunTimeExample/Module/RunTimeCoder/Controller/RunTimeCoderController.h | CainLuo/iOS-Project-Example | a02b669a14b5ade94456924c41421d511ffd12f7 | [
"MIT"
] | 1 | 2017-08-16T03:36:28.000Z | 2017-08-16T03:37:06.000Z | RunTime/Six/RunTimeExample/RunTimeExample/Module/RunTimeCoder/Controller/RunTimeCoderController.h | CainLuo/iOS-Project-Example | a02b669a14b5ade94456924c41421d511ffd12f7 | [
"MIT"
] | 6 | 2018-01-16T06:48:46.000Z | 2021-11-11T03:37:28.000Z | //
// RunTimeCoderController.h
// RunTimeExample
//
// Created by Mac on 2017/10/8.
// Copyright © 2017年 Cain. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface RunTimeCoderController : UIViewController
@end
| 16 | 52 | 0.714286 |
06985bb79d5cfc8249c6f7c1b37387dbf4052a9b | 648 | h | C | macOS/10.13/AVFoundation.framework/AVAudioConnectionPoint.h | onmyway133/Runtime-Headers | e9b80e7ab9103f37ad421ad6b8b58ee06369d21f | [
"MIT"
] | 30 | 2016-10-09T20:13:00.000Z | 2022-01-24T04:14:57.000Z | macOS/10.13/AVFoundation.framework/AVAudioConnectionPoint.h | onmyway133/Runtime-Headers | e9b80e7ab9103f37ad421ad6b8b58ee06369d21f | [
"MIT"
] | null | null | null | macOS/10.13/AVFoundation.framework/AVAudioConnectionPoint.h | onmyway133/Runtime-Headers | e9b80e7ab9103f37ad421ad6b8b58ee06369d21f | [
"MIT"
] | 7 | 2017-08-29T14:41:25.000Z | 2022-01-19T17:14:54.000Z | /* Generated by RuntimeBrowser
Image: /System/Library/Frameworks/AVFoundation.framework/Versions/A/Frameworks/AVFAudio.framework/Versions/A/AVFAudio
*/
@interface AVAudioConnectionPoint : NSObject {
unsigned long long _bus;
AVAudioNode * _node;
void * _reserved;
}
@property (nonatomic, readonly) unsigned long long bus;
@property (nonatomic, readonly) AVAudioNode *node;
+ (id)connectionPointWithNode:(id)arg1 bus:(unsigned long long)arg2;
- (unsigned long long)bus;
- (void)dealloc;
- (unsigned long long)hash;
- (id)init;
- (id)initWithNode:(id)arg1 bus:(unsigned long long)arg2;
- (BOOL)isEqual:(id)arg1;
- (id)node;
@end
| 25.92 | 120 | 0.737654 |
c37c6f53981101179abfd4dc6613d4e6d67e469e | 2,348 | h | C | singdemo/QjcHeader.h | Qiaojuncheng/Repository | 6220cfc278f3ecf1110e572c845b53951446648d | [
"MIT"
] | null | null | null | singdemo/QjcHeader.h | Qiaojuncheng/Repository | 6220cfc278f3ecf1110e572c845b53951446648d | [
"MIT"
] | null | null | null | singdemo/QjcHeader.h | Qiaojuncheng/Repository | 6220cfc278f3ecf1110e572c845b53951446648d | [
"MIT"
] | null | null | null | //
// QjcHeader.h
// singdemo
//
// Created by MYMAc on 2018/7/20.
// Copyright © 2018年 ShangYu. All rights reserved.
//
#ifndef QjcHeader_h
#define QjcHeader_h
#define RequestUrl @"http://dakawl.com/"
#define GetImageCode @"app/login/getCode"
#pragma mark 尺寸适配
#define MainScreen [[UIScreen mainScreen] bounds]
#define ScreenWidth MainScreen.size.width
#define ScreenHeight MainScreen.size.height
#define IS_IPHONE_5 (ScreenHeight == 568.0)
// 导航栏 加 状态栏
#define NavStatusBarHeight (44 + StatusBarHeight)
// 导航栏高度
#define NavBarHeight 44
//有导航控制器的时候 Tababar高度
#define NavTabBarHeight [self.navigationController.tabBarController.tabBar frame].size.height
// Tababar高度
#define TabBarHeight [self.tabBarController.tabBar frame].size.height
// 状态栏高度
#define StatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
//比例 以iPhone6 为基准
#define kRatio ScreenWidth/375
//按比例适配
#define kFit(num) kRatio * (num)
#pragma mark 颜色
// 主色 背景色 线条色
#define MAINCOLOR [UIColor colorWithHex:0x216BB0] // 主色
#define MainBackColor [UIColor colorWithHex:0xf5f5f5] // 背景颜色
#define LINECOLOR [UIColor colorWithHex:0xececec]//线条颜色
#define RandomColor [UIColor randomColor] // 随机色
// 字体颜色
#define DEEPTintColor [UIColor colorWithHex:0x333333]//字体黑色颜色
#define TintColor [UIColor colorWithHex:0x666666]//字体灰色颜色
#define ShallowTintColor [UIColor colorWithHex:0x999999]//字体浅色颜色
#pragma mark 字体
#define font17 [UIFont systemFontOfSize:17]
#define font16 [UIFont systemFontOfSize:16]
#define font15 [UIFont systemFontOfSize:15]
#define font14 [UIFont systemFontOfSize:14]
#define font12 [UIFont systemFontOfSize:12]
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#pragma mark ToolHeaders
#import "NSString+XPKit.h"
#import "UIColor+XPKit.h"
#import "UIView+XPKit.h"
#import "Utile.h"
#import "UIImageView+WebCache.h"
#pragma mark ThirdHeaders
#import "UIViewController+HUD.h"
#import "IQKeyboardManager.h"
#import "MJRefresh.h"
#import "GuideViewController.h"
#import "YYModel.h"
#pragma mark SimpleViewHeaders
#import "QJCBaseViewController.h"
#import "QJCNavigationViewController.h"
#import "QJCTabBarController.h"
#import "ZLAdManage.h"
#import "ZLAdvertView.h"
#import "ZLAdvertViewController.h"
#import "YSLoopBanner.h"
#import "MOFSPickerManager.h"
#endif /* QjcHeader_h */
| 23.019608 | 93 | 0.766184 |
f99e487496adc876450c1e1014948e142dfb3560 | 171 | h | C | Pods/Target Support Files/ASProgressHud/ASProgressHud-umbrella.h | naveenkashyap/InstantGram | 93c05f681996d1a8319a866b21f8e3fc43c99636 | [
"Apache-2.0"
] | null | null | null | Pods/Target Support Files/ASProgressHud/ASProgressHud-umbrella.h | naveenkashyap/InstantGram | 93c05f681996d1a8319a866b21f8e3fc43c99636 | [
"Apache-2.0"
] | null | null | null | Pods/Target Support Files/ASProgressHud/ASProgressHud-umbrella.h | naveenkashyap/InstantGram | 93c05f681996d1a8319a866b21f8e3fc43c99636 | [
"Apache-2.0"
] | null | null | null | #ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
FOUNDATION_EXPORT double ASProgressHudVersionNumber;
FOUNDATION_EXPORT const unsigned char ASProgressHudVersionString[];
| 19 | 67 | 0.842105 |
f9ab3e0d09f71357aaa2ba748ebb2a60a0bd109c | 456 | h | C | Telegraph/TGDropboxItem.h | miladajilian/MimMessenger | 72aca46135eed311f5f2fd3b711446a61b526548 | [
"MIT"
] | 6 | 2018-01-14T08:11:12.000Z | 2021-06-24T04:30:23.000Z | Telegraph/TGDropboxItem.h | miladajilian/MimMessenger | 72aca46135eed311f5f2fd3b711446a61b526548 | [
"MIT"
] | 1 | 2018-06-12T07:07:09.000Z | 2018-06-12T07:07:09.000Z | Telegraph/TGDropboxItem.h | miladajilian/MimMessenger | 72aca46135eed311f5f2fd3b711446a61b526548 | [
"MIT"
] | 6 | 2018-01-12T14:10:36.000Z | 2018-10-10T15:52:21.000Z | #import <Foundation/Foundation.h>
@interface TGDropboxItem : NSObject
@property (nonatomic, readonly) NSString *fileId;
@property (nonatomic, readonly) NSURL *fileUrl;
@property (nonatomic, readonly) NSURL *previewUrl;
@property (nonatomic, readonly) CGSize previewSize;
@property (nonatomic, readonly) NSString *fileName;
@property (nonatomic, readonly) NSUInteger fileSize;
+ (instancetype)dropboxItemWithDictionary:(NSDictionary *)dictionary;
@end
| 28.5 | 69 | 0.791667 |
2a0c1d64aa04b5110cb91ee0108db6a548afb51a | 1,575 | h | C | Classes/ParishMapViewController.h | LaudateCorpus1/Catholic-Diocese-App-iOS | e1ebb49f50f4e362cf4c52edcdb41cb910981eaf | [
"MIT"
] | 6 | 2018-02-24T03:11:44.000Z | 2020-05-12T18:46:09.000Z | Classes/ParishMapViewController.h | LaudateCorpus1/Catholic-Diocese-App-iOS | e1ebb49f50f4e362cf4c52edcdb41cb910981eaf | [
"MIT"
] | 1 | 2016-04-12T19:29:23.000Z | 2016-04-12T19:29:23.000Z | Classes/ParishMapViewController.h | LaudateCorpus1/Catholic-Diocese-App-iOS | e1ebb49f50f4e362cf4c52edcdb41cb910981eaf | [
"MIT"
] | 4 | 2015-10-29T06:19:43.000Z | 2021-11-30T04:48:20.000Z | //
// ParishMapViewController.h
// Catholic Diocese
//
// Created by Jeff Geerling on 2/3/11.
//
#import <UIKit/UIKit.h>
#import <Mapkit/MapKit.h>
@class AppDelegate;
@interface ParishMapViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate> {
AppDelegate *mainAppDelegate;
NSNumber *zoomToUserLocation;
IBOutlet MKMapView *parishMap;
IBOutlet UISegmentedControl *segmentedControlMapType;
}
@property (nonatomic, strong) AppDelegate *mainAppDelegate;
@property (nonatomic, strong) NSNumber *zoomToUserLocation;
@property (nonatomic, strong) IBOutlet MKMapView *parishMap;
@property (nonatomic, strong) IBOutlet UISegmentedControl *segmentedControlMapType;
- (void)updateParishMapCenter:(NSNotification *)note;
- (IBAction)btnSearch:(id)sender;
- (IBAction)btnLocateMe:(id)sender;
- (IBAction)changeMapType: (id)sender;
- (void)createAnnotationWithCoords:(CLLocationCoordinate2D)coords andTitle:(NSString *)title andSubtitle:(NSString *)subtitle andNumber:(NSNumber *)number;
- (void)createAnnotationsOfParishes;
@end
@interface parishAnnotation: NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
NSString *parishTitle;
NSNumber *number;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, strong) NSString *parishTitle;
@property (nonatomic, strong) NSNumber *number;
- (id)initWithCoordinate:(CLLocationCoordinate2D)coords;
@end
| 27.155172 | 155 | 0.786032 |
be321e1010061852977042a2d68fa44ca6061a3d | 7,490 | c | C | usb_key.c | Kirichenkov9/usb_key | 683a54369e0417c69702be07902cbf5f68df23b9 | [
"MIT"
] | null | null | null | usb_key.c | Kirichenkov9/usb_key | 683a54369e0417c69702be07902cbf5f68df23b9 | [
"MIT"
] | null | null | null | usb_key.c | Kirichenkov9/usb_key | 683a54369e0417c69702be07902cbf5f68df23b9 | [
"MIT"
] | null | null | null | #include <linux/init.h>
#include <linux/module.h>
#include <linux/usb.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <asm/segment.h>
#include <asm/uaccess.h>
#include <linux/fs_struct.h>
#include <asm/current.h>
#include <linux/proc_fs.h>
#include <linux/mount.h>
#include <linux/seq_file.h>
#include <linux/stat.h>
#include <linux/syscalls.h>
#include <linux/notifier.h>
#include "config.h"
#define USB_COUNT 4
#define NAME_USB_LEN 8
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Anton Kirichenkov <akirichenkov99@gmail.com>");
// Read password from USB device
static char *read_file(char *filename)
{
struct kstat *stat;
struct file *fp;
mm_segment_t fs;
loff_t pos = 0;
char *buf;
int size;
fp = filp_open(filename, O_RDWR, 0644);
if (IS_ERR(fp))
{
return NULL;
}
fs = get_fs();
set_fs(KERNEL_DS);
stat = (struct kstat *)kmalloc(sizeof(struct kstat), GFP_KERNEL);
if (!stat)
{
return NULL;
}
vfs_stat(filename, stat);
size = stat->size;
buf = kmalloc(size, GFP_KERNEL);
if (!buf)
{
kfree(stat);
return NULL;
}
kernel_read(fp, buf, size, &pos);
filp_close(fp, NULL);
set_fs(fs);
kfree(stat);
buf[size] = '\0';
return buf;
}
// Call decryption from user space
static int call_decryption(char *name_device)
{
printk(KERN_INFO "USB MODULE: Call_decrypt\n");
char path[80];
strcat(path, KEY_PATH);
char *data = read_file(path);
char *argv[] = {
"crypto",
data,
NULL};
static char *envp[] = {
"HOME=/",
"TERM=linux",
"PATH=/sbin:/bin:/usr/sbin:/usr/bin",
NULL};
if (call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC) < 0)
{
return -1;
}
return 0;
}
// Call encryption from user space
static int call_encryption(void)
{
printk(KERN_INFO "USB MODULE: Call_encrypt\n");
char *argv[] = {
"crypto",
NULL};
static char *envp[] = {
"HOME=/",
"TERM=linux",
"PATH=/sbin:/bin:/usr/sbin:/usr/bin",
NULL};
if (call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC) < 0)
{
return -1;
}
return 0;
}
typedef struct our_usb_device
{
struct usb_device_id dev_id;
// This is used to link nodes together in the list.
struct list_head list_node;
} our_usb_device_t;
// Declare and init the head node of the linked list.
LIST_HEAD(connected_devices);
// Match device with device id.
static bool device_match_device_id(struct usb_device *dev, const struct usb_device_id *dev_id)
{
// Check idVendor and idProduct, which are used.
if (dev_id->idVendor != dev->descriptor.idVendor)
return false;
if (dev_id->idProduct != dev->descriptor.idProduct)
return false;
return true;
}
// Match device id with device id.
static bool device_id_match_device_id(struct usb_device_id *new_dev_id, const struct usb_device_id *dev_id)
{
// Check idVendor and idProduct, which are used.
if (dev_id->idVendor != new_dev_id->idVendor)
return false;
if (dev_id->idProduct != new_dev_id->idProduct)
return false;
return true;
}
// Check our list of devices, if we know device.
static char *usb_device_id_is_known(struct usb_device_id *dev)
{
unsigned long known_devices_len = sizeof(known_devices) / sizeof(known_devices[0]);
int i = 0;
for (i = 0; i < known_devices_len; i++)
{
if (device_id_match_device_id(dev, &known_devices[i].dev_id))
{
int size = sizeof(known_devices[i].name);
char *name = (char *)kmalloc(size + 1, GFP_KERNEL);
int j = 0;
for (j = 0; j < size; j++)
name[j] = known_devices[i].name[j];
name[size + 1] = '\0';
return name;
}
}
return NULL;
}
static char *knowing_device(void)
{
our_usb_device_t *temp;
int count = 0;
char *name;
list_for_each_entry(temp, &connected_devices, list_node)
{
name = usb_device_id_is_known(&temp->dev_id);
if (!name)
return NULL;
count++;
}
if (0 == count)
return NULL;
return name;
}
static void print_our_usb_devices(void)
{
our_usb_device_t *temp;
int count = 0;
list_for_each_entry(temp, &connected_devices, list_node)
{
printk(KERN_INFO "USB MODULE: Node %d data = %x:%x\n", count++, temp->dev_id.idVendor, temp->dev_id.idProduct);
}
}
static void add_trusted_usb_device(struct usb_device *dev)
{
our_usb_device_t *new_usb_device = (our_usb_device_t *)kmalloc(sizeof(our_usb_device_t), GFP_KERNEL);
struct usb_device_id new_id = {USB_DEVICE(dev->descriptor.idVendor, dev->descriptor.idProduct)};
new_usb_device->dev_id = new_id;
list_add_tail(&new_usb_device->list_node, &connected_devices);
}
static void delete_trusted_usb_device(struct usb_device *dev)
{
our_usb_device_t *device, *temp;
list_for_each_entry_safe(device, temp, &connected_devices, list_node)
{
if (device_match_device_id(dev, &device->dev_id))
{
list_del(&device->list_node);
kfree(device);
}
}
}
// If usb device inserted.
static void usb_dev_insert(struct usb_device *dev)
{
add_trusted_usb_device(dev);
char *name = knowing_device();
if (name)
{
if (state_encrypt)
call_decryption(name);
state_encrypt = false;
printk(KERN_INFO "USB MODULE: New device we can encrypt.\n");
}
else
{
if (!state_encrypt)
call_encryption();
state_encrypt = true;
printk(KERN_INFO "USB MODULE: New device, we can't encrypt.\n");
}
}
// If usb device removed.
static void usb_dev_remove(struct usb_device *dev)
{
delete_trusted_usb_device(dev);
char *name = knowing_device();
if (name)
{
if (state_encrypt)
call_decryption(name);
state_encrypt = false;
printk(KERN_INFO "USB MODULE: Delete device, we can encrypt.\n");
}
else
{
if (!state_encrypt)
call_encryption();
state_encrypt = true;
printk(KERN_INFO "USB MODULE: Delete device, we can't encrypt.\n");
}
}
// New notify.
static int notify(struct notifier_block *self, unsigned long action, void *dev)
{
// Events, which our notifier react.
switch (action)
{
case USB_DEVICE_ADD:
usb_dev_insert(dev);
break;
case USB_DEVICE_REMOVE:
usb_dev_remove(dev);
break;
default:
break;
}
return 0;
}
// Struct to react on different notifies.
static struct notifier_block usb_notify = {
.notifier_call = notify,
};
static int __init my_module_init(void)
{
usb_register_notify(&usb_notify);
call_encryption();
printk(KERN_INFO "USB MODULE: loaded.\n");
return 0;
}
static void __exit my_module_exit(void)
{
usb_unregister_notify(&usb_notify);
printk(KERN_INFO "USB MODULE: unloaded.\n");
}
module_init(my_module_init);
module_exit(my_module_exit);
| 24.477124 | 120 | 0.604005 |
b3707938487488f259da0e96946e4b8a8d69b285 | 53 | h | C | emu/src/idf-inc/esp_system.h | JVeg199X/esp32-c3-playground | 16714eb221b58b714dfd7d83c595f143489c343b | [
"MIT"
] | null | null | null | emu/src/idf-inc/esp_system.h | JVeg199X/esp32-c3-playground | 16714eb221b58b714dfd7d83c595f143489c343b | [
"MIT"
] | null | null | null | emu/src/idf-inc/esp_system.h | JVeg199X/esp32-c3-playground | 16714eb221b58b714dfd7d83c595f143489c343b | [
"MIT"
] | null | null | null | #ifndef _ESP_SYSTEM_H_
#define _ESP_SYSTEM_H_
#endif | 13.25 | 22 | 0.849057 |
7e21da4ef5c19c909f81e6b6b283ecb924c05bc8 | 1,702 | h | C | runtime/ejs-map.h | carlosalberto/echo-js | 1d92b782cf0465321635242138a1d8c902b5ebb2 | [
"MIT"
] | 272 | 2015-01-24T10:03:22.000Z | 2021-12-21T02:10:04.000Z | runtime/ejs-map.h | carlosalberto/echo-js | 1d92b782cf0465321635242138a1d8c902b5ebb2 | [
"MIT"
] | 25 | 2015-01-27T05:07:02.000Z | 2017-06-06T04:41:18.000Z | runtime/ejs-map.h | carlosalberto/echo-js | 1d92b782cf0465321635242138a1d8c902b5ebb2 | [
"MIT"
] | 21 | 2015-01-27T00:12:04.000Z | 2018-09-01T11:59:53.000Z | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=4 sw=4 et tw=99 ft=cpp:
*/
#ifndef _ejs_map_h_
#define _ejs_map_h_
#include "ejs.h"
#include "ejs-value.h"
#include "ejs-object.h"
#define EJSVAL_IS_MAP(v) (EJSVAL_IS_OBJECT(v) && (EJSVAL_TO_OBJECT(v)->ops == &_ejs_Map_specops))
#define EJSVAL_TO_MAP(v) ((EJSMap*)EJSVAL_TO_OBJECT(v))
typedef struct _EJSKeyValueEntry {
// the next entry in insertion order
struct _EJSKeyValueEntry *next_insert;
ejsval key;
ejsval value;
} EJSKeyValueEntry;
typedef struct {
/* object header */
EJSObject obj;
ejsval comparator;
EJSKeyValueEntry* head_insert;
EJSKeyValueEntry* tail_insert;
} EJSMap;
EJS_BEGIN_DECLS
extern ejsval _ejs_Map;
extern ejsval _ejs_Map_prototype;
extern EJSSpecOps _ejs_Map_specops;
void _ejs_map_init(ejsval global);
ejsval _ejs_map_new ();
ejsval _ejs_map_delete(ejsval map, ejsval key);
ejsval _ejs_map_has(ejsval map, ejsval key);
ejsval _ejs_map_get(ejsval map, ejsval key);
ejsval _ejs_map_set(ejsval map, ejsval key, ejsval value);
#define EJSVAL_IS_MAPITERATOR(v) (EJSVAL_IS_OBJECT(v) && (EJSVAL_TO_OBJECT(v)->ops == &_ejs_MapIterator_specops))
typedef enum {
EJS_MAP_ITER_KIND_KEY,
EJS_MAP_ITER_KIND_VALUE,
EJS_MAP_ITER_KIND_KEYVALUE,
} EJSMapIteratorKind;
typedef struct {
/* object header */
EJSObject obj;
ejsval iterated;
EJSMapIteratorKind kind;
int next_index;
} EJSMapIterator;
extern ejsval _ejs_MapIterator;
extern ejsval _ejs_MapIterator_prototype;
extern EJSSpecOps _ejs_MapIterator_specops;
ejsval _ejs_map_iterator_new (ejsval map, EJSMapIteratorKind kind);
EJS_END_DECLS
#endif
| 23.315068 | 113 | 0.748531 |
24ee247bacf61229c3b6109b235bbab99cee7bea | 6,056 | h | C | main.h | BritishAmateurTelevisionClub/eshail-wb-fft-airspy | 5b46ecdb8b824b860784347e36d727f6be7d9f82 | [
"MIT"
] | 1 | 2022-03-16T20:44:27.000Z | 2022-03-16T20:44:27.000Z | main.h | BritishAmateurTelevisionClub/eshail-wb-fft-airspy | 5b46ecdb8b824b860784347e36d727f6be7d9f82 | [
"MIT"
] | 3 | 2019-07-15T14:41:58.000Z | 2020-08-25T21:05:43.000Z | main.h | BritishAmateurTelevisionClub/eshail-wb-fft-airspy | 5b46ecdb8b824b860784347e36d727f6be7d9f82 | [
"MIT"
] | 1 | 2020-08-30T12:26:16.000Z | 2020-08-30T12:26:16.000Z | /*
* libwebsockets-test-server - libwebsockets test implementation
*
* Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
*
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* The person who associated a work with this deed has dedicated
* the work to the public domain by waiving all of his or her rights
* to the work worldwide under copyright law, including all related
* and neighboring rights, to the extent allowed by law. You can copy,
* modify, distribute and perform the work, even for commercial purposes,
* all without asking permission.
*
* The test apps are intended to be adapted for use in your code, which
* may be proprietary. So unlike the library itself, they are licensed
* Public Domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <signal.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
#include <syslog.h>
#include <sys/time.h>
#include <unistd.h>
#include <inttypes.h>
#include <errno.h>
#include <libwebsockets.h>
#include <pthread.h>
#include <math.h>
#include <fftw3.h>
#include "libairspy/libairspy/src/airspy.h"
const int32_t fft_line_compensation[1024] = {
1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,
1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,1700,
1694,1776,1642,1742,1673,1742,1717,1680,1563,1609,1622,1662,1713,1694,1732,1702,1733,1672,1698,1714,1698,1707,1743,1749,1860,1892,1908,2008,2049,1906,1811,2078,2113,2129,2144,2181,2196,2223,2250,2297,2323,2369,2362,2383,2385,2411,2381,2389,2403,2439,2454,2458,2491,2502,2497,2508,2518,2538,2541,2575,2603,2632,2648,2633,2636,2637,2683,2676,2680,2704,2710,2728,2742,2785,2766,2764,2746,2731,2779,2777,2797,2765,2787,2803,2830,2876,2892,2909,2900,2924,2938,2985,3028,3018,3032,3049,3086,3101,3124,3110,3080,3078,3058,3053,3052,3066,3073,3102,3115,3121,3113,3108,3114,3110,3122,3144,3145,3141,3161,3184,3206,3210,3182,3168,3172,3207,3215,3197,3197,3194,3211,3220,3234,3239,3247,3238,3224,3225,3228,3241,3216,3242,3269,3297,3307,3316,3343,3382,3403,3403,3400,3436,3449,3472,3473,3519,3515,3487,3480,3483,3479,3471,3454,3480,3478,3486,3464,3474,3475,3483,3443,3451,3522,3520,3517,3504,3529,3527,3511,3512,3506,3523,3521,3534,3545,3576,3613,3590,3613,3647,3664,3666,3712,3702,3763,3789,3810,3844,3891,3904,3924,3900,3917,3920,3884,3904,3908,3923,3937,3895,3937,3954,3977,3967,3980,3991,4017,4047,4065,4117,4134,4143,4132,4171,4188,4175,4181,4176,4193,4207,4215,4207,4199,4195,4194,4216,4239,4248,4241,4280,4269,4275,4291,4306,4301,4301,4358,4388,4421,4440,4441,4446,4478,4481,4496,4525,4525,4516,4512,4555,4584,4561,4555,4536,4564,4530,4523,4529,4565,4548,4555,4582,4596,4619,4598,4610,4683,4767,4656,4535,4528,4565,4567,4648,4744,4841,4845,4712,4736,4730,4733,4853,4836,4841,4809,4823,4782,4786,4848,4712,4784,4755,4836,4733,4781,4734,4731,4681,4774,4647,4677,4847,4822,4848,5039,4944,4875,4822,4976,4943,4976,4978,4898,4918,4876,4846,4876,4855,4853,4824,4798,4917,4830,4846,4744,4775,4807,4747,4736,4738,4794,4794,4767,4759,4730,4705,4862,4892,4870,4925,4819,4793,4694,4760,4789,4725,4827,4749,4646,4673,4679,4713,4608,4491,4505,4583,4580,4450,4561,4555,4404,4498,4452,4389,4442,4413,4428,4515,4500,4515,4451,4427,4504,4491,4518,4473,4438,4441,4435,4445,4352,4294,4323,4354,4347,4389,4327,4157,4245,4254,4160,4111,4075,4112,4076,3956,3985,4053,3989,4021,3956,4023,3955,4031,3983,4025,4026,4058,4010,4069,4063,3931,3891,3881,3878,3858,3805,3844,3714,3709,3595,3536,3423,3448,3408,3602,3666,3736,3743,3689,3765,3736,3690,3753,3769,3828,3791,3733,3779,3755,3769,3736,3661,3702,3638,3565,3609,3546,3484,3484,3392,3444,3434,3414,3389,3366,3387,3307,3415,3407,3410,3483,3452,3532,3589,3500,3458,3499,3538,3603,3546,3519,3531,3461,3463,3530,3412,3422,3320,3308,3335,3248,3237,3246,3214,3129,3142,3097,3174,3185,3106,3039,3075,3115,3073,3059,3087,3101,3099,3037,3135,3102,3148,3068,3005,3090,2973,2945,2923,2846,2819,2787,2639,2655,2606,2477,2488,2430,2351,2297,2319,2272,2216,2236,2201,2183,2091,2091,2169,2174,2055,2055,2139,2088,2101,1961,2009,1947,1971,2004,1973,1799,1791,1730,1605,1597,1504,1362,1270,1109,1104,1104,952,1035,1075,1068,1135,1063,1083,1212,1173,1225,1200,1154,1181,1190,1188,1162,1115,1173,1175,1128,1132,1019,1035,947,921,863,858,843,762,847,701,744,693,705,697,687,644,622,716,696,642,665,706,638,570,607,651,787,706,680,685,682,641,742,654,565,583,493,484,494,375,430,395,292,389,394,350,235,229,304,355,364,330,186,269,283,347,341,423,461,395,514,350,326,396,303,320,396,321,335,190,227,199,220,292,239,210,63,133,115,125,87,14,69,163,138,180,153,101,202,185,179,177,194,175,169,146,181,129,114,146,96,0,45,56,100,46,100,72,68,41,83,109,101,61,164,312,319,328,445,390,342,407,535,452,416,371,447,421,421,489,518,383,472,528,458,446,470,472,455,535,479,482,523,559,559,624,649,623,659,645,673,672,794,765,853,794,708,737,762,771,877,851,804,789,763,845,821,808,743,745,836,885,899,891,910,973,989,973,1038,1012,1088,1021,991,1095,1085,930,1066,1055,1025,1084,1039,1079,1102,1135,1040,1140,1077,1058,963,978,984,1035,942,941,1024,1098,1111,1143,1141,1140,1240,1172,1234,1284,1348,1399,1380,1317,1261,1284,1286,1308,1159,1194,1314,1190,1121,1015,920,867,919,885,868,856,810,767,693,
700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,
700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,700,
};
| 118.745098 | 3,893 | 0.775099 |
a8a16906f2e2171da077edbe9eb008db5c68ccd2 | 444 | h | C | flixster/Views/MovieCell.h | bbenson09/flixster | e84b60adfa2b6395690a19076b491f0ddf90e7e9 | [
"Apache-2.0"
] | null | null | null | flixster/Views/MovieCell.h | bbenson09/flixster | e84b60adfa2b6395690a19076b491f0ddf90e7e9 | [
"Apache-2.0"
] | 1 | 2018-06-30T06:52:56.000Z | 2018-06-30T06:52:56.000Z | flixster/Views/MovieCell.h | bbenson09/flixster | e84b60adfa2b6395690a19076b491f0ddf90e7e9 | [
"Apache-2.0"
] | null | null | null | //
// MovieCell.h
// flixster
//
// Created by Bevin Benson on 6/27/18.
// Copyright © 2018 Bevin Benson. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Movie.h"
@interface MovieCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *synopsis;
@property (weak, nonatomic) IBOutlet UIImageView *posterView;
@property (nonatomic, strong) Movie *movie;
@end
| 22.2 | 61 | 0.72973 |
624337f141592baacd763475191c2488e1f97e18 | 2,851 | h | C | source/FormHeaders/ui_ChildForm.h | CoghettoR/gclc | b481b15d28ee66f995b73283e26c285ca8c4a821 | [
"MIT"
] | 21 | 2020-12-08T20:06:01.000Z | 2022-02-13T22:52:02.000Z | source/FormHeaders/ui_ChildForm.h | CoghettoR/gclc | b481b15d28ee66f995b73283e26c285ca8c4a821 | [
"MIT"
] | 9 | 2020-12-20T03:54:55.000Z | 2022-03-31T19:30:04.000Z | source/FormHeaders/ui_ChildForm.h | CoghettoR/gclc | b481b15d28ee66f995b73283e26c285ca8c4a821 | [
"MIT"
] | 5 | 2021-04-25T18:47:17.000Z | 2022-01-23T02:37:30.000Z | /********************************************************************************
** Form generated from reading UI file 'ChildForm.ui'
**
** Created by: Qt User Interface Compiler version 5.10.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_CHILDFORM_H
#define UI_CHILDFORM_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QGraphicsView>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QPlainTextEdit>
#include <QtWidgets/QSplitter>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_ChildForm
{
public:
QGridLayout *gridLayout;
QSplitter *splitter_2;
QSplitter *splitter;
QTextEdit *editor;
QGraphicsView *graphicsOutput;
QPlainTextEdit *output;
void setupUi(QWidget *ChildForm)
{
if (ChildForm->objectName().isEmpty())
ChildForm->setObjectName(QStringLiteral("ChildForm"));
ChildForm->resize(748, 542);
QIcon icon;
icon.addFile(QStringLiteral(":/icons/WinGCLC.ico"), QSize(), QIcon::Normal, QIcon::Off);
ChildForm->setWindowIcon(icon);
gridLayout = new QGridLayout(ChildForm);
gridLayout->setObjectName(QStringLiteral("gridLayout"));
splitter_2 = new QSplitter(ChildForm);
splitter_2->setObjectName(QStringLiteral("splitter_2"));
splitter_2->setOrientation(Qt::Vertical);
splitter = new QSplitter(splitter_2);
splitter->setObjectName(QStringLiteral("splitter"));
splitter->setOrientation(Qt::Horizontal);
editor = new QTextEdit(splitter);
editor->setObjectName(QStringLiteral("editor"));
splitter->addWidget(editor);
graphicsOutput = new QGraphicsView(splitter);
graphicsOutput->setObjectName(QStringLiteral("graphicsOutput"));
graphicsOutput->setMinimumSize(QSize(0, 0));
graphicsOutput->setBaseSize(QSize(0, 200));
splitter->addWidget(graphicsOutput);
splitter_2->addWidget(splitter);
output = new QPlainTextEdit(splitter_2);
output->setObjectName(QStringLiteral("output"));
output->setMinimumSize(QSize(0, 0));
output->setReadOnly(true);
splitter_2->addWidget(output);
gridLayout->addWidget(splitter_2, 0, 0, 1, 1);
retranslateUi(ChildForm);
QMetaObject::connectSlotsByName(ChildForm);
} // setupUi
void retranslateUi(QWidget *ChildForm)
{
ChildForm->setWindowTitle(QString());
} // retranslateUi
};
namespace Ui {
class ChildForm: public Ui_ChildForm {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_CHILDFORM_H
| 32.033708 | 96 | 0.655559 |
cd6212465ed1601c282418fc037e67c9167450cf | 3,303 | c | C | src/compression/fixpoint.c | ezavod/tng | b3a9ec25146760e23a6db377bfcc524abcbb894e | [
"BSD-3-Clause"
] | 11 | 2017-05-23T14:40:44.000Z | 2021-04-20T02:28:15.000Z | pytng/src/compression/fixpoint.c | hmacdope/pytng | 65b4c0c915fe60525d9b2dacb83c2c5d73b3f13f | [
"BSD-3-Clause"
] | 84 | 2017-05-24T06:35:09.000Z | 2022-03-28T10:36:17.000Z | pytng/src/compression/fixpoint.c | hmacdope/pytng | 65b4c0c915fe60525d9b2dacb83c2c5d73b3f13f | [
"BSD-3-Clause"
] | 4 | 2017-06-19T15:02:52.000Z | 2020-10-01T08:41:04.000Z | /*
* This code is part of the tng binary trajectory format.
*
* Copyright (c) 2010,2013, The GROMACS development team.
* Copyright (c) 2020, by the GROMACS development team.
* TNG was orginally written by Magnus Lundborg, Daniel Spångberg and
* Rossen Apostolov. The API is implemented mainly by Magnus Lundborg,
* Daniel Spångberg and Anders Gärdenäs.
*
* Please see the AUTHORS file for more information.
*
* The TNG library is free software; you can redistribute it and/or
* modify it under the terms of the Revised BSD License.
*
* To help us fund future development, we humbly ask that you cite
* the research papers on the package.
*
* Check out http://www.gromacs.org for more information.
*/
/* This code is part of the tng compression routines
* Written by Daniel Spangberg
*/
#include <stdio.h>
#include <math.h>
#include "../../include/compression/fixpoint.h"
#define MAX32BIT 4294967295UL
#define MAX31BIT 2147483647UL
#define SIGN32BIT 2147483648UL
/* Conversion routines from / to double precision */
/* Positive double to 32 bit fixed point value */
fix_t Ptngc_ud_to_fix_t(double d, const double max)
{
fix_t val;
if (d < 0.)
{
d = 0.;
}
if (d > max)
{
d = max;
}
val = (fix_t)(MAX32BIT * (d / max));
if (val > MAX32BIT)
{
val = MAX32BIT;
}
return val;
}
/* double to signed 32 bit fixed point value */
fix_t Ptngc_d_to_fix_t(double d, const double max)
{
fix_t val;
int sign = 0;
if (d < 0.)
{
sign = 1;
d = -d;
}
if (d > max)
{
d = max;
}
val = (fix_t)(MAX31BIT * (d / max));
if (val > MAX31BIT)
{
val = MAX31BIT;
}
if (sign)
{
val |= SIGN32BIT;
}
return val;
}
/* 32 bit fixed point value to positive double */
double Ptngc_fix_t_to_ud(fix_t f, const double max)
{
return (double)f * (max / MAX32BIT);
}
/* signed 32 bit fixed point value to double */
double Ptngc_fix_t_to_d(fix_t f, const double max)
{
int sign = 0;
double d;
if (f & SIGN32BIT)
{
sign = 1;
f &= MAX31BIT;
}
d = (double)f * (max / MAX31BIT);
if (sign)
{
d = -d;
}
return d;
}
/* Convert a floating point variable to two 32 bit integers with range
-2.1e9 to 2.1e9 and precision to somewhere around 1e-9. */
void Ptngc_d_to_i32x2(double d, fix_t* hi, fix_t* lo)
{
int sign = 0;
double frac;
double ent;
fix_t val, vallo;
if (d < 0.)
{
sign = 1;
d = -d;
}
/* First the integer part */
ent = floor(d);
/* Then the fractional part */
frac = d - ent;
val = (fix_t)ent;
if (sign)
{
val |= SIGN32BIT;
}
vallo = Ptngc_ud_to_fix_t(frac, 1.);
*hi = val;
*lo = vallo;
}
/* Convert two 32 bit integers to a floating point variable
-2.1e9 to 2.1e9 and precision to somewhere around 1e-9. */
double Ptngc_i32x2_to_d(fix_t hi, fix_t lo)
{
double ent, frac = 0.;
double val = 0.;
int sign = 0;
if (hi & SIGN32BIT)
{
sign = 1;
hi &= MAX31BIT;
}
ent = (double)hi;
frac = Ptngc_fix_t_to_ud(lo, 1.);
val = ent + frac;
if (sign)
{
val = -val;
}
return val;
}
| 20.905063 | 70 | 0.585226 |
28d69eb5d5cd6739c61d50c5ea84f95f80e0fbc7 | 583 | h | C | src/BLDCSpeaker.h | owennewo/tone-player | 01f0c4b9e715e04e17fd6be6c178cfd248afcb7a | [
"MIT"
] | 4 | 2020-10-05T18:32:58.000Z | 2021-09-14T14:49:32.000Z | src/BLDCSpeaker.h | owennewo/tone-player | 01f0c4b9e715e04e17fd6be6c178cfd248afcb7a | [
"MIT"
] | null | null | null | src/BLDCSpeaker.h | owennewo/tone-player | 01f0c4b9e715e04e17fd6be6c178cfd248afcb7a | [
"MIT"
] | null | null | null | #ifndef BLDC_SPEAKER_H
#define BLDC_SPEAKER_H
#include <BLDCMotor.h>
#include <Speaker.h>
enum WaveShape
{
Square,
Sinusoidal,
};
class BLDCSpeaker : public Speaker
{
public:
BLDCSpeaker(BLDCMotor *motor, float _voltage_limit, int volume = 50, int note_offset = 0);
void setVolume(float volume);
void setFrequency(float frequency);
void enable();
void disable();
void loop();
private:
BLDCMotor *motor;
int setPhaseVoltage(float volts, float angle);
float start_micros = 0;
float amplitude = 0;
WaveShape wave_shape;
};
#endif | 18.806452 | 94 | 0.694683 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.