gonzui


Format: Advanced Search

t2ex/t2ex_source/t2ex/datetime/src/service.cbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T2EX Software Package
    4:  *
    5:  *    Copyright 2012 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2012/12/12.
   10:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/04.
   11:  *
   12:  *----------------------------------------------------------------------
   13:  */
   14: /*
   15:  * This software package is available for use, modification, 
   16:  * and redistribution in accordance with the terms of the attached 
   17:  * T-License 2.x.
   18:  * If you want to redistribute the source code, you need to attach 
   19:  * the T-License 2.x document.
   20:  * There's no obligation to publish the content, and no obligation 
   21:  * to disclose it to the TRON Forum if you have modified the 
   22:  * software package.
   23:  * You can also distribute the modified source code. In this case, 
   24:  * please register the modification to T-Kernel traceability service.
   25:  * People can know the history of modifications by the service, 
   26:  * and can be sure that the version you have inherited some 
   27:  * modification of a particular version or not.
   28:  *
   29:  *    http://trace.tron.org/tk/?lang=en
   30:  *    http://trace.tron.org/tk/?lang=ja
   31:  *
   32:  * As per the provisions of the T-License 2.x, TRON Forum ensures that 
   33:  * the portion of the software that is copyrighted by Ken Sakamura or 
   34:  * the TRON Forum does not infringe the copyrights of a third party.
   35:  * However, it does not make any warranty other than this.
   36:  * DISCLAIMER: TRON Forum and Ken Sakamura shall not be held
   37:  * responsible for any consequences or damages caused directly or
   38:  * indirectly by the use of this software package.
   39:  *
   40:  * The source codes in bsd_source.tar.gz in this software package are 
   41:  * derived from NetBSD or OpenBSD and not covered under T-License 2.x.
   42:  * They need to be changed or redistributed according to the 
   43:  * representation of each source header.
   44:  */
   45: 
   46: /*
   47:  *      @(#)service.c
   48:  *
   49:  *       T2EX: calendar functions
   50:  *       manager initialization
   51:  */
   52: 
   53: #include <basic.h>
   54: #include <tk/tkernel.h>
   55: #include <t2ex/datetime.h>
   56: #include "ifdatetime.h"
   57: 
   58: IMPORT ER ChkT2EXLevel( void );
   59: 
   60: /* Manager lock */
   61: LOCAL   FastLock  dtLock;
   62: 
   63: /* System timezone */
   64: LOCAL   struct tzinfo     systemTimeZone = {
   65:         .tzname = {"JST", ""},
   66:         .offset = -9 * 60 * 60,
   67:         .daylight = 0,
   68: };
   69: 
   70: /*
   71:  * Set system timezone
   72:  */
   73: EXPORT  ER       _dt_setsystz(const struct tzinfo* tz)
   74: {
   75:         ER     er;
   76: 
   77:         er = ChkSpaceR(tz, sizeof(*tz));
   78:         if (er < E_OK) {
   79:                 return er;
   80:         }
   81: 
   82:         systemTimeZone = *tz;
   83:         return E_OK;
   84: }
   85: 
   86: /*
   87:  * Get system timezone
   88:  */
   89: EXPORT  ER       _dt_getsystz(struct tzinfo* tz)
   90: {
   91:         ER     er;
   92: 
   93:         er = ChkSpaceRW(tz, sizeof(*tz));
   94:         if (er < E_OK) {
   95:                 return er;
   96:         }
   97: 
   98:         *tz = systemTimeZone;
   99:         return E_OK;
  100: }
  101: 
  102: /*
  103:  * Service call entries
  104:  */
  105: LOCAL   ER        svcEntry(void* para, W fn)
  106: {
  107:         ER     er;
  108: 
  109:         er = ChkT2EXLevel();
  110:         if (er < E_OK) {
  111:                 return er;
  112:         }
  113: 
  114:         Lock(&dtLock);
  115: 
  116:         switch (fn) {
  117:         case DT_DT_SETSYSTZ_FN: {
  118:                 DT_DT_SETSYSTZ_PARA* p = (DT_DT_SETSYSTZ_PARA*)para;
  119:                 er = _dt_setsystz(p->tz);
  120:                 break;
  121:         }
  122:         case DT_DT_GETSYSTZ_FN: {
  123:                 DT_DT_GETSYSTZ_PARA* p = (DT_DT_GETSYSTZ_PARA*)para;
  124:                 er = _dt_getsystz(p->tz);             
  125:                 break;
  126:         }
  127:         default:
  128:                 er = E_RSFN;
  129:                 break;
  130:         }
  131: 
  132:         Unlock(&dtLock);
  133: 
  134:         return er;
  135: }
  136: 
  137: /*
  138:  * Calendar functions entry
  139:  */
  140: EXPORT  ER       dt_main(INT ac, UB* av[])
  141: {
  142:         ER     er;
  143:         T_DSSY dssy;
  144: 
  145:         if (ac < 0) {
  146:                 /* Stop other tasks from executing SVC */
  147:                 Lock(&dtLock);
  148: 
  149:                 /* Unregister subsystem */
  150:                 tk_def_ssy(DT_SVC, NULL);
  151: 
  152:                 /* Delete lock */
  153:                 DeleteLock(&dtLock);
  154:                 return E_OK;
  155:         }
  156: 
  157:         /* Create lock */
  158:         er = CreateLock(&dtLock, "dtLk");
  159:         if (er < E_OK) {
  160:                 goto err_ret0;
  161:         }
  162: 
  163:         /* Register subsystem */
  164:         dssy.ssyatr    = TA_NULL;
  165:         dssy.ssypri    = DT_PRI;
  166:         dssy.svchdr    = (FP)svcEntry;
  167:         dssy.breakfn   = NULL;
  168:         dssy.startupfn = NULL;
  169:         dssy.cleanupfn = NULL;
  170:         dssy.eventfn   = NULL;
  171:         dssy.resblksz  = 0;
  172:         er = tk_def_ssy(DT_SVC, &dssy);
  173:         if (er < E_OK) {
  174:                 goto err_ret1;
  175:         }
  176: 
  177:         return E_OK;
  178: 
  179: err_ret1:
  180:         DeleteLock(&dtLock);
  181:         
  182: err_ret0:
  183:         return er;
  184: }