Пример #1
0
void supla_client_locations::arr_clean(void) {

	safe_array_lock(arr);
	safe_array_clean(arr, arr_delcnd);
	safe_array_unlock(arr);

}
Пример #2
0
void supla_device_channels::arr_clean(void) {

	safe_array_lock(arr);
	safe_array_clean(arr, arr_delcnd);
	safe_array_unlock(arr);

}
Пример #3
0
bool supla_client_channels::remote_update_cv(void *srpc) {

	bool result = false;
	TSC_SuplaChannelValue channel_value;

	safe_array_lock(arr);

	for(int a=0;a<safe_array_count(arr);a++) {

		supla_client_channel *channel = (supla_client_channel *)safe_array_get(arr, a);
		if ( channel->marked_for_remote_update() == CC_REMOTEUPDATE_CHANNELVALUE ) {

			channel->proto_get_channel_value(&channel_value, client);
			channel->mark_for_remote_update(CC_REMOTEUPDATE_NONE);
			channel_value.EOL = get_marked() == NULL ? 1 : 0;

			result = true;
			break;

		}
	}

	safe_array_unlock(arr);

	if ( result ) {
		srpc_sc_async_channel_value_update(srpc, &channel_value);
	}

	return result;


}
Пример #4
0
void supla_client_channels::on_channel_value_changed(void *srpc, int DeviceId, int ChannelId) {

	supla_client_channel *channel;
	bool r = false;

	safe_array_lock(arr);

	for(int a=0;a<safe_array_count(arr);a++) {
		channel = (supla_client_channel *)safe_array_get(arr, a);
		if ( channel
			 && channel->getDeviceId() == DeviceId
			 && ( ChannelId == 0 || channel->getId() == ChannelId ) ) {

			channel->mark_for_remote_update(CC_REMOTEUPDATE_CHANNELVALUE);
			r = true;
		}
	}


	safe_array_unlock(arr);

	if ( srpc && r ) {
		remote_update(srpc);
	}

}
Пример #5
0
void supla_client_locations::add_location(int Id, const char *Caption) {
	safe_array_lock(arr);

	if ( safe_array_findcnd(arr, arr_findcmp, &Id) == 0 ) {
		safe_array_add(arr, new supla_client_location(Id, Caption));
	}

	safe_array_unlock(arr);
}
Пример #6
0
void supla_device_channels::add_channel(int Id, int Number, int Type, int Func, int Param1, int Param2, int Param3) {

	safe_array_lock(arr);

	if ( find_channel(Id) == 0 ) {
		safe_array_add(arr, new supla_device_channel(Id, Number, Type, Func, Param1, Param2, Param3));
	}

	safe_array_unlock(arr);

}
Пример #7
0
bool supla_client_channels::channel_exists(int ChannelID) {
	bool result = false;

	safe_array_lock(arr);

	if ( find_channel(ChannelID) != NULL )
		result = true;

	safe_array_unlock(arr);

	return result;
}
Пример #8
0
void supla_client_channels::update_device_channels(int DeviceId) {

	database *db = new database();

	if ( db->connect() == true ) {

		safe_array_lock(arr);
		db->get_client_channels(client->getID(), &DeviceId, this);
		safe_array_unlock(arr);
	}

	delete db;


}
Пример #9
0
int supla_device_channels::get_channel_id(unsigned char ChannelNumber) {

	int result = 0;

	safe_array_lock(arr);

	supla_device_channel *channel = find_channel_by_number(ChannelNumber);

	if ( channel )
		result = channel->getId();

	safe_array_unlock(arr);

	return result;
}
Пример #10
0
void supla_device_channels::set_channel_value(int ChannelID, char value[SUPLA_CHANNELVALUE_SIZE]) {

	if ( ChannelID == 0 )
		return;

	safe_array_lock(arr);

	supla_device_channel *channel = find_channel(ChannelID);

	if ( channel )
		channel->setValue(value);

	safe_array_unlock(arr);

}
Пример #11
0
void supla_device_channels::load(int DeviceID) {

	database *db = new database();

	if ( db->connect() == true ) {

		safe_array_lock(arr);
		arr_clean();

		db->get_device_channels(DeviceID, this);

		safe_array_unlock(arr);
	}

	delete db;

}
Пример #12
0
void supla_client_channels::load(void) {

	database *db = new database();

	if ( db->connect() == true ) {

		safe_array_lock(arr);
		arr_clean();

		db->get_client_channels(client->getID(), NULL, this);

		safe_array_unlock(arr);
	}

	delete db;

}
Пример #13
0
int supla_device_channels::ms_channel(int ChannelID, bool Master) {

	if ( ChannelID == 0 )
		return 0;

	int SubChannelId = 0;

	safe_array_lock(arr);

	supla_device_channel *channel = find_channel(ChannelID);

	if ( channel )
		SubChannelId = Master ? channel->master_channel() : channel->slave_channel();

	safe_array_unlock(arr);

	return SubChannelId;
}
Пример #14
0
int supla_device_channels::get_channel_func(int ChannelID) {

	if ( ChannelID == 0 )
		return 0;

	int Func = 0;

	safe_array_lock(arr);

	supla_device_channel *channel = find_channel(ChannelID);

	if ( channel )
		Func = channel->getFunc();

	safe_array_unlock(arr);

	return Func;

}
Пример #15
0
unsigned int supla_device_channels::get_channel_value_duration(int ChannelID) {

	if ( ChannelID == 0 )
		return 0;

	int Duration = 0;

	safe_array_lock(arr);

	supla_device_channel *channel = find_channel(ChannelID);

	if ( channel )
		Duration = channel->getValueDuration();

	safe_array_unlock(arr);

	return Duration;

}
Пример #16
0
bool supla_client_locations::remote_update(void *srpc) {


	TSC_SuplaLocationPack location_pack;
	memset(&location_pack, 0, sizeof(TSC_SuplaLocationPack));

	safe_array_lock(arr);

	supla_client_location *loc = NULL;

	do {

		loc = (supla_client_location *)safe_array_pop(arr);

		if ( loc && location_pack.count < SUPLA_LOCATIONPACK_MAXSIZE ) {

			loc->proto_get_location(&location_pack.locations[location_pack.count]);
			location_pack.locations[location_pack.count].EOL = 0;
			location_pack.count++;

			delete loc;

		} else {
			loc = NULL;
		}

	} while(loc != NULL);


	safe_array_unlock(arr);

	if ( location_pack.count > 0 ) {

		location_pack.locations[location_pack.count-1].EOL = 1;

		srpc_sc_async_locationpack_update(srpc, &location_pack);
		return true;
	}


	return false;
}
Пример #17
0
supla_channel_temphum* supla_device_channels::get_channel_temp_and_humidity_value(int ChannelID) {

	supla_channel_temphum *result = NULL;

	if ( ChannelID ) {

		safe_array_lock(arr);
		supla_device_channel *channel = find_channel(ChannelID);

		if ( channel ) {
			result = channel->getTempHum();
		}

		safe_array_unlock(arr);

	}

	return result;

}
Пример #18
0
bool supla_client_channels::remote_update_c(void *srpc) {

	TSC_SuplaChannelPack pack;
	memset(&pack, 0, sizeof(TSC_SuplaChannelPack));

	safe_array_lock(arr);

	for(int a=0;a<safe_array_count(arr);a++) {

		supla_client_channel *channel = (supla_client_channel *)safe_array_get(arr, a);

		if ( channel->marked_for_remote_update() == CC_REMOTEUPDATE_CHANNEL ) {

			if ( pack.count < SUPLA_CHANNELPACK_MAXSIZE ) {

				channel->proto_get_channel(&pack.channels[pack.count], client);
				pack.channels[pack.count].EOL = 0;
				channel->mark_for_remote_update(CC_REMOTEUPDATE_NONE);
		        pack.count++;

			} else {
				pack.total_left++;
			}

		}
	}

	safe_array_unlock(arr);

	if ( pack.count > 0 ) {

		if ( pack.total_left == 0 )
	    	pack.channels[pack.count-1].EOL = 1;

		srpc_sc_async_channelpack_update(srpc, &pack);
	}

	return pack.count > 0;


}
Пример #19
0
void supla_device_channels::set_device_channel_value(void *srpc, int SenderID, int ChannelID, const char value[SUPLA_CHANNELVALUE_SIZE])  {

	safe_array_lock(arr);

	supla_device_channel *channel = find_channel(ChannelID);

	if ( channel
		 && channel->isValueWritable() ) {

		TSD_SuplaChannelNewValue s;
		s.ChannelNumber = channel->getNumber();
		s.DurationMS = channel->getValueDuration();
		s.SenderID = SenderID;
		memcpy(s.value, value, SUPLA_CHANNELVALUE_SIZE);

		srpc_sd_async_set_channel_value(srpc, &s);
	}

	safe_array_unlock(arr);

}
Пример #20
0
bool supla_device_channels::get_channel_char_value(int ChannelID, char *Value) {

	bool result = false;

	if ( ChannelID ) {

		safe_array_lock(arr);
		supla_device_channel *channel = find_channel(ChannelID);

		if ( channel ) {
			channel->getChar(Value);
			result = true;
		}


		safe_array_unlock(arr);

	}

	return result;

}
Пример #21
0
bool supla_device_channels::get_channel_value(int ChannelID, char value[SUPLA_CHANNELVALUE_SIZE]) {

	bool result = false;

	if ( ChannelID ) {

		safe_array_lock(arr);
		supla_device_channel *channel = find_channel(ChannelID);

		if ( channel ) {
			channel->getValue(value);
			result = true;
		}


		safe_array_unlock(arr);

	}

	return result;

}
Пример #22
0
void supla_client_locations::load(int ClientID) {

	database *db = new database();
	int a, n;

	if ( db->connect() == true ) {

		safe_array_lock(arr);
		arr_clean();

		db->get_client_locations(ClientID, this);

		lck_lock(lck);
		ids_clean();

		n = safe_array_count(arr);

		if ( n > 0 ) {
			ids = (int*)malloc(sizeof(int)*n);
		}

		if ( ids )
			for(a=0;a<n;a++) {
				supla_client_location *loc = (supla_client_location *)safe_array_get(arr, a);
				if ( loc != NULL ) {
					ids[ids_count] = loc->getId();
					ids_count++;
				}
			}

		lck_unlock(lck);

		safe_array_unlock(arr);

	}

	delete db;

}
Пример #23
0
void supla_device_channels::get_temp_and_humidity(void *tarr) {

	int a;
	safe_array_lock(arr);

	for(a=0;a<safe_array_count(arr);a++) {

		supla_device_channel *channel = (supla_device_channel *)safe_array_get(arr, a);

		if ( channel != NULL ) {

			   supla_channel_temphum *temphum = channel->getTempHum();

			   if ( temphum != NULL )
				   safe_array_add(tarr, temphum);
		}

	}

	safe_array_unlock(arr);

}
Пример #24
0
void supla_client_channels::update_channel(int Id, int DeviceId, int LocationID, int Func, int Param1, const char *Caption) {

	safe_array_lock(arr);

	supla_client_channel *channel = NULL;

	if ( ( channel = find_channel(Id) ) == NULL ) {
		channel = new supla_client_channel(Id, DeviceId, LocationID, Func, Param1, Caption);
		safe_array_add(arr, channel);
	} else {
        channel->setCaption(Caption);
	}


	if ( channel ) {
		channel->mark_for_remote_update(CC_REMOTEUPDATE_CHANNEL);
	}


	safe_array_unlock(arr);

}
Пример #25
0
bool supla_client_channels::set_device_channel_new_value(TCS_SuplaChannelNewValue_B *channel_new_value) {


	if ( channel_exists(channel_new_value->ChannelId) ) {

		safe_array_lock(arr);

		supla_client_channel *channel;
		int DeviceID = 0;

		if ( NULL != ( channel = find_channel(channel_new_value->ChannelId) )  ) {
			DeviceID = channel->getDeviceId();
		}

		safe_array_unlock(arr);

		if ( DeviceID ) {
			client->getUser()->set_device_channel_value(client->getID(), DeviceID, channel_new_value->ChannelId, channel_new_value->value);
		}
	}

	return false;
}