APIEndpointIDOpt.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #include <oasys/util/StringBuffer.h>
00018 #include "APIEndpointIDOpt.h"
00019 #include "dtn_api.h"
00020 
00021 namespace dtn {
00022 
00023 APIEndpointIDOpt::APIEndpointIDOpt(const char* opt, dtn_endpoint_id_t* valp,
00024                                    const char* valdesc, const char* desc,
00025                                    bool* setp)
00026     : Opt(0, opt, valp, setp, true, valdesc, desc)
00027 {
00028 }
00029 
00030 APIEndpointIDOpt::APIEndpointIDOpt(char shortopt, const char* longopt,
00031                                    dtn_endpoint_id_t* valp,
00032                                    const char* valdesc, const char* desc,
00033                                    bool* setp)
00034     : Opt(shortopt, longopt, valp, setp, true, valdesc, desc)
00035 {
00036 }
00037 
00038 int
00039 APIEndpointIDOpt::set(const char* val, size_t len)
00040 {
00041     char buf[DTN_MAX_ENDPOINT_ID];
00042     if (len > (DTN_MAX_ENDPOINT_ID - 1)) {
00043         return -1;
00044     }
00045     
00046     memcpy(buf, val, len);
00047     buf[len] = '\0';
00048 
00049     int err = dtn_parse_eid_string(((dtn_endpoint_id_t*)valp_), buf);
00050     if (err != 0) {
00051         return -1;
00052     }
00053 
00054     if (setp_)
00055         *setp_ = true;
00056     
00057     return 0;
00058 }
00059 
00060 void
00061 APIEndpointIDOpt::get(oasys::StringBuffer* buf)
00062 {
00063     buf->append(((dtn_endpoint_id_t*)valp_)->uri);
00064 }
00065 
00066 } // namespace dtn

Generated on Sat Sep 8 08:43:23 2007 for DTN Reference Implementation by  doxygen 1.5.3