user_interaction.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include "user_interaction.h"
00036 #include "user_interaction_specific.hpp"
00037 #if LIBDARC_HAVE_LIBDAR_HPP
00038 #include <dar/libdar.hpp>
00039 #endif
00040
00041 #include <string>
00042
00043 NAMESPACE_LIBDAR_START
00044
00045
00046 extern "C" bool dar_user_interaction_struct_is_valid(dar_user_interaction_struct obj)
00047 {
00048 if ( obj.warning != NULL &&
00049 obj.answer != NULL &&
00050 obj.string != NULL
00051 )
00052 return true;
00053 else
00054 return false;
00055 }
00056
00057 user_interaction_callback_c::user_interaction_callback_c (dar_user_interaction_struct &callbacks)
00058 {
00059 m_warning = callbacks.warning;
00060 m_answer = callbacks.answer;
00061 m_string = callbacks.string;
00062 m_listing = callbacks.listing;
00063 if (callbacks.listing != NULL)
00064 set_use_listing(true);
00065 context_val = callbacks.context;
00066 }
00067
00068
00069 void user_interaction_callback_c::pause(const std::string & message)
00070 {
00071 bool ret = (*m_answer)((char*)message.c_str(), context_val);
00072 if ( !ret )
00073 throw Euser_abort("negative response returned from answer callback");
00074 return;
00075 }
00076
00077 void user_interaction_callback_c::warning(const std::string & message)
00078 {
00079 (*m_warning)((char*)message.c_str(), context_val);
00080 return;
00081 }
00082
00083 std::string user_interaction_callback_c::get_string(const std::string & message, bool echo)
00084 {
00085 char* ret = (*m_string)((char*)message.c_str(), echo, context_val);
00086 if (ret == NULL)
00087 {
00088 return std::string("");
00089 } else {
00090 std::string r(ret);
00091 free(ret);
00092 return r;
00093 }
00094 }
00095 void user_interaction_callback_c::listing(
00096 const std::string & flag,
00097 const std::string & perm,
00098 const std::string & uid,
00099 const std::string & gid,
00100 const std::string & size,
00101 const std::string & date,
00102 const std::string & filename,
00103 bool is_dir,
00104 bool has_children)
00105 {
00106 (*m_listing)( (char*)flag.c_str(),
00107 (char*)perm.c_str(),
00108 (char*)uid.c_str(),
00109 (char*)gid.c_str(),
00110 (char*)size.c_str(),
00111 (char*)date.c_str(),
00112 (char*)filename.c_str(),
00113 is_dir,
00114 has_children,
00115 context_val
00116 );
00117 return;
00118 }
00119
00120 user_interaction* user_interaction_callback_c::clone() const
00121 {
00122 dar_user_interaction_struct t;
00123 t.warning = m_warning;
00124 t.answer = m_answer;
00125 t.string = m_string;
00126 t.listing = m_listing;
00127 t.context = context_val;
00128 return new user_interaction_callback_c(t);
00129 }
00130
00131
00132
00133 user_interaction_null::user_interaction_null() {}
00134
00135
00136 void user_interaction_null::pause(const std::string & message)
00137 {
00138 return;
00139 }
00140
00141 void user_interaction_null::warning(const std::string & message)
00142 {
00143 return;
00144 }
00145
00146 std::string user_interaction_null::get_string(const std::string & message, bool echo)
00147 {
00148 return NULL;
00149 }
00150 void user_interaction_null::listing(
00151 const std::string & flag,
00152 const std::string & perm,
00153 const std::string & uid,
00154 const std::string & gid,
00155 const std::string & size,
00156 const std::string & date,
00157 const std::string & filename,
00158 bool is_dir,
00159 bool has_children)
00160 {
00161 return;
00162 }
00163
00164 user_interaction* user_interaction_null::clone() const
00165 {
00166 return new user_interaction_null();
00167 }
00168
00169
00170
00171
00172 NAMESPACE_LIBDAR_END
00173