#include
using namespace std;
#include
#define OTL_STREAM_READ_ITERATOR_ON
#define OTL_ORA9I // Compile OTL 4.0/OCI9i
#include // include the OTL 4.0 header file
#include "db.h"
#include "wdlib/wdlib.h"
#include "pthread.h"
otl_connect db; // connect object
extern pthread_mutex_t db_mutex;
int ConnectDB(char username[], char password[], char dbname[])
{
otl_connect::otl_initialize(); // initialize OCI environment
try{
char connstr[50] = {0};
sprintf(connstr, "%s/%s@%s", username, password, dbname);
db.rlogon(connstr); // connect to Oracle
info(0, "connect db successfully!/n");
} catch(otl_exception& p){ // intercept OTL exceptions
error(0, "%s", p.msg);
return -1;
}
return 0;
}
void DisconnectDB()
{
db.logoff(); // disconnect from Oracle
}
int EP_Command_Insert(int commType, unsigned char main_type[10], unsigned char secu_para[10], unsigned char load_len[10], unsigned char sub_type[10], unsigned char ep_id[20], unsigned char object_id[10], unsigned char action[10], unsigned char reserve[20], unsigned char random[10], unsigned char mac[10], unsigned char ep_command[128], int commStatus)
{
//#ifdef ORACLE_DB
pthread_mutex_lock(&db_mutex);
otl_stream o(1, // buffer size
"insert into ep_command_log(command_type, main_type, secu_para, load_len, sub_type, ep_id, object_id, action, reserve, random, mac, ep_command, command_status) values(:f11, :f12, :f13, :f14, :f15, :f16, :f17, :f18, :f19, :f20, :f21, :f22, :f23)",
// SQL statement
db // connect object
);
o<
pthread_mutex_unlock(&db_mutex);
return 0;
//#endif
}
int EP_Command_Update(unsigned char ep_command[128], int commStatus )
{
//#ifdef ORACLE_DB
pthread_mutex_lock(&db_mutex);
otl_stream o(1, // buffer size
"update ep_command_log set command_status=:f11 where ep_command =:f12",
// SQL statement
db // connect object
);
o<
pthread_mutex_unlock(&db_mutex);
return 0;
//#endif
}
int UpdateChannelStatus(int channelID, int max_streams, int max_comp_time, int status)
{
//#ifdef ORACLE_DB
pthread_mutex_lock(&db_mutex);
otl_stream o(1, // buffer size
"update channel_info set channel_status=:f11, max_streams=:f12, max_comp_time=:f13 where channel_ID=:f14", // SQL statement
db // connect object
);
o<
pthread_mutex_unlock(&db_mutex);
return 0;
//#endif
}
int UpdateStreamStatus(int channelID, int streamID, int status)
{
//#ifdef ORACLE_DB
pthread_mutex_lock(&db_mutex);
otl_stream o(1, // buffer size
"update channel_stream_info set stream_status=:f11, sent_num=0 where channel_ID=:f12 and stream_ID=:f13", // SQL statement
db // connect object
);
o<
pthread_mutex_unlock(&db_mutex);
return 0;
//#endif
}
int CloseStreamByChannelID(int channelID)
{
//#ifdef ORACLE_DB
pthread_mutex_lock(&db_mutex);
otl_stream o(1, // buffer size
"update channel_stream_info set stream_status=1, sent_num=0 where channel_ID=:f11", // SQL statement
db // connect object
);
o<
pthread_mutex_unlock(&db_mutex);
return 0;
//#endif
}
int UpdateStreamSentNum(int channelID, int streamID, int sent_num)
{
//#ifdef ORACLE_DB
pthread_mutex_lock(&db_mutex);
otl_stream o(1, // buffer size
"update channel_stream_info set sent_num=:f11 where channel_ID=:f12 and stream_ID=:f13", // SQL statement
db // connect object
);
o<
pthread_mutex_unlock(&db_mutex);
return 0;
//#endif
}
int QueryStreamStatus(int streamid, int *priority, int *ep_msg_type, int *repeat_num, char valid_time[5]){//#ifdef ORACLE_DB otl_stream o(1, // buffer size "select priority, ep_message_type, repeat_number, valid_time from stream_type_info where stream_ID=:f11", // SELECT statement db // connect object ); // create select stream otl_stream_read_iterator rs; rs.attach(o); // attach the iterator "rs" to the stream "o". o<