Esempio n. 1
0
static imgtoolerr_t rsdos_diskimage_writefile(imgtool_partition *partition, const char *fname, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions)
{
    floperr_t ferr;
    imgtoolerr_t err;
    imgtool_image *img = imgtool_partition_image(partition);
    struct rsdos_dirent ent, ent2;
    size_t i;
    UINT64 sz;
    UINT64 freespace = 0;
    unsigned char g;
    unsigned char *gptr;
    UINT8 granule_count;
    UINT8 granule_map[MAX_GRANULEMAP_SIZE];

    /* can we write to this image? */
    if (floppy_is_read_only(imgtool_floppy(img)))
        return IMGTOOLERR_READONLY;

    err = rsdos_diskimage_freespace(partition, &freespace);
    if (err)
        return err;

    /* is there enough space? */
    sz = stream_size(sourcef);
    if (sz > freespace)
        return IMGTOOLERR_NOSPACE;

    /* setup our directory entry */
    err = prepare_dirent(&ent, fname);
    if (err)
        return err;

    ent.ftype = writeoptions->lookup_int(RSDOS_OPTIONS_FTYPE);
    ent.asciiflag = UINT8(writeoptions->lookup_int(RSDOS_OPTIONS_ASCII)) - 1;
    ent.lastsectorbytes_lsb = sz % 256;
    ent.lastsectorbytes_msb = (((sz % 256) == 0) && (sz > 0)) ? 1 : 0;
    gptr = &ent.first_granule;

    ferr = get_granule_map(img, granule_map, &granule_count);
    if (ferr)
        return imgtool_floppy_error(ferr);

    g = 0x00;

    do
    {
        while (granule_map[g] != 0xff)
        {
            g++;
            if ((g >= granule_count) || (g == 0))
                return IMGTOOLERR_UNEXPECTED;   /* We should have already verified that there is enough space */
        }
        *gptr = g;
        gptr = &granule_map[g];


        i = std::min(sz, UINT64(9*256));
        err = transfer_to_granule(img, g, i, sourcef);
        if (err)
            return err;

        sz -= i;

        /* Go to next granule */
        g++;
    }
    while(sz > 0);

    /* Now that we are done with the file, we need to specify the final entry
     * in the file allocation table
     */
    *gptr = 0xc0 + ((i + 255) / 256);

    /* Now we need to find an empty directory entry */
    i = -1;
    do
    {
        ferr = get_rsdos_dirent(img, ++i, &ent2);
        if (ferr)
            return imgtool_floppy_error(ferr);
    }
    while((ent2.fname[0] != '\0') && strcmp(ent.fname, ent2.fname) && (ent2.fname[0] != -1));

    /* delete file if it already exists */
    if (ent2.fname[0] && (ent2.fname[0] != -1))
    {
        err = delete_entry(img, &ent2, i);
        if (err)
            return err;
    }

    ferr = put_rsdos_dirent(img, i, &ent);
    if (ferr)
        return imgtool_floppy_error(ferr);

    /* write the granule map back out */
    ferr = put_granule_map(img, granule_map, granule_count);
    if (ferr)
        return imgtool_floppy_error(ferr);

    return IMGTOOLERR_SUCCESS;
}
Esempio n. 2
0
/**
 * \brief This function initialize values of command Tag_Set
 */
