November 9 2006

Today I go on my debugging task.  This morning I finished the part of testing database codes.
Before 2 o,clock p.m. I finished the rest of debugging task.

  The main task of my debugging program is to inform other devices or hosts of the standard time
now.  Firstly, it must insure that there is only one time master, a host or a device.  It inquired
the field "timeMaster" of a table in a database, and get the value of that field.  The value must
be 1.  That is to say, if there are time masters more than one, the program will strike.

  There are two ways to launch it.  One is to tell it a host name at command line; another
is just to type the program name and press "Enter" key.  If the program find input a host name,
it will just create one thread for the host.  The thread get the retry times and time out
from a CSV file, a configuration file; and get now time by calling the time() system call;
fulfill a message datagram; connect to the host with UDP; then send it out.  If failure to
connect or to send, it retry the specified times.

  If it is launched in another way, it will get how many SMS, a device, here are; and create
a thread respectively for every SMS.  Every sub-thread get current system time and tell a SMS
through UDP.  The steps of them is same to that of the running thread in the first way.

  During debugging I found a strange code segment.  I copied it as follow.

  if( FALSE == getDataValue( DB_TYPE_U_CHAR, &result, &fieldType) ) {

          SGCMNsyslogErr("2006-11-07 LM Debug Print>>>>: Func %s Line %d FALSE == getDataValue( DB_TYPE_U_CHAR, &result, &fieldType). result=%s, fieldType=%u/n", __FUNCTION__, __LINE__, result, fieldType);

        if ( FALSE == getDataValue( DB_TYPE_STRING, &result, &fieldType) ) {
                SGCMNsyslogErr("getCLtimeMaster.c@parseCLtimeMasterDB():Read FieldType getDataValue() Error");
                ret =  FALSE;
        }
  }

  This code segment tries to get the value of a field type.  If can not get the DB_TYPE_U_CHAR type,
it tries to get DB_TYPE_STRING type.  Let's look at the following code segment.

  if (DB_TYPE_U_CHAR == fieldType) {
      SGCMNsyslogErr("2006-11-07 LM Debug Print>>>>: Func %s Line %d DB_TYPE_U_CHAR == fieldType./n", __FUNCTION__, __LINE__);
      //値の取得
      if( TRUE == getDataValue( fieldType, &result, timeMasterVal) ) {
        // 2006-11-07 add debug info.
        SGCMNsyslogErr("2006-11-07 LM Debug Print>>>>: Func %s Line %d timeMasterVal = %d/n", __FUNCTION__, __LINE__, *timeMasterVal);
      }
      else {
        SGCMNsyslogErr("getCLtimeMaster.c@parseCLtimeMasterDB():Read cal_no getDataValue() Error");
        ret =  FALSE;
    }
  }else {
    SGCMNsyslogErr("getCLtimeMaster.c@parseCLtimeMasterDB():Read cal_no TYPE Error");
    ret =  FALSE;
  }

  You will find that the program can not acquire the value of timeMaster if the "fieldType"
is not "DB_TYPE_U_CHAR".  These two code segments are both in one function.  I don't understand
why get another field type value after failure to get one.  If it get DB_TYPE_STRING value
successfully, the function still can not get the field value due to type error.  So, whether
it is a redundant.  It seems that only DB_TYPE_U_CHAR is valid.  Why it check whether the
field type is DB_TYPE_U_CHAR after getting successfully.

  Another thing I found is that these codes is easy to read.  Sometimes,  I am aware that
it was better and the binary program was smaller if programmers had applied some tricks.
For example, we can write a function to create a thread on that the way of creating a thread
is same.  We just pass a thread handler and a name into that function.  Whether one or more
than one threads, one "for" code segment can be up to do.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值