struct Generic_Cmd *v_tag_set_create(const uint32 node_id,
		const uint16 taggroup_id,
		const uint16 tag_id,
		const uint8 data_type,
		const uint8 count,
		const void *value)
{
	int i, cmd_id;
	struct Generic_Cmd *tag_set;

	assert(count<=4);

	/* Tricky part :-) */
	cmd_id = CMD_TAG_SET_UINT8 + 4*(data_type-1) + (count-1);

	tag_set = (struct Generic_Cmd *)malloc(UINT8_SIZE +
			cmd_struct[cmd_id].size);

	if(tag_set == NULL) {
		return NULL;
	}

	tag_set->id = cmd_id;
	UINT32(tag_set->data[0]) = node_id;
	UINT16(tag_set->data[UINT32_SIZE]) = taggroup_id;
	UINT16(tag_set->data[UINT32_SIZE + UINT16_SIZE]) = tag_id;

	switch(data_type) {
	case VRS_VALUE_TYPE_UINT8:
		for(i=0; i<count; i++) {
			UINT8(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*INT8_SIZE]) = ((uint8*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT16:
		for(i=0; i<count; i++) {
			UINT16(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*INT16_SIZE]) = ((uint16*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT32:
		for(i=0; i<count; i++) {
			UINT32(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE  + i*INT32_SIZE]) = ((uint32*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT64:
		for(i=0; i<count; i++) {
			UINT64(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*INT64_SIZE]) = ((uint64*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL16:
		for(i=0; i<count; i++) {
			REAL16(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*REAL16_SIZE]) = ((real16*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL32:
		for(i=0; i<count; i++) {
			REAL32(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*REAL32_SIZE]) = ((real32*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL64:
		for(i=0; i<count; i++) {
			REAL64(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + i*REAL64_SIZE]) = ((real64*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_STRING8:
		assert((char*)value != NULL);
		{
			char *name = (char*)value;
			size_t string8_len = strlen(name);

			/* The length of the name can't be longer then 255 bytes. Crop it, when it
			 * is necessary */
			if(string8_len > VRS_STRING8_MAX_SIZE) {
				v_print_log(VRS_PRINT_WARNING, "Cropping string8 %s(length:%d) to length: %d\n",
						name, string8_len, VRS_STRING8_MAX_SIZE);
				string8_len = VRS_STRING8_MAX_SIZE;
			}
			PTR(tag_set->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]) = strndup(name, string8_len);
		}
		break;
	}

	return tag_set;
}
Esempio n. 3
0
//
//  This program is distributed in the hope that it will be useful,
//  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.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
//*****************************************************************************

#include "mb96348hs.h"
#include "seg.h"
#include "seg.cfg.h"

static const uint8_t DEC7SEG[16] = { UINT8(~0x3f), UINT8(~0x06), UINT8(~0x5b), UINT8(~0x4f), UINT8(~0x66), UINT8(~0x6d), UINT8(~0x7d), UINT8(~0x07), UINT8(~0x7f), UINT8(~0x6f),
		UINT8(~0x77), UINT8(~0x7c), UINT8(~0x58), UINT8(~0x5e), UINT8(~0x79), UINT8(~0x71) };

void seg_init(void) {
	SEG0_PORT_DB = 0xff;
	SEG0_PORT_DDR = 0xff;
	SEG1_PORT_DB = 0xff;
	SEG1_PORT_DDR = 0xff;
}

void seg_num(uint8_t num) {
	if (num < 100) {
		seg_numLeft(num / 10);
		seg_numRight(num % 10);
	}
}
Esempio n. 4
0
void cam_loadParams()
{
	prm_add("Brightness", 0, 
		"Sets the average brightness of the camera, can be between 0 and 255 (default 90)", UINT8(CAM_BRIGHTNESS_DEFAULT), END);

	uint8_t brightness;
	prm_get("Brightness", &brightness, END);
	cam_setBrightness(brightness);
}
Esempio n. 5
0
static void loadParams()
{
	// exec's params added here
	prm_add("Default program", 0, 
		"Selects the program number that's run by default upon power-up. (default 0)", UINT8(0), END);
}
int main(int argc, char * argv[])
{
  int      i = 0;
  int      index;
  int      blocks_copied;
  int      pixy_init_status;
  char     buf[128];

  // Catch CTRL+C (SIGINT) signals //
  signal(SIGINT, handle_SIGINT);

  printf("Hello Pixy:\n libpixyusb Version: %s\n", __LIBPIXY_VERSION__);

  // Connect to Pixy //
  pixy_init_status = pixy_init();

  // Was there an error initializing pixy? //
  if(!pixy_init_status == 0)
  {
    // Error initializing Pixy //
    printf("pixy_init(): ");
    pixy_error(pixy_init_status);

    return pixy_init_status;
  }

  // Request Pixy firmware version //
  {
    uint16_t major;
    uint16_t minor;
    uint16_t build;
    int      return_value;

    return_value = pixy_get_firmware_version(&major, &minor, &build);

    if (return_value) {
      // Error //
      printf("Failed to retrieve Pixy firmware version. ");
      pixy_error(return_value);

      return return_value;
    } else {
      // Success //
      printf(" Pixy Firmware Version: %d.%d.%d\n", major, minor, build);
    }
  }

#if 0
  // Pixy Command Examples //
  {
    int32_t response;
    int     return_value;

    // Execute remote procedure call "cam_setAWB" with one output (host->pixy) parameter (Value = 1)
    //
    //   Parameters:                 Notes:
    //
    //   pixy_command("cam_setAWB",  String identifier for remote procedure
    //                        0x01,  Length (in bytes) of first output parameter
    //                           1,  Value of first output parameter
    //                           0,  Parameter list seperator token (See value of: END_OUT_ARGS)
    //                   &response,  Pointer to memory address for return value from remote procedure call
    //                           0); Parameter list seperator token (See value of: END_IN_ARGS)
    //

    // Enable auto white balance //
    pixy_command("cam_setAWB", UINT8(0x01), END_OUT_ARGS,  &response, END_IN_ARGS);

    // Execute remote procedure call "cam_getAWB" with no output (host->pixy) parameters
    //
    //   Parameters:                 Notes:
    //
    //   pixy_command("cam_setAWB",  String identifier for remote procedure
    //                           0,  Parameter list seperator token (See value of: END_OUT_ARGS)
    //                   &response,  Pointer to memory address for return value from remote procedure call
    //                           0); Parameter list seperator token (See value of: END_IN_ARGS)
    //

    // Get auto white balance //
    return_value = pixy_command("cam_getAWB", END_OUT_ARGS, &response, END_IN_ARGS);

    // Set auto white balance back to disabled //
    pixy_command("cam_setAWB", UINT8(0x00), END_OUT_ARGS,  &response, END_IN_ARGS);
  }
#endif

  printf("Detecting blocks...\n");
  while(run_flag)
  {
    // Wait for new blocks to be available //
    while(!pixy_blocks_are_new() && run_flag); 

    // Get blocks from Pixy //
    blocks_copied = pixy_get_blocks(BLOCK_BUFFER_SIZE, &blocks[0]);

    if(blocks_copied < 0) {
      // Error: pixy_get_blocks //
      printf("pixy_get_blocks(): ");
      pixy_error(blocks_copied);
    }

    // Display received blocks //
    printf("frame %d:\n", i);
    for(index = 0; index != blocks_copied; ++index) {    
       blocks[index].print(buf);
       printf("  %s\n", buf);
    }
    i++;
  }
  pixy_close();
}
/* ChapelStandard.chpl:23 */
void chpl__init_ChapelStandard(int64_t _ln, int32_t _fn) {
  c_string modFormatStr;
  c_string modStr;
  _ref_int32_t refIndentLevel = NULL;
#line 23 "ChapelStandard.chpl"
  if (chpl__init_ChapelStandard_p) /* ZLINE: 23 /home/agobin/Documents/chapel-1.13.0/modules/internal/ChapelStandard.chpl */
#line 23 "ChapelStandard.chpl"
  {
#line 23 "ChapelStandard.chpl"
    goto _exit_chpl__init_ChapelStandard;
#line 23 "ChapelStandard.chpl"
  }
#line 23 "ChapelStandard.chpl"
  modFormatStr = "%*s\n";
#line 23 "ChapelStandard.chpl"
  modStr = "ChapelStandard";
#line 23 "ChapelStandard.chpl"
  printModuleInit(modFormatStr, modStr, INT64(14), _ln, _fn);
#line 23 "ChapelStandard.chpl"
  refIndentLevel = &moduleInitLevel;
#line 23 "ChapelStandard.chpl"
  *(refIndentLevel) += INT64(1);
#line 23 "ChapelStandard.chpl"
  chpl__init_ChapelStandard_p = UINT8(true);
#line 23 "ChapelStandard.chpl"
  {
#line 23 "ChapelStandard.chpl"
    chpl__init_CPtr(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_CString(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_String(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_ChapelBase(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_MemConsistency(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_Atomics(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_AtomicsCommon(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_ChapelThreads(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_ChapelTuple(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_ChapelRange(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_LocaleModel(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_ChapelLocale(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_DefaultRectangular(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_LocalesArray(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_ChapelArray(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_ChapelDistribution(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_ChapelIO(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_LocaleTree(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_DefaultAssociative(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_ChapelTaskTable(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_MemTracking(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_ChapelUtil(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_ChapelDynDispHack(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_Assert(_ln, _fn);
#line 23 "ChapelStandard.chpl"
    chpl__init_CommDiagnostics(_ln, _fn);
#line 23 "ChapelStandard.chpl"
  }
#line 23 "ChapelStandard.chpl"
  *(refIndentLevel) -= INT64(1);
#line 23 "ChapelStandard.chpl"
  _exit_chpl__init_ChapelStandard:;
#line 23 "ChapelStandard.chpl"
  return;
#line 23 "ChapelStandard.chpl"
}
Esempio n. 8
0
void ser_loadParams()
{
	prm_add("Data out port", 0, 
		"@c Interface Selects the port that's used to output data, 0=Arduino ICSP SPI, 1=SPI with SS, 2=I2C, 3=UART, 4=analog/digital x, 5=analog/digital y (default 0)", UINT8(0), END);
	prm_add("I2C address", PRM_FLAG_HEX_FORMAT, 
		"@c Interface Sets the I2C address if you are using I2C data out port. (default 0x54)", UINT8(I2C_DEFAULT_SLAVE_ADDR), END);
	prm_add("UART baudrate", 0, 
		"@c Interface Sets the UART baudrate if you are using UART data out port. (default 19200)", UINT32(19200), END);

	uint8_t interface, addr;
	uint32_t baudrate;

	prm_get("Data out port", &interface, END);
	ser_setInterface(interface);

	prm_get("I2C address", &addr, END);
	g_i2c0->setSlaveAddr(addr);

	prm_get("UART baudrate", &baudrate, END);
	g_uart0->setBaudrate(baudrate);
}
Esempio n. 9
0
uint16_t hal_nrf_read_rx_payload(uint8_t *rx_pload)
{
  return hal_nrf_read_multibyte_reg(UINT8(HAL_NRF_RX_PLOAD), rx_pload);
}
Esempio n. 10
0
/**
 * \brief This function initialize values of command Tag_Set
 */
struct Generic_Cmd *v_layer_set_value_create(const uint32 node_id,
		const uint16 layer_id,
		const uint32 item_id,
		const uint8 data_type,
		const uint8 count,
		const void *value)
{
	int i, cmd_id;
	struct Generic_Cmd *layer_set;

	assert(count<=4);

	/* Tricky part :-) */
	cmd_id = CMD_LAYER_SET_UINT8 + 4*(data_type-1) + (count-1);

	layer_set = (struct Generic_Cmd *)malloc(UINT8_SIZE +
			cmd_struct[cmd_id].size);

	layer_set->id = cmd_id;
	UINT32(layer_set->data[0]) = node_id;
	UINT16(layer_set->data[UINT32_SIZE]) = layer_id;
	UINT32(layer_set->data[UINT32_SIZE + UINT16_SIZE]) = item_id;

	switch(data_type) {
	case VRS_VALUE_TYPE_UINT8:
		for(i=0; i<count; i++) {
			UINT8(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE + i*INT8_SIZE]) = ((uint8*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT16:
		for(i=0; i<count; i++) {
			UINT16(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE + i*INT16_SIZE]) = ((uint16*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT32:
		for(i=0; i<count; i++) {
			UINT32(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE  + i*INT32_SIZE]) = ((uint32*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_UINT64:
		for(i=0; i<count; i++) {
			UINT64(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE + i*INT64_SIZE]) = ((uint64*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL16:
		for(i=0; i<count; i++) {
			REAL16(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE + i*REAL16_SIZE]) = ((real16*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL32:
		for(i=0; i<count; i++) {
			REAL32(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE + i*REAL32_SIZE]) = ((real32*)value)[i];
		}
		break;
	case VRS_VALUE_TYPE_REAL64:
		for(i=0; i<count; i++) {
			REAL64(layer_set->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE + i*REAL64_SIZE]) = ((real64*)value)[i];
		}
		break;
	}

	return layer_set;
}
Esempio n. 11
0
File: vs_tag.c Progetto: verse/verse
/**
 * \brief This function tries to handle Tag_Create command
 */
int vs_handle_tag_create(struct VS_CTX *vs_ctx,
                         struct VSession *vsession,
                         struct Generic_Cmd *tag_create)
{
    struct VSNode			*node;
    struct VSTagGroup		*tg;
    struct VSTag			*tag;
    struct VBucket			*vbucket;
    struct VSEntitySubscriber	*tg_subscriber;
    uint32 					node_id = UINT32(tag_create->data[0]);
    uint16 					taggroup_id = UINT16(tag_create->data[UINT32_SIZE]);
    uint16					tag_id = UINT16(tag_create->data[UINT32_SIZE + UINT16_SIZE]);
    uint8					data_type = UINT8(tag_create->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]);
    uint8					count = UINT8(tag_create->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + UINT8_SIZE]);
    uint16 					type = UINT16(tag_create->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + UINT8_SIZE + UINT8_SIZE]);
    int						ret = 0;

    /* Try to find node */
    if((node = vs_node_find(vs_ctx, node_id)) == NULL) {
        v_print_log(VRS_PRINT_DEBUG_MSG, "%s() node (id: %d) not found\n",
                    __FUNCTION__, node_id);
        return 0;
    }

    pthread_mutex_lock(&node->mutex);

    /* Node has to be created */
    if(vs_node_is_created(node) != 1) {
        goto end;
    }

    /* User has to have permission to write to the node */
    if(vs_node_can_write(vsession, node) != 1) {
        v_print_log(VRS_PRINT_DEBUG_MSG,
                    "%s(): user: %s can't write to node: %d\n",
                    __FUNCTION__,
                    ((struct VSUser *)vsession->user)->username,
                    node->id);
        goto end;
    }

    /* Try to find TagGroup */
    if( (tg = vs_taggroup_find(node, taggroup_id)) == NULL) {
        v_print_log(VRS_PRINT_DEBUG_MSG, "%s() tag_group (id: %d) in node (id: %d) not found\n",
                    __FUNCTION__, taggroup_id, node_id);
        goto end;
    }

    /* Tag Group has to be created too (it can't be in DELETING or DELETED state ) */
    if(!(tg->state == ENTITY_CREATED || tg->state == ENTITY_CREATING)) {
        v_print_log(VRS_PRINT_DEBUG_MSG, "%s() tag group (id: %d) from node (id: %d) is not in CREATING or CREATED state: %d\n",
                    __FUNCTION__, tg->id, node->id, tg->state);
        goto end;
    }

    /* Client has to send tag_create command with tag_id equal to
     * the value 0xFFFF */
    if(tag_id != RESERVED_TAG_ID) {
        v_print_log(VRS_PRINT_DEBUG_MSG, "%s() tag_id: %d is not 0xFFFF\n",
                    __FUNCTION__, tag_id);
        goto end;
    }

    /* Is type of Tag supported? */
    if(!(data_type>VRS_VALUE_TYPE_RESERVED && data_type<=VRS_VALUE_TYPE_STRING8)) {
        v_print_log(VRS_PRINT_DEBUG_MSG, "%s() tag_type: %d is not supported\n",
                    __FUNCTION__, data_type);
        goto end;
    }

    vbucket = tg->tags.lb.first;
    /* Check, if there isn't tag with the same type */
    while(vbucket != NULL) {
        tag = vbucket->data;
        if(tag->custom_type == type) {
            v_print_log(VRS_PRINT_DEBUG_MSG, "%s() tag type: %d is already used in taggroup: %d\n",
                        __FUNCTION__, type, tg->id);
            goto end;
        }
        vbucket = vbucket->next;
    }

    if (v_hash_array_count_items(&tg->tags) > MAX_TAGS_COUNT) {
        v_print_log(VRS_PRINT_DEBUG_MSG, "%s() max number of tags in node: %d tag_group: %d was reached\n",
                    tg->id);
        goto end;
    }

    /* Try to create new tag */
    tag = vs_tag_create(tg, RESERVED_TAG_ID, data_type, count, type);
    if(tag == NULL) {
        goto end;
    }

    ret = 1;

    tag->state = ENTITY_CREATING;

    /* Send TagCreate to all subscribers of tag group */
    tg_subscriber = tg->tg_subs.first;
    while(tg_subscriber != NULL) {
        if(vs_tag_send_create(tg_subscriber, node, tg, tag) != 1) {
            ret = 0;
        }
        tg_subscriber = tg_subscriber->next;
    }

end:
    pthread_mutex_unlock(&node->mutex);

    return ret;
}
Esempio n. 12
0
File: verse.c Progetto: laishi/verse
/**
 * \brief This functions calls registered callback function for appropriate
 * commands
 */
static void vc_call_callback_func(const uint8 session_id,
		struct Generic_Cmd *cmd)
{
	switch(cmd->id) {
	case FAKE_CMD_CONNECT_ACCEPT:
		if(vc_ctx->vfs.receive_connect_accept != NULL) {
			vc_ctx->vfs.receive_connect_accept(session_id,
					((struct Connect_Accept_Cmd*)cmd)->user_id,
					((struct Connect_Accept_Cmd*)cmd)->avatar_id);
		}
		break;
	case FAKE_CMD_CONNECT_TERMINATE:
		if(vc_ctx->vfs.receive_connect_terminate != NULL) {
			vc_ctx->vfs.receive_connect_terminate(session_id,
					((struct Connect_Terminate_Cmd*)cmd)->error_num);
		}
		break;
	case FAKE_CMD_USER_AUTHENTICATE:
		if(vc_ctx->vfs.receive_user_authenticate != NULL) {
			vc_ctx->vfs.receive_user_authenticate(session_id,
					((struct User_Authenticate_Cmd*)cmd)->username,
					((struct User_Authenticate_Cmd*)cmd)->auth_meth_count,
					((struct User_Authenticate_Cmd*)cmd)->methods);
		}
		break;
	case CMD_NODE_CREATE:
		if(vc_ctx->vfs.receive_node_create != NULL) {
			vc_ctx->vfs.receive_node_create(session_id,
					UINT32(cmd->data[UINT16_SIZE+UINT32_SIZE]),
					UINT32(cmd->data[UINT16_SIZE]),
					UINT16(cmd->data[0]),
					UINT16(cmd->data[UINT16_SIZE+UINT32_SIZE+UINT32_SIZE]));
		}
		break;
	case CMD_NODE_DESTROY:
		if(vc_ctx->vfs.receive_node_destroy != NULL) {
			vc_ctx->vfs.receive_node_destroy(session_id,
					UINT32(cmd->data[0]));
		}
		break;
	case CMD_NODE_SUBSCRIBE:
		if(vc_ctx->vfs.receive_node_subscribe != NULL) {
			vc_ctx->vfs.receive_node_subscribe(session_id,
					UINT32(cmd->data[0]),
					UINT32(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE + UINT32_SIZE]));
		}
		break;
	case CMD_NODE_UNSUBSCRIBE:
		if(vc_ctx->vfs.receive_node_unsubscribe != NULL) {
			vc_ctx->vfs.receive_node_unsubscribe(session_id,
					UINT32(cmd->data[0]),
					UINT32(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE + UINT32_SIZE]));
		}
		break;
	case CMD_NODE_PERMISSION:
		if(vc_ctx->vfs.receive_node_perm != NULL) {
			vc_ctx->vfs.receive_node_perm(session_id,
					UINT32(cmd->data[UINT16_SIZE+UINT8_SIZE]),
					UINT16(cmd->data[0]),
					UINT8(cmd->data[UINT16_SIZE]));
		}
		break;
	case CMD_NODE_OWNER:
		if(vc_ctx->vfs.receive_node_owner != NULL) {
			vc_ctx->vfs.receive_node_owner(session_id,
					UINT32(cmd->data[UINT16_SIZE]),
					UINT16(cmd->data[0]));
		}
		break;
	case CMD_NODE_LOCK:
		if(vc_ctx->vfs.receive_node_lock != NULL) {
			vc_ctx->vfs.receive_node_lock(session_id,
					UINT32(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[0]));
		}
		break;
	case CMD_NODE_UNLOCK:
		if(vc_ctx->vfs.receive_node_unlock != NULL) {
			vc_ctx->vfs.receive_node_unlock(session_id,
					UINT32(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[0]));
		}
		break;
	case CMD_NODE_LINK:
		if(vc_ctx->vfs.receive_node_link != NULL) {
			vc_ctx->vfs.receive_node_link(session_id,
					UINT32(cmd->data[0]),
					UINT32(cmd->data[UINT32_SIZE]));
		}
		break;
	case CMD_TAGGROUP_CREATE:
		if(vc_ctx->vfs.receive_taggroup_create != NULL) {
			vc_ctx->vfs.receive_taggroup_create(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT16(cmd->data[UINT32_SIZE+UINT16_SIZE]));
		}
		break;
	case CMD_TAGGROUP_DESTROY:
		if(vc_ctx->vfs.receive_taggroup_destroy) {
			vc_ctx->vfs.receive_taggroup_destroy(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]));
		}
		break;
	case CMD_TAGGROUP_SUBSCRIBE:
		if(vc_ctx->vfs.receive_taggroup_subscribe) {
			vc_ctx->vfs.receive_taggroup_subscribe(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE+UINT16_SIZE]),
					UINT32(cmd->data[UINT32_SIZE+UINT16_SIZE+UINT32_SIZE]));
		}
		break;
	case CMD_TAGGROUP_UNSUBSCRIBE:
		if(vc_ctx->vfs.receive_taggroup_unsubscribe) {
			vc_ctx->vfs.receive_taggroup_unsubscribe(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE+UINT16_SIZE]),
					UINT32(cmd->data[UINT32_SIZE+UINT16_SIZE+UINT32_SIZE]));
		}
		break;
	case CMD_TAG_CREATE:
		if(vc_ctx->vfs.receive_tag_create != NULL) {
			vc_ctx->vfs.receive_tag_create(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT16(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					UINT8(cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]),
					UINT8(cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + UINT8_SIZE]),
					UINT16(cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + UINT8_SIZE + UINT8_SIZE]));
		}
		break;
	case CMD_TAG_DESTROY:
		if(vc_ctx->vfs.receive_tag_destroy != NULL) {
			vc_ctx->vfs.receive_tag_destroy(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT16(cmd->data[UINT32_SIZE + UINT16_SIZE]));
		}
		break;
	case CMD_TAG_SET_UINT8:
	case CMD_TAG_SET_VEC2_UINT8:
	case CMD_TAG_SET_VEC3_UINT8:
	case CMD_TAG_SET_VEC4_UINT8:
		if(vc_ctx->vfs.receive_tag_set_value != NULL) {
			vc_ctx->vfs.receive_tag_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT16(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_UINT8,
					cmd->id - CMD_TAG_SET_UINT8 + 1,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]);
		}
		break;
	case CMD_TAG_SET_UINT16:
	case CMD_TAG_SET_VEC2_UINT16:
	case CMD_TAG_SET_VEC3_UINT16:
	case CMD_TAG_SET_VEC4_UINT16:
		if(vc_ctx->vfs.receive_tag_set_value != NULL) {
			vc_ctx->vfs.receive_tag_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT16(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_UINT16,
					cmd->id - CMD_TAG_SET_UINT16 + 1 ,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]);
		}
		break;
	case CMD_TAG_SET_UINT32:
	case CMD_TAG_SET_VEC2_UINT32:
	case CMD_TAG_SET_VEC3_UINT32:
	case CMD_TAG_SET_VEC4_UINT32:
		if(vc_ctx->vfs.receive_tag_set_value != NULL) {
			vc_ctx->vfs.receive_tag_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT16(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_UINT32,
					cmd->id - CMD_TAG_SET_UINT32 + 1,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]);
		}
		break;
	case CMD_TAG_SET_UINT64:
	case CMD_TAG_SET_VEC2_UINT64:
	case CMD_TAG_SET_VEC3_UINT64:
	case CMD_TAG_SET_VEC4_UINT64:
		if(vc_ctx->vfs.receive_tag_set_value != NULL) {
			vc_ctx->vfs.receive_tag_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT16(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_UINT64,
					cmd->id - CMD_TAG_SET_UINT64 + 1,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]);
		}
		break;
	case CMD_TAG_SET_REAL16:
	case CMD_TAG_SET_VEC2_REAL16:
	case CMD_TAG_SET_VEC3_REAL16:
	case CMD_TAG_SET_VEC4_REAL16:
		if(vc_ctx->vfs.receive_tag_set_value != NULL) {
			vc_ctx->vfs.receive_tag_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT16(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_REAL16,
					cmd->id - CMD_TAG_SET_REAL16 + 1,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]);
		}
		break;
	case CMD_TAG_SET_REAL32:
	case CMD_TAG_SET_VEC2_REAL32:
	case CMD_TAG_SET_VEC3_REAL32:
	case CMD_TAG_SET_VEC4_REAL32:
		if(vc_ctx->vfs.receive_tag_set_value != NULL) {
			vc_ctx->vfs.receive_tag_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT16(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_REAL32,
					cmd->id - CMD_TAG_SET_REAL32 + 1,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]);
		}
		break;
	case CMD_TAG_SET_REAL64:
	case CMD_TAG_SET_VEC2_REAL64:
	case CMD_TAG_SET_VEC3_REAL64:
	case CMD_TAG_SET_VEC4_REAL64:
		if(vc_ctx->vfs.receive_tag_set_value != NULL) {
			vc_ctx->vfs.receive_tag_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT16(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_REAL64,
					cmd->id - CMD_TAG_SET_REAL64 + 1,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]);
		}
		break;
	case CMD_TAG_SET_STRING8:
		if(vc_ctx->vfs.receive_tag_set_value != NULL) {
			vc_ctx->vfs.receive_tag_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT16(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_STRING8,
					1,
					PTR(cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]));
		}
		break;
	case CMD_LAYER_CREATE:
		if(vc_ctx->vfs.receive_layer_create != NULL) {
			vc_ctx->vfs.receive_layer_create(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT16(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					UINT8(cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE]),
					UINT8(cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + UINT8_SIZE]),
					UINT16(cmd->data[UINT32_SIZE + UINT16_SIZE + UINT16_SIZE + UINT8_SIZE  + UINT8_SIZE]));
		}
		break;
	case CMD_LAYER_DESTROY:
		if(vc_ctx->vfs.receive_layer_destroy != NULL) {
			vc_ctx->vfs.receive_layer_destroy(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]));
		}
		break;
	case CMD_LAYER_SUBSCRIBE:
		if(vc_ctx->vfs.receive_layer_subscribe != NULL) {
			vc_ctx->vfs.receive_layer_subscribe(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE+UINT16_SIZE]),
					UINT32(cmd->data[UINT32_SIZE+UINT16_SIZE+UINT32_SIZE]));
		}
		break;
	case CMD_LAYER_UNSUBSCRIBE:
		if(vc_ctx->vfs.receive_layer_unsubscribe != NULL) {
			vc_ctx->vfs.receive_layer_unsubscribe(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE+UINT16_SIZE]),
					UINT32(cmd->data[UINT32_SIZE+UINT16_SIZE+UINT32_SIZE]));
		}
		break;
	case CMD_LAYER_UNSET_VALUE:
		if(vc_ctx->vfs.receive_layer_unset_value != NULL) {
			vc_ctx->vfs.receive_layer_unset_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE + UINT16_SIZE]));
		}
		break;
	case CMD_LAYER_SET_UINT8:
	case CMD_LAYER_SET_VEC2_UINT8:
	case CMD_LAYER_SET_VEC3_UINT8:
	case CMD_LAYER_SET_VEC4_UINT8:
		if(vc_ctx->vfs.receive_layer_set_value != NULL) {
			vc_ctx->vfs.receive_layer_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_UINT8,
					cmd->id - CMD_LAYER_SET_UINT8 + 1,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE]);
		}
		break;
	case CMD_LAYER_SET_UINT16:
	case CMD_LAYER_SET_VEC2_UINT16:
	case CMD_LAYER_SET_VEC3_UINT16:
	case CMD_LAYER_SET_VEC4_UINT16:
		if(vc_ctx->vfs.receive_layer_set_value != NULL) {
			vc_ctx->vfs.receive_layer_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_UINT16,
					cmd->id - CMD_LAYER_SET_UINT16 + 1,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE]);
		}
		break;
	case CMD_LAYER_SET_UINT32:
	case CMD_LAYER_SET_VEC2_UINT32:
	case CMD_LAYER_SET_VEC3_UINT32:
	case CMD_LAYER_SET_VEC4_UINT32:
		if(vc_ctx->vfs.receive_layer_set_value != NULL) {
			vc_ctx->vfs.receive_layer_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_UINT32,
					cmd->id - CMD_LAYER_SET_UINT32 + 1,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE]);
		}
		break;
	case CMD_LAYER_SET_UINT64:
	case CMD_LAYER_SET_VEC2_UINT64:
	case CMD_LAYER_SET_VEC3_UINT64:
	case CMD_LAYER_SET_VEC4_UINT64:
		if(vc_ctx->vfs.receive_layer_set_value != NULL) {
			vc_ctx->vfs.receive_layer_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_UINT64,
					cmd->id - CMD_LAYER_SET_UINT64 + 1,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE]);
		}
		break;
	case CMD_LAYER_SET_REAL16:
	case CMD_LAYER_SET_VEC2_REAL16:
	case CMD_LAYER_SET_VEC3_REAL16:
	case CMD_LAYER_SET_VEC4_REAL16:
		if(vc_ctx->vfs.receive_layer_set_value != NULL) {
			vc_ctx->vfs.receive_layer_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_REAL16,
					cmd->id - CMD_LAYER_SET_REAL16 + 1,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE]);
		}
		break;
	case CMD_LAYER_SET_REAL32:
	case CMD_LAYER_SET_VEC2_REAL32:
	case CMD_LAYER_SET_VEC3_REAL32:
	case CMD_LAYER_SET_VEC4_REAL32:
		if(vc_ctx->vfs.receive_layer_set_value != NULL) {
			vc_ctx->vfs.receive_layer_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_REAL32,
					cmd->id - CMD_LAYER_SET_REAL32 + 1,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE]);
		}
		break;
	case CMD_LAYER_SET_REAL64:
	case CMD_LAYER_SET_VEC2_REAL64:
	case CMD_LAYER_SET_VEC3_REAL64:
	case CMD_LAYER_SET_VEC4_REAL64:
		if(vc_ctx->vfs.receive_layer_set_value != NULL) {
			vc_ctx->vfs.receive_layer_set_value(session_id,
					UINT32(cmd->data[0]),
					UINT16(cmd->data[UINT32_SIZE]),
					UINT32(cmd->data[UINT32_SIZE + UINT16_SIZE]),
					VRS_VALUE_TYPE_REAL64,
					cmd->id - CMD_LAYER_SET_REAL64 + 1,
					&cmd->data[UINT32_SIZE + UINT16_SIZE + UINT32_SIZE]);
		}
		break;
	default:
		v_print_log(VRS_PRINT_ERROR, "This command: %d is not supported yet\n", cmd->id);
		break;
	}
}